diff options
author | Giuseppe Scrivano <gscrivano@gnu.org> | 2015-11-02 19:05:10 +0000 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2015-11-29 08:20:53 -0800 |
commit | 875ca7183bd4b098f2d8fb71b10553df2d4d2d11 (patch) | |
tree | 08f0f4c16a5734dea68ac3b99810be0c8ced17f7 | |
parent | 0e72de47952beead69e44a4a8c9b4994992ef8ac (diff) | |
download | diffutils-875ca7183bd4b098f2d8fb71b10553df2d4d2d11.tar.gz |
tests: Add tests for --color and --palette
* tests/colors: New file.
* tests/Makefile.am (TESTS): Add colors.
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rwxr-xr-x | tests/colors | 119 |
2 files changed, 121 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 438fbdf..805ccc2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,7 +15,8 @@ TESTS = \ no-newline-at-eof \ stdin \ strcoll-0-names \ - filename-quoting + filename-quoting \ + colors EXTRA_DIST = \ $(TESTS) init.sh t-local.sh diff --git a/tests/colors b/tests/colors new file mode 100755 index 0000000..facfd8d --- /dev/null +++ b/tests/colors @@ -0,0 +1,119 @@ +#!/bin/sh + +. "${srcdir=.}/init.sh"; path_prepend_ ../src + +TZ=UTC0 +export TZ + +fail=0 + +echo a > a +echo b > b + +epoch='1970-01-01 00:00:00' +touch --date="$epoch" a b + +gen_exp_u() +{ + local tab=$(printf '\t') + local epoch_plus="$epoch.000000000 +0000" + local rs=$(printf "\e[${rs}m") + local hd=$(printf "\e[${hd}m") + local ad=$(printf "\e[${ad}m") + local de=$(printf "\e[${de}m") + local ln=$(printf "\e[${ln}m") + printf '%s' \ +"$hd--- a$tab$epoch_plus ++++ b$tab$epoch_plus +$rs${ln}@@ -1 +1 @@$rs +$de-a$rs +$ad+b$rs +" +} + +gen_exp_c() +{ + local tab=$(printf '\t') + local epoch_posix_1003_1_2001="Thu Jan 1 00:00:00 1970" + local rs=$(printf "\e[${rs}m") + local hd=$(printf "\e[${hd}m") + local ad=$(printf "\e[${ad}m") + local de=$(printf "\e[${de}m") + local ln=$(printf "\e[${ln}m") + printf '%s' \ +"$hd*** a$tab$epoch_posix_1003_1_2001 +--- b$tab$epoch_posix_1003_1_2001 +$rs*************** +$ln*** 1 ****$rs +$de! a$rs +$ln--- 1 ----$rs +$ad! b$rs +" +} + +gen_exp_default() +{ + printf '%s' \ +"1c1 +< a +--- +> b +" +} + +gen_exp_default_colors() +{ + local rs=$(printf "\e[${rs}m") + local hd=$(printf "\e[${hd}m") + local ad=$(printf "\e[${ad}m") + local de=$(printf "\e[${de}m") + local ln=$(printf "\e[${ln}m") + printf '%s' \ +"${ln}1c1$rs +$de< a$rs +--- +$ad> b$rs +" +} + +# Compare with some known outputs + +rs=0 hd=1 ad=32 de=31 ln=36 + +diff --color=auto a b > out +test $? = 1 || fail=1 +gen_exp_default > exp || framework_failure_ +compare exp out || fail=1 + +diff --color=never a b > out +test $? = 1 || fail=1 +gen_exp_default > exp || framework_failure_ +compare exp out || fail=1 + +diff a b > out +test $? = 1 || fail=1 +gen_exp_default > exp || framework_failure_ +compare exp out || fail=1 + +diff --color=always a b > out +test $? = 1 || fail=1 +gen_exp_default_colors > exp || framework_failure_ +compare exp out || fail=1 + +diff -u --color=always a b > out +test $? = 1 || fail=1 +gen_exp_u > exp || framework_failure_ +compare exp out || fail=1 + +diff -c --color=always a b > out +test $? = 1 || fail=1 +gen_exp_c > exp || framework_failure_ +compare exp out || fail=1 + +rs=0 hd=33 ad=34 de=35 ln=36 +diff -u --color=always --palette="rs=0:hd=33:ad=34:de=35:ln=36" a b > out +test $? = 1 || fail=1 +gen_exp_u > exp || framework_failure_ +compare exp out || fail=1 + +Exit $fail |