summaryrefslogtreecommitdiffstats
path: root/tests/shtest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/shtest')
-rwxr-xr-xtests/shtest54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/shtest b/tests/shtest
index cec1fc59..af1b159e 100755
--- a/tests/shtest
+++ b/tests/shtest
@@ -244,4 +244,58 @@ if [ "`$VALGRIND $Q $JQ -n '"xyz\n"|halt_error(1)' 2>&1`" != xyz ]; then
exit 1
fi
+# Check $JQ_COLORS
+$JQ -Ccn . > $d/color
+printf '\033[1;30mnull\033[0m\n' > $d/expect
+cmp $d/color $d/expect
+JQ_COLORS='4;31' $JQ -Ccn . > $d/color
+printf '\033[4;31mnull\033[0m\n' > $d/expect
+cmp $d/color $d/expect
+JQ_COLORS='1;30:0;31:0;32:0;33:0;34:1;35:1;36' \
+ $JQ -Ccn '[{"a":true,"b":false},123,null]' > $d/color
+(
+printf '\033[1;35m[\033[1;36m{'
+printf '\033[0m\033[34;1m"a"\033['
+printf '0m\033[1;36m:\033[0m\033['
+printf '0;32mtrue\033[0m\033[1'
+printf ';36m,\033[0m\033[34;1m'
+printf '"b"\033[0m\033[1;36m:\033'
+printf '[0m\033[0;31mfalse\033'
+printf '[0m\033[1;36m\033[1;36'
+printf 'm}\033[0m\033[1;35m,\033['
+printf '0;33m123\033[0m\033[1;'
+printf '35m,\033[1;30mnull\033'
+printf '[0m\033[1;35m\033[1;35'
+printf 'm]\033[0m\n'
+) > $d/expect
+cmp $d/color $d/expect
+
+# Check garbage in JQ_COLORS. We write each color sequence into a 16
+# char buffer that needs to hold ESC [ <color> m NUL, so each color
+# sequence can be no more than 12 chars (bytes). These emit a warning
+# on stderr.
+set -vx
+echo 'Failed to set $JQ_COLORS' > $d/expect_warning
+$JQ -Ccn '[{"a":true,"b":false},123,null]' > $d/expect
+JQ_COLORS='garbage;30:*;31:,;3^:0;$%:0;34:1;35:1;36' \
+ $JQ -Ccn '[{"a":true,"b":false},123,null]' > $d/color 2>$d/warning
+cmp $d/color $d/expect
+cmp $d/warning $d/expect_warning
+JQ_COLORS='1234567890123456789;30:0;31:0;32:0;33:0;34:1;35:1;36' \
+ $JQ -Ccn '[{"a":true,"b":false},123,null]' > $d/color 2>$d/warning
+cmp $d/color $d/expect
+cmp $d/warning $d/expect_warning
+JQ_COLORS='1;31234567890123456789:0;31:0;32:0;33:0;34:1;35:1;36' \
+ $JQ -Ccn '[{"a":true,"b":false},123,null]' > $d/color 2>$d/warning
+cmp $d/color $d/expect
+cmp $d/warning $d/expect_warning
+JQ_COLORS='1234567890123456;1234567890123456:1234567890123456;1234567890123456:1234567890123456;1234567890123456:1234567890123456;1234567890123456:1234567890123456;1234567890123456:1234567890123456;1234567890123456:1234567890123456;1234567890123456' \
+ $JQ -Ccn '[{"a":true,"b":false},123,null]' > $d/color 2>$d/warning
+cmp $d/color $d/expect
+cmp $d/warning $d/expect_warning
+JQ_COLORS="0123456789123:0123456789123:0123456789123:0123456789123:0123456789123:0123456789123:0123456789123:0123456789123:" \
+ $JQ -Ccn '[{"a":true,"b":false},123,null]' > $d/color 2>$d/warning
+cmp $d/color $d/expect
+cmp $d/warning $d/expect_warning
+
exit 0