mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-16 10:42:25 +01:00
f7cd0ba051
This PR introduces a new `TEST_CASE` macro called `TEST_CASE_PERSISTENT_FIXTURE`. `TEST_CASE_PERSISTENT_FIXTURE` offers the same functionality as `TEST_CASE_METHOD` except for one difference. The object on which the test method is invoked is only created once for all invocations of the test case. The object is created just after the `testCaseStarting` event is broadcast and the object is destroyed just before the `testCaseEnding` event is broadcast. The main motivation for this new functionality is to allow `TEST_CASE`s to do expensive setup and teardown once per `TEST_CASE`, without having to resort to abusing event listeners or static function variables with manual initialization. Implements #1602 --------- Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
63 lines
1.6 KiB
CMake
63 lines
1.6 KiB
CMake
cmake_minimum_required( VERSION 3.10 )
|
|
|
|
project( Catch2Examples LANGUAGES CXX )
|
|
|
|
message( STATUS "Examples included" )
|
|
|
|
|
|
# Some one-offs first:
|
|
# 1) Tests and main in one file
|
|
add_executable( 010-TestCase
|
|
010-TestCase.cpp
|
|
)
|
|
|
|
# 2) Tests and main across two files
|
|
add_executable( 020-MultiFile
|
|
020-TestCase-1.cpp
|
|
020-TestCase-2.cpp
|
|
)
|
|
|
|
add_executable(231-Cfg_OutputStreams
|
|
231-Cfg-OutputStreams.cpp
|
|
)
|
|
target_link_libraries(231-Cfg_OutputStreams Catch2_buildall_interface)
|
|
target_compile_definitions(231-Cfg_OutputStreams PUBLIC CATCH_CONFIG_NOSTDOUT)
|
|
|
|
# These examples use the standard separate compilation
|
|
set( SOURCES_IDIOMATIC_EXAMPLES
|
|
030-Asn-Require-Check.cpp
|
|
100-Fix-Section.cpp
|
|
110-Fix-ClassFixture.cpp
|
|
111-Fix-PersistentFixture.cpp
|
|
120-Bdd-ScenarioGivenWhenThen.cpp
|
|
210-Evt-EventListeners.cpp
|
|
232-Cfg-CustomMain.cpp
|
|
300-Gen-OwnGenerator.cpp
|
|
301-Gen-MapTypeConversion.cpp
|
|
302-Gen-Table.cpp
|
|
310-Gen-VariablesInGenerators.cpp
|
|
311-Gen-CustomCapture.cpp
|
|
)
|
|
|
|
string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}" )
|
|
set( TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES} )
|
|
|
|
|
|
foreach( name ${TARGETS_IDIOMATIC_EXAMPLES} )
|
|
add_executable( ${name} ${name}.cpp )
|
|
endforeach()
|
|
|
|
set(ALL_EXAMPLE_TARGETS
|
|
${TARGETS_IDIOMATIC_EXAMPLES}
|
|
010-TestCase
|
|
020-MultiFile
|
|
)
|
|
|
|
foreach( name ${ALL_EXAMPLE_TARGETS} )
|
|
target_link_libraries( ${name} Catch2WithMain )
|
|
endforeach()
|
|
|
|
|
|
list(APPEND CATCH_WARNING_TARGETS ${ALL_EXAMPLE_TARGETS})
|
|
set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)
|