Add new SKIP macro for skipping tests at runtime (#2360)

* Add new SKIP macro for skipping tests at runtime

This adds a new `SKIP` macro for dynamically skipping tests at runtime.
The "skipped" status of a test case is treated as a first-class citizen,
like "succeeded" or "failed", and is reported with a new color on the
console.

* Don't show "skipped assertions" in console/compact reporters

Also extend skip tests to cover a few more use cases.

* Return exit code 4 if all test cases are skipped

* Use LightGrey for the skip colour

This isn't great, but is better than the deep blue that was borderline
invisible on dark backgrounds. The fix is to redo the colouring
a bit, including introducing light-blue that is actually visible.

* Add support for explicit skips in all reporters

* --allow-running-no-tests also allows all tests to be skipped

* Add docs for SKIP macro, deprecate IEventListener::skipTest

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
This commit is contained in:
Philip Salzmann
2023-01-12 15:01:47 +01:00
committed by GitHub
parent 52066dbc2a
commit d548be26e3
47 changed files with 3722 additions and 2171 deletions

View File

@@ -1164,6 +1164,14 @@ Exception.tests.cpp:<line number>: FAILED:
due to unexpected exception with message:
unexpected exception
-------------------------------------------------------------------------------
a succeeding test can still be skipped
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
-------------------------------------------------------------------------------
checkedElse, failing
-------------------------------------------------------------------------------
@@ -1186,6 +1194,87 @@ Misc.tests.cpp:<line number>: FAILED:
with expansion:
false
-------------------------------------------------------------------------------
dynamic skipping works with generators
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
explicitly with message:
skipping because answer = 41
-------------------------------------------------------------------------------
dynamic skipping works with generators
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
explicitly with message:
skipping because answer = 43
-------------------------------------------------------------------------------
failed assertions before SKIP cause test case to fail
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: FAILED:
CHECK( 3 == 4 )
Skip.tests.cpp:<line number>: SKIPPED:
-------------------------------------------------------------------------------
failing for some generator values causes entire test case to fail
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: FAILED:
-------------------------------------------------------------------------------
failing for some generator values causes entire test case to fail
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
-------------------------------------------------------------------------------
failing for some generator values causes entire test case to fail
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: FAILED:
-------------------------------------------------------------------------------
failing for some generator values causes entire test case to fail
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
-------------------------------------------------------------------------------
failing in some unskipped sections causes entire test case to fail
skipped
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
-------------------------------------------------------------------------------
failing in some unskipped sections causes entire test case to fail
not skipped
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: FAILED:
loose text artifact
-------------------------------------------------------------------------------
just failure
@@ -1304,6 +1393,19 @@ Misc.tests.cpp:<line number>: FAILED:
with expansion:
1 == 2
a!
b1!
-------------------------------------------------------------------------------
nested sections can be skipped dynamically at runtime
B
B2
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
!
-------------------------------------------------------------------------------
not prints unscoped info from previous failures
-------------------------------------------------------------------------------
@@ -1338,6 +1440,15 @@ Message.tests.cpp:<line number>: FAILED:
with message:
this SHOULD be seen only ONCE
-------------------------------------------------------------------------------
sections can be skipped dynamically at runtime
skipped
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
-------------------------------------------------------------------------------
send a single char to INFO
-------------------------------------------------------------------------------
@@ -1361,6 +1472,16 @@ with messages:
hi
i := 7
-------------------------------------------------------------------------------
skipped tests can optionally provide a reason
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
explicitly with message:
skipping because answer = 43
-------------------------------------------------------------------------------
stacks unscoped info in loops
-------------------------------------------------------------------------------
@@ -1383,6 +1504,14 @@ with messages:
5
6
-------------------------------------------------------------------------------
tests can be skipped dynamically at runtime
-------------------------------------------------------------------------------
Skip.tests.cpp:<line number>
...............................................................................
Skip.tests.cpp:<line number>: SKIPPED:
-------------------------------------------------------------------------------
thrown std::strings are translated
-------------------------------------------------------------------------------
@@ -1394,6 +1523,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 395 | 319 passed | 69 failed | 7 failed as expected
assertions: 2148 | 1993 passed | 128 failed | 27 failed as expected
test cases: 404 | 319 passed | 69 failed | 6 skipped | 10 failed as expected
assertions: 2156 | 1997 passed | 128 failed | 31 failed as expected