Debian Codegraph @

tests/functional/cli/05-colour.t

raw
1 #!/usr/bin/env bash
2 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #-------------------------------------------------------------------------------
18
19 # Test that CLI colour output is disabled if output is not to a terminal.
20 # Uses the "script" command to make stdout log file look like a terminal.
21
22 . "$(dirname "$0")/test_header"
23 if [[ "$OSTYPE" != "linux-gnu"* ]]; then
24 skip_all "Tests not compatibile with $OSTYPE"
25 fi
26 set_test_number 7
27
28 ANSI='\e\['
29
30 # No redirection.
31 script -q -c "cylc scan -t rich" log > /dev/null 2>&1
32 grep_ok "$ANSI" log -P # color
33
34 # FIXME: this test doesn't work because the output includes a color reset char
35 # at the end for some reason: https://github.com/cylc/cylc-flow/issues/6467
36 # script -q -c "cylc scan -t rich --color=never" log > /dev/null 2>&1
37 # grep_fail "$ANSI" log -P # no color
38
39 # Redirected.
40 cylc scan -t rich > log
41 grep_fail "$ANSI" log -P # no color
42
43 cylc scan -t rich --color=always > log
44 grep_ok "$ANSI" log -P # color
45
46 # Check command help too (gets printed during command line parsing).
47
48 # No redirection.
49 script -q -c "cylc scan --help" log > /dev/null 2>&1
50 grep_ok "$ANSI" log -P # color
51
52 script -q -c "cylc scan --help --color never" log > /dev/null 2>&1
53 grep_fail "$ANSI" log -P # no color
54
55 # Redirected.
56 cylc scan --help > log
57 grep_fail "$ANSI" log -P # no color
58
59 cylc scan --help --color=always > log
60 grep_ok "$ANSI" log -P # color