Skip to content

Commit 04f2ddd

Browse files
committed
Merge branch 'tr/test-v-and-v-subtest-only'
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
2 parents 56df44a + 62a23c9 commit 04f2ddd

File tree

6 files changed

+276
-53
lines changed

6 files changed

+276
-53
lines changed

t/README

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ appropriately before running "make".
7676
command being run and their output if any are also
7777
output.
7878

79+
--verbose-only=<pattern>::
80+
Like --verbose, but the effect is limited to tests with
81+
numbers matching <pattern>. The number matched against is
82+
simply the running count of the test within the file.
83+
7984
--debug::
8085
This may help the person who is developing a new test.
8186
It causes the command defined with test_debug to run.
@@ -121,6 +126,11 @@ appropriately before running "make".
121126
the 't/valgrind/' directory and use the commands under
122127
't/valgrind/bin/'.
123128

129+
--valgrind-only=<pattern>::
130+
Like --valgrind, but the effect is limited to tests with
131+
numbers matching <pattern>. The number matched against is
132+
simply the running count of the test within the file.
133+
124134
--tee::
125135
In addition to printing the test output to the terminal,
126136
write it to files named 't/test-results/$TEST_NAME.out'.

t/perf/perf-lib.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ exit $ret' >&3 2>&4
150150

151151

152152
test_perf () {
153+
test_start_
153154
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
154155
test "$#" = 2 ||
155156
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
@@ -187,7 +188,7 @@ test_perf () {
187188
base="$perf_results_dir"/"$perf_results_prefix$(basename "$0" .sh)"."$test_count"
188189
"$TEST_DIRECTORY"/perf/min_time.perl test_time.* >"$base".times
189190
fi
190-
echo >&3 ""
191+
test_finish_
191192
}
192193

193194
# We extend test_done to print timings at the end (./run disables this

t/t0000-basic.sh

Lines changed: 60 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,60 @@ 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+
253+
test_expect_success 'test --verbose-only' '
254+
test_must_fail run_sub_test_lib_test \
255+
test-verbose-only-2 "test verbose-only=2" \
256+
--verbose-only=2 <<-\EOF &&
257+
test_expect_success "passing test" true
258+
test_expect_success "test with output" "echo foo"
259+
test_expect_success "failing test" false
260+
test_done
261+
EOF
262+
check_sub_test_lib_test test-verbose-only-2 <<-\EOF
263+
> ok 1 - passing test
264+
> Z
265+
> expecting success: echo foo
266+
> foo
267+
> Z
268+
> ok 2 - test with output
269+
> Z
270+
> not ok 3 - failing test
271+
> # false
272+
> # failed 1 among 3 test(s)
273+
> 1..3
274+
EOF
275+
'
276+
218277
test_set_prereq HAVEIT
219278
haveit=no
220279
test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '

t/test-lib-functions.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ test_declared_prereq () {
343343
}
344344

345345
test_expect_failure () {
346+
test_start_
346347
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
347348
test "$#" = 2 ||
348349
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
@@ -357,10 +358,11 @@ test_expect_failure () {
357358
test_known_broken_failure_ "$1"
358359
fi
359360
fi
360-
echo >&3 ""
361+
test_finish_
361362
}
362363

363364
test_expect_success () {
365+
test_start_
364366
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
365367
test "$#" = 2 ||
366368
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
@@ -375,7 +377,7 @@ test_expect_success () {
375377
test_failure_ "$@"
376378
fi
377379
fi
378-
echo >&3 ""
380+
test_finish_
379381
}
380382

381383
# test_external runs external test scripts that provide continuous

0 commit comments

Comments
 (0)