| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
. "${srcdir=.}/init.sh"; path_prepend_ ../src |
| 4 |
|
| 5 |
TZ=UTC0 |
| 6 |
export TZ |
| 7 |
|
| 8 |
fail=0 |
| 9 |
|
| 10 |
echo a > a |
| 11 |
echo b > b |
| 12 |
|
| 13 |
# On systems lacking fractional timestamp support, diff -u does not print |
| 14 |
# a decimal point and 9-digit nanosecond suffix. |
| 15 |
nanosecond_zeros=$(diff -u a b|grep '\.' > /dev/null && echo .000000000) |
| 16 |
|
| 17 |
epoch='1970-01-01 00:00:00' |
| 18 |
touch -t 197001010000.00 a b |
| 19 |
|
| 20 |
e=$(printf '\033') |
| 21 |
tab=$(printf '\t') |
| 22 |
|
| 23 |
gen_exp_u() |
| 24 |
{ |
| 25 |
local epoch_plus="$epoch$nanosecond_zeros +0000" |
| 26 |
local rs=$(printf "$e[${rs}m") |
| 27 |
local hd=$(printf "$e[${hd}m") |
| 28 |
local ad=$(printf "$e[${ad}m") |
| 29 |
local de=$(printf "$e[${de}m") |
| 30 |
local ln=$(printf "$e[${ln}m") |
| 31 |
printf '%s' \ |
| 32 |
"$hd--- a$tab$epoch_plus$rs |
| 33 |
$hd+++ b$tab$epoch_plus$rs |
| 34 |
${ln}@@ -1 +1 @@$rs |
| 35 |
$de-a$rs |
| 36 |
$ad+b$rs |
| 37 |
" |
| 38 |
} |
| 39 |
|
| 40 |
gen_exp_c() |
| 41 |
{ |
| 42 |
local epoch_posix_1003_1_2001="Thu Jan 1 00:00:00 1970" |
| 43 |
local rs=$(printf "$e[${rs}m") |
| 44 |
local hd=$(printf "$e[${hd}m") |
| 45 |
local ad=$(printf "$e[${ad}m") |
| 46 |
local de=$(printf "$e[${de}m") |
| 47 |
local ln=$(printf "$e[${ln}m") |
| 48 |
printf '%s' \ |
| 49 |
"$hd*** a$tab$epoch_posix_1003_1_2001$rs |
| 50 |
$hd--- b$tab$epoch_posix_1003_1_2001$rs |
| 51 |
*************** |
| 52 |
$ln*** 1 ****$rs |
| 53 |
$de! a$rs |
| 54 |
$ln--- 1 ----$rs |
| 55 |
$ad! b$rs |
| 56 |
" |
| 57 |
} |
| 58 |
|
| 59 |
gen_exp_default() |
| 60 |
{ |
| 61 |
printf '%s' \ |
| 62 |
"1c1 |
| 63 |
< a |
| 64 |
--- |
| 65 |
> b |
| 66 |
" |
| 67 |
} |
| 68 |
|
| 69 |
gen_exp_default_colors() |
| 70 |
{ |
| 71 |
local rs=$(printf "$e[${rs}m") |
| 72 |
local hd=$(printf "$e[${hd}m") |
| 73 |
local ad=$(printf "$e[${ad}m") |
| 74 |
local de=$(printf "$e[${de}m") |
| 75 |
local ln=$(printf "$e[${ln}m") |
| 76 |
printf '%s' \ |
| 77 |
"${ln}1c1$rs |
| 78 |
$de< a$rs |
| 79 |
--- |
| 80 |
$ad> b$rs |
| 81 |
" |
| 82 |
} |
| 83 |
|
| 84 |
# Compare with some known outputs |
| 85 |
|
| 86 |
rs=0 hd=1 ad=32 de=31 ln=36 |
| 87 |
|
| 88 |
returns_ 1 diff --color=auto a b > out || fail=1 |
| 89 |
gen_exp_default > exp || framework_failure_ |
| 90 |
compare exp out || fail=1 |
| 91 |
|
| 92 |
returns_ 1 env PATH="$PATH" TERM=dumb \ |
| 93 |
diff ---presume-output-tty --color=auto a b > out \ |
| 94 |
|| fail=1 |
| 95 |
gen_exp_default > exp || framework_failure_ |
| 96 |
compare exp out || fail=1 |
| 97 |
|
| 98 |
returns_ 1 diff --color=never a b > out || fail=1 |
| 99 |
gen_exp_default > exp || framework_failure_ |
| 100 |
compare exp out || fail=1 |
| 101 |
|
| 102 |
returns_ 1 diff a b > out || fail=1 |
| 103 |
gen_exp_default > exp || framework_failure_ |
| 104 |
compare exp out || fail=1 |
| 105 |
|
| 106 |
returns_ 1 diff --color=always a b > out || fail=1 |
| 107 |
gen_exp_default_colors > exp || framework_failure_ |
| 108 |
compare exp out || fail=1 |
| 109 |
|
| 110 |
returns_ 1 diff -u --color=always a b > out || fail=1 |
| 111 |
gen_exp_u > exp || framework_failure_ |
| 112 |
compare exp out || fail=1 |
| 113 |
|
| 114 |
returns_ 1 diff -c --color=always a b > out || fail=1 |
| 115 |
gen_exp_c > exp || framework_failure_ |
| 116 |
compare exp out || fail=1 |
| 117 |
|
| 118 |
rs=0 hd=33 ad=34 de=35 ln=36 |
| 119 |
returns_ 1 diff -u --color=always \ |
| 120 |
--palette="rs=0:hd=33:ad=34:de=35:ln=36" a b > out || fail=1 |
| 121 |
gen_exp_u > exp || framework_failure_ |
| 122 |
compare exp out || fail=1 |
| 123 |
|
| 124 |
# Before the fix in http://debbugs.gnu.org/22067, |
| 125 |
# this test would trigger an infinite loop bug. |
| 126 |
mkfifo fifo |
| 127 |
printf '%1000000s-a' > a |
| 128 |
printf '%1000000s-b' > b |
| 129 |
head -c 10 < fifo > /dev/null & |
| 130 |
diff --color=always ---presume-output-tty a b > fifo |
| 131 |
|
| 132 |
# Depending on version of GNU make (4.3.92-4.4 set SIGPIPE to "ignore"), |
| 133 |
# either of these is acceptable. |
| 134 |
case $? in 2|141) ;; *) fail=1 ;; esac |
| 135 |
|
| 136 |
Exit $fail |