3 test_description
='various sanity checks
5 Many of these are "tolerate_failure" checks
6 as there are workarounds in place for them.
17 test_tolerate_failure
'POSIX tr to NUL processing' '
18 printf "1x2x3x" | tr "x" "\\000" >lines3z &&
19 val="$(xargs -0 <lines3z printf "%s\n" | wc -l)" &&
23 test_expect_success
'POSIX tr from NUL processing' '
24 val="$(echo "x@@@y" | tr "x@y" "1\\0005" | tr "\\000" 2)" &&
25 test z"$val" = z"12225"
30 test_tolerate_failure
'POSIX unset behavior' '
31 test z"$(unset it && unset it && echo good || echo bad)" = z"good"
34 test_tolerate_failure
'POSIX exec behavior' '
35 test z"$(false() { :; }; (exec false) && echo "bad" || echo "good")" = z"good"
38 test_tolerate_failure
'POSIX eval behavior' '
39 setec() { ! : || eval "ec=\$?"; } &&
40 setec && test z"$ec" = z"1"
43 test_tolerate_failure
'POSIX trap EXIT behavior' '
44 nomsg() { trap "echo bad" EXIT; } &&
45 result="$(nomsg && trap - EXIT)" &&
46 test z"${result:-good}" = z"good"
49 test_tolerate_failure
'POSIX alias' '
53 test_tolerate_failure LASTOK
'POSIX unalias -a (no subshell)' '
58 test_tolerate_failure LASTOK
'POSIX unalias -a (subshell w/o aliases)' '
62 test_tolerate_failure
'POSIX function redir ops' '
67 test z"$(redir && echo good)" = z"good"
70 test_tolerate_failure
'unsettable LINENO' '
71 { unset LINENO || :; }
74 test_tolerate_failure
'working awk implementation' '
75 # mawk will have a segmentation fault with this
89 test_tolerate_failure
'POSIX awk pattern brace quantifiers' '
90 # mawk stupidly does not support these
91 # can you hear us mocking you mawk?
92 result="$(echo not-mawk | awk "/^[a-z-]{5,}\$/")" &&
93 test z"$result" = z"not-mawk"
96 test_expect_success
'POSIX awk ENVIRON array' '
97 EVAR="This is some test here" &&
99 val="$(awk "BEGIN{exit}END{print ENVIRON[\"EVAR\"]}")" &&
100 test z"$val" = z"$EVAR"
103 test_expect_success
'POSIX awk ENVIRON array detects unset' '
106 val="$(awk "BEGIN{exit}END{print ((\"EVAR\" in ENVIRON)?1:0)}")" &&
107 test z"$val" = z"0" &&
110 val="$(awk "BEGIN{exit}END{print ((\"EVAR\" in ENVIRON)?1:0)}")" &&
114 test_expect_success
'POSIX awk backslash continues line' - <<'EOT'
125 for (i = 1; i <= n; ++i) {
126 if (i > 1) ans = ans " "
132 test z"$val" = z"One Line Now"
135 test_tolerate_failure
'POSIX export unset var exports it' '
136 say_color info "# POSIX is, regrettably, quite explicit about this" &&
137 say_color info "# POSIX requires EVERY exported variable to be in child environment" &&
139 export NO_SUCH_VAR &&
140 printenv NO_SUCH_VAR >/dev/null
143 v_count_words
() { eval "${1:-scratch_}=\"$(( $# - 1 ))\""; }
145 test_expect_success
'count word function works' '
146 sane_unset scratch_ &&
147 v_count_words && test "$scratch_" = "-1" &&
148 sane_unset scratch_ &&
149 test "${scratch_+yes}" != "yes" &&
150 v_count_words zero && test "$zero" = "0" &&
151 v_count_words one 1 && test "$one" = "1" &&
152 v_count_words one "a b c" && test "$one" = "1" &&
153 v_count_words two a b && test "$two" = "2" &&
154 v_count_words three three 2 1 && test "$three" = "3" &&
155 line="\"a b c d\" e f g" &&
156 eval v_count_words four "$line" && test "$four" = "4" &&
157 line="\"a b c d\" e" &&
158 v_count_words five $line && test "$five" = "5" &&
159 test "${scratch_+yes}" != "yes"
162 test_expect_success
'cat -' '
169 echo four >expected &&
170 test_cmp four expected &&
171 cat - <<-EOT >five &&
174 echo five >expected &&
175 test_cmp five expected &&
176 cat - three <<-EOT >xthree &&
180 echo three >>expected &&
181 test_cmp xthree expected &&
182 cat four - <<-EOT >foury &&
185 echo four >expected &&
187 test_cmp foury expected &&
188 cat one - two <<-EOT >one_two &&
191 echo one >expected &&
192 echo 1.5 >>expected &&
193 echo two >>expected &&
194 test_cmp one_two expected &&
195 cat one - two - three <<-EOT >one_two_three &&
198 echo one >expected &&
199 echo 1.9 >>expected &&
200 echo two >>expected &&
201 echo three >>expected &&
202 test_cmp one_two_three expected