Skip to content

Commit 517cd55

Browse files
Thomas Rastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ae75342 commit 517cd55

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

t/t0000-basic.sh

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ test_expect_failure 'pretend we have a known breakage' '
4747

4848
run_sub_test_lib_test () {
4949
name="$1" descr="$2" # stdin is the body of the test code
50+
shift 2
5051
mkdir "$name" &&
5152
(
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 &&
5257
cd "$name" &&
5358
cat >"$name.sh" <<-EOF &&
5459
#!$SHELL_PATH
@@ -65,7 +70,7 @@ run_sub_test_lib_test () {
6570
cat >>"$name.sh" &&
6671
chmod +x "$name.sh" &&
6772
export TEST_DIRECTORY &&
68-
./"$name.sh" >out 2>err
73+
./"$name.sh" "$@" >out 2>err
6974
)
7075
}
7176

@@ -215,6 +220,36 @@ test_expect_success 'pretend we have a mix of all possible results' "
215220
EOF
216221
"
217222

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+
218253
test_set_prereq HAVEIT
219254
haveit=no
220255
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '

t/test-lib.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ test_at_end_hook_ () {
414414
test_done () {
415415
GIT_EXIT_OK=t
416416

417+
# Note: t0000 relies on $HARNESS_ACTIVE disabling the .counts
418+
# output file
417419
if test -z "$HARNESS_ACTIVE"
418420
then
419421
test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"

0 commit comments

Comments
 (0)