Mercurial > public > mercurial-scm > hg-stable
diff tests/test-run-tests.t @ 32356:7340465bd788
run-tests: support multiple cases in .t test
Sometimes we want to run similar tests with slightly different
configurations. Previously we duplicate the test files. This patch
introduces special "#testcases" syntax that allows a single .t file to
contain multiple test cases.
Defined cases could be tested using "#if".
For example, if a test should behave the same with or without an
experimental flag, we can add the following to the .t header:
#testcases default experimental-a
#if experimental-a
$ cat >> $HGRCPATH << EOF
> [experimental]
> feature=a
> EOF
#endif
The "experimental-a" block won't be executed when running the "default" test
case.
author | Jun Wu <quark@fb.com> |
---|---|
date | Tue, 16 May 2017 23:10:31 -0700 |
parents | 4eec2f04a672 |
children | c2b7fb580794 |
line wrap: on
line diff
--- a/tests/test-run-tests.t Wed May 17 19:52:18 2017 -0700 +++ b/tests/test-run-tests.t Tue May 16 23:10:31 2017 -0700 @@ -900,3 +900,78 @@ # Ran 1 tests, 0 skipped, 0 warned, 1 failed. python hash seed: * (glob) [1] + + $ cd .. + +Test cases in .t files +====================== + $ mkdir cases + $ cd cases + $ cat > test-cases-abc.t <<'EOF' + > #testcases A B C + > $ V=B + > #if A + > $ V=A + > #endif + > #if C + > $ V=C + > #endif + > $ echo $V | sed 's/A/C/' + > C + > #if C + > $ [ $V = C ] + > #endif + > #if A + > $ [ $V = C ] + > [1] + > #endif + > #if no-C + > $ [ $V = C ] + > [1] + > #endif + > $ [ $V = D ] + > [1] + > EOF + $ rt + . + --- $TESTTMP/anothertests/cases/test-cases-abc.t + +++ $TESTTMP/anothertests/cases/test-cases-abc.t.B.err + @@ -7,7 +7,7 @@ + $ V=C + #endif + $ echo $V | sed 's/A/C/' + - C + + B + #if C + $ [ $V = C ] + #endif + + ERROR: test-cases-abc.t (case B) output changed + !. + Failed test-cases-abc.t (case B): output changed + # Ran 3 tests, 0 skipped, 0 warned, 1 failed. + python hash seed: * (glob) + [1] + +--restart works + + $ rt --restart + + --- $TESTTMP/anothertests/cases/test-cases-abc.t + +++ $TESTTMP/anothertests/cases/test-cases-abc.t.B.err + @@ -7,7 +7,7 @@ + $ V=C + #endif + $ echo $V | sed 's/A/C/' + - C + + B + #if C + $ [ $V = C ] + #endif + + ERROR: test-cases-abc.t (case B) output changed + !. + Failed test-cases-abc.t (case B): output changed + # Ran 2 tests, 0 skipped, 0 warned, 1 failed. + python hash seed: * (glob) + [1]