From 23e6698dc8354b41a489986acb9aa1e8e5ee261b Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 30 Aug 2021 17:16:19 +0200 Subject: [PATCH] cmake: Force color in the tests For littlecheck/pexpect this just unconditionally enables color. I have no idea what happens if you run cmake outside of a terminal , but the worst that can happen is that *errors* have color escapes in them. If someone figures out how to get cmake to tell us if it's running in a terminal, we can add a check. --- build_tools/littlecheck.py | 9 ++++++++- build_tools/pexpect_helper.py | 2 +- cmake/Tests.cmake | 2 +- tests/test.fish | 6 +++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/build_tools/littlecheck.py b/build_tools/littlecheck.py index 0f56f8744..03daa7a79 100755 --- a/build_tools/littlecheck.py +++ b/build_tools/littlecheck.py @@ -688,6 +688,13 @@ def get_argparse(): help="Show the files to be checked", default=False, ) + parser.add_argument( + "--force-color", + action="store_true", + dest="force_color", + help="Force usage of color even if not connected to a terminal", + default=False, + ) parser.add_argument("file", nargs="+", help="File to check") return parser @@ -702,7 +709,7 @@ def main(): failed = False skip_count = 0 config = Config() - config.colorize = sys.stdout.isatty() + config.colorize = args.force_color or sys.stdout.isatty() config.progress = args.progress fields = config.colors() diff --git a/build_tools/pexpect_helper.py b/build_tools/pexpect_helper.py index bc963bedd..37c112c65 100644 --- a/build_tools/pexpect_helper.py +++ b/build_tools/pexpect_helper.py @@ -143,7 +143,7 @@ class SpawnedProc(object): if name not in env: raise ValueError("'%s' variable not found in environment" % name) exe_path = env.get(name) - self.colorize = sys.stdout.isatty() + self.colorize = sys.stdout.isatty() or env.get("FISH_FORCE_COLOR", "0") == "1" self.messages = [] self.start_time = None self.spawn = pexpect.spawn(exe_path, env=env, encoding="utf-8", timeout=timeout, **kwargs) diff --git a/cmake/Tests.cmake b/cmake/Tests.cmake index f0a041080..94f88f621 100644 --- a/cmake/Tests.cmake +++ b/cmake/Tests.cmake @@ -34,7 +34,7 @@ if(POLICY CMP0037) cmake_policy(SET CMP0037 OLD) endif() add_custom_target(test - COMMAND env CTEST_PARALLEL_LEVEL=${CTEST_PARALLEL_LEVEL} + COMMAND env CTEST_PARALLEL_LEVEL=${CTEST_PARALLEL_LEVEL} FISH_FORCE_COLOR=1 ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure --progress DEPENDS fish_tests tests_buildroot_target diff --git a/tests/test.fish b/tests/test.fish index 0d699a622..a7f353741 100644 --- a/tests/test.fish +++ b/tests/test.fish @@ -30,8 +30,12 @@ set -g python (__fish_anypython) set -l skipped 0 set -l failed 0 if set -q files_to_test[1] + set -l force_color + test "$FISH_FORCE_COLOR" = 1 + and set force_color --force-color + $python -S ../littlecheck.py \ - --progress \ + --progress $force_color \ -s fish=../test/root/bin/fish \ -s fish_test_helper=../test/root/bin/fish_test_helper \ $files_to_test