From f52fb42f88a0eb53416177e9f4ede7c9011583e3 Mon Sep 17 00:00:00 2001 From: Boyan Date: Thu, 28 Sep 2023 22:14:28 +0200 Subject: [PATCH] Made it work with outputs as well --- ucompile | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/ucompile b/ucompile index cdecc04..6d2bd67 100755 --- a/ucompile +++ b/ucompile @@ -3,16 +3,29 @@ import argparse from os import system,popen from glob import glob -def run_input_cases(program, verbose=False): +def run_input_cases(program, verbose, output): input_files = glob("./*.in") if len(input_files) < 1: + return system(program) for input_file in input_files: print(f"Running {input_file}") - print(popen(f"{program} < {input_file}").read()) + end_command = f"{program} < {input_file}" if verbose: print("Input:") system(f"cat {input_file}") + print("") + if (out := glob(input_file.replace(".in", ".out"))[0]): + if verbose: + print("Expected output:") + system(f"cat {out}") + print("") + if output: + end_command += f" | diff {out} -" + print(popen(end_command).read()) + + print("-----------") + return def python_compile(file_name, verbose=False): @@ -29,9 +42,9 @@ def java_compile(file_name, maven=False, verbose=False): run_input_cases("java " + file_name[:file_name.rfind(".")], verbose) return -def c_compile(file_name, verbose=False): +def c_compile(file_name, verbose=False, output=False): system("gcc -Wall -pedantic --std=c99 -g -o program -lm -Wno-unused-result " + file_name) - run_input_cases("./program", verbose) + run_input_cases("./program", verbose, output) return def main(): @@ -43,6 +56,8 @@ def main(): parser.add_argument("filename", metavar="N", type=str) parser.add_argument("-v", "--verbose", action="store_true", default=False) parser.add_argument("-a", "--alternative", action="store_true", default=False) + parser.add_argument("-o", "--output", action="store_true", default=False) + args = parser.parse_args() file_name = args.filename file_ext = file_name[file_name.rfind("."):] @@ -51,7 +66,7 @@ def main(): return if file_ext == ".c": - c_compile(file_name, args.verbose) + c_compile(file_name, args.verbose, args.output) elif file_ext == ".py": python_compile(file_name, args.verbose) elif file_ext == ".java":