Skip to content

Commit 77eae8b

Browse files
committed
Turn IResultCapture::lastAssertionPassed into a free function
The thread-safety changes in assertions & messages turned whether the last assertion passed or failed into thread-local state, instead of being member of the `RunContext`. However, this change was not reflected in the API `CHECKED_IF`/`CHECKED_ELSE` used, which in turn required `catch_test_macro_impl.hpp` to include `catch_interfaces_capture.hpp` for it. Thanks to the combination of this commit and the previous similar commit for the message stack handling, the main include path does not need to include `catch_interfaces_capture.hpp` anymore.
1 parent 3ab0d7c commit 77eae8b

4 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/catch2/interfaces/catch_interfaces_capture.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ namespace Catch {
6161
virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
6262
virtual void benchmarkFailed( StringRef error ) = 0;
6363

64-
6564
virtual void handleFatalErrorCondition( StringRef message ) = 0;
6665

6766
virtual void handleExpr
@@ -87,9 +86,6 @@ namespace Catch {
8786
ResultWas::OfType resultType,
8887
AssertionReaction &reaction ) = 0;
8988

90-
91-
virtual bool lastAssertionPassed() = 0;
92-
9389
// Deprecated, do not use:
9490
virtual std::string getCurrentTestName() const = 0;
9591
virtual const AssertionResult* getLastResult() const = 0;

src/catch2/internal/catch_run_context.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ namespace Catch {
324324
void addUnscopedMessage( MessageInfo&& message ) {
325325
Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( message ) );
326326
}
327+
328+
bool lastAssertionPassed() { return Detail::g_lastAssertionPassed; }
329+
327330
} // namespace Detail
328331

329332
RunContext::RunContext(IConfig const* _config, IEventListenerPtr&& reporter)
@@ -720,10 +723,6 @@ namespace Catch {
720723
m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false));
721724
}
722725

723-
bool RunContext::lastAssertionPassed() {
724-
return Detail::g_lastAssertionPassed;
725-
}
726-
727726
void RunContext::assertionPassedFastPath(SourceLineInfo lineInfo) {
728727
// We want to save the line info for better experience with unexpected assertions
729728
Detail::g_lastKnownLineInfo = lineInfo;
@@ -953,7 +952,6 @@ namespace Catch {
953952
}
954953
}
955954

956-
957955
void seedRng(IConfig const& config) {
958956
sharedRng().seed(config.rngSeed());
959957
}

src/catch2/internal/catch_run_context.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ namespace Catch {
102102

103103
void handleFatalErrorCondition( StringRef message ) override;
104104

105-
bool lastAssertionPassed() override;
106-
107105
public:
108106
// !TBD We need to do this another way!
109107
bool aborting() const;

src/catch2/internal/catch_test_macro_impl.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111
#include <catch2/catch_user_config.hpp>
1212
#include <catch2/internal/catch_assertion_handler.hpp>
1313
#include <catch2/internal/catch_preprocessor_internal_stringify.hpp>
14-
#include <catch2/interfaces/catch_interfaces_capture.hpp>
1514
#include <catch2/internal/catch_stringref.hpp>
1615
#include <catch2/internal/catch_source_line_info.hpp>
1716

17+
namespace Catch {
18+
namespace Detail {
19+
// Defined in catch_run_context.cpp, where the thread-local data lives.
20+
bool lastAssertionPassed();
21+
}
22+
}
23+
1824
// We need this suppression to leak, because it took until GCC 10
1925
// for the front end to handle local suppression via _Pragma properly
2026
#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ <= 9
@@ -57,12 +63,12 @@
5763
///////////////////////////////////////////////////////////////////////////////
5864
#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
5965
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
60-
if( Catch::getResultCapture().lastAssertionPassed() )
66+
if( Catch::Detail::lastAssertionPassed() )
6167

6268
///////////////////////////////////////////////////////////////////////////////
6369
#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
6470
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
65-
if( !Catch::getResultCapture().lastAssertionPassed() )
71+
if( !Catch::Detail::lastAssertionPassed() )
6672

6773
///////////////////////////////////////////////////////////////////////////////
6874
#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \

0 commit comments

Comments
 (0)