Skip to content

Commit 04ece59

Browse files
author
Junio C Hamano
committed
GIT_SKIP_TESTS: allow users to omit tests that are known to break
In some environments, certain tests have no way of succeeding due to platform limitation, such as lack of 'unzip' program, or filesystem that do not allow arbitrary sequence of non-NUL bytes as pathnames. You should be able to say something like $ cd t $ GIT_SKIP_TESTS=t9200.8 t9200-git-cvsexport-commit.sh and even: $ GIT_SKIP_TESTS='t[0-4]??? t91?? t9200.8' make test to omit such tests. The value of the environment variable is a SP separated list of patterns that tells which tests to skip, and either can match the "t[0-9]{4}" part to skip the whole test, or t[0-9]{4} followed by ".$number" to say which particular test to skip. Note that some tests in the existing test suite rely on previous test item, so you cannot arbitrarily disable one and expect the remainder of test to check what the test originally was intended to check. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 3bd5c81 commit 04ece59

File tree

1 file changed

+70
-18
lines changed

1 file changed

+70
-18
lines changed

t/test-lib.sh

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,44 +125,77 @@ test_run_ () {
125125
return 0
126126
}
127127

128+
test_skip () {
129+
this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
130+
this_test="$this_test.$(expr "$test_count" + 1)"
131+
to_skip=
132+
for skp in $GIT_SKIP_TESTS
133+
do
134+
case "$this_test" in
135+
$skp)
136+
to_skip=t
137+
esac
138+
done
139+
case "$to_skip" in
140+
t)
141+
say >&3 "skipping test: $@"
142+
test_count=$(expr "$test_count" + 1)
143+
say "skip $test_count: $1"
144+
: true
145+
;;
146+
*)
147+
false
148+
;;
149+
esac
150+
}
151+
128152
test_expect_failure () {
129153
test "$#" = 2 ||
130154
error "bug in the test script: not 2 parameters to test-expect-failure"
131-
say >&3 "expecting failure: $2"
132-
test_run_ "$2"
133-
if [ "$?" = 0 -a "$eval_ret" != 0 -a "$eval_ret" -lt 129 ]
155+
if ! test_skip "$@"
134156
then
135-
test_ok_ "$1"
136-
else
137-
test_failure_ "$@"
157+
say >&3 "expecting failure: $2"
158+
test_run_ "$2"
159+
if [ "$?" = 0 -a "$eval_ret" != 0 -a "$eval_ret" -lt 129 ]
160+
then
161+
test_ok_ "$1"
162+
else
163+
test_failure_ "$@"
164+
fi
138165
fi
139166
echo >&3 ""
140167
}
141168

142169
test_expect_success () {
143170
test "$#" = 2 ||
144171
error "bug in the test script: not 2 parameters to test-expect-success"
145-
say >&3 "expecting success: $2"
146-
test_run_ "$2"
147-
if [ "$?" = 0 -a "$eval_ret" = 0 ]
172+
if ! test_skip "$@"
148173
then
149-
test_ok_ "$1"
150-
else
151-
test_failure_ "$@"
174+
say >&3 "expecting success: $2"
175+
test_run_ "$2"
176+
if [ "$?" = 0 -a "$eval_ret" = 0 ]
177+
then
178+
test_ok_ "$1"
179+
else
180+
test_failure_ "$@"
181+
fi
152182
fi
153183
echo >&3 ""
154184
}
155185

156186
test_expect_code () {
157187
test "$#" = 3 ||
158188
error "bug in the test script: not 3 parameters to test-expect-code"
159-
say >&3 "expecting exit code $1: $3"
160-
test_run_ "$3"
161-
if [ "$?" = 0 -a "$eval_ret" = "$1" ]
189+
if ! test_skip "$@"
162190
then
163-
test_ok_ "$2"
164-
else
165-
test_failure_ "$@"
191+
say >&3 "expecting exit code $1: $3"
192+
test_run_ "$3"
193+
if [ "$?" = 0 -a "$eval_ret" = "$1" ]
194+
then
195+
test_ok_ "$2"
196+
else
197+
test_failure_ "$@"
198+
fi
166199
fi
167200
echo >&3 ""
168201
}
@@ -223,3 +256,22 @@ test=trash
223256
rm -fr "$test"
224257
test_create_repo $test
225258
cd "$test"
259+
260+
this_test=$(expr "./$0" : '.*/\(t[0-9]*\)-[^/]*$')
261+
for skp in $GIT_SKIP_TESTS
262+
do
263+
to_skip=
264+
for skp in $GIT_SKIP_TESTS
265+
do
266+
case "$this_test" in
267+
$skp)
268+
to_skip=t
269+
esac
270+
done
271+
case "$to_skip" in
272+
t)
273+
say >&3 "skipping test $this_test altogether"
274+
say "skip all tests in $this_test"
275+
test_done
276+
esac
277+
done

0 commit comments

Comments
 (0)