README-TESTLIB-TG: fix typo
[topgit/pro.git] / t / t0001-sanity.sh
blob1db538db694c032c5bf058e925e71d9f5ac65465
1 #!/bin/sh
3 test_description='various sanity checks
5 Most of these are "tolerate_failure" checks
6 as there are workarounds in place for them.
9 TEST_NO_CREATE_REPO=1
11 . ./test-lib.sh
13 test_plan 15
15 # required working
17 test_expect_success 'POSIX tr to NUL processing' '
18 printf "1x2x3x" | tr "x" "\\000" >lines3z &&
19 val="$(xargs -0 <lines3z printf "%s\n" | wc -l)" &&
20 test $val -eq 3
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"
28 # tolerated breakage
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' '
50 alias some=alias
53 test_tolerate_failure LASTOK 'POSIX unalias -a (no subshell)' '
54 alias some=alias &&
55 unalias -a
58 test_tolerate_failure LASTOK 'POSIX unalias -a (subshell w/o aliases)' '
59 unalias -a
62 test_tolerate_failure 'POSIX function redir ops' '
63 redir() {
64 echo bad stderr >&2
65 echo bad stdout
66 } >/dev/null 2>&1 &&
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
76 awk "
77 function f1(a1) {}
78 function f2(a2) {
79 f1(a2);
80 for (;;) break;
82 function f3() {
83 f2(a3);
84 a3[1];
86 BEGIN { exit; }
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_tolerate_failure 'POSIX awk ENVIRON array' '
97 EVAR="This is some test here" &&
98 export EVAR &&
99 val="$(awk "BEGIN{exit}END{print ENVIRON[\"EVAR\"]}")" &&
100 test z"$val" = z"$EVAR"
103 test_tolerate_failure 'POSIX export unset var exports it' '
104 say_color info "# POSIX is, regrettably, quite explicit about this" &&
105 say_color info "# POSIX requires EVERY exported variable to be in child environment" &&
106 unset NO_SUCH_VAR &&
107 export NO_SUCH_VAR &&
108 printenv NO_SUCH_VAR >/dev/null
111 test_done