Debian Codegraph @

tests/yesno

raw
1 #! /bin/sh
2 # Test feature interaction of -C, -v, -o, and -m.
3 #
4 # Copyright (C) 2001, 2006, 2009-2025 Free Software Foundation, Inc.
5 #
6 # Copying and distribution of this file, with or without modification,
7 # are permitted in any medium without royalty provided the copyright
8 # notice and this notice are preserved.
9 #
10 # This set of tests was started by Charles Levert.
11
12 . "${srcdir=.}/init.sh"; path_prepend_ ../src
13
14 : ${VERBOSE=} # empty or "1"
15 failures=0
16
17 # Lines, including terminating LF, contain 10 octets.
18 # The words "yes" and "no" are at zero-based octet offsets of 5, 15, ...
19 yn='yesno.txt'
20 cat > "$yn" <<EOF
21 [A01 no ]
22 [B02 no ]
23 [C03 yes]
24 [D04 yes]
25 [E05 yes]
26 [F06 no ]
27 [G07 no ]
28 [H08 yes]
29 [I09 yes]
30 [J10 no ]
31 [K11 no ]
32 [L12 no ]
33 [M13 yes]
34 [N14 yes]
35 EOF
36 # Noticed the symmetry?
37
38 # All possible output substrings (lines):
39 # selected whole, rejected whole, never-read whole, selected part, rejected part.
40 A='1:0:[A01 no ]/'; rA='1-0-[A01 no ]/'; XA='X[A01 no ]/';
41 B='2:10:[B02 no ]/'; rB='2-10-[B02 no ]/'; XB='X[B02 no ]/';
42 C='3:20:[C03 yes]/'; rC='3-20-[C03 yes]/'; XC='X[C03 yes]/'; c='3:25:yes/'; rc='3-25-yes/'
43 D='4:30:[D04 yes]/'; rD='4-30-[D04 yes]/'; XD='X[D04 yes]/'; d='4:35:yes/'; rd='4-35-yes/'
44 E='5:40:[E05 yes]/'; rE='5-40-[E05 yes]/'; XE='X[E05 yes]/'; e='5:45:yes/'; re='5-45-yes/'
45 F='6:50:[F06 no ]/'; rF='6-50-[F06 no ]/'; XF='X[F06 no ]/';
46 G='7:60:[G07 no ]/'; rG='7-60-[G07 no ]/'; XG='X[G07 no ]/';
47 H='8:70:[H08 yes]/'; rH='8-70-[H08 yes]/'; XH='X[H08 yes]/'; h='8:75:yes/'; rh='8-75-yes/'
48 I='9:80:[I09 yes]/'; rI='9-80-[I09 yes]/'; XI='X[I09 yes]/'; i='9:85:yes/'; ri='9-85-yes/'
49 J='10:90:[J10 no ]/'; rJ='10-90-[J10 no ]/'; XJ='X[J10 no ]/';
50 K='11:100:[K11 no ]/'; rK='11-100-[K11 no ]/'; XK='X[K11 no ]/';
51 L='12:110:[L12 no ]/'; rL='12-110-[L12 no ]/'; XL='X[L12 no ]/';
52 M='13:120:[M13 yes]/'; rM='13-120-[M13 yes]/'; XM='X[M13 yes]/'; m='13:125:yes/'; rm='13-125-yes/'
53 N='14:130:[N14 yes]/'; rN='14-130-[N14 yes]/'; XN='X[N14 yes]/'; n='14:135:yes/'; rn='14-135-yes/'
54 # Group separators.
55 s='--/'
56 S='XYZ/'
57 # Exit statuses.
58 z0='?0/'
59 z1='?1/'
60 z2='?2/'
61
62 # What needs fixing? Specification, documentation, implementation, or this?
63 # The individual tests.
64 set x \
65 '' "$C$D$E$H$I$M$N$z0" \
66 '-o' "$c$d$e$h$i$m$n$z0" \
67 '-C,1' "$rB$C$D$E$rF$rG$H$I$rJ$s$rL$M$N$z0" \
68 '-C,1,-o' "$c$d$e$h$i$s$m$n$z0" \
69 '-C,1,-o,--group=XYZ' "$c$d$e$h$i$S$m$n$z0" \
70 '-C,1,-o,--no-gr' "$c$d$e$h$i$m$n$z0" \
71 '-C,4,-1' "$rB$C$D$E$rF$rG$H$I$rJ$s$rL$M$N$z0" \
72 '-C,1,--group=XYZ' "$rB$C$D$E$rF$rG$H$I$rJ$S$rL$M$N$z0" \
73 '-C,1,--no-gr' "$rB$C$D$E$rF$rG$H$I$rJ$rL$M$N$z0" \
74 '-m,4' "$C$D$E$H$z0$XI$XJ$XK$XL$XM$XN" \
75 '-m,4,-o' "$c$d$e$h$z0$XI$XJ$XK$XL$XM$XN" \
76 '-m,4,-C,1' "$rB$C$D$E$rF$rG$H$rI$z0$XI$XJ$XK$XL$XM$XN" \
77 '-m,4,-C,1,-o' "$c$d$e$h$z0$XI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-m,3,-v' "$A$B$F$z0$XG$XH$XI$XJ$XK$XL$XM$XN" \
100 '-m,3,-v,-o' "$z0$XG$XH$XI$XJ$XK$XL$XM$XN" \
101 '-m,3,-v,-C,1' "$A$B$rC$s$rE$F$rG$z0$XG$XH$XI$XJ$XK$XL$XM$XN" \
102 '-m,3,-v,-C,1,-o' "$rc$s$re$z0$XG$XH$XI$XJ$XK$XL$XM$XN" \
103 x
104 shift
105 # Comment out cases that are known to fail. These should be uncommented after the 2.5.4 release. TAA.
106 # These should be added back in above and fixed in the code. TAA.
107 # '-m,5,-C,1' "$rB$C$D$E$rF$rG$H$I$z0$XJ$XK$XL$XM$XN" \
108 # '-m,2,-v,-C,1' "$A$B$z0$XC$XD$XE$XF$XG$XH$XI$XJ$XK$XL$XM$XN" \
109 # '-m,2,-v,-C,1,-o' "$z0$XC$XD$XE$XF$XG$XH$XI$XJ$XK$XL$XM$XN" \
110
111 # Test execution and reporting.
112 t=1
113 while test xx != "x$1"; do
114 opts=$(echo "$1" | sed 's/,/ /g')
115 expect="$2"
116 shift 2
117
118 output=$({ grep -F -n -b $opts yes 2>/dev/null; echo "?$?"; sed 's!^!X!'; } < "$yn" | tr '\n' '/')
119
120 if test "$output" != "$expect" || test "$VERBOSE" = "1"; then
121 echo " Test #$t: { grep -F -n -b $opts yes; echo \"?\$?\"; sed 's!^!X!'; }"
122 echo " output: \"$output\""
123 fi
124 if test "$output" != "$expect"; then
125 echo " expect: \"$expect\""
126 echo ' FAIL'
127 failures=1
128 elif test "$VERBOSE" = "1"; then
129 echo ' PASS'
130 fi
131
132 t=$(expr $t + 1)
133 done
134
135 Exit $failures