Skip to content

Commit

Permalink
--list-* flags write to target specified by the -o flag
Browse files Browse the repository at this point in the history
Also added tests for the default implementations of list* reporter
helpers.

Closes #2061
  • Loading branch information
horenmar committed Jan 26, 2021
1 parent 6798c13 commit 971b1fc
Show file tree
Hide file tree
Showing 17 changed files with 1,965 additions and 29 deletions.
16 changes: 0 additions & 16 deletions src/catch2/interfaces/catch_interfaces_reporter.cpp
Expand Up @@ -108,20 +108,4 @@ namespace Catch {

void IStreamingReporter::fatalErrorEncountered( StringRef ) {}

void IStreamingReporter::listReporters(std::vector<ReporterDescription> const& descriptions) {
defaultListReporters(
Catch::cout(), descriptions, m_config->verbosity() );
}

void IStreamingReporter::listTests(std::vector<TestCaseHandle> const& tests) {
defaultListTests( Catch::cout(),
tests,
m_config->hasTestFilters(),
m_config->verbosity() );
}

void IStreamingReporter::listTags(std::vector<TagInfo> const& tags) {
defaultListTags( Catch::cout(), tags, m_config->hasTestFilters() );
}

} // end namespace Catch
6 changes: 3 additions & 3 deletions src/catch2/interfaces/catch_interfaces_reporter.hpp
Expand Up @@ -222,11 +222,11 @@ namespace Catch {
virtual void fatalErrorEncountered( StringRef name );

//! Writes out information about provided reporters using reporter-specific format
virtual void listReporters(std::vector<ReporterDescription> const& descriptions);
virtual void listReporters(std::vector<ReporterDescription> const& descriptions) = 0;
//! Writes out information about provided tests using reporter-specific format
virtual void listTests(std::vector<TestCaseHandle> const& tests);
virtual void listTests(std::vector<TestCaseHandle> const& tests) = 0;
//! Writes out information about the provided tags using reporter-specific format
virtual void listTags(std::vector<TagInfo> const& tags);
virtual void listTags(std::vector<TagInfo> const& tags) = 0;

};
using IStreamingReporterPtr = Detail::unique_ptr<IStreamingReporter>;
Expand Down
16 changes: 16 additions & 0 deletions src/catch2/reporters/catch_reporter_cumulative_base.cpp
Expand Up @@ -6,6 +6,7 @@

// SPDX-License-Identifier: BSL-1.0
#include <catch2/reporters/catch_reporter_cumulative_base.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -110,4 +111,19 @@ namespace Catch {
testRunEndedCumulative();
}

void CumulativeReporterBase::listReporters(std::vector<ReporterDescription> const& descriptions) {
defaultListReporters(stream, descriptions, m_config->verbosity());
}

void CumulativeReporterBase::listTests(std::vector<TestCaseHandle> const& tests) {
defaultListTests(stream,
tests,
m_config->hasTestFilters(),
m_config->verbosity());
}

void CumulativeReporterBase::listTags(std::vector<TagInfo> const& tags) {
defaultListTags( stream, tags, m_config->hasTestFilters() );
}

} // end namespace Catch
5 changes: 5 additions & 0 deletions src/catch2/reporters/catch_reporter_cumulative_base.hpp
Expand Up @@ -69,6 +69,11 @@ namespace Catch {

void skipTest(TestCaseInfo const&) override {}

void listReporters( std::vector<ReporterDescription> const& descriptions ) override;
void listTests( std::vector<TestCaseHandle> const& tests ) override;
void listTags( std::vector<TagInfo> const& tags ) override;


std::ostream& stream;
// Note: We rely on pointer identity being stable, which is why
// which is why we store around pointers rather than values.
Expand Down
16 changes: 16 additions & 0 deletions src/catch2/reporters/catch_reporter_streaming_base.cpp
Expand Up @@ -6,6 +6,7 @@

// SPDX-License-Identifier: BSL-1.0
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
#include <catch2/reporters/catch_reporter_helpers.hpp>

namespace Catch {

Expand All @@ -31,4 +32,19 @@ namespace Catch {
currentTestRunInfo.reset();
}

void StreamingReporterBase::listReporters(std::vector<ReporterDescription> const& descriptions) {
defaultListReporters( stream, descriptions, m_config->verbosity() );
}

void StreamingReporterBase::listTests(std::vector<TestCaseHandle> const& tests) {
defaultListTests(stream,
tests,
m_config->hasTestFilters(),
m_config->verbosity());
}

void StreamingReporterBase::listTags(std::vector<TagInfo> const& tags) {
defaultListTags( stream, tags, m_config->hasTestFilters() );
}

} // end namespace Catch
4 changes: 4 additions & 0 deletions src/catch2/reporters/catch_reporter_streaming_base.hpp
Expand Up @@ -71,6 +71,10 @@ namespace Catch {
// It can optionally be overridden in the derived class.
}

void listReporters( std::vector<ReporterDescription> const& descriptions ) override;
void listTests( std::vector<TestCaseHandle> const& tests ) override;
void listTags( std::vector<TagInfo> const& tags ) override;

std::ostream& stream;

LazyStat<TestRunInfo> currentTestRunInfo;
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Expand Up @@ -23,6 +23,7 @@ set(TEST_SOURCES
${SELF_TEST_DIR}/IntrospectiveTests/InternalBenchmark.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/Reporters.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp
Expand Down
2 changes: 2 additions & 0 deletions tests/SelfTest/Baselines/automake.sw.approved.txt
Expand Up @@ -185,6 +185,7 @@ Nor would this
:test-result: FAIL Reconstruction should be based on stringification: #914
:test-result: FAIL Regex string matcher
:test-result: PASS Regression test #1
:test-result: PASS Reporter's write listings to provided stream
:test-result: PASS SUCCEED counts as a test pass
:test-result: PASS SUCCEED does not require an argument
:test-result: PASS Scenario: BDD tests requiring Fixtures to provide commonly-accessed data or methods
Expand Down Expand Up @@ -231,6 +232,7 @@ Message from section two
:test-result: PASS Test enum bit values
:test-result: PASS Test with special, characters "in name
:test-result: FAIL The NO_FAIL macro reports a failure but does not fail the test
:test-result: PASS The default listing implementation write to provided stream
:test-result: FAIL This test 'should' fail but doesn't
:test-result: FAIL Thrown string literals are translated
:test-result: PASS Tracker
Expand Down
178 changes: 178 additions & 0 deletions tests/SelfTest/Baselines/compact.sw.approved.txt
Expand Up @@ -1273,6 +1273,169 @@ Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("this
Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("contains 'abc' as a substring") for: "this string contains 'abc' as a substring" matches "contains 'abc' as a substring" case sensitively
Matchers.tests.cpp:<line number>: failed: testStringForMatching(), Matches("this string contains 'abc' as a") for: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively
Matchers.tests.cpp:<line number>: passed: actual, !UnorderedEquals(expected) for: { 'a', 'b' } not UnorderedEquals: { 'c', 'b' }
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "All available tags:
1 [fakeTag]
1 tag

" contains: "fakeTag" with 1 message: 'Tested reporter: automake'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "Available reporters:
fake reporter: fake description

" contains: "fake reporter" with 1 message: 'Tested reporter: automake'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: automake'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "All available tags:
1 [fakeTag]
1 tag

" contains: "fakeTag" with 1 message: 'Tested reporter: compact'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "Available reporters:
fake reporter: fake description

" contains: "fake reporter" with 1 message: 'Tested reporter: compact'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: compact'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "All available tags:
1 [fakeTag]
1 tag

" contains: "fakeTag" with 1 message: 'Tested reporter: console'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "Available reporters:
fake reporter: fake description

" contains: "fake reporter" with 1 message: 'Tested reporter: console'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: console'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "<?xml version="1.0" encoding="UTF-8"?>
All available tags:
1 [fakeTag]
1 tag

" contains: "fakeTag" with 1 message: 'Tested reporter: junit'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "<?xml version="1.0" encoding="UTF-8"?>
Available reporters:
fake reporter: fake description

" contains: "fake reporter" with 1 message: 'Tested reporter: junit'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "<?xml version="1.0" encoding="UTF-8"?>
All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: junit'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "<?xml version="1.0" encoding="UTF-8"?>
All available tags:
1 [fakeTag]
1 tag

" contains: "fakeTag" with 1 message: 'Tested reporter: sonarqube'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "<?xml version="1.0" encoding="UTF-8"?>
Available reporters:
fake reporter: fake description

" contains: "fake reporter" with 1 message: 'Tested reporter: sonarqube'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "<?xml version="1.0" encoding="UTF-8"?>
All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: sonarqube'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "All available tags:
1 [fakeTag]
1 tag

" contains: "fakeTag" with 1 message: 'Tested reporter: tap'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "Available reporters:
fake reporter: fake description

" contains: "fake reporter" with 1 message: 'Tested reporter: tap'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: tap'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "All available tags:
1 [fakeTag]
1 tag

" contains: "fakeTag" with 1 message: 'Tested reporter: teamcity'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "Available reporters:
fake reporter: fake description

" contains: "fake reporter" with 1 message: 'Tested reporter: teamcity'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: teamcity'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fakeTag"s) for: "<?xml version="1.0" encoding="UTF-8"?>
<TagsFromMatchingTests>
<Tag>
<Count>1</Count>
<Aliases>
<Alias>fakeTag</Alias>
</Aliases>
</Tag>
</TagsFromMatchingTests>" contains: "fakeTag" with 1 message: 'Tested reporter: xml'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "<?xml version="1.0" encoding="UTF-8"?>
<AvailableReporters>
<Reporter>
<Name>fake reporter</Name>
<Description>fake description</Description>
</Reporter>
</AvailableReporters>" contains: "fake reporter" with 1 message: 'Tested reporter: xml'
Reporters.tests.cpp:<line number>: passed: !(factories.empty()) for: !false
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "<?xml version="1.0" encoding="UTF-8"?>
<MatchingTests>
<TestCase>
<Name>fake test name</Name>
<ClassName/>
<Tags>[fakeTestTag]</Tags>
<SourceInfo>
<File>fake-file.cpp</File>
<Line>123456789</Line>
</SourceInfo>
</TestCase>
</MatchingTests>" ( contains: "fake test name" and contains: "fakeTestTag" ) with 1 message: 'Tested reporter: xml'
Message.tests.cpp:<line number>: passed: with 1 message: 'this is a success'
Message.tests.cpp:<line number>: passed:
BDD.tests.cpp:<line number>: passed: before == 0 for: 0 == 0
Expand Down Expand Up @@ -1563,6 +1726,21 @@ VariadicMacros.tests.cpp:<line number>: passed: with 1 message: 'no assertions'
Tricky.tests.cpp:<line number>: passed: 0x<hex digits> == bit30and31 for: 3221225472 (0x<hex digits>) == 3221225472
CmdLine.tests.cpp:<line number>: passed:
Message.tests.cpp:<line number>: failed - but was ok: 1 == 2
Reporters.tests.cpp:<line number>: passed: listingString, Contains("[fakeTag]"s) for: "All available tags:
1 [fakeTag]
1 tag

" contains: "[fakeTag]"
Reporters.tests.cpp:<line number>: passed: listingString, Contains("fake reporter"s) for: "Available reporters:
fake reporter: fake description

" contains: "fake reporter"
Reporters.tests.cpp:<line number>: passed: listingString, Contains( "fake test name"s ) && Contains( "fakeTestTag"s ) for: "All available test cases:
fake test name
[fakeTestTag]
1 test case

" ( contains: "fake test name" and contains: "fakeTestTag" )
Misc.tests.cpp:<line number>: passed: with 1 message: 'oops!'
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'For some reason someone is throwing a string literal!'
PartTracker.tests.cpp:<line number>: passed: testCase.isOpen() for: true
Expand Down
4 changes: 2 additions & 2 deletions tests/SelfTest/Baselines/console.std.approved.txt
Expand Up @@ -1380,6 +1380,6 @@ due to unexpected exception with message:
Why would you throw a std::string?

===============================================================================
test cases: 354 | 280 passed | 70 failed | 4 failed as expected
assertions: 2037 | 1885 passed | 131 failed | 21 failed as expected
test cases: 356 | 282 passed | 70 failed | 4 failed as expected
assertions: 2088 | 1936 passed | 131 failed | 21 failed as expected

0 comments on commit 971b1fc

Please sign in to comment.