diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-06-29 19:28:09 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-06-29 19:28:09 +0100 |
| commit | 67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b (patch) | |
| tree | 1ecd818f4bcf7d12622d43dc92c4d4bb9b746d0f /contrib/catch2/tests/ExtraTests | |
| parent | a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df (diff) | |
| parent | bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1 (diff) | |
| download | nihil-67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b.tar.gz nihil-67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b.tar.bz2 | |
Add 'contrib/catch2/' from commit 'bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1'
git-subtree-dir: contrib/catch2
git-subtree-mainline: a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df
git-subtree-split: bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1
Diffstat (limited to 'contrib/catch2/tests/ExtraTests')
31 files changed, 1850 insertions, 0 deletions
diff --git a/contrib/catch2/tests/ExtraTests/CMakeLists.txt b/contrib/catch2/tests/ExtraTests/CMakeLists.txt new file mode 100644 index 0000000..3c38d67 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/CMakeLists.txt @@ -0,0 +1,577 @@ +# +# Build extra tests. +# + +cmake_minimum_required( VERSION 3.16 ) + +project( Catch2ExtraTests LANGUAGES CXX ) + +message( STATUS "Extra tests included" ) + +add_test( + NAME TestShardingIntegration + COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testSharding.py $<TARGET_FILE:SelfTest> +) +set_tests_properties(TestShardingIntegration + PROPERTIES + LABELS "uses-python" +) + +add_test( + NAME TestSharding::OverlyLargeShardIndex + COMMAND $<TARGET_FILE:SelfTest> --shard-index 5 --shard-count 5 +) +set_tests_properties( + TestSharding::OverlyLargeShardIndex + PROPERTIES + PASS_REGULAR_EXPRESSION "The shard count \\(5\\) must be greater than the shard index \\(5\\)" +) + +# The MinDuration reporting tests do not need separate compilation, but +# they have non-trivial execution time, so they are categorized as +# extra tests, so that they are run less. +add_test(NAME MinDuration::SimpleThreshold COMMAND $<TARGET_FILE:SelfTest> --min-duration 0.950 [min_duration_test]) +set_tests_properties( + MinDuration::SimpleThreshold + PROPERTIES + PASS_REGULAR_EXPRESSION "s: sleep_for_1000ms" + FAIL_REGULAR_EXPRESSION "sleep_for_100ms" + RUN_SERIAL ON # The test is timing sensitive, so we want to run it + # serially to avoid false positives on oversubscribed machines +) + +# -d yes overrides the threshold, so we should see the faster test even +# with a ridiculous high min duration threshold +add_test(NAME MinDuration::DurationOverrideYes COMMAND $<TARGET_FILE:SelfTest> --min-duration 1.0 -d yes [min_duration_test]) +set_tests_properties( + MinDuration::DurationOverrideYes + PROPERTIES + PASS_REGULAR_EXPRESSION "s: sleep_for_100ms" +) + +# -d no overrides the threshold, so we should never see any tests even +# with ridiculously low min duration threshold +add_test(NAME MinDuration::DurationOverrideNo COMMAND $<TARGET_FILE:SelfTest> --min-duration 0.0001 -d no [min_duration_test]) +set_tests_properties( + MinDuration::DurationOverrideNo + PROPERTIES + FAIL_REGULAR_EXPRESSION "sleep_for_250ms" +) + + +# ------------ end of duration reporting tests + +# define folders used: +set( TESTS_DIR ${CATCH_DIR}/tests/ExtraTests ) + +add_executable(PrefixedMacros ${TESTS_DIR}/X01-PrefixedMacros.cpp) +target_compile_definitions( PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL CATCH_CONFIG_RUNTIME_STATIC_REQUIRE ) +# Macro configuration does not touch the compiled parts, so we can link +# it against the main library +target_link_libraries( PrefixedMacros Catch2WithMain ) + +add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s) +set_tests_properties( + CATCH_CONFIG_PREFIX_ALL + PROPERTIES + PASS_REGULAR_EXPRESSION "CATCH_" + FAIL_REGULAR_EXPRESSION + # The spaces are important -> They disambiguate between CATCH_REQUIRE + # and REQUIRE without prefix. + " REQUIRE; REQUIRE_FALSE; REQUIRE_THROWS; REQUIRE_THROWS_AS; REQUIRE_THROWS_WITH; REQUIRE_THROWS_MATCHES; REQUIRE_NOTHROW; CHECK; CHECK_FALSE; CHECKED_IF; CHECKED_ELSE; CHECK_NOFAIL; CHECK_THROWS; CHECK_THROWS_AS; CHECK_THROWS_WITH; CHECK_THROWS_MATCHES; CHECK_NOTHROW; REQUIRE_THAT; CHECK_THAT" +) + + +add_executable(DisabledMacros ${TESTS_DIR}/X02-DisabledMacros.cpp) +target_compile_definitions( DisabledMacros PRIVATE CATCH_CONFIG_DISABLE ) +# Macro configuration does not touch the compiled parts, so we can link +# it against the main library +target_link_libraries( DisabledMacros Catch2WithMain ) + +add_test(NAME CATCH_CONFIG_DISABLE-1 COMMAND DisabledMacros -s) +set_tests_properties( + CATCH_CONFIG_DISABLE-1 + PROPERTIES + PASS_REGULAR_EXPRESSION "No tests ran" + FAIL_REGULAR_EXPRESSION "This should not happen" +) +add_test(NAME CATCH_CONFIG_DISABLE-2 COMMAND DisabledMacros --list-tests) +set_tests_properties( + CATCH_CONFIG_DISABLE-2 + PROPERTIES + PASS_REGULAR_EXPRESSION "0 test cases" +) + +add_executable( DisabledExceptions-DefaultHandler ${TESTS_DIR}/X03-DisabledExceptions-DefaultHandler.cpp ) +add_executable( DisabledExceptions-CustomHandler ${TESTS_DIR}/X04-DisabledExceptions-CustomHandler.cpp ) + +foreach(target DisabledExceptions-DefaultHandler DisabledExceptions-CustomHandler) + target_compile_options( ${target} + PUBLIC + $<$<CXX_COMPILER_ID:MSVC>:/EHs-c-;/D_HAS_EXCEPTIONS=0> + $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:AppleClang>>:-fno-exceptions> + ) + target_link_libraries(${target} Catch2_buildall_interface) +endforeach() +target_compile_definitions( DisabledExceptions-CustomHandler PUBLIC CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER ) + + +add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-1 COMMAND DisabledExceptions-DefaultHandler "Tests that run") +set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-1 + PROPERTIES + PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed" + FAIL_REGULAR_EXPRESSION "abort;terminate;fatal" +) + +add_executable( BazelReporter ${TESTS_DIR}/X30-BazelReporter.cpp ) +target_compile_definitions( BazelReporter PRIVATE CATCH_CONFIG_BAZEL_SUPPORT ) +target_link_libraries(BazelReporter Catch2_buildall_interface) +add_test(NAME CATCH_CONFIG_BAZEL_REPORTER-1 + COMMAND + "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelReporter.py" $<TARGET_FILE:BazelReporter> "${CMAKE_CURRENT_BINARY_DIR}" +) +set_tests_properties(CATCH_CONFIG_BAZEL_REPORTER-1 + PROPERTIES + LABELS "uses-python" +) + +# We must now test this works without the build flag. +add_executable( BazelReporterNoCatchConfig ${TESTS_DIR}/X30-BazelReporter.cpp ) +target_link_libraries(BazelReporterNoCatchConfig Catch2WithMain) +add_test(NAME NO_CATCH_CONFIG_BAZEL_REPORTER-1 + COMMAND + "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelReporter.py" $<TARGET_FILE:BazelReporterNoCatchConfig> "${CMAKE_CURRENT_BINARY_DIR}" +) +set_tests_properties(NO_CATCH_CONFIG_BAZEL_REPORTER-1 + PROPERTIES + LABELS "uses-python" + ENVIRONMENT "BAZEL_TEST=1" +) + +add_test(NAME BazelEnv::TESTBRIDGE_TEST_ONLY + COMMAND + $<TARGET_FILE:BazelReporterNoCatchConfig> +) +set_tests_properties(BazelEnv::TESTBRIDGE_TEST_ONLY + PROPERTIES + ENVIRONMENT "BAZEL_TEST=1;TESTBRIDGE_TEST_ONLY=Passing test case" + PASS_REGULAR_EXPRESSION "All tests passed \\(1 assertion in 1 test case\\)" +) + + +add_test(NAME BazelEnv::Sharding + COMMAND + "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelSharding.py" + $<TARGET_FILE:BazelReporterNoCatchConfig> + "${CMAKE_CURRENT_BINARY_DIR}" +) +set_tests_properties(BazelEnv::Sharding + PROPERTIES + LABELS "uses-python" +) + + +# The default handler on Windows leads to the just-in-time debugger firing, +# which makes this test unsuitable for CI and headless runs, as it opens +# up an interactive dialog. +if (NOT WIN32) + add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-2 COMMAND DisabledExceptions-DefaultHandler "Tests that abort") + set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-2 + PROPERTIES + PASS_REGULAR_EXPRESSION "Catch will terminate" + ) +endif() + + +add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-3 COMMAND DisabledExceptions-CustomHandler "Tests that run") +set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-3 + PROPERTIES + PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed" + FAIL_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======" +) + +add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-4 COMMAND DisabledExceptions-CustomHandler "Tests that abort") +set_tests_properties( + CATCH_CONFIG_DISABLE_EXCEPTIONS-4 + PROPERTIES + PASS_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======" +) + + +add_executable(DeferredStaticChecks ${TESTS_DIR}/X05-DeferredStaticChecks.cpp) +target_link_libraries(DeferredStaticChecks PRIVATE Catch2WithMain) +target_compile_definitions(DeferredStaticChecks PRIVATE "CATCH_CONFIG_RUNTIME_STATIC_REQUIRE") + +add_test(NAME DeferredStaticChecks COMMAND DeferredStaticChecks -r compact) +set_tests_properties( + DeferredStaticChecks + PROPERTIES + PASS_REGULAR_EXPRESSION "test cases: 1 \\| 1 failed\nassertions: 3 \\| 3 failed" +) + + +add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp) +target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier ) +target_link_libraries( FallbackStringifier Catch2WithMain ) + +add_test(NAME FallbackStringifier COMMAND FallbackStringifier -r compact -s) +set_tests_properties( + FallbackStringifier + PROPERTIES + PASS_REGULAR_EXPRESSION "foo{} for: { !!! }" +) + + +add_executable(DisableStringification ${TESTS_DIR}/X11-DisableStringification.cpp) +target_compile_definitions( DisableStringification PRIVATE CATCH_CONFIG_DISABLE_STRINGIFICATION ) +target_link_libraries(DisableStringification Catch2WithMain) +add_test(NAME CATCH_CONFIG_DISABLE_STRINGIFICATION COMMAND DisableStringification -r compact -s) +set_tests_properties( + CATCH_CONFIG_DISABLE_STRINGIFICATION + PROPERTIES + PASS_REGULAR_EXPRESSION "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" + FAIL_REGULAR_EXPRESSION "Hidden{} == Hidden{}" +) + + +# This test touches windows.h, so it should only be compiled under msvc +if (MSVC) + # This test fails if it does not compile and succeeds otherwise + add_executable(WindowsHeader ${TESTS_DIR}/X90-WindowsHeaderInclusion.cpp) + target_link_libraries( WindowsHeader Catch2WithMain ) + add_test(NAME WindowsHeader COMMAND WindowsHeader -r compact) + list(APPEND CATCH_WARNING_TARGETS ${EXTRA_TEST_BINARIES} WindowsHeader) +endif() + + +add_executable(PartialTestCaseEvents ${TESTS_DIR}/X21-PartialTestCaseEvents.cpp) +target_link_libraries(PartialTestCaseEvents PRIVATE Catch2WithMain) +add_test( + NAME PartialTestCaseEvents + COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testPartialTestCaseEvent.py $<TARGET_FILE:PartialTestCaseEvents> +) +set_tests_properties(PartialTestCaseEvents + PROPERTIES + LABELS "uses-python" +) + +add_executable(BenchmarksInCumulativeReporter ${TESTS_DIR}/X22-BenchmarksInCumulativeReporter.cpp) +target_link_libraries(BenchmarksInCumulativeReporter PRIVATE Catch2::Catch2WithMain) +add_test( + NAME BenchmarksInCumulativeReporter + COMMAND BenchmarksInCumulativeReporter --reporter testReporter +) +set_tests_properties( + BenchmarksInCumulativeReporter + PROPERTIES + PASS_REGULAR_EXPRESSION "1\n2\n3\n4\n5\n" + COST 30 +) + + +add_executable(CasingInReporterNames ${TESTS_DIR}/X23-CasingInReporterNames.cpp) +target_link_libraries(CasingInReporterNames PRIVATE Catch2::Catch2WithMain) +add_test( + NAME Reporters::registration-is-case-preserving + COMMAND CasingInReporterNames --list-reporters +) +set_tests_properties( + Reporters::registration-is-case-preserving + PROPERTIES + PASS_REGULAR_EXPRESSION "testReporterCASED" +) +add_test( + NAME Reporters::selection-is-case-insensitive + COMMAND CasingInReporterNames -r testReportercased +) +set_tests_properties( + Reporters::selection-is-case-insensitive + PROPERTIES + PASS_REGULAR_EXPRESSION "TestReporter constructed" +) + +add_executable(CapturedStdoutInTestCaseEvents ${TESTS_DIR}/X27-CapturedStdoutInTestCaseEvents.cpp) +target_link_libraries(CapturedStdoutInTestCaseEvents PRIVATE Catch2::Catch2WithMain) +add_test( + NAME Reporters::CapturedStdOutInEvents + COMMAND CapturedStdoutInTestCaseEvents + --reporter test-reporter +) +set_tests_properties( + Reporters::CapturedStdOutInEvents + PROPERTIES + PASS_REGULAR_EXPRESSION "X27 - TestReporter constructed" + FAIL_REGULAR_EXPRESSION "X27 ERROR" +) + + +if (MSVC) + set(_NullFile "NUL") +else() + set(_NullFile "/dev/null") +endif() + +add_executable(ListenerStdoutCaptureInMultireporter ${TESTS_DIR}/X24-ListenerStdoutCaptureInMultireporter.cpp) +target_link_libraries(ListenerStdoutCaptureInMultireporter PRIVATE Catch2::Catch2WithMain) + +# This test checks that there is nothing written out from the process, +# but if CMake is running the tests under Valgrind or similar tool, then +# that will write its own output to stdout and the test would fail. +if (NOT MEMORYCHECK_COMMAND) + add_test( + NAME MultiReporter::NoncapturingListenerDoesntCauseStdoutPassThrough + COMMAND ListenerStdoutCaptureInMultireporter + --reporter xml::out=${_NullFile} + --reporter junit::out=${_NullFile} + ) + + set_tests_properties( + MultiReporter::NoncapturingListenerDoesntCauseStdoutPassThrough + PROPERTIES + PASS_REGULAR_EXPRESSION "X24 - NonCapturingListener initialized" + FAIL_REGULAR_EXPRESSION "X24 - FooBarBaz" + ) +endif() + + +add_executable(ListenerCanAskForCapturedStdout ${TESTS_DIR}/X25-ListenerCanAskForCapturedStdout.cpp) +target_link_libraries(ListenerCanAskForCapturedStdout PRIVATE Catch2::Catch2WithMain) +add_test( + NAME MultiReporter::CapturingListenerCausesStdoutCapture + COMMAND ListenerCanAskForCapturedStdout + --reporter compact::out=${_NullFile} + --reporter console::out=${_NullFile} +) +set_tests_properties( + MultiReporter::CapturingListenerCausesStdoutCapture + PROPERTIES + PASS_REGULAR_EXPRESSION "CapturingListener initialized" + FAIL_REGULAR_EXPRESSION "X25 - ERROR" +) + +add_executable(ReporterPreferencesForPassingAssertionsIsRespected ${TESTS_DIR}/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp) +target_link_libraries(ReporterPreferencesForPassingAssertionsIsRespected PRIVATE Catch2::Catch2WithMain) +add_test( + NAME Reporters::PreferencesForPassingAssertionsIsRespected + COMMAND ReporterPreferencesForPassingAssertionsIsRespected + --reporter test-reporter +) +set_tests_properties( + Reporters::PreferencesForPassingAssertionsIsRespected + PROPERTIES + PASS_REGULAR_EXPRESSION "X26 - TestReporter constructed" + FAIL_REGULAR_EXPRESSION "X26 - assertionEnded" +) +add_test( + NAME MultiReporter::PreferencesForPassingAssertionsIsRespected + COMMAND ReporterPreferencesForPassingAssertionsIsRespected + --reporter test-reporter + --reporter console::out=${_NullFile} +) +set_tests_properties( + MultiReporter::PreferencesForPassingAssertionsIsRespected + PROPERTIES + PASS_REGULAR_EXPRESSION "X26 - TestReporter constructed" + FAIL_REGULAR_EXPRESSION "X26 - assertionEnded" +) + +add_executable(ListenersGetEventsBeforeReporters ${TESTS_DIR}/X28-ListenersGetEventsBeforeReporters.cpp) +target_link_libraries(ListenersGetEventsBeforeReporters PRIVATE Catch2::Catch2WithMain) +add_test( + NAME ListenersGetEventsBeforeReporters + COMMAND ListenersGetEventsBeforeReporters --reporter test-reporter +) +set_tests_properties( + ListenersGetEventsBeforeReporters + PROPERTIES + PASS_REGULAR_EXPRESSION "X28 - TestReporter constructed" + FAIL_REGULAR_EXPRESSION "X28 - ERROR" +) + +add_executable(CustomArgumentsForReporters ${TESTS_DIR}/X29-CustomArgumentsForReporters.cpp) +target_link_libraries(CustomArgumentsForReporters PRIVATE Catch2::Catch2WithMain) +add_test( + NAME CustomArgumentsForReporters + COMMAND CustomArgumentsForReporters + --reporter "test-reporter::Xa b=c 1::Xz:e = 1234" +) +set_tests_properties( + CustomArgumentsForReporters + PROPERTIES + PASS_REGULAR_EXPRESSION "Xa b=c 1::Xz:e = 1234" +) + + +add_executable(DuplicatedTestCases-SameNameAndTags ${TESTS_DIR}/X31-DuplicatedTestCases.cpp) +target_link_libraries(DuplicatedTestCases-SameNameAndTags PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::SameNameAndTags + COMMAND $<TARGET_FILE:DuplicatedTestCases-SameNameAndTags> +) +set_tests_properties( + DuplicatedTestCases::SameNameAndTags + PROPERTIES + PASS_REGULAR_EXPRESSION "error: .* already defined\\." +) + +add_executable(DuplicatedTestCases-SameNameDifferentTags ${TESTS_DIR}/X32-DuplicatedTestCasesDifferentTags.cpp) +target_link_libraries(DuplicatedTestCases-SameNameDifferentTags PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::SameNameDifferentTags + COMMAND $<TARGET_FILE:DuplicatedTestCases-SameNameDifferentTags> +) +set_tests_properties( + DuplicatedTestCases::SameNameDifferentTags + PROPERTIES + FAIL_REGULAR_EXPRESSION "error: .* already defined\\." +) + +add_executable(DuplicatedTestCases-DuplicatedTestCaseMethods ${TESTS_DIR}/X33-DuplicatedTestCaseMethods.cpp) +target_link_libraries(DuplicatedTestCases-DuplicatedTestCaseMethods PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::DuplicatedTestCaseMethods + COMMAND $<TARGET_FILE:DuplicatedTestCases-DuplicatedTestCaseMethods> +) +set_tests_properties( + DuplicatedTestCases::DuplicatedTestCaseMethods + PROPERTIES + PASS_REGULAR_EXPRESSION "error: .* already defined\\." +) + +add_executable(DuplicatedTestCases-DifferentFixtures ${TESTS_DIR}/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp) +target_link_libraries(DuplicatedTestCases-DifferentFixtures PRIVATE Catch2::Catch2WithMain) +add_test( + NAME DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures + COMMAND $<TARGET_FILE:DuplicatedTestCases-DifferentFixtures> +) +set_tests_properties( + DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures + PROPERTIES + FAIL_REGULAR_EXPRESSION "error: .* already defined\\." +) + + +add_executable(DuplicatedReporters ${TESTS_DIR}/X35-DuplicatedReporterNames.cpp) +target_link_libraries(DuplicatedReporters PRIVATE Catch2::Catch2WithMain) +add_test( + NAME Reporters::RegistrationErrorsAreCaught + COMMAND $<TARGET_FILE:DuplicatedReporters> +) +set_tests_properties( + Reporters::RegistrationErrorsAreCaught + PROPERTIES + PASS_REGULAR_EXPRESSION "Errors occurred during startup!" +) + +add_executable(ReportingCrashWithJunitReporter ${TESTS_DIR}/X36-ReportingCrashWithJunitReporter.cpp) +target_link_libraries(ReportingCrashWithJunitReporter PRIVATE Catch2::Catch2WithMain) +add_test( + NAME Reporters::CrashInJunitReporter + COMMAND ${CMAKE_COMMAND} -E env $<TARGET_FILE:ReportingCrashWithJunitReporter> --reporter JUnit +) +set_tests_properties( + Reporters::CrashInJunitReporter + PROPERTIES + PASS_REGULAR_EXPRESSION "</testsuites>" + LABELS "uses-signals" +) + +add_executable(AssertionStartingEventGoesBeforeAssertionIsEvaluated + X20-AssertionStartingEventGoesBeforeAssertionIsEvaluated.cpp +) +target_link_libraries(AssertionStartingEventGoesBeforeAssertionIsEvaluated + PRIVATE Catch2::Catch2WithMain +) +add_test( + NAME ReporterEvents::AssertionStartingHappensBeforeAssertionIsEvaluated + COMMAND $<TARGET_FILE:AssertionStartingEventGoesBeforeAssertionIsEvaluated> +) + +#add_executable(DebugBreakMacros ${TESTS_DIR}/X12-CustomDebugBreakMacro.cpp) +#target_link_libraries(DebugBreakMacros Catch2) +#add_test(NAME DebugBreakMacros COMMAND DebugBreakMacros --break) +#set_tests_properties( +# DebugBreakMacros +# PROPERTIES +# PASS_REGULAR_EXPRESSION "Pretty please, break into debugger" +#) + +add_executable(NoTests ${TESTS_DIR}/X92-NoTests.cpp) +target_link_libraries(NoTests PRIVATE Catch2::Catch2WithMain) + +add_test( + NAME TestSpecs::EmptySpecWithNoTestsFails + COMMAND $<TARGET_FILE:NoTests> +) +set_tests_properties(TestSpecs::EmptySpecWithNoTestsFails + PROPERTIES + WILL_FAIL ON +) + +add_test( + NAME TestSpecs::OverrideFailureWithEmptySpec + COMMAND $<TARGET_FILE:NoTests> --allow-running-no-tests +) + +add_test( + NAME List::Listeners::WorksWithoutRegisteredListeners + COMMAND $<TARGET_FILE:NoTests> --list-listeners +) + + +add_executable(AllSkipped ${TESTS_DIR}/X93-AllSkipped.cpp) +target_link_libraries(AllSkipped PRIVATE Catch2::Catch2WithMain) + +add_test( + NAME TestSpecs::SkippingAllTestsFails + COMMAND $<TARGET_FILE:AllSkipped> +) +set_tests_properties(TestSpecs::SkippingAllTestsFails + PROPERTIES + WILL_FAIL ON +) + +set( EXTRA_TEST_BINARIES + AllSkipped + PrefixedMacros + DisabledMacros + DisabledExceptions-DefaultHandler + DisabledExceptions-CustomHandler + FallbackStringifier + DisableStringification + PartialTestCaseEvents + DuplicatedTestCases-SameNameAndTags + DuplicatedTestCases-SameNameDifferentTags + DuplicatedTestCases-DuplicatedTestCaseMethods + NoTests + ListenersGetEventsBeforeReporters +# DebugBreakMacros +) + +# Notice that we are modifying EXTRA_TEST_BINARIES destructively, do not +# use it after this point! +list(FILTER EXTRA_TEST_BINARIES EXCLUDE REGEX "DisabledExceptions.*") +list(APPEND CATCH_WARNING_TARGETS ${EXTRA_TEST_BINARIES}) +set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE) + + +# This sets up a one-off executable that compiles against the amalgamated +# files, and then runs it for a super simple check that the amalgamated +# files are usable. +add_executable(AmalgamatedTestCompilation + ${TESTS_DIR}/X91-AmalgamatedCatch.cpp + ${CATCH_DIR}/extras/catch_amalgamated.hpp + ${CATCH_DIR}/extras/catch_amalgamated.cpp +) +target_include_directories(AmalgamatedTestCompilation PRIVATE ${CATCH_DIR}/extras) +target_compile_features(AmalgamatedTestCompilation PRIVATE cxx_std_14) + +add_test(NAME AmalgamatedFileTest COMMAND AmalgamatedTestCompilation) +set_tests_properties( + AmalgamatedFileTest + PROPERTIES + PASS_REGULAR_EXPRESSION "All tests passed \\(14 assertions in 3 test cases\\)" +) diff --git a/contrib/catch2/tests/ExtraTests/ToDo.txt b/contrib/catch2/tests/ExtraTests/ToDo.txt new file mode 100644 index 0000000..a2ed36b --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/ToDo.txt @@ -0,0 +1,10 @@ +Configuration options that are left default and thus are not properly tested +yet: + + CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases + CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows + CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed + CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals + CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap + CATCH_CONFIG_DEFAULT_REPORTER + CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS diff --git a/contrib/catch2/tests/ExtraTests/X01-PrefixedMacros.cpp b/contrib/catch2/tests/ExtraTests/X01-PrefixedMacros.cpp new file mode 100644 index 0000000..d1c246e --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X01-PrefixedMacros.cpp @@ -0,0 +1,97 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that Catch's prefixed macros compile and run properly. + * + * We intentionally do not provide full coverage of all macros, but we + * test a smattering and can add other ones as they have regressions. + */ + + +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_predicate.hpp> +#include <catch2/matchers/catch_matchers_string.hpp> + +#include <type_traits> +#include <stdexcept> + +namespace { + [[noreturn]] + void this_throws() { + throw std::runtime_error("Some msg"); + } + void this_doesnt_throw() {} +} + +CATCH_TEST_CASE("PrefixedMacros") { + using namespace Catch::Matchers; + + CATCH_REQUIRE( 1 == 1 ); + CATCH_REQUIRE_FALSE( 1 != 1 ); + + CATCH_REQUIRE_THROWS(this_throws()); + CATCH_REQUIRE_THROWS_AS(this_throws(), std::runtime_error); + CATCH_REQUIRE_THROWS_WITH(this_throws(), "Some msg"); + CATCH_REQUIRE_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; })); + CATCH_REQUIRE_NOTHROW(this_doesnt_throw()); + + CATCH_CHECK( 1 == 1 ); + CATCH_CHECK_FALSE( 1 != 1 ); + CATCH_CHECKED_IF( 1 == 1 ) { + CATCH_SUCCEED("don't care"); + } CATCH_CHECKED_ELSE ( 1 == 1 ) { + CATCH_SUCCEED("don't care"); + } + + CATCH_CHECK_NOFAIL(1 == 2); + + CATCH_CHECK_THROWS(this_throws()); + CATCH_CHECK_THROWS_AS(this_throws(), std::runtime_error); + CATCH_CHECK_THROWS_WITH(this_throws(), "Some msg"); + CATCH_CHECK_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; })); + CATCH_CHECK_NOTHROW(this_doesnt_throw()); + + CATCH_REQUIRE_THAT("abcd", Equals("abcd")); + CATCH_CHECK_THAT("bdef", Equals("bdef")); + + CATCH_INFO( "some info" ); + CATCH_UNSCOPED_INFO( "some info" ); + CATCH_WARN( "some warn" ); + CATCH_SECTION("some section") { + int i = 1; + CATCH_CAPTURE( i ); + CATCH_CAPTURE( i, i + 1 ); + CATCH_DYNAMIC_SECTION("Dynamic section: " << i) { + CATCH_FAIL_CHECK( "failure" ); + } + } + + CATCH_STATIC_REQUIRE( std::is_void<void>::value ); + CATCH_STATIC_REQUIRE_FALSE( std::is_void<int>::value ); + CATCH_STATIC_CHECK( std::is_void<void>::value ); + CATCH_STATIC_CHECK_FALSE( std::is_void<int>::value ); + CATCH_FAIL(""); +} + +// Missing: + +// +// #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +// #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +// #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +// +// // "BDD-style" convenience wrappers +// #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) +// #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) +// #define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) +// #define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) +// #define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And when: " << desc ) +// #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) +// #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) +// diff --git a/contrib/catch2/tests/ExtraTests/X02-DisabledMacros.cpp b/contrib/catch2/tests/ExtraTests/X02-DisabledMacros.cpp new file mode 100644 index 0000000..231adfb --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X02-DisabledMacros.cpp @@ -0,0 +1,79 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that CATCH_CONFIG_DISABLE turns off TEST_CASE autoregistration + * and expressions in assertion macros are not run. + */ + +#include <catch2/benchmark/catch_benchmark.hpp> +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers.hpp> +#include <catch2/matchers/catch_matchers_predicate.hpp> + +#include <iostream> + +struct foo { + foo() { REQUIRE_NOTHROW( print() ); } + void print() const { std::cout << "This should not happen\n"; } +}; + +#if defined( __clang__ ) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wglobal-constructors" +#endif +// Construct foo, but `foo::print` should not be run +static foo f; + +#if defined( __clang__ ) +// The test is unused since the registration is disabled +# pragma clang diagnostic ignored "-Wunused-function" +#endif + +// This test should not be run, because it won't be registered +TEST_CASE( "Disabled Macros" ) { + CHECK( 1 == 2 ); + REQUIRE( 1 == 2 ); + std::cout << "This should not happen\n"; + FAIL(); + + // Test that static assertions don't fire when macros are disabled + STATIC_CHECK( 0 == 1 ); + STATIC_REQUIRE( !true ); + + CAPTURE( 1 ); + CAPTURE( 1, "captured" ); + + REQUIRE_THAT( 1, + Catch::Matchers::Predicate( []( int ) { return false; } ) ); + BENCHMARK( "Disabled benchmark" ) { REQUIRE( 1 == 2 ); }; +} + +struct DisabledFixture {}; + +TEST_CASE_PERSISTENT_FIXTURE( DisabledFixture, "Disabled Persistent Fixture" ) { + CHECK( 1 == 2 ); + REQUIRE( 1 == 2 ); + std::cout << "This should not happen\n"; + FAIL(); + + // Test that static assertions don't fire when macros are disabled + STATIC_CHECK( 0 == 1 ); + STATIC_REQUIRE( !true ); + + CAPTURE( 1 ); + CAPTURE( 1, "captured" ); + + REQUIRE_THAT( 1, + Catch::Matchers::Predicate( []( int ) { return false; } ) ); + BENCHMARK( "Disabled benchmark" ) { REQUIRE( 1 == 2 ); }; +} + +#if defined( __clang__ ) +# pragma clang diagnostic pop +#endif diff --git a/contrib/catch2/tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp b/contrib/catch2/tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp new file mode 100644 index 0000000..5b6d4b1 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp @@ -0,0 +1,39 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include <catch2/catch_test_macros.hpp> +#include <catch2/benchmark/catch_benchmark.hpp> +#include <catch2/matchers/catch_matchers.hpp> +#include <catch2/matchers/catch_matchers_predicate.hpp> + +TEST_CASE("Tests that run") { + // All of these should be run and be reported + CHECK(1 == 2); + CHECK(1 == 1); + CHECK(1 != 3); + CHECK(1 == 4); +} + + + +TEST_CASE("Tests that abort") { + // Avoid abort and other exceptional exits -- there is no way + // to tell CMake that abort is the desired outcome of a test. + std::set_terminate([](){exit(1);}); + REQUIRE(1 == 1); + REQUIRE(1 != 2); + REQUIRE(1 == 3); + // We should not get here, because the test above aborts + REQUIRE(1 != 4); +} + +TEST_CASE( "Misc. macros to check that they compile without exceptions" ) { + BENCHMARK( "simple benchmark" ) { return 1 * 2 + 3; }; + REQUIRE_THAT( 1, + Catch::Matchers::Predicate<int>( []( int i ) { return i == 1; } ) ); +} diff --git a/contrib/catch2/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp b/contrib/catch2/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp new file mode 100644 index 0000000..e1f1e70 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp @@ -0,0 +1,40 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include <catch2/catch_test_macros.hpp> + +#include <iostream> + +namespace Catch { + [[noreturn]] + void throw_exception(std::exception const& e) { + std::cerr << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\n" + << "The message was: " << e.what() << '\n'; + // Avoid abort and other exceptional exits -- there is no way + // to tell CMake that abort is the desired outcome of a test. + exit(1); + } +} + +TEST_CASE("Tests that run") { + // All of these should be run and be reported + CHECK(1 == 2); + CHECK(1 == 1); + CHECK(1 != 3); + CHECK(1 == 4); +} + + + +TEST_CASE("Tests that abort") { + REQUIRE(1 == 1); + REQUIRE(1 != 2); + REQUIRE(1 == 3); + // We should not get here, because the test above aborts + REQUIRE(1 != 4); +} diff --git a/contrib/catch2/tests/ExtraTests/X05-DeferredStaticChecks.cpp b/contrib/catch2/tests/ExtraTests/X05-DeferredStaticChecks.cpp new file mode 100644 index 0000000..8005dbc --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X05-DeferredStaticChecks.cpp @@ -0,0 +1,21 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that when `STATIC_CHECK` is deferred to runtime and fails, it + * does not abort the test case. + */ + +#include <catch2/catch_test_macros.hpp> + +TEST_CASE("Deferred static checks") { + STATIC_CHECK(1 == 2); + STATIC_CHECK_FALSE(1 != 2); + // This last assertion must be executed too + CHECK(1 == 2); +} diff --git a/contrib/catch2/tests/ExtraTests/X10-FallbackStringifier.cpp b/contrib/catch2/tests/ExtraTests/X10-FallbackStringifier.cpp new file mode 100644 index 0000000..8525a81 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X10-FallbackStringifier.cpp @@ -0,0 +1,35 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that the user can define custom fallbackStringifier + * + * This is done by defining a custom fallback stringifier that prints + * out a specific string, and then asserting (to cause stringification) + * over a type without stringification support. + */ + +#include <string> + +// A catch-all stringifier +template <typename T> +std::string fallbackStringifier(T const&) { + return "{ !!! }"; +} + +#include <catch2/catch_test_macros.hpp> + +struct foo { + explicit operator bool() const { + return true; + } +}; + +TEST_CASE("aa") { + REQUIRE(foo{}); +} diff --git a/contrib/catch2/tests/ExtraTests/X11-DisableStringification.cpp b/contrib/catch2/tests/ExtraTests/X11-DisableStringification.cpp new file mode 100644 index 0000000..f899627 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X11-DisableStringification.cpp @@ -0,0 +1,27 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that stringification of original expression can be disabled. + * + * This is a workaround for VS 2017, 2019 issue with Raw String literals + * and preprocessor token pasting. + */ + + +#include <catch2/catch_test_macros.hpp> + +namespace { + struct Hidden {}; + + bool operator==(Hidden, Hidden) { return true; } +} + +TEST_CASE("DisableStringification") { + REQUIRE( Hidden{} == Hidden{} ); +} diff --git a/contrib/catch2/tests/ExtraTests/X12-CustomDebugBreakMacro.cpp b/contrib/catch2/tests/ExtraTests/X12-CustomDebugBreakMacro.cpp new file mode 100644 index 0000000..e6d3e38 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X12-CustomDebugBreakMacro.cpp @@ -0,0 +1,26 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that user-defined `CATCH_BREAK_INTO_DEBUGGER` is respected and used. + */ + +#include <iostream> + +void custom_debug_break() { + std::cerr << "Pretty please, break into debugger\n"; +} + +#define CATCH_BREAK_INTO_DEBUGGER() custom_debug_break() + +#define CATCH_CONFIG_MAIN +#include <catch2/catch.hpp> + +TEST_CASE("Failing test that breaks into debugger", "[macros]") { + REQUIRE(1 == 2); +} diff --git a/contrib/catch2/tests/ExtraTests/X20-AssertionStartingEventGoesBeforeAssertionIsEvaluated.cpp b/contrib/catch2/tests/ExtraTests/X20-AssertionStartingEventGoesBeforeAssertionIsEvaluated.cpp new file mode 100644 index 0000000..6f44bf6 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X20-AssertionStartingEventGoesBeforeAssertionIsEvaluated.cpp @@ -0,0 +1,77 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Registers an event listener to increments counter of assertionStarting events. + * + * Different assertion macros then check that the counter is at expected + * value when they are evaluated. + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_event_listener.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> +#include <catch2/matchers/catch_matchers_predicate.hpp> + +namespace { + + static size_t assertion_starting_events_seen = 0; + + class AssertionStartingListener : public Catch::EventListenerBase { + public: + AssertionStartingListener( Catch::IConfig const* config ): + EventListenerBase( config ) {} + + void assertionStarting( Catch::AssertionInfo const& ) override { + ++assertion_starting_events_seen; + } + }; + + static bool f1() { + return assertion_starting_events_seen == 1; + } + + static void f2() { + if ( assertion_starting_events_seen != 2 ) { throw 1; } + } + + static void f3() { + if ( assertion_starting_events_seen == 3 ) { throw 1; } + } + + static bool f4() { return assertion_starting_events_seen == 4; } + + static void f5() { throw assertion_starting_events_seen; } + +} // anonymous namespace + +CATCH_REGISTER_LISTENER( AssertionStartingListener ) + +TEST_CASE() { + // **IMPORTANT** + // The order of assertions below matters. + REQUIRE( f1() ); + REQUIRE_NOTHROW( f2() ); + REQUIRE_THROWS( f3() ); + REQUIRE_THAT( f4(), + Catch::Matchers::Predicate<bool>( []( bool b ) { return b; } ) ); + REQUIRE_THROWS_MATCHES( + f5(), size_t, Catch::Matchers::Predicate<size_t>( []( size_t i ) { + return i == 5; + } ) ); + + CAPTURE( assertion_starting_events_seen ); // **not** an assertion + INFO( "some info msg" ); // **not** an assertion + WARN( "warning! warning!" ); // assertion-like message + SUCCEED(); // assertion-like message + + // We skip FAIL/SKIP and so on, which fail the test. + + // This require will also increment the count once + REQUIRE( assertion_starting_events_seen == 8 ); +} diff --git a/contrib/catch2/tests/ExtraTests/X21-PartialTestCaseEvents.cpp b/contrib/catch2/tests/ExtraTests/X21-PartialTestCaseEvents.cpp new file mode 100644 index 0000000..aa5204c --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X21-PartialTestCaseEvents.cpp @@ -0,0 +1,74 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Registers custom reporter that reports testCase* events + * + * The resulting executable can then be used by an external Python script + * to verify that testCase{Starting,Ended} and testCasePartial{Starting,Ended} + * events are properly nested. + */ + + +#include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> +#include <catch2/catch_test_case_info.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> +#include <catch2/generators/catch_generators.hpp> + + +#include <iostream> + +using Catch::TestCaseInfo; +using Catch::TestCaseStats; + +class PartialReporter : public Catch::StreamingReporterBase { +public: + using StreamingReporterBase::StreamingReporterBase; + + ~PartialReporter() override; // = default + + static std::string getDescription() { + return "Special reporter for testing TestCasePartialStarting/Ended events"; + } + + //! Called _once_ for each TEST_CASE, no matter how many times it is entered + void testCaseStarting(TestCaseInfo const& testInfo) override { + std::cout << "TestCaseStarting: " << testInfo.name << '\n'; + } + //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections) + void testCasePartialStarting(TestCaseInfo const& testInfo, uint64_t partNumber) override { + std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n'; + } + + + //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections) + void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber) override { + std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n'; + } + //! Called _once_ for each TEST_CASE, no matter how many times it is entered + void testCaseEnded(TestCaseStats const& testCaseStats) override { + std::cout << "TestCaseEnded: " << testCaseStats.testInfo->name << '\n'; + } +}; +PartialReporter::~PartialReporter() = default; + + +CATCH_REGISTER_REPORTER("partial", PartialReporter) + +TEST_CASE("section") { + SECTION("A") {} + SECTION("B") {} + SECTION("C") {} + SECTION("D") {} +} + +TEST_CASE("generator") { + auto _ = GENERATE(1, 2, 3, 4); + (void)_; +} diff --git a/contrib/catch2/tests/ExtraTests/X22-BenchmarksInCumulativeReporter.cpp b/contrib/catch2/tests/ExtraTests/X22-BenchmarksInCumulativeReporter.cpp new file mode 100644 index 0000000..33399a6 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X22-BenchmarksInCumulativeReporter.cpp @@ -0,0 +1,79 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that the cumulative reporter base stores both assertions and + * benchmarks, and stores them in the right order. + * + * This is done through a custom reporter that writes out the assertions + * and benchmarks and checking that the output is in right order. + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/benchmark/catch_benchmark.hpp> +#include <catch2/reporters/catch_reporter_cumulative_base.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <iostream> +#include <utility> + +class CumulativeBenchmarkReporter final : public Catch::CumulativeReporterBase { + +public: + CumulativeBenchmarkReporter(Catch::ReporterConfig&& _config) : + CumulativeReporterBase(std::move(_config)) { + m_preferences.shouldReportAllAssertions = true; + } + + static std::string getDescription() { + return "Custom reporter for testing cumulative reporter base"; + } + + void testRunEndedCumulative() override; +}; + +CATCH_REGISTER_REPORTER("testReporter", CumulativeBenchmarkReporter) + +#include <chrono> +#include <thread> + +TEST_CASE("Some assertions and benchmarks") { + using namespace std::chrono_literals; + + REQUIRE(1); + BENCHMARK("2") { + std::this_thread::sleep_for(1ms); + }; + REQUIRE(3); + BENCHMARK("4") { + std::this_thread::sleep_for(1ms); + }; + REQUIRE(5); +} + +void CumulativeBenchmarkReporter::testRunEndedCumulative() { + auto const& testCases = m_testRun->children; + assert(testCases.size() == 1); + + auto const& testCase = *testCases.front(); + auto const& sections = testCase.children; + assert(sections.size() == 1); + + auto const& section = *sections.front(); + assert(section.childSections.empty()); + for (auto const& aob : section.assertionsAndBenchmarks) { + if (aob.isAssertion()) { + auto const& assertion = aob.asAssertion(); + std::cout << assertion.assertionResult.getExpandedExpression() << '\n'; + } + if (aob.isBenchmark()) { + auto const& bench = aob.asBenchmark(); + std::cout << bench.info.name << '\n'; + } + } +} diff --git a/contrib/catch2/tests/ExtraTests/X23-CasingInReporterNames.cpp b/contrib/catch2/tests/ExtraTests/X23-CasingInReporterNames.cpp new file mode 100644 index 0000000..3052373 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X23-CasingInReporterNames.cpp @@ -0,0 +1,41 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that reporter registration is case-preserving, selection is + * case-insensitive. + * + * This is done by registering a custom reporter that prints out a marker + * string upon construction and then invoking the binary with different + * casings of the name. + */ + +#include <catch2/reporters/catch_reporter_streaming_base.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <iostream> +#include <utility> + +class TestReporter : public Catch::StreamingReporterBase { +public: + TestReporter(Catch::ReporterConfig&& _config): + StreamingReporterBase(std::move(_config)) { + std::cout << "TestReporter constructed\n"; + } + + static std::string getDescription() { + return "Reporter for testing casing handling in reporter registration/selection"; + } + + ~TestReporter() override; +}; + +TestReporter::~TestReporter() = default; + +CATCH_REGISTER_REPORTER("testReporterCASED", TestReporter) + diff --git a/contrib/catch2/tests/ExtraTests/X24-ListenerStdoutCaptureInMultireporter.cpp b/contrib/catch2/tests/ExtraTests/X24-ListenerStdoutCaptureInMultireporter.cpp new file mode 100644 index 0000000..ffb706e --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X24-ListenerStdoutCaptureInMultireporter.cpp @@ -0,0 +1,40 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Registers custom listener that does not ask for captured stdout/err + * + * Running the binary with this listener, and asking for multiple _capturing_ + * reporters (one would be sufficient, but that would also mean depending on + * implementation details inside Catch2's handling of listeners), we check that + * nothing is written to stdout, because listeners should not be considered in + * whether the stdout should be passed-through or not. + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_event_listener.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <iostream> + +namespace { + class NonCapturingListener : public Catch::EventListenerBase { + public: + NonCapturingListener( Catch::IConfig const* config ): + EventListenerBase( config ) { + m_preferences.shouldRedirectStdOut = false; + std::cerr << "X24 - NonCapturingListener initialized.\n"; + } + }; +} + +CATCH_REGISTER_LISTENER( NonCapturingListener ) + +TEST_CASE( "Writes to stdout" ) { + std::cout << "X24 - FooBarBaz\n"; +} diff --git a/contrib/catch2/tests/ExtraTests/X25-ListenerCanAskForCapturedStdout.cpp b/contrib/catch2/tests/ExtraTests/X25-ListenerCanAskForCapturedStdout.cpp new file mode 100644 index 0000000..de75ef4 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X25-ListenerCanAskForCapturedStdout.cpp @@ -0,0 +1,47 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Registers custom listener that asks for captured stdout/err + * + * Running the binary with this listener, and asking for multiple _noncapturing_ + * reporters (one would be sufficient, but that would also mean depending on + * implementation details inside Catch2's handling of listeners), we check that + * the listener gets redirected stdout, even though the reporters didn't ask for + * it. + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_event_listener.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <iostream> + +namespace { + class CapturingListener : public Catch::EventListenerBase { + public: + CapturingListener( Catch::IConfig const* config ): + EventListenerBase( config ) { + m_preferences.shouldRedirectStdOut = true; + std::cerr << "CapturingListener initialized\n"; + } + + void + testCaseEnded( Catch::TestCaseStats const& testCaseStats ) override { + if ( testCaseStats.stdOut.empty() ) { + std::cerr << "X25 - ERROR: empty stdout\n"; + } + } + }; +} + +CATCH_REGISTER_LISTENER( CapturingListener ) + +TEST_CASE( "Writes to stdout" ) { + std::cout << "X25 - FooBarBaz\n"; +} diff --git a/contrib/catch2/tests/ExtraTests/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp b/contrib/catch2/tests/ExtraTests/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp new file mode 100644 index 0000000..90a5885 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp @@ -0,0 +1,52 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that reporter is not passed passing assertions when it + * doesn't ask for it. + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <iostream> +#include <utility> + +namespace { + + class TestReporter : public Catch::StreamingReporterBase { + public: + TestReporter(Catch::ReporterConfig&& _config): + StreamingReporterBase(std::move(_config)) { + m_preferences.shouldReportAllAssertions = false; + std::cout << "X26 - TestReporter constructed\n"; + } + + static std::string getDescription() { + return "X26 - test reporter that opts out of passing assertions"; + } + + void + assertionEnded( Catch::AssertionStats const& ) override { + std::cerr << "X26 - assertionEnded\n"; + } + + ~TestReporter() override; + }; + + TestReporter::~TestReporter() = default; + +} + +CATCH_REGISTER_REPORTER("test-reporter", TestReporter) + +TEST_CASE( "Test with only passing assertions" ) { + REQUIRE( 1 == 1 ); + REQUIRE( 2 == 2 ); +} diff --git a/contrib/catch2/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp b/contrib/catch2/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp new file mode 100644 index 0000000..61aaa02 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X27-CapturedStdoutInTestCaseEvents.cpp @@ -0,0 +1,82 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that the captured stdout/err in (partial) testCaseEnded events + * is correct (e.g. that the partial test case event does not get accumulated + * output). + * + * This is done by having a single test case that is entered multiple + * times through generator, and a custom capturing reporter that knows + * what it should expect captured from the test case. + */ + + +#include <catch2/catch_test_macros.hpp> +#include <catch2/generators/catch_generators.hpp> +#include <catch2/generators/catch_generators_range.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + + +#include <iostream> +#include <string> +#include <utility> + +class TestReporter : public Catch::StreamingReporterBase { + std::string stdOutString( uint64_t iter ){ + return "stdout " + std::to_string( iter ) + '\n'; + } + std::string stdErrString(uint64_t iter) { + return "stderr " + std::to_string( iter ) + '\n'; + } + +public: + TestReporter( Catch::ReporterConfig&& _config ): + StreamingReporterBase( std::move(_config) ) { + m_preferences.shouldRedirectStdOut = true; + std::cout << "X27 - TestReporter constructed\n"; + } + + static std::string getDescription() { + return "X27 test reporter"; + } + + void testCasePartialEnded( Catch::TestCaseStats const& stats, + uint64_t iter ) override { + if ( stats.stdOut != stdOutString( iter ) ) { + std::cerr << "X27 ERROR in partial stdout\n" << stats.stdOut; + } + if ( stats.stdErr != stdErrString( iter ) ) { + std::cerr << "X27 ERROR in partial stderr\n" << stats.stdErr; + } + } + + void testCaseEnded( Catch::TestCaseStats const& stats ) override { + if ( stats.stdOut != "stdout 0\nstdout 1\nstdout 2\nstdout 3\nstdout 4\nstdout 5\n" ) { + std::cerr << "X27 ERROR in full stdout\n" << stats.stdOut; + } + if ( stats.stdErr != "stderr 0\nstderr 1\nstderr 2\nstderr 3\nstderr 4\nstderr 5\n" ) { + std::cerr << "X27 ERROR in full stderr\n" << stats.stdErr; + } + } + + ~TestReporter() override; +}; + +TestReporter::~TestReporter() = default; + +CATCH_REGISTER_REPORTER( "test-reporter", TestReporter ) + +TEST_CASE( "repeatedly entered test case" ) { + auto i = GENERATE( range(0, 6) ); + std::cout << "stdout " << i << '\n'; + // Switch between writing to std::cerr and std::clog just to make sure + // both are properly captured and redirected. + ( ( i % 2 == 0 ) ? std::cerr : std::clog ) << "stderr " << i << '\n'; +} diff --git a/contrib/catch2/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp b/contrib/catch2/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp new file mode 100644 index 0000000..4098c8b --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X28-ListenersGetEventsBeforeReporters.cpp @@ -0,0 +1,99 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that the different events are sent to listeners before they are + * sent to the reporters. + * + * We only do this for a subset of the events, as doing all of them would + * be annoying, and we can assume that their implementation is roughly + * the same, and thus if few work, all work. + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_event_listener.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> + +#include <iostream> +#include <utility> + +namespace { + + static bool testRunStartingReceivedByListener = false; + static bool testRunEndedReceivedByListener = false; + static bool assertionStartingReceivedByListener = false; + static bool assertionEndedReceivedByListener = false; + + class TestListener : public Catch::EventListenerBase { + public: + TestListener( Catch::IConfig const* config ): + EventListenerBase( config ) { + std::cout << "X28 - TestListener constructed.\n"; + } + + void testRunStarting( Catch::TestRunInfo const& ) override { + testRunStartingReceivedByListener = true; + } + + void testRunEnded( Catch::TestRunStats const& ) override { + testRunEndedReceivedByListener = true; + } + + void assertionStarting( Catch::AssertionInfo const& ) override { + assertionStartingReceivedByListener = true; + } + + void assertionEnded( Catch::AssertionStats const& ) override { + assertionEndedReceivedByListener = true; + } + }; + + class TestReporter : public Catch::StreamingReporterBase { + public: + TestReporter( Catch::ReporterConfig&& _config ): + StreamingReporterBase( std::move(_config) ) { + std::cout << "X28 - TestReporter constructed\n"; + } + + void testRunStarting( Catch::TestRunInfo const& ) override { + if ( !testRunStartingReceivedByListener ) { + std::cout << "X28 - ERROR\n"; + } + } + + void testRunEnded( Catch::TestRunStats const& ) override { + if ( !testRunEndedReceivedByListener ) { + std::cout << "X28 - ERROR\n"; + } + } + + void assertionStarting( Catch::AssertionInfo const& ) override { + if ( !assertionStartingReceivedByListener ) { + std::cout << "X28 - ERROR\n"; + } + } + + void assertionEnded( Catch::AssertionStats const& ) override { + if ( !assertionEndedReceivedByListener ) { + std::cout << "X28 - ERROR\n"; + } + } + + static std::string getDescription() { return "X28 test reporter"; } + ~TestReporter() override; + }; + + TestReporter::~TestReporter() = default; + +} // end unnamed namespace + +CATCH_REGISTER_REPORTER( "test-reporter", TestReporter ) +CATCH_REGISTER_LISTENER( TestListener ) + +TEST_CASE( "Dummy test case" ) { REQUIRE( 1 == 1 ); } diff --git a/contrib/catch2/tests/ExtraTests/X29-CustomArgumentsForReporters.cpp b/contrib/catch2/tests/ExtraTests/X29-CustomArgumentsForReporters.cpp new file mode 100644 index 0000000..13d9fc1 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X29-CustomArgumentsForReporters.cpp @@ -0,0 +1,60 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that custom options are properly passed down to the reporter. + * + * We print out the arguments sorted by key, to have a stable expected + * output. + */ + +#include <catch2/catch_test_macros.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> +#include <catch2/reporters/catch_reporter_registrars.hpp> + +#include <algorithm> +#include <iostream> +#include <string> +#include <utility> +#include <vector> + +class TestReporter : public Catch::StreamingReporterBase { +public: + TestReporter( Catch::ReporterConfig&& _config ): + StreamingReporterBase( std::move(_config) ) { + std::cout << "X29 - TestReporter constructed\n"; + } + + static std::string getDescription() { + return "X29 test reporter"; + } + + void testRunStarting( Catch::TestRunInfo const& ) override { + std::vector<std::pair<std::string, std::string>> options; + options.reserve( m_customOptions.size() ); + for ( auto const& kv : m_customOptions ) { + options.push_back( kv ); + } + std::sort( options.begin(), options.end() ); + bool first = true; + for ( auto const& kv : options ) { + if ( !first ) { std::cout << "::"; } + std::cout << kv.first << "=" << kv.second; + first = false; + } + std::cout << '\n'; + } + + ~TestReporter() override; +}; + +TestReporter::~TestReporter() = default; + +CATCH_REGISTER_REPORTER( "test-reporter", TestReporter ) + +TEST_CASE( "Just a test case to run things" ) {} diff --git a/contrib/catch2/tests/ExtraTests/X30-BazelReporter.cpp b/contrib/catch2/tests/ExtraTests/X30-BazelReporter.cpp new file mode 100644 index 0000000..2a25941 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X30-BazelReporter.cpp @@ -0,0 +1,17 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test the Bazel report functionality with a simple set + * of dummy test cases. + */ + +#include <catch2/catch_test_macros.hpp> + +TEST_CASE( "Passing test case" ) { REQUIRE( 1 == 1 ); } +TEST_CASE( "Failing test case" ) { REQUIRE( 2 == 1 ); } diff --git a/contrib/catch2/tests/ExtraTests/X31-DuplicatedTestCases.cpp b/contrib/catch2/tests/ExtraTests/X31-DuplicatedTestCases.cpp new file mode 100644 index 0000000..0d09175 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X31-DuplicatedTestCases.cpp @@ -0,0 +1,16 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test cases with identical name and tags are reported as error + */ + +#include <catch2/catch_test_macros.hpp> + +TEST_CASE("A test case with duplicated name and tags", "[tag1][tag2]") {} +TEST_CASE("A test case with duplicated name and tags", "[tag1][tag2]") {} diff --git a/contrib/catch2/tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp b/contrib/catch2/tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp new file mode 100644 index 0000000..b0aa417 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp @@ -0,0 +1,17 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test cases with identical name but different tags are + * not reported as an error. + */ + +#include <catch2/catch_test_macros.hpp> + +TEST_CASE("A test case with duplicated name but different tags", "[tag1]") {} +TEST_CASE("A test case with duplicated name but different tags", "[tag2]") {} diff --git a/contrib/catch2/tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp b/contrib/catch2/tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp new file mode 100644 index 0000000..d3c3449 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp @@ -0,0 +1,22 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test case methods with identical class, name and tags are + * reported as error. + */ + +#include <catch2/catch_test_macros.hpp> + +class TestCaseFixture { +public: + int m_a; +}; + +TEST_CASE_METHOD(TestCaseFixture, "A test case with duplicated name and tags", "[tag1]") {} +TEST_CASE_METHOD(TestCaseFixture, "A test case with duplicated name and tags", "[tag1]") {} diff --git a/contrib/catch2/tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp b/contrib/catch2/tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp new file mode 100644 index 0000000..397cf15 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp @@ -0,0 +1,27 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that test case methods with different class, but same name and + * tags name and tags are not reported as error. + */ + +#include <catch2/catch_test_macros.hpp> + +class TestCaseFixture1 { +public: + int m_a; +}; + +class TestCaseFixture2 { +public: + int m_a; +}; + +TEST_CASE_METHOD(TestCaseFixture1, "A test case with duplicated name and tags", "[tag1]") {} +TEST_CASE_METHOD(TestCaseFixture2, "A test case with duplicated name and tags", "[tag1]") {} diff --git a/contrib/catch2/tests/ExtraTests/X35-DuplicatedReporterNames.cpp b/contrib/catch2/tests/ExtraTests/X35-DuplicatedReporterNames.cpp new file mode 100644 index 0000000..a978448 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X35-DuplicatedReporterNames.cpp @@ -0,0 +1,31 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that reporter registration errors are caught and handled as + * startup errors, by causing a registration error by registering multiple + * reporters with the same name. + */ + +#include <catch2/catch_test_macros.hpp> + +#include <catch2/reporters/catch_reporter_registrars.hpp> +#include <catch2/reporters/catch_reporter_streaming_base.hpp> + +namespace { + //! Trivial custom reporter for registration + class TestReporter : public Catch::StreamingReporterBase { + public: + using StreamingReporterBase::StreamingReporterBase; + + static std::string getDescription() { return "X35 test reporter"; } + }; +} + +CATCH_REGISTER_REPORTER( "test-reporter", TestReporter ) +CATCH_REGISTER_REPORTER( "test-reporter", TestReporter ) diff --git a/contrib/catch2/tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp b/contrib/catch2/tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp new file mode 100644 index 0000000..34f4cd8 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp @@ -0,0 +1,32 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Checks that signals/SEH within open section does not hard crash JUnit + * (or similar reporter) while we are trying to report fatal error. + */ + +#include <catch2/catch_test_macros.hpp> + +#include <csignal> + +// On Windows we need to send SEH and not signal to test the +// RunContext::handleFatalErrorCondition code path +#if defined( _MSC_VER ) +# include <windows.h> +#endif + +TEST_CASE( "raises signal" ) { + SECTION( "section" ) { +#if defined( _MSC_VER ) + RaiseException( 0xC0000005, 0, 0, NULL ); +#else + std::raise( SIGILL ); +#endif + } +} diff --git a/contrib/catch2/tests/ExtraTests/X90-WindowsHeaderInclusion.cpp b/contrib/catch2/tests/ExtraTests/X90-WindowsHeaderInclusion.cpp new file mode 100644 index 0000000..dff542a --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X90-WindowsHeaderInclusion.cpp @@ -0,0 +1,21 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Test that the Catch2 header compiles even after including windows.h + * without defining NOMINMAX first. + * + * As an FYI, if you do that, you are wrong. + */ + +#include <windows.h> +#include <catch2/catch_test_macros.hpp> + +TEST_CASE("Catch2 did survive compilation with windows.h", "[compile-test]") { + SUCCEED(); +} diff --git a/contrib/catch2/tests/ExtraTests/X91-AmalgamatedCatch.cpp b/contrib/catch2/tests/ExtraTests/X91-AmalgamatedCatch.cpp new file mode 100644 index 0000000..78d45a2 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X91-AmalgamatedCatch.cpp @@ -0,0 +1,38 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * This file serves as a simple compilation test against the amalgamated + * version of Catch2. + */ + +#include "catch_amalgamated.hpp" + +TEST_CASE("Just a dummy test") { + auto i = GENERATE(1, 2, 3); + SECTION("a") { + REQUIRE(i != 4); + } + SECTION("b") { + CHECK(i != 5); + } + REQUIRE_THAT(1, + Catch::Matchers::Predicate<int>([](int i) { + return i % 2 == 1; + })); +} + +TEMPLATE_TEST_CASE("Trivial template test case", "", char, short) { + STATIC_REQUIRE(sizeof(TestType) <= sizeof(int)); +} + +TEST_CASE("Benchmark test", "[!benchmark]") { + BENCHMARK("Allocation benchmark") { + return std::vector<int>(10); + }; +} diff --git a/contrib/catch2/tests/ExtraTests/X92-NoTests.cpp b/contrib/catch2/tests/ExtraTests/X92-NoTests.cpp new file mode 100644 index 0000000..9591e54 --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X92-NoTests.cpp @@ -0,0 +1,11 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Links into executable with no tests which should fail when run + */ diff --git a/contrib/catch2/tests/ExtraTests/X93-AllSkipped.cpp b/contrib/catch2/tests/ExtraTests/X93-AllSkipped.cpp new file mode 100644 index 0000000..8e7d0af --- /dev/null +++ b/contrib/catch2/tests/ExtraTests/X93-AllSkipped.cpp @@ -0,0 +1,16 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include <catch2/catch_test_macros.hpp> + +TEST_CASE( "this test case is being skipped" ) { SKIP(); } + +TEST_CASE( "all sections in this test case are being skipped" ) { + SECTION( "A" ) { SKIP(); } + SECTION( "B" ) { SKIP(); } +} |
