Added visual cues (emojis) when comparing intended vs actual output
This commit is contained in:
parent
13356348da
commit
1c98618d65
53
ucompile
53
ucompile
@ -2,27 +2,63 @@
|
||||
import argparse
|
||||
import os
|
||||
from glob import glob
|
||||
import subprocess
|
||||
|
||||
def run_input_cases(program, verbose, output=False, tests_dir="."):
|
||||
input_files = glob(os.path.join(tests_dir, "*.in"))
|
||||
|
||||
if len(input_files) < 1:
|
||||
return os.system(program)
|
||||
|
||||
for input_file in input_files:
|
||||
print(f"Running {input_file}")
|
||||
end_command = f"{program} < {input_file}"
|
||||
|
||||
with open(input_file, 'r') as f:
|
||||
input_data = f.read()
|
||||
|
||||
out_file = input_file.replace(".in", ".out")
|
||||
expected_output = None
|
||||
if os.path.exists(out_file):
|
||||
with open(out_file, 'r') as f:
|
||||
expected_output = f.read()
|
||||
|
||||
result = subprocess.run(end_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||
program_output = result.stdout
|
||||
|
||||
if verbose:
|
||||
print("Input:")
|
||||
os.system(f"cat {input_file}")
|
||||
print(input_data)
|
||||
print("")
|
||||
out_file = input_file.replace(".in", ".out")
|
||||
if os.path.exists(out_file):
|
||||
if verbose:
|
||||
if expected_output is not None:
|
||||
print("Expected output:")
|
||||
os.system(f"cat {out_file}")
|
||||
print(expected_output)
|
||||
print("")
|
||||
if output:
|
||||
end_command += f" | diff {out_file} -"
|
||||
print(os.popen(end_command).read())
|
||||
print("Program output:")
|
||||
print(program_output.strip())
|
||||
print("")
|
||||
|
||||
|
||||
if output:
|
||||
if expected_output is not None:
|
||||
# Compare the outputs
|
||||
if program_output == expected_output:
|
||||
print("✅")
|
||||
else:
|
||||
print("❌")
|
||||
print("Expected output:")
|
||||
print(expected_output.strip())
|
||||
print("Program output:")
|
||||
print(program_output.strip())
|
||||
else:
|
||||
print("Expected output file not found; cannot compare outputs.")
|
||||
if not verbose:
|
||||
print("Program output:")
|
||||
print(program_output.strip())
|
||||
else:
|
||||
if not verbose:
|
||||
print(program_output.strip())
|
||||
|
||||
print("-----------")
|
||||
return
|
||||
|
||||
@ -65,6 +101,7 @@ def main():
|
||||
print("Unsupported language")
|
||||
return
|
||||
|
||||
# Use the specified tests directory or default to current directory
|
||||
tests_dir = args.tests if args.tests else "."
|
||||
|
||||
if file_ext == ".c":
|
||||
|
Loading…
x
Reference in New Issue
Block a user