Skip to content

Commit ca8470f

Browse files
dvirtzhorenmar
authored andcommitted
catchorg#1175 - don't list hidden tests by default
1 parent 355b3f9 commit ca8470f

14 files changed

+134
-31
lines changed

CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,23 @@ if (BUILD_TESTING AND NOT_SUBPROJECT)
357357
add_test(NAME RunTests COMMAND $<TARGET_FILE:SelfTest>)
358358

359359
add_test(NAME ListTests COMMAND $<TARGET_FILE:SelfTest> --list-tests --verbosity high)
360-
set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
360+
set_tests_properties(ListTests PROPERTIES
361+
PASS_REGULAR_EXPRESSION "[0-9]+ test cases"
362+
FAIL_REGULAR_EXPRESSION "Hidden Test"
363+
)
361364

362365
add_test(NAME ListTags COMMAND $<TARGET_FILE:SelfTest> --list-tags)
363-
set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
366+
set_tests_properties(ListTags PROPERTIES
367+
PASS_REGULAR_EXPRESSION "[0-9]+ tags"
368+
FAIL_REGULAR_EXPRESSION "[.]")
364369

365370
add_test(NAME ListReporters COMMAND $<TARGET_FILE:SelfTest> --list-reporters)
366371
set_tests_properties(ListReporters PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:")
367372

368373
add_test(NAME ListTestNamesOnly COMMAND $<TARGET_FILE:SelfTest> --list-test-names-only)
369-
set_tests_properties(ListTestNamesOnly PROPERTIES PASS_REGULAR_EXPRESSION "Regex string matcher")
374+
set_tests_properties(ListTestNamesOnly PROPERTIES
375+
PASS_REGULAR_EXPRESSION "Regex string matcher"
376+
FAIL_REGULAR_EXPRESSION "Hidden Test")
370377

371378
add_test(NAME NoAssertions COMMAND $<TARGET_FILE:SelfTest> -w NoAssertions)
372379
set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case")

include/internal/catch_config.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ namespace Catch {
1515
: m_data( data ),
1616
m_stream( openStream() )
1717
{
18-
if( !data.testsOrTags.empty() ) {
19-
TestSpecParser parser( ITagAliasRegistry::get() );
18+
TestSpecParser parser(ITagAliasRegistry::get());
19+
if (data.testsOrTags.empty()) {
20+
parser.parse("~[.]"); // All not hidden tests
21+
}
22+
else {
23+
m_hasTestFilters = true;
2024
for( auto const& testOrTags : data.testsOrTags )
2125
parser.parse( testOrTags );
22-
m_testSpec = parser.testSpec();
2326
}
27+
m_testSpec = parser.testSpec();
2428
}
2529

2630
std::string const& Config::getFilename() const {
@@ -39,6 +43,7 @@ namespace Catch {
3943
std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
4044

4145
TestSpec const& Config::testSpec() const { return m_testSpec; }
46+
bool Config::hasTestFilters() const { return m_hasTestFilters; }
4247

4348
bool Config::showHelp() const { return m_data.showHelp; }
4449

include/internal/catch_config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace Catch {
8282
std::vector<std::string> const& getSectionsToRun() const override;
8383

8484
virtual TestSpec const& testSpec() const override;
85+
bool hasTestFilters() const override;
8586

8687
bool showHelp() const;
8788

@@ -109,6 +110,7 @@ namespace Catch {
109110

110111
std::unique_ptr<IStream const> m_stream;
111112
TestSpec m_testSpec;
113+
bool m_hasTestFilters = false;
112114
};
113115

114116
} // end namespace Catch

include/internal/catch_interfaces_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace Catch {
6868
virtual bool showInvisibles() const = 0;
6969
virtual ShowDurations::OrNot showDurations() const = 0;
7070
virtual TestSpec const& testSpec() const = 0;
71+
virtual bool hasTestFilters() const = 0;
7172
virtual RunTests::InWhatOrder runOrder() const = 0;
7273
virtual unsigned int rngSeed() const = 0;
7374
virtual int benchmarkResolutionMultiple() const = 0;

include/internal/catch_list.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ namespace Catch {
2828

2929
std::size_t listTests( Config const& config ) {
3030
TestSpec testSpec = config.testSpec();
31-
if( config.testSpec().hasFilters() )
31+
if( config.hasTestFilters() )
3232
Catch::cout() << "Matching test cases:\n";
3333
else {
3434
Catch::cout() << "All available test cases:\n";
35-
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
3635
}
3736

3837
auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
@@ -54,7 +53,7 @@ namespace Catch {
5453
Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n";
5554
}
5655

57-
if( !config.testSpec().hasFilters() )
56+
if( !config.hasTestFilters() )
5857
Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl;
5958
else
6059
Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl;
@@ -63,8 +62,6 @@ namespace Catch {
6362

6463
std::size_t listTestsNamesOnly( Config const& config ) {
6564
TestSpec testSpec = config.testSpec();
66-
if( !config.testSpec().hasFilters() )
67-
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
6865
std::size_t matchedTests = 0;
6966
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
7067
for( auto const& testCaseInfo : matchedTestCases ) {
@@ -94,11 +91,10 @@ namespace Catch {
9491

9592
std::size_t listTags( Config const& config ) {
9693
TestSpec testSpec = config.testSpec();
97-
if( config.testSpec().hasFilters() )
94+
if( config.hasTestFilters() )
9895
Catch::cout() << "Tags for matching test cases:\n";
9996
else {
10097
Catch::cout() << "All available tags:\n";
101-
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
10298
}
10399

104100
std::map<std::string, TagInfo> tagCounts;

include/internal/catch_session.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ namespace Catch {
7070
context.testGroupStarting(config->name(), 1, 1);
7171

7272
TestSpec testSpec = config->testSpec();
73-
if (!testSpec.hasFilters())
74-
testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("~[.]").testSpec(); // All not hidden tests
7573

7674
auto const& allTestCases = getAllTestCasesSorted(*config);
7775
for (auto const& testCase : allTestCases) {

projects/SelfTest/Baselines/compact.sw.approved.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Compilation.tests.cpp:<line number>: passed: t1 < t2 for: {?} < {?}
99
Compilation.tests.cpp:<line number>: passed: t1 > t2 for: {?} > {?}
1010
Compilation.tests.cpp:<line number>: passed: t1 <= t2 for: {?} <= {?}
1111
Compilation.tests.cpp:<line number>: passed: t1 >= t2 for: {?} >= {?}
12+
Misc.tests.cpp:<line number>: passed:
1213
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception'
1314
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception'
1415
Exception.tests.cpp:<line number>: passed: thisThrows() with 1 message: 'answer := 42'
@@ -514,13 +515,17 @@ CmdLine.tests.cpp:<line number>: passed: config.shouldDebugBreak == false for: f
514515
CmdLine.tests.cpp:<line number>: passed: config.abortAfter == -1 for: -1 == -1
515516
CmdLine.tests.cpp:<line number>: passed: config.noThrow == false for: false == false
516517
CmdLine.tests.cpp:<line number>: passed: config.reporterNames.empty() for: true
518+
CmdLine.tests.cpp:<line number>: passed: !(cfg.hasTestFilters()) for: !false
517519
CmdLine.tests.cpp:<line number>: passed: result for: {?}
520+
CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true
518521
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("notIncluded")) == false for: false == false
519522
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("test1")) for: true
520523
CmdLine.tests.cpp:<line number>: passed: result for: {?}
524+
CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true
521525
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("test1")) == false for: false == false
522526
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("alwaysIncluded")) for: true
523527
CmdLine.tests.cpp:<line number>: passed: result for: {?}
528+
CmdLine.tests.cpp:<line number>: passed: cfg.hasTestFilters() for: true
524529
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("test1")) == false for: false == false
525530
CmdLine.tests.cpp:<line number>: passed: cfg.testSpec().matches(fakeTestCase("alwaysIncluded")) for: true
526531
CmdLine.tests.cpp:<line number>: passed: cli.parse({"test", "-r", "console"}) for: {?}

projects/SelfTest/Baselines/console.std.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,6 @@ with expansion:
10641064
"first" == "second"
10651065

10661066
===============================================================================
1067-
test cases: 198 | 147 passed | 47 failed | 4 failed as expected
1068-
assertions: 999 | 873 passed | 105 failed | 21 failed as expected
1067+
test cases: 199 | 148 passed | 47 failed | 4 failed as expected
1068+
assertions: 1004 | 878 passed | 105 failed | 21 failed as expected
10691069

projects/SelfTest/Baselines/console.sw.approved.txt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ PASSED:
9393
with expansion:
9494
{?} >= {?}
9595

96+
-------------------------------------------------------------------------------
97+
#1175 - Hidden Test
98+
-------------------------------------------------------------------------------
99+
Misc.tests.cpp:<line number>
100+
...............................................................................
101+
102+
Misc.tests.cpp:<line number>:
103+
PASSED:
104+
96105
-------------------------------------------------------------------------------
97106
#748 - captures with unexpected exceptions
98107
outside assertions
@@ -3965,6 +3974,12 @@ PASSED:
39653974
with expansion:
39663975
true
39673976

3977+
CmdLine.tests.cpp:<line number>:
3978+
PASSED:
3979+
CHECK_FALSE( cfg.hasTestFilters() )
3980+
with expansion:
3981+
!false
3982+
39683983
-------------------------------------------------------------------------------
39693984
Process can be configured on command line
39703985
test lists
@@ -3979,6 +3994,12 @@ PASSED:
39793994
with expansion:
39803995
{?}
39813996

3997+
CmdLine.tests.cpp:<line number>:
3998+
PASSED:
3999+
REQUIRE( cfg.hasTestFilters() )
4000+
with expansion:
4001+
true
4002+
39824003
CmdLine.tests.cpp:<line number>:
39834004
PASSED:
39844005
REQUIRE( cfg.testSpec().matches(fakeTestCase("notIncluded")) == false )
@@ -4005,6 +4026,12 @@ PASSED:
40054026
with expansion:
40064027
{?}
40074028

4029+
CmdLine.tests.cpp:<line number>:
4030+
PASSED:
4031+
REQUIRE( cfg.hasTestFilters() )
4032+
with expansion:
4033+
true
4034+
40084035
CmdLine.tests.cpp:<line number>:
40094036
PASSED:
40104037
REQUIRE( cfg.testSpec().matches(fakeTestCase("test1")) == false )
@@ -4031,6 +4058,12 @@ PASSED:
40314058
with expansion:
40324059
{?}
40334060

4061+
CmdLine.tests.cpp:<line number>:
4062+
PASSED:
4063+
REQUIRE( cfg.hasTestFilters() )
4064+
with expansion:
4065+
true
4066+
40344067
CmdLine.tests.cpp:<line number>:
40354068
PASSED:
40364069
REQUIRE( cfg.testSpec().matches(fakeTestCase("test1")) == false )
@@ -8466,6 +8499,6 @@ Misc.tests.cpp:<line number>:
84668499
PASSED:
84678500

84688501
===============================================================================
8469-
test cases: 198 | 133 passed | 61 failed | 4 failed as expected
8470-
assertions: 1010 | 869 passed | 120 failed | 21 failed as expected
8502+
test cases: 199 | 134 passed | 61 failed | 4 failed as expected
8503+
assertions: 1015 | 874 passed | 120 failed | 21 failed as expected
84718504

projects/SelfTest/Baselines/console.swa4.approved.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ PASSED:
9393
with expansion:
9494
{?} >= {?}
9595

96+
-------------------------------------------------------------------------------
97+
#1175 - Hidden Test
98+
-------------------------------------------------------------------------------
99+
Misc.tests.cpp:<line number>
100+
...............................................................................
101+
102+
Misc.tests.cpp:<line number>:
103+
PASSED:
104+
96105
-------------------------------------------------------------------------------
97106
#748 - captures with unexpected exceptions
98107
outside assertions
@@ -299,6 +308,6 @@ with expansion:
299308
!true
300309

301310
===============================================================================
302-
test cases: 11 | 8 passed | 1 failed | 2 failed as expected
303-
assertions: 34 | 27 passed | 4 failed | 3 failed as expected
311+
test cases: 12 | 9 passed | 1 failed | 2 failed as expected
312+
assertions: 35 | 28 passed | 4 failed | 3 failed as expected
304313

projects/SelfTest/Baselines/junit.sw.approved.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuitesloose text artifact
33
>
4-
<testsuite name="<exe-name>" errors="15" failures="106" tests="1011" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
4+
<testsuite name="<exe-name>" errors="15" failures="106" tests="1016" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
55
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
66
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
77
<testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
88
<testcase classname="<exe-name>.global" name="#1147" time="{duration}"/>
9+
<testcase classname="<exe-name>.global" name="#1175 - Hidden Test" time="{duration}"/>
910
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
1011
<error type="TEST_CASE">
1112
expected exception

0 commit comments

Comments
 (0)