11"""
2- recreation of internal `create_database_utils.py` to run the tests locally, with minimal
3- and swift-specialized functionality
2+ Simplified version of internal `create_database_utils.py` used to run the tests locally, with
3+ minimal and swift-specialized functionality
4+ TODO unify integration testing code across the public and private repositories
45"""
56import subprocess
67import pathlib
78import sys
9+ import shutil
810
911
10- def run_codeql_database_create (cmds , lang , keep_trap = True ):
12+ def runSuccessfully (cmd ):
13+ res = subprocess .run (cmd )
14+ if res .returncode :
15+ print ("FAILED" , file = sys .stderr )
16+ print (" " , * cmd , f"(exit code { res .returncode } )" , file = sys .stderr )
17+ sys .exit (res .returncode )
18+
19+ def runUnsuccessfully (cmd ):
20+ res = subprocess .run (cmd )
21+ if res .returncode == 0 :
22+ print ("FAILED" , file = sys .stderr )
23+ print (" " , * cmd , f"(exit code 0, expected to fail)" , file = sys .stderr )
24+ sys .exit (1 )
25+
26+
27+ def run_codeql_database_create (cmds , lang , keep_trap = True , db = None , runFunction = runSuccessfully ):
28+ """ db parameter is here solely for compatibility with the internal test runner """
1129 assert lang == 'swift'
1230 codeql_root = pathlib .Path (__file__ ).parents [2 ]
31+ shutil .rmtree ("db" , ignore_errors = True )
1332 cmd = [
1433 "codeql" , "database" , "create" ,
1534 "-s" , "." , "-l" , "swift" , "--internal-use-lua-tracing" , f"--search-path={ codeql_root } " , "--no-cleanup" ,
@@ -19,8 +38,4 @@ def run_codeql_database_create(cmds, lang, keep_trap=True):
1938 for c in cmds :
2039 cmd += ["-c" , c ]
2140 cmd .append ("db" )
22- res = subprocess .run (cmd )
23- if res .returncode :
24- print ("FAILED" , file = sys .stderr )
25- print (" " , * cmd , file = sys .stderr )
26- sys .exit (res .returncode )
41+ runFunction (cmd )
0 commit comments