t0001: add export unset works test
[topgit/pro.git] / t / t0001-sanity.sh
blob4fc23cbbde9ceb69ada0120543faca8fb9b3eb2f
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 14
15 test_tolerate_failure 'POSIX unset behavior' '
16 test z"$(unset it && unset it && echo good || echo bad)" = z"good"
19 test_tolerate_failure 'POSIX exec behavior' '
20 test z"$(false() { :; }; (exec false) && echo "bad" || echo "good")" = z"good"
23 test_tolerate_failure 'POSIX eval behavior' '
24 setec() { ! : || eval "ec=\$?"; } &&
25 setec && test z"$ec" = z"1"
28 test_tolerate_failure 'POSIX trap EXIT behavior' '
29 nomsg() { trap "echo bad" EXIT; } &&
30 result="$(nomsg && trap - EXIT)" &&
31 test z"${result:-good}" = z"good"
34 test_tolerate_failure 'POSIX alias' '
35 alias some=alias
38 test_tolerate_failure LASTOK 'POSIX unalias -a (no subshell)' '
39 alias some=alias &&
40 unalias -a
43 test_tolerate_failure LASTOK 'POSIX unalias -a (subshell w/o aliases)' '
44 unalias -a
47 test_tolerate_failure 'POSIX function redir ops' '
48 redir() {
49 echo bad stderr >&2
50 echo bad stdout
51 } >/dev/null 2>&1 &&
52 test z"$(redir && echo good)" = z"good"
55 test_tolerate_failure 'unsettable LINENO' '
56 { unset LINENO || :; }
59 test_tolerate_failure 'working awk implementation' '
60 # mawk will have a segmentation fault with this
61 awk "
62 function f1(a1) {}
63 function f2(a2) {
64 f1(a2);
65 for (;;) break;
67 function f3() {
68 f2(a3);
69 a3[1];
71 BEGIN { exit; }
74 test_tolerate_failure 'POSIX awk pattern brace quantifiers' '
75 # mawk stupidly does not support these
76 # can you hear us mocking you mawk?
77 result="$(echo not-mawk | awk "/^[a-z-]{5,}\$/")" &&
78 test z"$result" = z"not-mawk"
81 test_tolerate_failure 'POSIX awk ENVIRON array' '
82 EVAR="This is some test here" &&
83 export EVAR &&
84 val="$(awk "BEGIN{exit}END{print ENVIRON[\"EVAR\"]}")" &&
85 test z"$val" = z"$EVAR"
88 test_tolerate_failure 'POSIX tr NUL processing' '
89 val="$(perl -e "print 1,\"\\000\" x 3, 5" | tr "\\000" 2)" &&
90 test z"$val" = z"12225"
93 test_tolerate_failure 'POSIX export unset var exports it' '
94 say_color info "# POSIX is, regrettably, quite explicit about this" &&
95 say_color info "# POSIX requires EVERY exported variable to be in child environment" &&
96 unset NO_SUCH_VAR &&
97 export NO_SUCH_VAR &&
98 printenv NO_SUCH_VAR >/dev/null
101 test_done