Retry only for https protocol
[elinks.git] / test / libtest.sh
bloba16e4577f5c0b901d88d7fe1c1378eadd23acb79
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 # For repeatability, reset the environment to known value.
7 LANG=C
8 LC_ALL=C
9 PAGER=cat
10 TZ=UTC
11 export LANG LC_ALL PAGER TZ
13 # Each test should start with something like this, after copyright notices:
15 # test_description='Description of this test...
16 # This test checks if command xyzzy does the right thing...
17 # '
18 # . "$TEST_LIB
20 error () {
21 echo "* error: $*"
22 trap - exit
23 exit 1
26 say () {
27 echo "* $*"
30 normalize () {
31 echo "$@" | sed '
32 s/^[ \t]*\[[^]]*\][ \t]*//;
33 s/[:., \t][:., \t]*/-/g;
34 s/_/-/g;
35 # *cough*
36 y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;
37 s/[^a-zA-Z0-9-]//g;'
41 test "${test_description}" != "" ||
42 error "Test script did not set test_description."
44 while test "$#" -ne 0
46 case "$1" in
47 -d|--d|--de|--deb|--debu|--debug)
48 debug=t; shift ;;
49 -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
50 immediate=t; shift ;;
51 -h|--h|--he|--hel|--help)
52 echo "$test_description"
53 exit 0 ;;
54 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
55 verbose=t; shift ;;
57 break ;;
58 esac
59 done
61 exec 5>&1
62 if test "$verbose" = "t"
63 then
64 exec 4>&2 3>&1
65 else
66 exec 4>/dev/null 3>/dev/null
69 test_failure=0
70 test_count=0
72 trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit
74 # Test the binaries we have just built. The tests are kept in
75 # test/ subdirectory and are run in test/trash subdirectory.
76 export PATH="$(pwd):$PATH"
78 for dep in $DEPS; do
79 test -e "$dep" || error "You haven't built things yet, have you?"
80 done
83 # You are not expected to call test_ok_ and test_failure_ directly, use
84 # the text_expect_* functions instead.
86 test_ok_ () {
87 test_count=$(expr "$test_count" + 1)
88 say " ok $test_count: $@"
91 test_failure_ () {
92 test_count=$(expr "$test_count" + 1)
93 test_failure=$(expr "$test_failure" + 1);
94 say "FAIL $test_count: $1"
95 shift
96 echo "$@" | sed -e 's/^/ /'
97 test "$immediate" = "" || { trap - exit; exit 1; }
101 test_debug () {
102 test "$debug" = "" || eval "$1"
105 test_run_ () {
106 eval >&3 2>&4 "$1"
107 eval_ret="$?"
108 return 0
111 test_expect_failure () {
112 test "$#" = 2 ||
113 error "bug in the test script: not 2 parameters to test-expect-failure"
114 say >&3 "expecting failure: $2"
115 test_run_ "$2"
116 if [ "$?" = 0 -a "$eval_ret" != 0 ]
117 then
118 test_ok_ "$1"
119 else
120 test_failure_ "$@"
124 test_expect_success () {
125 test "$#" = 2 ||
126 error "bug in the test script: not 2 parameters to test-expect-success"
127 say >&3 "expecting success: $2"
128 test_run_ "$2"
129 if [ "$?" = 0 -a "$eval_ret" = 0 ]
130 then
131 test_ok_ "$1"
132 else
133 test_failure_ "$@"
137 test_expect_code () {
138 test "$#" = 3 ||
139 error "bug in the test script: not 3 parameters to test-expect-code"
140 say >&3 "expecting exit code $1: $3"
141 test_run_ "$3"
142 if [ "$?" = 0 -a "$eval_ret" = "$1" ]
143 then
144 test_ok_ "$2"
145 else
146 test_failure_ "$@"
150 test_done () {
151 trap - exit
152 case "$test_failure" in
154 # We could:
155 # cd .. && rm -fr trash
156 # but that means we forbid any tests that use their own
157 # subdirectory from calling test_done without coming back
158 # to where they started from.
159 # The Makefile provided will clean this test area so
160 # we will leave things as they are.
162 say "passed all $test_count test(s)"
163 exit 0 ;;
166 say "failed $test_failure among $test_count test(s)"
167 exit 1 ;;
169 esac
172 # Test repository
173 test=trash
174 rm -fr "$test"
175 mkdir "$test"
176 cd "$test" || error "Cannot setup test environment"