Skip to content

Commit

Permalink
Add more unit tests
Browse files Browse the repository at this point in the history
* Call order of listeners/reporters in multireporter
* Adding listeners/reporters properly updates reporter preferences
  • Loading branch information
horenmar committed Dec 29, 2021
1 parent 4f10efe commit 3d5c13f
Show file tree
Hide file tree
Showing 19 changed files with 836 additions and 19 deletions.
7 changes: 2 additions & 5 deletions src/catch2/reporters/catch_reporter_listening.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ namespace Catch {

public:
ListeningReporter( IConfig const* config ):
IStreamingReporter( config ) {
// We will assume that listeners will always want all assertions
m_preferences.shouldReportAllAssertions = true;
}

IStreamingReporter( config )
{}

void addListener( IStreamingReporterPtr&& listener );
void addReporter( IStreamingReporterPtr&& reporter );
Expand Down
2 changes: 2 additions & 0 deletions tests/SelfTest/Baselines/automake.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ Nor would this
:test-result: FAIL Matchers can be negated (Not) with the ! operator - failing
:test-result: XFAIL Mayfail test case with nested sections
:test-result: FAIL Mismatching exception messages failing the test
:test-result: PASS Multireporter calls reporters and listeners in correct order
:test-result: PASS Multireporter updates ReporterPreferences properly
:test-result: PASS Nested generators and captured variables
:test-result: FAIL Nice descriptive name
:test-result: FAIL Non-std exceptions can be translated
Expand Down
2 changes: 2 additions & 0 deletions tests/SelfTest/Baselines/automake.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@
:test-result: FAIL Matchers can be negated (Not) with the ! operator - failing
:test-result: XFAIL Mayfail test case with nested sections
:test-result: FAIL Mismatching exception messages failing the test
:test-result: PASS Multireporter calls reporters and listeners in correct order
:test-result: PASS Multireporter updates ReporterPreferences properly
:test-result: PASS Nested generators and captured variables
:test-result: FAIL Nice descriptive name
:test-result: FAIL Non-std exceptions can be translated
Expand Down
19 changes: 19 additions & 0 deletions tests/SelfTest/Baselines/compact.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,25 @@ Condition.tests.cpp:<line number>: failed: explicitly
Condition.tests.cpp:<line number>: failed: explicitly
Exception.tests.cpp:<line number>: passed: thisThrows(), "expected exception" for: "expected exception" equals: "expected exception"
Exception.tests.cpp:<line number>: failed: thisThrows(), "should fail" for: "expected exception" equals: "should fail"
Reporters.tests.cpp:<line number>: passed: records == expected for: { "Hello", "world", "Goodbye", "world" }
==
{ "Hello", "world", "Goodbye", "world" }
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Generators.tests.cpp:<line number>: passed: values > -6 for: 3 > -6
Generators.tests.cpp:<line number>: passed: values > -6 for: 4 > -6
Generators.tests.cpp:<line number>: passed: values > -6 for: 5 > -6
Expand Down
19 changes: 19 additions & 0 deletions tests/SelfTest/Baselines/compact.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,25 @@ Condition.tests.cpp:<line number>: failed: explicitly
Condition.tests.cpp:<line number>: failed: explicitly
Exception.tests.cpp:<line number>: passed: thisThrows(), "expected exception" for: "expected exception" equals: "expected exception"
Exception.tests.cpp:<line number>: failed: thisThrows(), "should fail" for: "expected exception" equals: "should fail"
Reporters.tests.cpp:<line number>: passed: records == expected for: { "Hello", "world", "Goodbye", "world" }
==
{ "Hello", "world", "Goodbye", "world" }
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == false for: false == false
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldRedirectStdOut == true for: true == true
Reporters.tests.cpp:<line number>: passed: multiReporter.getPreferences().shouldReportAllAssertions == true for: true == true
Generators.tests.cpp:<line number>: passed: values > -6 for: 3 > -6
Generators.tests.cpp:<line number>: passed: values > -6 for: 4 > -6
Generators.tests.cpp:<line number>: passed: values > -6 for: 5 > -6
Expand Down
4 changes: 2 additions & 2 deletions tests/SelfTest/Baselines/console.std.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,6 @@ due to unexpected exception with message:
Why would you throw a std::string?

===============================================================================
test cases: 384 | 307 passed | 70 failed | 7 failed as expected
assertions: 2196 | 2040 passed | 129 failed | 27 failed as expected
test cases: 386 | 309 passed | 70 failed | 7 failed as expected
assertions: 2213 | 2057 passed | 129 failed | 27 failed as expected

123 changes: 121 additions & 2 deletions tests/SelfTest/Baselines/console.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7199,6 +7199,125 @@ Exception.tests.cpp:<line number>: FAILED:
with expansion:
"expected exception" equals: "should fail"

-------------------------------------------------------------------------------
Multireporter calls reporters and listeners in correct order
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( records == expected )
with expansion:
{ "Hello", "world", "Goodbye", "world" }
==
{ "Hello", "world", "Goodbye", "world" }

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
Adding listeners
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
Adding reporters
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

-------------------------------------------------------------------------------
Nested generators and captured variables
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -17701,6 +17820,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:

===============================================================================
test cases: 384 | 291 passed | 86 failed | 7 failed as expected
assertions: 2213 | 2040 passed | 146 failed | 27 failed as expected
test cases: 386 | 293 passed | 86 failed | 7 failed as expected
assertions: 2230 | 2057 passed | 146 failed | 27 failed as expected

123 changes: 121 additions & 2 deletions tests/SelfTest/Baselines/console.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7197,6 +7197,125 @@ Exception.tests.cpp:<line number>: FAILED:
with expansion:
"expected exception" equals: "should fail"

-------------------------------------------------------------------------------
Multireporter calls reporters and listeners in correct order
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( records == expected )
with expansion:
{ "Hello", "world", "Goodbye", "world" }
==
{ "Hello", "world", "Goodbye", "world" }

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
Adding listeners
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

-------------------------------------------------------------------------------
Multireporter updates ReporterPreferences properly
Adding reporters
-------------------------------------------------------------------------------
Reporters.tests.cpp:<line number>
...............................................................................

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == false )
with expansion:
false == false

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldRedirectStdOut == true )
with expansion:
true == true

Reporters.tests.cpp:<line number>: PASSED:
REQUIRE( multiReporter.getPreferences().shouldReportAllAssertions == true )
with expansion:
true == true

-------------------------------------------------------------------------------
Nested generators and captured variables
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -17693,6 +17812,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:

===============================================================================
test cases: 384 | 291 passed | 86 failed | 7 failed as expected
assertions: 2213 | 2040 passed | 146 failed | 27 failed as expected
test cases: 386 | 293 passed | 86 failed | 7 failed as expected
assertions: 2230 | 2057 passed | 146 failed | 27 failed as expected

6 changes: 5 additions & 1 deletion tests/SelfTest/Baselines/junit.sw.approved.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="129" tests="2213" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="129" tests="2230" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
Expand Down Expand Up @@ -870,6 +870,10 @@ with expansion:
Exception.tests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="Multireporter calls reporters and listeners in correct order" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Multireporter updates ReporterPreferences properly" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Multireporter updates ReporterPreferences properly/Adding listeners" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Multireporter updates ReporterPreferences properly/Adding reporters" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Nested generators and captured variables" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Nice descriptive name" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="Non-std exceptions can be translated" time="{duration}" status="run">
Expand Down
Loading

0 comments on commit 3d5c13f

Please sign in to comment.