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>maint
parent
ae75342cff
commit
517cd55fd5
|
@ -47,8 +47,13 @@ test_expect_failure 'pretend we have a known breakage' '
|
||||||
|
|
||||||
run_sub_test_lib_test () {
|
run_sub_test_lib_test () {
|
||||||
name="$1" descr="$2" # stdin is the body of the test code
|
name="$1" descr="$2" # stdin is the body of the test code
|
||||||
|
shift 2
|
||||||
mkdir "$name" &&
|
mkdir "$name" &&
|
||||||
(
|
(
|
||||||
|
# Pretend we're a test harness. This prevents
|
||||||
|
# test-lib from writing the counts to a file that will
|
||||||
|
# later be summarized, showing spurious "failed" tests
|
||||||
|
export HARNESS_ACTIVE=t &&
|
||||||
cd "$name" &&
|
cd "$name" &&
|
||||||
cat >"$name.sh" <<-EOF &&
|
cat >"$name.sh" <<-EOF &&
|
||||||
#!$SHELL_PATH
|
#!$SHELL_PATH
|
||||||
|
@ -65,7 +70,7 @@ run_sub_test_lib_test () {
|
||||||
cat >>"$name.sh" &&
|
cat >>"$name.sh" &&
|
||||||
chmod +x "$name.sh" &&
|
chmod +x "$name.sh" &&
|
||||||
export TEST_DIRECTORY &&
|
export TEST_DIRECTORY &&
|
||||||
./"$name.sh" >out 2>err
|
./"$name.sh" "$@" >out 2>err
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +220,36 @@ test_expect_success 'pretend we have a mix of all possible results' "
|
||||||
EOF
|
EOF
|
||||||
"
|
"
|
||||||
|
|
||||||
|
test_expect_success 'test --verbose' '
|
||||||
|
test_must_fail run_sub_test_lib_test \
|
||||||
|
test-verbose "test verbose" --verbose <<-\EOF &&
|
||||||
|
test_expect_success "passing test" true
|
||||||
|
test_expect_success "test with output" "echo foo"
|
||||||
|
test_expect_success "failing test" false
|
||||||
|
test_done
|
||||||
|
EOF
|
||||||
|
mv test-verbose/out test-verbose/out+
|
||||||
|
grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
|
||||||
|
check_sub_test_lib_test test-verbose <<-\EOF
|
||||||
|
> expecting success: true
|
||||||
|
> Z
|
||||||
|
> ok 1 - passing test
|
||||||
|
> Z
|
||||||
|
> expecting success: echo foo
|
||||||
|
> foo
|
||||||
|
> Z
|
||||||
|
> ok 2 - test with output
|
||||||
|
> Z
|
||||||
|
> expecting success: false
|
||||||
|
> Z
|
||||||
|
> not ok 3 - failing test
|
||||||
|
> # false
|
||||||
|
> Z
|
||||||
|
> # failed 1 among 3 test(s)
|
||||||
|
> 1..3
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
|
||||||
test_set_prereq HAVEIT
|
test_set_prereq HAVEIT
|
||||||
haveit=no
|
haveit=no
|
||||||
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
|
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
|
||||||
|
|
|
@ -414,6 +414,8 @@ test_at_end_hook_ () {
|
||||||
test_done () {
|
test_done () {
|
||||||
GIT_EXIT_OK=t
|
GIT_EXIT_OK=t
|
||||||
|
|
||||||
|
# Note: t0000 relies on $HARNESS_ACTIVE disabling the .counts
|
||||||
|
# output file
|
||||||
if test -z "$HARNESS_ACTIVE"
|
if test -z "$HARNESS_ACTIVE"
|
||||||
then
|
then
|
||||||
test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"
|
test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"
|
||||||
|
|
Loading…
Reference in New Issue