3 # Simple shell command language test library.
5 # Tests must follow the basic form:
7 # begin_test "the thing"
15 # When a test fails its stdout and stderr are shown.
17 # Note that tests must `set -e' within the subshell block or failed assertions
18 # will not cause the test to fail and the result may be misreported.
20 # Copyright (c) 2011-13 by Ryan Tomayko <http://tomayko.com>
25 . "$(dirname "$0")/testenv.sh"
28 # keep track of num tests and failures
32 # this runs at process exit
34 tap_show_plan "$tests"
37 if [ $failures -gt 0 ]; then
44 # create the trash dir
45 trap "atexit" SIGKILL SIGINT SIGTERM EXIT
52 GITSERVER=$(cat "$LFS_URL_FILE")
53 SSLGITSERVER=$(cat "$LFS_SSL_URL_FILE")
54 CLIENTCERTGITSERVER=$(cat "$LFS_CLIENT_CERT_URL_FILE")
57 # Mark the beginning of a test. A subshell should immediately follow this
61 [ -n "$test_description" ] && end_test $test_status
64 tests=$(( tests + 1 ))
70 trace="$TRASHDIR/trace"
72 exec 1>"$out" 2>"$err"
74 # enabling GIT_TRACE can cause Windows git to stall, esp with fd 5
75 # other fd numbers like 8/9 don't stall but still don't work, so disable
76 if [ $IS_WINDOWS -eq 0 ]; then
81 # reset global git config
83 rm -rf "$TRASHDIR/home"
85 cp "$TESTHOME/.gitconfig" "$HOME/.gitconfig"
87 # do not let Git use a different configuration file
91 # allow the subshell to exit non-zero without exiting this process
95 # Mark the end of a test.
97 test_status="${1:-$?}"
100 # close fd 5 (GIT_TRACE)
103 if [ "$test_status" -eq 0 ]; then
104 printf "ok %d - %-60s\n" "$tests" "$test_description ..."
106 failures=$(( failures + 1 ))
107 printf "not ok %d - %-60s\n" "$tests" "$test_description ..."
109 echo "# -- stdout --"
110 sed 's/^/# /' <"$TRASHDIR/out"
111 echo "# -- stderr --"
112 grep -v -e '^\+ end_test' -e '^+ set +x' <"$TRASHDIR/err" |
114 if [ $IS_WINDOWS -eq 0 ]; then
115 echo "# -- git trace --"
116 sed 's/^/# /' <"$TRASHDIR/trace"
121 unset test_description