diff --git a/CMakeLists.txt b/CMakeLists.txt index ce374079..009fec94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,14 @@ include(CTest) # than later in the install block set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2") +# We have some Windows builds that test `wmain` entry point, +# and we need this change to be present in all binaries that +# are built during these tests, so this is required here, before +# the subdirectories are added. +if(CATCH_TEST_USE_WMAIN) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") +endif() + # Basic paths set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}) @@ -76,9 +84,6 @@ endif() # #set_property(GLOBAL PROPERTY USE_FOLDERS ON) # -#if(USE_WMAIN) -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") -#endif() # # # diff --git a/examples/010-TestCase.cpp b/examples/010-TestCase.cpp index d9939958..70a0b4c1 100644 --- a/examples/010-TestCase.cpp +++ b/examples/010-TestCase.cpp @@ -1,8 +1,4 @@ // 010-TestCase.cpp - -// Let Catch provide main(): -#include - // And write tests in the same file: #include diff --git a/examples/020-TestCase-1.cpp b/examples/020-TestCase-1.cpp index 5d17016a..5d7d8de6 100644 --- a/examples/020-TestCase-1.cpp +++ b/examples/020-TestCase-1.cpp @@ -1,11 +1,5 @@ // 020-TestCase-1.cpp -// In a Catch project with multiple files, dedicate one file to compile the -// source code of Catch itself and reuse the resulting object file for linking. - -// Let Catch provide main(): -#include - #include TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:1]" ) { diff --git a/examples/231-Cfg-OutputStreams.cpp b/examples/231-Cfg-OutputStreams.cpp index d0c1a632..b77c1273 100644 --- a/examples/231-Cfg-OutputStreams.cpp +++ b/examples/231-Cfg-OutputStreams.cpp @@ -5,9 +5,6 @@ // semantic, because it buffers the output. For most uses however, // there is no important difference between having `std::cerr` buffered // or unbuffered. - -#include - #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5ac14d1..662e7a2a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,7 +55,6 @@ set(INTERNAL_HEADERS ${SOURCES_DIR}/internal/catch_debug_console.hpp ${SOURCES_DIR}/internal/catch_debugger.hpp ${SOURCES_DIR}/internal/catch_decomposer.hpp - ${SOURCES_DIR}/internal/catch_default_main.hpp ${SOURCES_DIR}/internal/catch_enforce.hpp ${SOURCES_DIR}/internal/catch_enum_values_registry.hpp ${SOURCES_DIR}/internal/catch_errno_guard.hpp @@ -318,6 +317,8 @@ if (CATCH_BUILD_EXAMPLES OR CATCH_BUILD_EXTRA_TESTS) ${INTERNAL_FILES} ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES} + # Also include main entry point + ${SOURCES_DIR}/internal/catch_main.cpp ) target_include_directories(Catch2_buildall_interface INTERFACE diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp index e7d3bfd9..5c6b09d2 100644 --- a/src/catch2/catch_all.hpp +++ b/src/catch2/catch_all.hpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include diff --git a/src/catch2/internal/catch_default_main.hpp b/src/catch2/internal/catch_default_main.hpp deleted file mode 100644 index 4404f0c8..00000000 --- a/src/catch2/internal/catch_default_main.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Created by Phil on 20/05/2011. - * Copyright 2011 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) - */ -#ifndef TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED -#define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED - -#include -#include -#include -#include - -namespace Catch { - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS - LeakDetector leakDetector; - CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -} - -#if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) -// Standard C/C++ Win32 Unicode wmain entry point -extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { -#else -// Standard C/C++ main entry point -int main (int argc, char * argv[]) { -#endif - - // We want to force the linker not to discard the global variable - // and its constructor, as it (optionally) registers leak detector - (void)&Catch::leakDetector; - - return Catch::Session().run( argc, argv ); -} - -#endif // TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED diff --git a/src/catch2/internal/catch_main.cpp b/src/catch2/internal/catch_main.cpp index 8eca23c9..4e79d4a7 100644 --- a/src/catch2/internal/catch_main.cpp +++ b/src/catch2/internal/catch_main.cpp @@ -3,4 +3,29 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ -#include +#include +#include +#include +#include + +namespace Catch { + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS + LeakDetector leakDetector; + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +} + +#if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) +// Standard C/C++ Win32 Unicode wmain entry point +extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { +#else +// Standard C/C++ main entry point +int main (int argc, char * argv[]) { +#endif + + // We want to force the linker not to discard the global variable + // and its constructor, as it (optionally) registers leak detector + (void)&Catch::leakDetector; + + return Catch::Session().run( argc, argv ); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f38ca4b9..8b3c9092 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,7 +15,7 @@ endif(MSVC) #Temporary workaround # define the sources of the self test # Please keep these ordered alphabetically set(TEST_SOURCES - ${SELF_TEST_DIR}/TestMain.cpp + ${SELF_TEST_DIR}/TestRegistrations.cpp ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -72,7 +72,7 @@ set(HEADERS include(CTest) add_executable(SelfTest ${TEST_SOURCES}) -target_link_libraries(SelfTest PRIVATE Catch2) +target_link_libraries(SelfTest PRIVATE Catch2WithMain) if (CATCH_ENABLE_COVERAGE) set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE) diff --git a/tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp b/tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp index 5deb30f9..c981fa0b 100644 --- a/tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp +++ b/tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp @@ -1,4 +1,3 @@ -#include #include TEST_CASE("Tests that run") { diff --git a/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp b/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp index 0870e9ca..ae698165 100644 --- a/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp +++ b/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp @@ -1,4 +1,3 @@ -#include #include namespace Catch { diff --git a/tests/SelfTest/TestMain.cpp b/tests/SelfTest/TestRegistrations.cpp similarity index 93% rename from tests/SelfTest/TestMain.cpp rename to tests/SelfTest/TestRegistrations.cpp index 88025d3a..dc3625fe 100644 --- a/tests/SelfTest/TestMain.cpp +++ b/tests/SelfTest/TestRegistrations.cpp @@ -24,5 +24,3 @@ struct TestListener : Catch::TestEventListenerBase { #include CATCH_REGISTER_LISTENER( TestListener ) - -#include diff --git a/tools/misc/appveyorBuildConfigurationScript.bat b/tools/misc/appveyorBuildConfigurationScript.bat index 1a01a6af..9ebd6ae0 100644 --- a/tools/misc/appveyorBuildConfigurationScript.bat +++ b/tools/misc/appveyorBuildConfigurationScript.bat @@ -10,12 +10,12 @@ if "%CONFIGURATION%"=="Debug" ( @REM # coverage needs to build the special helper as well as the main cmake -Htools/misc -Bbuild-misc -A%PLATFORM% || exit /b !ERRORLEVEL! cmake --build build-misc || exit /b !ERRORLEVEL! - cmake -H. -BBuild -A%PLATFORM% -DUSE_WMAIN=%wmain% -DMEMORYCHECK_COMMAND=build-misc\Debug\CoverageHelper.exe -DMEMORYCHECK_COMMAND_OPTIONS=--sep-- -DMEMORYCHECK_TYPE=Valgrind -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! + cmake -H. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DMEMORYCHECK_COMMAND=build-misc\Debug\CoverageHelper.exe -DMEMORYCHECK_COMMAND_OPTIONS=--sep-- -DMEMORYCHECK_TYPE=Valgrind -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! ) else ( @REM # We know that coverage is 0 - cmake -H. -BBuild -A%PLATFORM% -DUSE_WMAIN=%wmain% -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! + cmake -H. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! ) ) if "%CONFIGURATION%"=="Release" ( - cmake -H. -BBuild -A%PLATFORM% -DUSE_WMAIN=%wmain% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! + cmake -H. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! )