mirror of
https://github.com/catchorg/Catch2.git
synced 2025-02-22 14:13:30 +01:00
VS integration part 1 - allow catch_message.hpp to be included by more than 1 source file
This commit is contained in:
parent
8e411d27f6
commit
e9a2230ad8
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,11 +2,13 @@
|
|||||||
*.pbxuser
|
*.pbxuser
|
||||||
*.mode1v3
|
*.mode1v3
|
||||||
*.ncb
|
*.ncb
|
||||||
|
*.sdf
|
||||||
*.suo
|
*.suo
|
||||||
Debug
|
Debug
|
||||||
Release
|
Release
|
||||||
*.user
|
*.user
|
||||||
*.xcuserstate
|
*.xcuserstate
|
||||||
|
*.o
|
||||||
.DS_Store
|
.DS_Store
|
||||||
xcuserdata
|
xcuserdata
|
||||||
CatchSelfTest.xcscheme
|
CatchSelfTest.xcscheme
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( CATCH_CONFIG_MAIN ) || defined( CATCH_CONFIG_RUNNER )
|
#if defined( CATCH_CONFIG_MAIN ) || defined( CATCH_CONFIG_RUNNER )
|
||||||
|
#define INTERNAL_CATCH_INLINE
|
||||||
#include "internal/catch_impl.hpp"
|
#include "internal/catch_impl.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -31,8 +31,6 @@ namespace Catch {
|
|||||||
bool operator < ( MessageInfo const& other ) const {
|
bool operator < ( MessageInfo const& other ) const {
|
||||||
return sequence < other.sequence;
|
return sequence < other.sequence;
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
static unsigned int globalCount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MessageBuilder {
|
struct MessageBuilder {
|
||||||
|
@ -12,28 +12,32 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
MessageInfo::MessageInfo( std::string const& _macroName,
|
template <typename T>
|
||||||
|
struct MessageInfoCounter {
|
||||||
|
// This may need protecting if threading support is added
|
||||||
|
static T globalCount;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
T MessageInfoCounter<T>::globalCount = T();
|
||||||
|
|
||||||
|
INTERNAL_CATCH_INLINE MessageInfo::MessageInfo( std::string const& _macroName,
|
||||||
SourceLineInfo const& _lineInfo,
|
SourceLineInfo const& _lineInfo,
|
||||||
ResultWas::OfType _type )
|
ResultWas::OfType _type )
|
||||||
: macroName( _macroName ),
|
: macroName( _macroName ),
|
||||||
lineInfo( _lineInfo ),
|
lineInfo( _lineInfo ),
|
||||||
type( _type ),
|
type( _type ),
|
||||||
sequence( ++globalCount )
|
sequence( ++MessageInfoCounter<unsigned int>::globalCount )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// This may need protecting if threading support is added
|
|
||||||
unsigned int MessageInfo::globalCount = 0;
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ScopedMessage::ScopedMessage( MessageBuilder const& builder )
|
INTERNAL_CATCH_INLINE ScopedMessage::ScopedMessage( MessageBuilder const& builder )
|
||||||
: m_info( builder.m_info )
|
: m_info( builder.m_info )
|
||||||
{
|
{
|
||||||
m_info.message = builder.m_stream.str();
|
m_info.message = builder.m_stream.str();
|
||||||
getResultCapture().pushScopedMessage( m_info );
|
getResultCapture().pushScopedMessage( m_info );
|
||||||
}
|
}
|
||||||
ScopedMessage::~ScopedMessage() {
|
INTERNAL_CATCH_INLINE ScopedMessage::~ScopedMessage() {
|
||||||
getResultCapture().popScopedMessage( m_info );
|
getResultCapture().popScopedMessage( m_info );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
50
projects/SelfTest/MessageInstantiationTests1.cpp
Normal file
50
projects/SelfTest/MessageInstantiationTests1.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 09/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch.hpp"
|
||||||
|
#undef INTERNAL_CATCH_INLINE
|
||||||
|
#define INTERNAL_CATCH_INLINE inline
|
||||||
|
#include "internal/catch_message.hpp"
|
||||||
|
|
||||||
|
namespace Counter {
|
||||||
|
int g_haveCountedMessages = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test works with the equivalent in MessageInstantiationTests2.cpp
|
||||||
|
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||||
|
// just check the value. The purpose of this test is to verify that the compiler's
|
||||||
|
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||||
|
// references to the globalCount
|
||||||
|
|
||||||
|
TEST_CASE("message counting1","")
|
||||||
|
{
|
||||||
|
if( Counter::g_haveCountedMessages > 0 ) {
|
||||||
|
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||||
|
Counter::g_haveCountedMessages = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace LongCounter {
|
||||||
|
int g_haveCountedMessagesLong = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("long message counting1","")
|
||||||
|
{
|
||||||
|
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||||
|
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++Catch::MessageInfoCounter<long>::globalCount;
|
||||||
|
LongCounter::g_haveCountedMessagesLong = 1;
|
||||||
|
}
|
||||||
|
}
|
49
projects/SelfTest/MessageInstantiationTests2.cpp
Normal file
49
projects/SelfTest/MessageInstantiationTests2.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 09/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch.hpp"
|
||||||
|
#define INTERNAL_CATCH_INLINE inline
|
||||||
|
#include "internal/catch_message.hpp"
|
||||||
|
|
||||||
|
namespace Counter {
|
||||||
|
extern int g_haveCountedMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test works with the equivalent in MessageInstantiationTests1.cpp
|
||||||
|
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||||
|
// just check the value. The purpose of this test is to verify that the compiler's
|
||||||
|
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||||
|
// references to the globalCount
|
||||||
|
|
||||||
|
TEST_CASE("message counting2","")
|
||||||
|
{
|
||||||
|
if( Counter::g_haveCountedMessages > 0 ) {
|
||||||
|
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||||
|
Counter::g_haveCountedMessages = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace LongCounter {
|
||||||
|
extern int g_haveCountedMessagesLong;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("long message counting2","")
|
||||||
|
{
|
||||||
|
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||||
|
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++Catch::MessageInfoCounter<long>::globalCount;
|
||||||
|
LongCounter::g_haveCountedMessagesLong = 1;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@ SOURCES = ApproxTests.cpp \
|
|||||||
ExceptionTests.cpp \
|
ExceptionTests.cpp \
|
||||||
GeneratorTests.cpp \
|
GeneratorTests.cpp \
|
||||||
MessageTests.cpp \
|
MessageTests.cpp \
|
||||||
|
MessageInstantiationTests1.cpp \
|
||||||
|
MessageInstantiationTests2.cpp \
|
||||||
MiscTests.cpp \
|
MiscTests.cpp \
|
||||||
TestMain.cpp \
|
TestMain.cpp \
|
||||||
TrickyTests.cpp \
|
TrickyTests.cpp \
|
||||||
@ -18,4 +20,4 @@ CatchSelfTest: $(OBJECTS)
|
|||||||
$(CXX) -o $@ $^
|
$(CXX) -o $@ $^
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJECTS)
|
rm -f CatchSelfTest CatchSelfTest.exe $(OBJECTS)
|
||||||
|
@ -94,6 +94,8 @@
|
|||||||
<ClCompile Include="..\..\..\SelfTest\ApproxTests.cpp" />
|
<ClCompile Include="..\..\..\SelfTest\ApproxTests.cpp" />
|
||||||
<ClCompile Include="..\..\..\SelfTest\BDDTests.cpp" />
|
<ClCompile Include="..\..\..\SelfTest\BDDTests.cpp" />
|
||||||
<ClCompile Include="..\..\..\SelfTest\CmdLineTests.cpp" />
|
<ClCompile Include="..\..\..\SelfTest\CmdLineTests.cpp" />
|
||||||
|
<ClCompile Include="..\..\..\SelfTest\MessageInstantiationTests1.cpp" />
|
||||||
|
<ClCompile Include="..\..\..\SelfTest\MessageInstantiationTests2.cpp" />
|
||||||
<ClCompile Include="..\..\..\SelfTest\SectionTrackerTests.cpp" />
|
<ClCompile Include="..\..\..\SelfTest\SectionTrackerTests.cpp" />
|
||||||
<ClCompile Include="..\..\..\SelfTest\TestMain.cpp" />
|
<ClCompile Include="..\..\..\SelfTest\TestMain.cpp" />
|
||||||
<ClCompile Include="..\..\..\SelfTest\catch_self_test.cpp" />
|
<ClCompile Include="..\..\..\SelfTest\catch_self_test.cpp" />
|
||||||
@ -108,42 +110,81 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\..\include\catch.hpp" />
|
<ClInclude Include="..\..\..\..\include\catch.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\catch_objc.hpp" />
|
|
||||||
<ClInclude Include="..\..\..\..\include\catch_objc_main.hpp" />
|
|
||||||
<ClInclude Include="..\..\..\..\include\catch_runner.hpp" />
|
<ClInclude Include="..\..\..\..\include\catch_runner.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\catch_with_main.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_approx.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_assertionresult.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_assertionresult.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_capture.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_capture.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_commandline.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_commandline.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_common.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_common.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_compiler_capabilities.h" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_config.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_config.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_console_colour.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_console_colour_impl.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_context.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_context_impl.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_debugger.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_debugger.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_default_main.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_evaluate.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_evaluate.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_exception_translator_registry.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_exception_translator_registry.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_expressionresult_builder.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_expressionresult_builder.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_expression_decomposer.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_expression_lhs.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_generators.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_generators.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_generators_impl.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_generators_impl.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_hub.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_impl.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_hub_impl.hpp" />
|
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_capture.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_capture.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_config.h" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_exception.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_exception.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_generators.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_registry_hub.h" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_reporter.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_reporter.h" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_runner.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_runner.h" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_testcase.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_interfaces_testcase.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_legacy_reporter_adapter.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_legacy_reporter_adapter.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_list.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_list.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_matchers.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_message.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_message.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_notimplemented_exception.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_notimplemented_exception.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_objc.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_objc_arc.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_option.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_platform.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_ptr.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_registry_hub.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_reporter_registrars.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_reporter_registrars.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_reporter_registry.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_reporter_registry.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_result_type.h" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_result_type.h" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_resultinfo.hpp" />
|
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_runner_impl.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_runner_impl.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_section.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_section.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_self_test.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_self_test.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_sfinae.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_stream.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_stream.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_streambuf.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_tags.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_test_case_info.h" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_test_case_info.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_test_case_info.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_test_case_registry_impl.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_test_case_registry_impl.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_test_case_tracker.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_test_registry.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_test_registry.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_test_spec.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_text.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_text.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_timer.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_timer.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_tostring.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_totals.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_version.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\include\internal\catch_version.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\internal\catch_xmlwriter.hpp" />
|
<ClInclude Include="..\..\..\..\include\internal\catch_xmlwriter.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\reporters\catch_reporter_basic.hpp" />
|
<ClInclude Include="..\..\..\..\include\reporters\catch_reporter_console.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\reporters\catch_reporter_junit.hpp" />
|
<ClInclude Include="..\..\..\..\include\reporters\catch_reporter_junit.hpp" />
|
||||||
<ClInclude Include="..\..\..\..\include\reporters\catch_reporter_xml.hpp" />
|
<ClInclude Include="..\..\..\..\include\reporters\catch_reporter_xml.hpp" />
|
||||||
|
<ClInclude Include="..\..\..\selftest\catch_self_test.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="ReadMe.txt" />
|
<None Include="ReadMe.txt" />
|
||||||
|
Loading…
Reference in New Issue
Block a user