Allow enabling multiple warnings in one invocation

This commit is contained in:
Martin Hořeňovský 2021-12-18 20:48:43 +01:00
parent 840acedf62
commit 3cc0c033e4
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
14 changed files with 165 additions and 11 deletions

View File

@ -217,6 +217,8 @@ flag for C++ compilers. It turns some suspicious occurences, like a section
without assertions, into errors. Because these might be intended, warnings
are not enabled by default, but user can opt in.
You can enable multiple warnings at the same time.
There are currently two warnings implemented:
```

View File

@ -174,6 +174,7 @@ new design.
* You can have multiple tests with the same name, as long as other parts of the test identity differ (#1915, #1999, #2175)
* Test identity includes test's name, test's tags and and test's class name if applicable.
* Added new warning, `UnmatchedTestSpec`, to error on test specs with no matching tests
* The `-w`, `--warn` warning flags can now be provided multiple times to enable multiple warnings
### Fixes

View File

@ -25,10 +25,10 @@ namespace Catch {
auto const setWarning = [&]( std::string const& warning ) {
if ( warning == "NoAssertions" ) {
config.warnings = WarnAbout::NoAssertions;
config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::NoAssertions);
return ParserResult::ok( ParseResultType::Matched );
} else if ( warning == "UnmatchedTestSpec" ) {
config.warnings = WarnAbout::UnmatchedTestSpec;
config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::UnmatchedTestSpec);
return ParserResult::ok( ParseResultType::Matched );
}
@ -217,7 +217,7 @@ namespace Catch {
| Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" )
["-x"]["--abortx"]
( "abort after x failures" )
| Opt( setWarning, "warning name" )
| Opt( accept_many, setWarning, "warning name" )
["-w"]["--warn"]
( "enable warnings" )
| Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" )

View File

@ -237,6 +237,13 @@ set_tests_properties(Warnings::UnmatchedTestSpecIsAccepted
FAIL_REGULAR_EXPRESSION "Unrecognised warning option: "
)
add_test(NAME Warnings::MultipleWarningsCanBeSpecified
COMMAND
$<TARGET_FILE:SelfTest> Tracker
--warn NoAssertions
--warn UnmatchedTestSpec
)
add_test(NAME TestSpecs::WarnUnmatchedTestSpecFailsWithUnmatchedTestSpec
COMMAND
$<TARGET_FILE:SelfTest> Tracker, "___nonexistent_test___" --warn UnmatchedTestSpec

View File

@ -179,6 +179,7 @@ Nor would this
:test-result: PASS Overloaded comma or address-of operators are not used
:test-result: PASS Parse test names and tags
:test-result: PASS Parsing sharding-related cli flags
:test-result: PASS Parsing warnings
:test-result: PASS Pointers can be compared to null
:test-result: PASS Precision of floating point stringification can be set
:test-result: PASS Predicate matcher can accept const char*

View File

@ -1200,6 +1200,11 @@ CmdLine.tests.cpp:<line number>: passed: !(result) for: !{?}
CmdLine.tests.cpp:<line number>: passed: result.errorMessage(), ContainsSubstring("Shard index must be a non-negative number") for: "Shard index must be a non-negative number" contains: "Shard index must be a non-negative number"
CmdLine.tests.cpp:<line number>: passed: cli.parse({ "test", "--shard-index=0" }) for: {?}
CmdLine.tests.cpp:<line number>: passed: config.shardIndex == 0 for: 0 == 0
CmdLine.tests.cpp:<line number>: passed: cli.parse( { "test", "-w", "NoAssertions" } ) for: {?}
CmdLine.tests.cpp:<line number>: passed: config.warnings == WarnAbout::NoAssertions for: 1 == 1
CmdLine.tests.cpp:<line number>: passed: !(cli.parse( { "test", "-w", "NoTests" } )) for: !{?}
CmdLine.tests.cpp:<line number>: passed: cli.parse( { "test", "--warn", "NoAssertions", "--warn", "UnmatchedTestSpec" } ) for: {?}
CmdLine.tests.cpp:<line number>: passed: config.warnings == ( WarnAbout::NoAssertions | WarnAbout::UnmatchedTestSpec ) for: 3 == 3
Condition.tests.cpp:<line number>: passed: p == 0 for: 0 == 0
Condition.tests.cpp:<line number>: passed: p == pNULL for: 0 == 0
Condition.tests.cpp:<line number>: passed: p != 0 for: 0x<hex digits> != 0

View File

@ -1426,6 +1426,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 376 | 299 passed | 70 failed | 7 failed as expected
assertions: 2149 | 1993 passed | 129 failed | 27 failed as expected
test cases: 377 | 300 passed | 70 failed | 7 failed as expected
assertions: 2154 | 1998 passed | 129 failed | 27 failed as expected

View File

@ -8784,6 +8784,52 @@ CmdLine.tests.cpp:<line number>: PASSED:
with expansion:
0 == 0
-------------------------------------------------------------------------------
Parsing warnings
NoAssertions
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( cli.parse( { "test", "-w", "NoAssertions" } ) )
with expansion:
{?}
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( config.warnings == WarnAbout::NoAssertions )
with expansion:
1 == 1
-------------------------------------------------------------------------------
Parsing warnings
NoTests is no longer supported
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( cli.parse( { "test", "-w", "NoTests" } ) )
with expansion:
!{?}
-------------------------------------------------------------------------------
Parsing warnings
Combining multiple warnings
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( cli.parse( { "test", "--warn", "NoAssertions", "--warn", "UnmatchedTestSpec" } ) )
with expansion:
{?}
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( config.warnings == ( WarnAbout::NoAssertions | WarnAbout::UnmatchedTestSpec ) )
with expansion:
3 == 3
-------------------------------------------------------------------------------
Pointers can be compared to null
-------------------------------------------------------------------------------
@ -17275,6 +17321,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 376 | 283 passed | 86 failed | 7 failed as expected
assertions: 2166 | 1993 passed | 146 failed | 27 failed as expected
test cases: 377 | 284 passed | 86 failed | 7 failed as expected
assertions: 2171 | 1998 passed | 146 failed | 27 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="129" tests="2166" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="129" tests="2171" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
@ -1070,6 +1070,9 @@ Message.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Parsing sharding-related cli flags/shard-index" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Parsing sharding-related cli flags/Negative shard index reports error" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Parsing sharding-related cli flags/Shard index 0 is accepted" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Parsing warnings/NoAssertions" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Parsing warnings/NoTests is no longer supported" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Parsing warnings/Combining multiple warnings" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Pointers can be compared to null" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Precision of floating point stringification can be set/Floats" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Precision of floating point stringification can be set/Double" time="{duration}" status="run"/>

View File

@ -52,6 +52,9 @@
<testCase name="Parsing sharding-related cli flags/shard-index" duration="{duration}"/>
<testCase name="Parsing sharding-related cli flags/Negative shard index reports error" duration="{duration}"/>
<testCase name="Parsing sharding-related cli flags/Shard index 0 is accepted" duration="{duration}"/>
<testCase name="Parsing warnings/NoAssertions" duration="{duration}"/>
<testCase name="Parsing warnings/NoTests is no longer supported" duration="{duration}"/>
<testCase name="Parsing warnings/Combining multiple warnings" duration="{duration}"/>
<testCase name="Process can be configured on command line/empty args don't cause a crash" duration="{duration}"/>
<testCase name="Process can be configured on command line/default - no arguments" duration="{duration}"/>
<testCase name="Process can be configured on command line/test lists/Specify one test case using" duration="{duration}"/>

View File

@ -2322,6 +2322,16 @@ ok {test-number} - result.errorMessage(), ContainsSubstring("Shard index must be
ok {test-number} - cli.parse({ "test", "--shard-index=0" }) for: {?}
# Parsing sharding-related cli flags
ok {test-number} - config.shardIndex == 0 for: 0 == 0
# Parsing warnings
ok {test-number} - cli.parse( { "test", "-w", "NoAssertions" } ) for: {?}
# Parsing warnings
ok {test-number} - config.warnings == WarnAbout::NoAssertions for: 1 == 1
# Parsing warnings
ok {test-number} - !(cli.parse( { "test", "-w", "NoTests" } )) for: !{?}
# Parsing warnings
ok {test-number} - cli.parse( { "test", "--warn", "NoAssertions", "--warn", "UnmatchedTestSpec" } ) for: {?}
# Parsing warnings
ok {test-number} - config.warnings == ( WarnAbout::NoAssertions | WarnAbout::UnmatchedTestSpec ) for: 3 == 3
# Pointers can be compared to null
ok {test-number} - p == 0 for: 0 == 0
# Pointers can be compared to null
@ -4334,5 +4344,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2166
1..2171

View File

@ -463,6 +463,8 @@ Message.tests.cpp:<line number>|nexplicit failure with message:|n "Message from
##teamcity[testFinished name='Parse test names and tags' duration="{duration}"]
##teamcity[testStarted name='Parsing sharding-related cli flags']
##teamcity[testFinished name='Parsing sharding-related cli flags' duration="{duration}"]
##teamcity[testStarted name='Parsing warnings']
##teamcity[testFinished name='Parsing warnings' duration="{duration}"]
##teamcity[testStarted name='Pointers can be compared to null']
##teamcity[testFinished name='Pointers can be compared to null' duration="{duration}"]
##teamcity[testStarted name='Precision of floating point stringification can be set']

View File

@ -10679,6 +10679,58 @@ Nor would this
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Parsing warnings" tags="[cli][warnings]" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Section name="NoAssertions" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Original>
cli.parse( { "test", "-w", "NoAssertions" } )
</Original>
<Expanded>
{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Original>
config.warnings == WarnAbout::NoAssertions
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<Section name="NoTests is no longer supported" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Original>
!(cli.parse( { "test", "-w", "NoTests" } ))
</Original>
<Expanded>
!{?}
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Combining multiple warnings" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Original>
cli.parse( { "test", "--warn", "NoAssertions", "--warn", "UnmatchedTestSpec" } )
</Original>
<Expanded>
{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp" >
<Original>
config.warnings == ( WarnAbout::NoAssertions | WarnAbout::UnmatchedTestSpec )
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Pointers can be compared to null" filename="tests/<exe-name>/UsageTests/Condition.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Condition.tests.cpp" >
<Original>
@ -20238,6 +20290,6 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1993" failures="146" expectedFailures="27"/>
<OverallResultsCases successes="283" failures="86" expectedFailures="7"/>
<OverallResults successes="1998" failures="146" expectedFailures="27"/>
<OverallResultsCases successes="284" failures="86" expectedFailures="7"/>
</Catch2TestRun>

View File

@ -618,6 +618,28 @@ TEST_CASE("Parsing sharding-related cli flags", "[sharding]") {
}
TEST_CASE( "Parsing warnings", "[cli][warnings]" ) {
using Catch::WarnAbout;
Catch::ConfigData config;
auto cli = Catch::makeCommandLineParser( config );
SECTION( "NoAssertions" ) {
REQUIRE(cli.parse( { "test", "-w", "NoAssertions" } ));
REQUIRE( config.warnings == WarnAbout::NoAssertions );
}
SECTION( "NoTests is no longer supported" ) {
REQUIRE_FALSE(cli.parse( { "test", "-w", "NoTests" } ));
}
SECTION( "Combining multiple warnings" ) {
REQUIRE( cli.parse( { "test",
"--warn", "NoAssertions",
"--warn", "UnmatchedTestSpec" } ) );
REQUIRE( config.warnings == ( WarnAbout::NoAssertions | WarnAbout::UnmatchedTestSpec ) );
}
}
TEST_CASE("Test with special, characters \"in name", "[cli][regression]") {
// This test case succeeds if we can invoke it from the CLI
SUCCEED();