Made it work with outputs as well
This commit is contained in:
parent
81a63fac6d
commit
f52fb42f88
25
ucompile
25
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":
|
||||
|
Loading…
x
Reference in New Issue
Block a user