Added visual cues (emojis) when comparing intended vs actual output
This commit is contained in:
parent
13356348da
commit
1c98618d65
51
ucompile
51
ucompile
@ -2,27 +2,63 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
import subprocess
|
||||||
|
|
||||||
def run_input_cases(program, verbose, output=False, tests_dir="."):
|
def run_input_cases(program, verbose, output=False, tests_dir="."):
|
||||||
input_files = glob(os.path.join(tests_dir, "*.in"))
|
input_files = glob(os.path.join(tests_dir, "*.in"))
|
||||||
|
|
||||||
if len(input_files) < 1:
|
if len(input_files) < 1:
|
||||||
return os.system(program)
|
return os.system(program)
|
||||||
|
|
||||||
for input_file in input_files:
|
for input_file in input_files:
|
||||||
print(f"Running {input_file}")
|
print(f"Running {input_file}")
|
||||||
end_command = f"{program} < {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:
|
if verbose:
|
||||||
print("Input:")
|
print("Input:")
|
||||||
os.system(f"cat {input_file}")
|
print(input_data)
|
||||||
print("")
|
print("")
|
||||||
out_file = input_file.replace(".in", ".out")
|
if expected_output is not None:
|
||||||
if os.path.exists(out_file):
|
|
||||||
if verbose:
|
|
||||||
print("Expected output:")
|
print("Expected output:")
|
||||||
os.system(f"cat {out_file}")
|
print(expected_output)
|
||||||
print("")
|
print("")
|
||||||
|
print("Program output:")
|
||||||
|
print(program_output.strip())
|
||||||
|
print("")
|
||||||
|
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
end_command += f" | diff {out_file} -"
|
if expected_output is not None:
|
||||||
print(os.popen(end_command).read())
|
# 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("-----------")
|
print("-----------")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -65,6 +101,7 @@ def main():
|
|||||||
print("Unsupported language")
|
print("Unsupported language")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Use the specified tests directory or default to current directory
|
||||||
tests_dir = args.tests if args.tests else "."
|
tests_dir = args.tests if args.tests else "."
|
||||||
|
|
||||||
if file_ext == ".c":
|
if file_ext == ".c":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user