Skip to content

Commit

Permalink
Merge branch 'tr/test-v-and-v-subtest-only'
Browse files Browse the repository at this point in the history
Allows N instances of tests run in parallel, each running 1/N parts
of the test suite under Valgrind, to speed things up.

* tr/test-v-and-v-subtest-only:
  perf-lib: fix start/stop of perf tests
  test-lib: support running tests under valgrind in parallel
  test-lib: allow prefixing a custom string before "ok N" etc.
  test-lib: valgrind for only tests matching a pattern
  test-lib: verbose mode for only tests matching a pattern
  test-lib: self-test that --verbose works
  test-lib: rearrange start/end of test_expect_* and test_skip
  test-lib: refactor $GIT_SKIP_TESTS matching
  test-lib: enable MALLOC_* for the actual tests
  • Loading branch information
Junio C Hamano committed Jul 5, 2013
2 parents 56df44a + 62a23c9 commit 04f2ddd
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 53 deletions.
10 changes: 10 additions & 0 deletions t/README
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ appropriately before running "make".
command being run and their output if any are also
output.

--verbose-only=<pattern>::
Like --verbose, but the effect is limited to tests with
numbers matching <pattern>. The number matched against is
simply the running count of the test within the file.

--debug::
This may help the person who is developing a new test.
It causes the command defined with test_debug to run.
Expand Down Expand Up @@ -121,6 +126,11 @@ appropriately before running "make".
the 't/valgrind/' directory and use the commands under
't/valgrind/bin/'.

--valgrind-only=<pattern>::
Like --valgrind, but the effect is limited to tests with
numbers matching <pattern>. The number matched against is
simply the running count of the test within the file.

--tee::
In addition to printing the test output to the terminal,
write it to files named 't/test-results/$TEST_NAME.out'.
Expand Down
3 changes: 2 additions & 1 deletion t/perf/perf-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ exit $ret' >&3 2>&4


test_perf () {
test_start_
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
Expand Down Expand Up @@ -187,7 +188,7 @@ test_perf () {
base="$perf_results_dir"/"$perf_results_prefix$(basename "$0" .sh)"."$test_count"
"$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".times
fi
echo >&3 ""
test_finish_
}

# We extend test_done to print timings at the end (./run disables this
Expand Down
61 changes: 60 additions & 1 deletion t/t0000-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ test_expect_failure 'pretend we have a known breakage' '

run_sub_test_lib_test () {
name="$1" descr="$2" # stdin is the body of the test code
shift 2
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" &&
cat >"$name.sh" <<-EOF &&
#!$SHELL_PATH
Expand All @@ -65,7 +70,7 @@ run_sub_test_lib_test () {
cat >>"$name.sh" &&
chmod +x "$name.sh" &&
export TEST_DIRECTORY &&
./"$name.sh" >out 2>err
./"$name.sh" "$@" >out 2>err
)
}

Expand Down Expand Up @@ -215,6 +220,60 @@ test_expect_success 'pretend we have a mix of all possible results' "
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_expect_success 'test --verbose-only' '
test_must_fail run_sub_test_lib_test \
test-verbose-only-2 "test verbose-only=2" \
--verbose-only=2 <<-\EOF &&
test_expect_success "passing test" true
test_expect_success "test with output" "echo foo"
test_expect_success "failing test" false
test_done
EOF
check_sub_test_lib_test test-verbose-only-2 <<-\EOF
> ok 1 - passing test
> Z
> expecting success: echo foo
> foo
> Z
> ok 2 - test with output
> Z
> not ok 3 - failing test
> # false
> # failed 1 among 3 test(s)
> 1..3
EOF
'

test_set_prereq HAVEIT
haveit=no
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
Expand Down
6 changes: 4 additions & 2 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ test_declared_prereq () {
}

test_expect_failure () {
test_start_
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
Expand All @@ -357,10 +358,11 @@ test_expect_failure () {
test_known_broken_failure_ "$1"
fi
fi
echo >&3 ""
test_finish_
}

test_expect_success () {
test_start_
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
Expand All @@ -375,7 +377,7 @@ test_expect_success () {
test_failure_ "$@"
fi
fi
echo >&3 ""
test_finish_
}

# test_external runs external test scripts that provide continuous
Expand Down
Loading

0 comments on commit 04f2ddd

Please sign in to comment.