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.
This commit is contained in:
Fabian Homborg 2021-08-30 17:16:19 +02:00
parent aa17ed51ce
commit 23e6698dc8
4 changed files with 15 additions and 4 deletions

View file

@ -688,6 +688,13 @@ def get_argparse():
help="Show the files to be checked", help="Show the files to be checked",
default=False, 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") parser.add_argument("file", nargs="+", help="File to check")
return parser return parser
@ -702,7 +709,7 @@ def main():
failed = False failed = False
skip_count = 0 skip_count = 0
config = Config() config = Config()
config.colorize = sys.stdout.isatty() config.colorize = args.force_color or sys.stdout.isatty()
config.progress = args.progress config.progress = args.progress
fields = config.colors() fields = config.colors()

View file

@ -143,7 +143,7 @@ class SpawnedProc(object):
if name not in env: if name not in env:
raise ValueError("'%s' variable not found in environment" % name) raise ValueError("'%s' variable not found in environment" % name)
exe_path = env.get(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.messages = []
self.start_time = None self.start_time = None
self.spawn = pexpect.spawn(exe_path, env=env, encoding="utf-8", timeout=timeout, **kwargs) self.spawn = pexpect.spawn(exe_path, env=env, encoding="utf-8", timeout=timeout, **kwargs)

View file

@ -34,7 +34,7 @@ if(POLICY CMP0037)
cmake_policy(SET CMP0037 OLD) cmake_policy(SET CMP0037 OLD)
endif() endif()
add_custom_target(test 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 ${CMAKE_CTEST_COMMAND} --force-new-ctest-process
--output-on-failure --progress --output-on-failure --progress
DEPENDS fish_tests tests_buildroot_target DEPENDS fish_tests tests_buildroot_target

View file

@ -30,8 +30,12 @@ set -g python (__fish_anypython)
set -l skipped 0 set -l skipped 0
set -l failed 0 set -l failed 0
if set -q files_to_test[1] 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 \ $python -S ../littlecheck.py \
--progress \ --progress $force_color \
-s fish=../test/root/bin/fish \ -s fish=../test/root/bin/fish \
-s fish_test_helper=../test/root/bin/fish_test_helper \ -s fish_test_helper=../test/root/bin/fish_test_helper \
$files_to_test $files_to_test