Skip to content

Commit

Permalink
misc: colored output
Browse files Browse the repository at this point in the history
  • Loading branch information
himkt committed Apr 5, 2024
1 parent f7ee2c5 commit 35b1aae
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions bin/ac-random-test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import argparse
import os
import shutil
import subprocess
import sys

"""
Example of gen-input-program:
Expand All @@ -18,9 +19,18 @@ with open("in.txt", "w") as f:
```
"""

class bcolors:
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'

devnull = open(os.devnull, "w")


def run_and_decode(args: list[str]) -> str:
ret = subprocess.check_output(args, stdin=open("in.txt"))
ret = subprocess.check_output(args, stdin=open("in.txt"), stderr=devnull)
return ret.decode("utf-8").rstrip()


Expand All @@ -31,15 +41,23 @@ def verify(args: argparse.Namespace):
gen_input_cmd = args.gen_input_cmd
else:
gen_input_cmd = [os.path.abspath(args.gen_input_cmd)]
subprocess.check_call(gen_input_cmd)
subprocess.check_call(gen_input_cmd, stdout=devnull, stderr=devnull)

run_cmd: list[str] = args.run_cmd.split(" ")
ret_cmd = [s.format(argv0=name) for s in run_cmd]
ret_lazy_cmd = [s.format(argv0=f"{name}_lazy") for s in run_cmd]

ret = run_and_decode(ret_cmd)
ret_lazy = run_and_decode(ret_lazy_cmd)
assert ret_lazy == ret, f"lazy={ret_lazy}, ans={ret}"

if ret_lazy == ret:
print("Check: " + bcolors.OKGREEN + "passed" + bcolors.ENDC)
else:
print("Check: " + bcolors.FAIL + "failed" + bcolors.ENDC)
print("Found the edge case and stored in in.txt.", end="")
print(" (output: expected=" + bcolors.OKGREEN + ret_lazy + bcolors.ENDC, end="")
print(", got=" + bcolors.FAIL + ret + bcolors.ENDC + ")")
sys.exit(1)


if __name__ == "__main__":
Expand Down

0 comments on commit 35b1aae

Please sign in to comment.