diff --git a/docs/command-line.md b/docs/command-line.md index 37199c44..b03e7e3c 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -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: ``` diff --git a/docs/release-notes.md b/docs/release-notes.md index 5b3e5c65..ad424c50 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -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 diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp index 71550945..de27e899 100644 --- a/src/catch2/internal/catch_commandline.cpp +++ b/src/catch2/internal/catch_commandline.cpp @@ -25,10 +25,10 @@ namespace Catch { auto const setWarning = [&]( std::string const& warning ) { if ( warning == "NoAssertions" ) { - config.warnings = WarnAbout::NoAssertions; + config.warnings = static_cast(config.warnings | WarnAbout::NoAssertions); return ParserResult::ok( ParseResultType::Matched ); } else if ( warning == "UnmatchedTestSpec" ) { - config.warnings = WarnAbout::UnmatchedTestSpec; + config.warnings = static_cast(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" ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 838227aa..6857f1bd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -237,6 +237,13 @@ set_tests_properties(Warnings::UnmatchedTestSpecIsAccepted FAIL_REGULAR_EXPRESSION "Unrecognised warning option: " ) +add_test(NAME Warnings::MultipleWarningsCanBeSpecified + COMMAND + $ Tracker + --warn NoAssertions + --warn UnmatchedTestSpec +) + add_test(NAME TestSpecs::WarnUnmatchedTestSpecFailsWithUnmatchedTestSpec COMMAND $ Tracker, "___nonexistent_test___" --warn UnmatchedTestSpec diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index c77739c3..8fff84db 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -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* diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 3cd8ba4c..66b385a5 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1200,6 +1200,11 @@ CmdLine.tests.cpp:: passed: !(result) for: !{?} CmdLine.tests.cpp:: 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:: passed: cli.parse({ "test", "--shard-index=0" }) for: {?} CmdLine.tests.cpp:: passed: config.shardIndex == 0 for: 0 == 0 +CmdLine.tests.cpp:: passed: cli.parse( { "test", "-w", "NoAssertions" } ) for: {?} +CmdLine.tests.cpp:: passed: config.warnings == WarnAbout::NoAssertions for: 1 == 1 +CmdLine.tests.cpp:: passed: !(cli.parse( { "test", "-w", "NoTests" } )) for: !{?} +CmdLine.tests.cpp:: passed: cli.parse( { "test", "--warn", "NoAssertions", "--warn", "UnmatchedTestSpec" } ) for: {?} +CmdLine.tests.cpp:: passed: config.warnings == ( WarnAbout::NoAssertions | WarnAbout::UnmatchedTestSpec ) for: 3 == 3 Condition.tests.cpp:: passed: p == 0 for: 0 == 0 Condition.tests.cpp:: passed: p == pNULL for: 0 == 0 Condition.tests.cpp:: passed: p != 0 for: 0x != 0 diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 17f9d281..4147f373 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -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 diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 32654bc3..764ac970 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -8784,6 +8784,52 @@ CmdLine.tests.cpp:: PASSED: with expansion: 0 == 0 +------------------------------------------------------------------------------- +Parsing warnings + NoAssertions +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + REQUIRE( cli.parse( { "test", "-w", "NoAssertions" } ) ) +with expansion: + {?} + +CmdLine.tests.cpp:: PASSED: + REQUIRE( config.warnings == WarnAbout::NoAssertions ) +with expansion: + 1 == 1 + +------------------------------------------------------------------------------- +Parsing warnings + NoTests is no longer supported +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + REQUIRE_FALSE( cli.parse( { "test", "-w", "NoTests" } ) ) +with expansion: + !{?} + +------------------------------------------------------------------------------- +Parsing warnings + Combining multiple warnings +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + REQUIRE( cli.parse( { "test", "--warn", "NoAssertions", "--warn", "UnmatchedTestSpec" } ) ) +with expansion: + {?} + +CmdLine.tests.cpp:: 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: Misc.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 0047eb70..49640ad3 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1070,6 +1070,9 @@ Message.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index e56652ce..dc1f7a54 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -52,6 +52,9 @@ + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 087064df..fe02346f 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -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 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 933ac413..b570833f 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -463,6 +463,8 @@ Message.tests.cpp:|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'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 008cd139..d09dde34 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -10679,6 +10679,58 @@ Nor would this + +
+ + + cli.parse( { "test", "-w", "NoAssertions" } ) + + + {?} + + + + + config.warnings == WarnAbout::NoAssertions + + + 1 == 1 + + + +
+
+ + + !(cli.parse( { "test", "-w", "NoTests" } )) + + + !{?} + + + +
+
+ + + cli.parse( { "test", "--warn", "NoAssertions", "--warn", "UnmatchedTestSpec" } ) + + + {?} + + + + + config.warnings == ( WarnAbout::NoAssertions | WarnAbout::UnmatchedTestSpec ) + + + 3 == 3 + + + +
+ +
@@ -20238,6 +20290,6 @@ loose text artifact - - + + diff --git a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index 332cbe50..16a77bc1 100644 --- a/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -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();