Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-09-12 00:00:47 +0200
committerMartin Hořeňovský2021-09-14 13:19:45 +0200
commit10fb93cce8cb878fdfe8faa118b531258db96a26 (patch)
tree41eadf4802932051def7770b52a4a7fe94260c80 /src
parent4dcf8382c70c25a3ccfbe5d9e37276adf7c6058f (diff)
downloadcatch3-10fb93cce8cb878fdfe8faa118b531258db96a26.tar.gz
Add new reporter event called for each test case enter/exit
This means that e.g. for `TEST_CASE` with two sibling `SECTION`s the event will fire twice, because the `TEST_CASE` will be entered twice. Closes #2107 (the event mentioned there already exists, but this is its counterpart that we also want to provide to users)
Diffstat (limited to 'src')
-rw-r--r--src/catch2/interfaces/catch_interfaces_reporter.hpp6
-rw-r--r--src/catch2/internal/catch_run_context.cpp19
-rw-r--r--src/catch2/reporters/catch_reporter_combined_tu.cpp2
-rw-r--r--src/catch2/reporters/catch_reporter_cumulative_base.hpp3
-rw-r--r--src/catch2/reporters/catch_reporter_event_listener.hpp5
-rw-r--r--src/catch2/reporters/catch_reporter_listening.cpp17
-rw-r--r--src/catch2/reporters/catch_reporter_listening.hpp2
-rw-r--r--src/catch2/reporters/catch_reporter_streaming_base.hpp2
8 files changed, 53 insertions, 3 deletions
diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp
index 09480f04..0056c8ad 100644
--- a/src/catch2/interfaces/catch_interfaces_reporter.hpp
+++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp
@@ -177,7 +177,10 @@ namespace Catch {
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
+ //! Called _once_ for each TEST_CASE, no matter how many times it is entered
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
+ //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
+ virtual void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber ) = 0;
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
virtual void benchmarkPreparing( StringRef ) {}
@@ -191,6 +194,9 @@ namespace Catch {
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
+ //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
+ virtual void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber ) = 0;
+ //! Called _once_ for each TEST_CASE, no matter how many times it is entered
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 222ee932..1e4cc6b1 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -176,7 +176,7 @@ namespace Catch {
}
Totals RunContext::runTest(TestCaseHandle const& testCase) {
- Totals prevTotals = m_totals;
+ const Totals prevTotals = m_totals;
std::string redirectedCout;
std::string redirectedCerr;
@@ -191,10 +191,25 @@ namespace Catch {
ITracker& rootTracker = m_trackerContext.startRun();
assert(rootTracker.isSectionTracker());
static_cast<SectionTracker&>(rootTracker).addInitialFilters(m_config->getSectionsToRun());
+
+ uint64_t testRuns = 0;
do {
m_trackerContext.startCycle();
m_testCaseTracker = &SectionTracker::acquire(m_trackerContext, TestCaseTracking::NameAndLocation(testInfo.name, testInfo.lineInfo));
- runCurrentTest(redirectedCout, redirectedCerr);
+
+ m_reporter->testCasePartialStarting(testInfo, testRuns);
+
+ const auto beforeRunTotals = m_totals;
+ std::string oneRunCout, oneRunCerr;
+ runCurrentTest(oneRunCout, oneRunCerr);
+ redirectedCout += oneRunCout;
+ redirectedCerr += oneRunCerr;
+
+ const auto singleRunTotals = m_totals.delta(beforeRunTotals);
+ auto statsForOneRun = TestCaseStats(testInfo, singleRunTotals, redirectedCout, oneRunCerr, aborting());
+
+ m_reporter->testCasePartialEnded(statsForOneRun, testRuns);
+ ++testRuns;
} while (!m_testCaseTracker->isSuccessfullyCompleted() && !aborting());
Totals deltaTotals = m_totals.delta(prevTotals);
diff --git a/src/catch2/reporters/catch_reporter_combined_tu.cpp b/src/catch2/reporters/catch_reporter_combined_tu.cpp
index 084f46c5..dc5dc427 100644
--- a/src/catch2/reporters/catch_reporter_combined_tu.cpp
+++ b/src/catch2/reporters/catch_reporter_combined_tu.cpp
@@ -232,8 +232,10 @@ namespace Catch {
void EventListenerBase::noMatchingTestCases( std::string const& ) {}
void EventListenerBase::testRunStarting( TestRunInfo const& ) {}
void EventListenerBase::testCaseStarting( TestCaseInfo const& ) {}
+ void EventListenerBase::testCasePartialStarting(TestCaseInfo const&, uint64_t) {}
void EventListenerBase::sectionStarting( SectionInfo const& ) {}
void EventListenerBase::sectionEnded( SectionStats const& ) {}
+ void EventListenerBase::testCasePartialEnded(TestCaseStats const&, uint64_t) {}
void EventListenerBase::testCaseEnded( TestCaseStats const& ) {}
void EventListenerBase::testRunEnded( TestRunStats const& ) {}
void EventListenerBase::skipTest( TestCaseInfo const& ) {}
diff --git a/src/catch2/reporters/catch_reporter_cumulative_base.hpp b/src/catch2/reporters/catch_reporter_cumulative_base.hpp
index 8340aadb..0c7f7def 100644
--- a/src/catch2/reporters/catch_reporter_cumulative_base.hpp
+++ b/src/catch2/reporters/catch_reporter_cumulative_base.hpp
@@ -52,13 +52,14 @@ namespace Catch {
void testRunStarting( TestRunInfo const& ) override {}
void testCaseStarting( TestCaseInfo const& ) override {}
-
+ void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {}
void sectionStarting( SectionInfo const& sectionInfo ) override;
void assertionStarting( AssertionInfo const& ) override {}
bool assertionEnded( AssertionStats const& assertionStats ) override;
void sectionEnded( SectionStats const& sectionStats ) override;
+ void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {}
void testCaseEnded( TestCaseStats const& testCaseStats ) override;
void testRunEnded( TestRunStats const& testRunStats ) override;
//! Customization point: called after last test finishes (testRunEnded has been handled)
diff --git a/src/catch2/reporters/catch_reporter_event_listener.hpp b/src/catch2/reporters/catch_reporter_event_listener.hpp
index 034c6f3c..855acc43 100644
--- a/src/catch2/reporters/catch_reporter_event_listener.hpp
+++ b/src/catch2/reporters/catch_reporter_event_listener.hpp
@@ -35,11 +35,16 @@ namespace Catch {
void noMatchingTestCases( std::string const& spec ) override;
void testRunStarting( TestRunInfo const& testRunInfo ) override;
void testCaseStarting( TestCaseInfo const& testInfo ) override;
+ void testCasePartialStarting( TestCaseInfo const& testInfo,
+ uint64_t partNumber ) override;
void sectionStarting( SectionInfo const& sectionInfo ) override;
void sectionEnded( SectionStats const& sectionStats ) override;
+ void testCasePartialEnded( TestCaseStats const& testCaseStats,
+ uint64_t partNumber ) override;
void testCaseEnded( TestCaseStats const& testCaseStats ) override;
void testRunEnded( TestRunStats const& testRunStats ) override;
void skipTest( TestCaseInfo const& testInfo ) override;
+
};
} // end namespace Catch
diff --git a/src/catch2/reporters/catch_reporter_listening.cpp b/src/catch2/reporters/catch_reporter_listening.cpp
index 74cfd0aa..62f6af55 100644
--- a/src/catch2/reporters/catch_reporter_listening.cpp
+++ b/src/catch2/reporters/catch_reporter_listening.cpp
@@ -76,6 +76,15 @@ namespace Catch {
m_reporter->testCaseStarting( testInfo );
}
+ void
+ ListeningReporter::testCasePartialStarting( TestCaseInfo const& testInfo,
+ uint64_t partNumber ) {
+ for ( auto& listener : m_listeners ) {
+ listener->testCasePartialStarting( testInfo, partNumber );
+ }
+ m_reporter->testCasePartialStarting( testInfo, partNumber );
+ }
+
void ListeningReporter::sectionStarting( SectionInfo const& sectionInfo ) {
for ( auto& listener : m_listeners ) {
listener->sectionStarting( sectionInfo );
@@ -105,6 +114,14 @@ namespace Catch {
m_reporter->sectionEnded( sectionStats );
}
+ void ListeningReporter::testCasePartialEnded( TestCaseStats const& testInfo,
+ uint64_t partNumber ) {
+ for ( auto& listener : m_listeners ) {
+ listener->testCasePartialEnded( testInfo, partNumber );
+ }
+ m_reporter->testCasePartialEnded( testInfo, partNumber );
+ }
+
void ListeningReporter::testCaseEnded( TestCaseStats const& testCaseStats ) {
for ( auto& listener : m_listeners ) {
listener->testCaseEnded( testCaseStats );
diff --git a/src/catch2/reporters/catch_reporter_listening.hpp b/src/catch2/reporters/catch_reporter_listening.hpp
index d00320b0..0e317653 100644
--- a/src/catch2/reporters/catch_reporter_listening.hpp
+++ b/src/catch2/reporters/catch_reporter_listening.hpp
@@ -41,12 +41,14 @@ namespace Catch {
void testRunStarting( TestRunInfo const& testRunInfo ) override;
void testCaseStarting( TestCaseInfo const& testInfo ) override;
+ void testCasePartialStarting(TestCaseInfo const& testInfo, uint64_t partNumber) override;
void sectionStarting( SectionInfo const& sectionInfo ) override;
void assertionStarting( AssertionInfo const& assertionInfo ) override;
// The return value indicates if the messages buffer should be cleared:
bool assertionEnded( AssertionStats const& assertionStats ) override;
void sectionEnded( SectionStats const& sectionStats ) override;
+ void testCasePartialEnded(TestCaseStats const& testInfo, uint64_t partNumber) override;
void testCaseEnded( TestCaseStats const& testCaseStats ) override;
void testRunEnded( TestRunStats const& testRunStats ) override;
diff --git a/src/catch2/reporters/catch_reporter_streaming_base.hpp b/src/catch2/reporters/catch_reporter_streaming_base.hpp
index c51595e6..3051294e 100644
--- a/src/catch2/reporters/catch_reporter_streaming_base.hpp
+++ b/src/catch2/reporters/catch_reporter_streaming_base.hpp
@@ -51,6 +51,7 @@ namespace Catch {
void testCaseStarting(TestCaseInfo const& _testInfo) override {
currentTestCaseInfo = &_testInfo;
}
+ void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {}
void sectionStarting(SectionInfo const& _sectionInfo) override {
m_sectionStack.push_back(_sectionInfo);
}
@@ -61,6 +62,7 @@ namespace Catch {
void sectionEnded(SectionStats const& /* _sectionStats */) override {
m_sectionStack.pop_back();
}
+ void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {}
void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override {
currentTestCaseInfo = nullptr;
}