Skip to content

Commit e8d3c8a

Browse files
committed
chore: Simplify test runner by introducing "run()" function
This change refactors the test runner script by adding a `run()` function for executing compiler commands, capturing their output, and returning the results.
1 parent 4056cd5 commit e8d3c8a

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

run-tests.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ def cleanup(out):
7878
'pr57580.c',
7979
]
8080

81+
82+
def run(compiler_executable, compiler_args):
83+
"""Execute a compiler command and capture its output."""
84+
compiler_cmd = [compiler_executable]
85+
compiler_cmd.extend(compiler_args)
86+
p = subprocess.Popen(compiler_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
87+
comm = p.communicate()
88+
exit_code = p.returncode
89+
output = cleanup(comm[0])
90+
error = comm[0].decode('utf-8').strip()
91+
return (exit_code, output, error)
92+
93+
8194
numberOfSkipped = 0
8295
numberOfFailed = 0
8396
numberOfFixed = 0
@@ -89,26 +102,12 @@ def cleanup(out):
89102
numberOfSkipped = numberOfSkipped + 1
90103
continue
91104

92-
clang_cmd = ['clang']
93-
clang_cmd.extend(cmd.split(' '))
94-
p = subprocess.Popen(clang_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
95-
comm = p.communicate()
96-
clang_output = cleanup(comm[0])
105+
clang_output = run('clang', cmd.split(' '))[1]
97106

98-
gcc_cmd = ['gcc']
99-
gcc_cmd.extend(cmd.split(' '))
100-
p = subprocess.Popen(gcc_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
101-
comm = p.communicate()
102-
gcc_output = cleanup(comm[0])
107+
gcc_output = run('gcc', cmd.split(' '))[1]
103108

104-
simplecpp_cmd = ['./simplecpp']
105109
# -E is not supported and we bail out on unknown options
106-
simplecpp_cmd.extend(cmd.replace('-E ', '', 1).split(' '))
107-
p = subprocess.Popen(simplecpp_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
108-
comm = p.communicate()
109-
simplecpp_ec = p.returncode
110-
simplecpp_output = cleanup(comm[0])
111-
simplecpp_err = comm[0].decode('utf-8').strip()
110+
simplecpp_ec, simplecpp_output, simplecpp_err = run('./simplecpp', cmd.replace('-E ', '', 1).split(' '))
112111

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

0 commit comments

Comments
 (0)