Skip to content

Commit 9ffcfbc

Browse files
Add --force option
1 parent 8ab0fd5 commit 9ffcfbc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

java/ql/src/utils/GenerateFlowTestCase.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
if any(s == "--help" for s in sys.argv):
1515
print("""Usage:
16-
GenerateFlowTestCase.py specsToTest.csv projectPom.xml outdir
16+
GenerateFlowTestCase.py specsToTest.csv projectPom.xml outdir [--force]
1717
1818
This generates test cases exercising function model specifications found in specsToTest.csv
1919
producing files Test.java, test.ql and test.expected in outdir.
@@ -22,15 +22,23 @@
2222
Typically this means supplying a skeleton POM <dependencies> section that retrieves whatever jars
2323
contain the needed classes.
2424
25+
If --force is present, existing files may be overwritten.
26+
2527
Requirements: `mvn` and `codeql` should both appear on your path.
2628
2729
After test generation completes, any lines in specsToTest.csv that didn't produce tests are output.
2830
If this happens, check the spelling of class and method names, and the syntax of input and output specifications.
2931
""")
3032
sys.exit(0)
3133

34+
force = False
35+
if "--force" in sys.argv:
36+
sys.argv.remove("--force")
37+
force = True
38+
3239
if len(sys.argv) != 4:
33-
print("Usage: GenerateFlowTestCase.py specsToTest.csv projectPom.xml outdir", file=sys.stderr)
40+
print(
41+
"Usage: GenerateFlowTestCase.py specsToTest.csv projectPom.xml outdir [--force]", file=sys.stderr)
3442
print("specsToTest.csv should contain CSV rows describing method taint-propagation specifications to test", file=sys.stderr)
3543
print("projectPom.xml should import dependencies sufficient to resolve the types used in specsToTest.csv", file=sys.stderr)
3644
sys.exit(1)
@@ -45,7 +53,7 @@
4553
resultJava = os.path.join(sys.argv[3], "Test.java")
4654
resultQl = os.path.join(sys.argv[3], "test.ql")
4755

48-
if os.path.exists(resultJava) or os.path.exists(resultQl):
56+
if not force and (os.path.exists(resultJava) or os.path.exists(resultQl)):
4957
print("Won't overwrite existing files '%s' or '%s'" %
5058
(resultJava, resultQl), file=sys.stderr)
5159
sys.exit(1)

0 commit comments

Comments
 (0)