diff options
author | Sven Gothel <[email protected]> | 2020-12-25 01:34:31 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-12-25 01:34:31 +0100 |
commit | 7028191778fc56646adee24b1805138e4a3a5b9e (patch) | |
tree | da80a8852d2095939d6805c438f6ca2a12d78c82 /include/catch2 | |
parent | a3098623819455cf918dcfb425b1f6baab1ba408 (diff) |
catch2: Move 'main()' from libcatch.a -> catch*.hpp, enabled only if defined(CATCH_CONFIG_MAIN)
This brings back the desired behavior of injecting our own main function for unit tests.
Diffstat (limited to 'include/catch2')
-rw-r--r-- | include/catch2/catch_amalgamated.cpp | 3 | ||||
-rw-r--r-- | include/catch2/catch_amalgamated.hpp | 5 | ||||
-rw-r--r-- | include/catch2/catch_main.cpp | 33 |
3 files changed, 40 insertions, 1 deletions
diff --git a/include/catch2/catch_amalgamated.cpp b/include/catch2/catch_amalgamated.cpp index 43f3eed..3053887 100644 --- a/include/catch2/catch_amalgamated.cpp +++ b/include/catch2/catch_amalgamated.cpp @@ -3907,7 +3907,7 @@ namespace Catch { } // end namespace Catch - +#if 0 namespace Catch { CATCH_INTERNAL_START_WARNINGS_SUPPRESSION @@ -3931,6 +3931,7 @@ int main (int argc, char * argv[]) { return Catch::Session().run( argc, argv ); } +#endif #include <cstdio> diff --git a/include/catch2/catch_amalgamated.hpp b/include/catch2/catch_amalgamated.hpp index 7f83241..ddbbb4e 100644 --- a/include/catch2/catch_amalgamated.hpp +++ b/include/catch2/catch_amalgamated.hpp @@ -10984,4 +10984,9 @@ namespace Catch { #endif // CATCH_REPORTERS_ALL_HPP_INCLUDED #endif // CATCH_ALL_HPP_INCLUDED + +#if defined(CATCH_CONFIG_MAIN) +#include <catch2/catch_main.cpp> +#endif /* defined(CATCH_CONFIG_MAIN) */ + #endif // CATCH_AMALGAMATED_HPP_INCLUDED diff --git a/include/catch2/catch_main.cpp b/include/catch2/catch_main.cpp new file mode 100644 index 0000000..2104955 --- /dev/null +++ b/include/catch2/catch_main.cpp @@ -0,0 +1,33 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 +// #include <catch2/catch_session.hpp> +// #include <catch2/internal/catch_compiler_capabilities.hpp> +// #include <catch2/internal/catch_leak_detector.hpp> +// #include <catch2/internal/catch_platform.hpp> + +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 ); +} |