From ad6b3245c4420155e3dd48f449cbb6ab0a3f5a04 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Mon, 30 Jan 2023 20:34:07 +0530 Subject: [PATCH] Add no_color option in run_tests.py --- ci/test.xsh | 2 +- run_tests.py | 7 +++++-- src/libasr/compiler_tester/tester.py | 24 +++++++++++++++++++----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ci/test.xsh b/ci/test.xsh index 53cd439515..50622fd55f 100644 --- a/ci/test.xsh +++ b/ci/test.xsh @@ -16,7 +16,7 @@ src/bin/lpython --show-asr tests/doconcurrentloop_01.py src/bin/lpython --show-cpp tests/doconcurrentloop_01.py if $WIN == "1": - python run_tests.py --skip-run-with-dbg + python run_tests.py --skip-run-with-dbg --no-color else: python run_tests.py cd integration_tests diff --git a/run_tests.py b/run_tests.py index dd32d5eb9c..6363b1c0d4 100755 --- a/run_tests.py +++ b/run_tests.py @@ -10,7 +10,7 @@ def single_test(test, verbose, no_llvm, skip_run_with_dbg, update_reference, - specific_backends=None, excluded_backends=None): + no_color, specific_backends=None, excluded_backends=None): filename = test["filename"] def is_included(backend): return test.get(backend, False) \ @@ -36,7 +36,10 @@ def is_included(backend): if pass_ and (pass_ not in ["do_loops", "global_stmts"] and pass_ not in optimization_passes): raise Exception(f"Unknown pass: {pass_}") - log.debug(f"{color(style.bold)} START TEST: {color(style.reset)} {filename}") + if no_color: + log.debug(f" START TEST: {filename}") + else: + log.debug(f"{color(style.bold)} START TEST: {color(style.reset)} {filename}") extra_args = f"--no-error-banner {show_verbose}" diff --git a/src/libasr/compiler_tester/tester.py b/src/libasr/compiler_tester/tester.py index 116c488eca..9b4f404abb 100644 --- a/src/libasr/compiler_tester/tester.py +++ b/src/libasr/compiler_tester/tester.py @@ -29,6 +29,7 @@ SRC_DIR = os.path.dirname(LIBASR_DIR) ROOT_DIR = os.path.dirname(SRC_DIR) +no_color = False class RunException(Exception): pass @@ -329,7 +330,10 @@ def run_test(testname, basename, cmd, infile, update_reference=False, raise RunException( "Testing with reference output failed." + full_err_str) - log.debug(s + " " + check()) + if no_color: + log.debug(s + " PASS") + else: + log.debug(s + " " + check()) def tester_main(compiler, single_test): @@ -358,6 +362,8 @@ def tester_main(compiler, single_test): help="Skip runtime tests with debugging information enabled") parser.add_argument("-s", "--sequential", action="store_true", help="Run all tests sequentially") + parser.add_argument("--no-color", action="store_true", + help="Turn off colored tests output") args = parser.parse_args() update_reference = args.update list_tests = args.list @@ -374,6 +380,8 @@ def tester_main(compiler, single_test): verbose = args.verbose no_llvm = args.no_llvm skip_run_with_dbg = args.skip_run_with_dbg + global no_color + no_color = args.no_color # So that the tests find the `lcompiler` executable os.environ["PATH"] = os.path.join(SRC_DIR, "bin") \ @@ -401,7 +409,8 @@ def tester_main(compiler, single_test): excluded_backends=excluded_backends, verbose=verbose, no_llvm=no_llvm, - skip_run_with_dbg=skip_run_with_dbg) + skip_run_with_dbg=skip_run_with_dbg, + no_color=no_color) # run in parallel else: single_tester_partial_args = partial( @@ -411,7 +420,8 @@ def tester_main(compiler, single_test): excluded_backends=excluded_backends, verbose=verbose, no_llvm=no_llvm, - skip_run_with_dbg=skip_run_with_dbg) + skip_run_with_dbg=skip_run_with_dbg, + no_color=no_color) with ThreadPoolExecutor() as ex: futures = ex.map(single_tester_partial_args, filtered_tests) for f in futures: @@ -423,5 +433,9 @@ def tester_main(compiler, single_test): if update_reference: log.info("Test references updated.") else: - log.info( - f"{(color(fg.green) + color(style.bold))}TESTS PASSED{color(fg.reset) + color(style.reset)}") + if no_color: + log.info("TESTS PASSED") + else: + log.info( + f"{(color(fg.green) + color(style.bold))}TESTS PASSED" + f"{color(fg.reset) + color(style.reset)}")