test-lib: self-test that --verbose works
t0000 contains some light self-tests of test-lib.sh, but --verbose was not covered. Add a test. The only catch is that the presence of a test harness influences the output (specifically, the presence of some empty lines). So we need to unset TEST_HARNESS or set it to a known value. Leaving it unset leads to spurious test failures in the final summary, which come from the subtest. So we always set it. Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Jun 23, 2013 at 20:12 UTC
517cd55fd51ebf4c6c20597055ff191fefe5dda0
2 files changed
+38
-1
t/t0000-basic.sh
+36
-1
@@ -47,8 +47,13 @@ test_expect_failure 'pretend we have a known breakage' '
47
48
run_sub_test_lib_test () {
49
name="$1" descr="$2" # stdin is the body of the test code
50
+ shift 2
51
mkdir "$name" &&
52
(
53
+ # Pretend we're a test harness. This prevents
54
+ # test-lib from writing the counts to a file that will
55
+ # later be summarized, showing spurious "failed" tests
56
+ export HARNESS_ACTIVE=t &&
57
cd "$name" &&
58
cat >"$name.sh" <<-EOF &&
59
#!$SHELL_PATH
@@ -65,7 +70,7 @@ run_sub_test_lib_test () {
70
cat >>"$name.sh" &&
71
chmod +x "$name.sh" &&
72
export TEST_DIRECTORY &&
68
- ./"$name.sh" >out 2>err
73
+ ./"$name.sh" "$@" >out 2>err
74
)
75
}
76
@@ -215,6 +220,36 @@ test_expect_success 'pretend we have a mix of all possible results' "
220
EOF
221
"
222
223
+test_expect_success 'test --verbose' '
224
+ test_must_fail run_sub_test_lib_test \
225
+ test-verbose "test verbose" --verbose <<-\EOF &&
226
+ test_expect_success "passing test" true
227
+ test_expect_success "test with output" "echo foo"
228
+ test_expect_success "failing test" false
229
+ test_done
230
+ EOF
231
+ mv test-verbose/out test-verbose/out+
232
+ grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
233
+ check_sub_test_lib_test test-verbose <<-\EOF
234
+ > expecting success: true
235
+ > Z
236
+ > ok 1 - passing test
237
+ > Z
238
+ > expecting success: echo foo
239
+ > foo
240
+ > Z
241
+ > ok 2 - test with output
242
+ > Z
243
+ > expecting success: false
244
+ > Z
245
+ > not ok 3 - failing test
246
+ > # false
247
+ > Z
248
+ > # failed 1 among 3 test(s)
249
+ > 1..3
250
+ EOF
251
+'
252
+
253
test_set_prereq HAVEIT
254
haveit=no
255
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
t/test-lib.sh
+2
@@ -414,6 +414,8 @@ test_at_end_hook_ () {
414
test_done () {
415
GIT_EXIT_OK=t
416
417
+ # Note: t0000 relies on $HARNESS_ACTIVE disabling the .counts
418
+ # output file
419
if test -z "$HARNESS_ACTIVE"
420
then
421
test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"