Skip to content

Commit 3505c8f

Browse files
committed
tests: Update test runner to fail early if prerequisites are missing
This change updates the test runner script to check for the presence of required compilers (clang, gcc, simplecpp) before running tests.
1 parent 7249120 commit 3505c8f

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

run-tests.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import glob
33
import os
4+
import shutil
45
import subprocess
56
import sys
67

@@ -13,6 +14,22 @@ def cleanup(out):
1314
ret = ret + s
1415
return ret
1516

17+
18+
# Check for required compilers and exit if any are missing
19+
CLANG_EXE = shutil.which('clang')
20+
if not CLANG_EXE:
21+
sys.exit('Failed to run tests: clang compiler not found')
22+
23+
GCC_EXE = shutil.which('gcc')
24+
if not GCC_EXE:
25+
sys.exit('Failed to run tests: gcc compiler not found')
26+
27+
os.environ["PATH"] = os.getcwd() + os.pathsep + os.environ["PATH"]
28+
SIMPLECPP_EXE = shutil.which('simplecpp')
29+
if not SIMPLECPP_EXE:
30+
sys.exit('Failed to run tests: simplecpp compiler not found')
31+
32+
1633
commands = []
1734

1835
for f in sorted(glob.glob(os.path.expanduser('testsuite/clang-preprocessor-tests/*.c*'))):
@@ -102,12 +119,12 @@ def run(compiler_executable, compiler_args):
102119
numberOfSkipped = numberOfSkipped + 1
103120
continue
104121

105-
clang_output = run('clang', cmd.split(' '))[1]
122+
clang_output = run(CLANG_EXE, cmd.split(' '))[1]
106123

107-
gcc_output = run('gcc', cmd.split(' '))[1]
124+
gcc_output = run(GCC_EXE, cmd.split(' '))[1]
108125

109126
# -E is not supported and we bail out on unknown options
110-
simplecpp_ec, simplecpp_output, simplecpp_err = run('./simplecpp', cmd.replace('-E ', '', 1).split(' '))
127+
simplecpp_ec, simplecpp_output, simplecpp_err = run(SIMPLECPP_EXE, cmd.replace('-E ', '', 1).split(' '))
111128

112129
if simplecpp_output != clang_output and simplecpp_output != gcc_output:
113130
filename = cmd[cmd.rfind('/')+1:]

0 commit comments

Comments
 (0)