├── .bazelrc ├── .clang-format ├── .clang-tidy ├── .conan ├── build.py └── test_package │ ├── CMakeLists.txt │ ├── conanfile.py │ └── test_package.cpp ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ ├── linux-bazel-builds.yml │ ├── linux-meson-builds.yml │ ├── linux-other-builds.yml │ ├── linux-simple-builds.yml │ ├── mac-builds.yml │ ├── package-manager-builds.yaml │ ├── validate-header-guards.yml │ └── windows-simple-builds.yml ├── .gitignore ├── BUILD.bazel ├── CMake ├── Catch2Config.cmake.in ├── CatchConfigOptions.cmake ├── CatchMiscFunctions.cmake ├── FindGcov.cmake ├── FindLcov.cmake ├── Findcodecov.cmake ├── catch2-with-main.pc.in ├── catch2.pc.in └── llvm-cov-wrapper ├── CMakeLists.txt ├── CMakePresets.json ├── CODE_OF_CONDUCT.md ├── Doxyfile ├── LICENSE.txt ├── MAINTAINERS.md ├── MODULE.bazel ├── README.md ├── SECURITY.md ├── appveyor.yml ├── codecov.yml ├── conanfile.py ├── data └── artwork │ ├── catch2-c-logo.png │ ├── catch2-hand-logo.png │ ├── catch2-logo-small-with-background.png │ └── catch2-logo-small.png ├── docs ├── Readme.md ├── assertions.md ├── benchmarks.md ├── ci-and-misc.md ├── cmake-integration.md ├── command-line.md ├── commercial-users.md ├── comparing-floating-point-numbers.md ├── configuration.md ├── contributing.md ├── deprecations.md ├── event-listeners.md ├── faq.md ├── generators.md ├── limitations.md ├── list-of-examples.md ├── logging.md ├── matchers.md ├── migrate-v2-to-v3.md ├── opensource-users.md ├── other-macros.md ├── own-main.md ├── release-notes.md ├── release-process.md ├── reporter-events.md ├── reporters.md ├── skipping-passing-failing.md ├── test-cases-and-sections.md ├── test-fixtures.md ├── tostring.md ├── tutorial.md ├── usage-tips.md └── why-catch.md ├── examples ├── 010-TestCase.cpp ├── 020-TestCase-1.cpp ├── 020-TestCase-2.cpp ├── 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 ├── 231-Cfg-OutputStreams.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 └── CMakeLists.txt ├── extras ├── Catch.cmake ├── CatchAddTests.cmake ├── CatchShardTests.cmake ├── CatchShardTestsImpl.cmake ├── ParseAndAddCatchTests.cmake ├── catch_amalgamated.cpp ├── catch_amalgamated.hpp ├── gdbinit └── lldbinit ├── fuzzing ├── CMakeLists.txt ├── NullOStream.cpp ├── NullOStream.h ├── build_fuzzers.sh ├── fuzz_TestSpecParser.cpp ├── fuzz_XmlWriter.cpp └── fuzz_textflow.cpp ├── mdsnippets.json ├── meson.build ├── meson_options.txt ├── src ├── CMakeLists.txt └── catch2 │ ├── benchmark │ ├── catch_benchmark.hpp │ ├── catch_benchmark_all.hpp │ ├── catch_chronometer.cpp │ ├── catch_chronometer.hpp │ ├── catch_clock.hpp │ ├── catch_constructor.hpp │ ├── catch_environment.hpp │ ├── catch_estimate.hpp │ ├── catch_execution_plan.hpp │ ├── catch_optimizer.hpp │ ├── catch_outlier_classification.hpp │ ├── catch_sample_analysis.hpp │ └── detail │ │ ├── catch_analyse.cpp │ │ ├── catch_analyse.hpp │ │ ├── catch_benchmark_function.cpp │ │ ├── catch_benchmark_function.hpp │ │ ├── catch_benchmark_stats.hpp │ │ ├── catch_benchmark_stats_fwd.hpp │ │ ├── catch_complete_invoke.hpp │ │ ├── catch_estimate_clock.hpp │ │ ├── catch_measure.hpp │ │ ├── catch_repeat.hpp │ │ ├── catch_run_for_at_least.cpp │ │ ├── catch_run_for_at_least.hpp │ │ ├── catch_stats.cpp │ │ ├── catch_stats.hpp │ │ └── catch_timing.hpp │ ├── catch_all.hpp │ ├── catch_approx.cpp │ ├── catch_approx.hpp │ ├── catch_assertion_info.hpp │ ├── catch_assertion_result.cpp │ ├── catch_assertion_result.hpp │ ├── catch_case_sensitive.hpp │ ├── catch_config.cpp │ ├── catch_config.hpp │ ├── catch_get_random_seed.cpp │ ├── catch_get_random_seed.hpp │ ├── catch_message.cpp │ ├── catch_message.hpp │ ├── catch_registry_hub.cpp │ ├── catch_section_info.hpp │ ├── catch_session.cpp │ ├── catch_session.hpp │ ├── catch_tag_alias.hpp │ ├── catch_tag_alias_autoregistrar.cpp │ ├── catch_tag_alias_autoregistrar.hpp │ ├── catch_template_test_macros.hpp │ ├── catch_test_case_info.cpp │ ├── catch_test_case_info.hpp │ ├── catch_test_macros.hpp │ ├── catch_test_spec.cpp │ ├── catch_test_spec.hpp │ ├── catch_timer.cpp │ ├── catch_timer.hpp │ ├── catch_tostring.cpp │ ├── catch_tostring.hpp │ ├── catch_totals.cpp │ ├── catch_totals.hpp │ ├── catch_translate_exception.cpp │ ├── catch_translate_exception.hpp │ ├── catch_user_config.hpp.in │ ├── catch_version.cpp │ ├── catch_version.hpp │ ├── catch_version_macros.hpp │ ├── generators │ ├── catch_generator_exception.cpp │ ├── catch_generator_exception.hpp │ ├── catch_generators.cpp │ ├── catch_generators.hpp │ ├── catch_generators_adapters.hpp │ ├── catch_generators_all.hpp │ ├── catch_generators_random.cpp │ ├── catch_generators_random.hpp │ └── catch_generators_range.hpp │ ├── interfaces │ ├── catch_interfaces_all.hpp │ ├── catch_interfaces_capture.cpp │ ├── catch_interfaces_capture.hpp │ ├── catch_interfaces_config.cpp │ ├── catch_interfaces_config.hpp │ ├── catch_interfaces_enum_values_registry.hpp │ ├── catch_interfaces_exception.cpp │ ├── catch_interfaces_exception.hpp │ ├── catch_interfaces_generatortracker.cpp │ ├── catch_interfaces_generatortracker.hpp │ ├── catch_interfaces_registry_hub.cpp │ ├── catch_interfaces_registry_hub.hpp │ ├── catch_interfaces_reporter.cpp │ ├── catch_interfaces_reporter.hpp │ ├── catch_interfaces_reporter_factory.cpp │ ├── catch_interfaces_reporter_factory.hpp │ ├── catch_interfaces_tag_alias_registry.hpp │ ├── catch_interfaces_test_invoker.hpp │ ├── catch_interfaces_testcase.cpp │ └── catch_interfaces_testcase.hpp │ ├── internal │ ├── catch_assertion_handler.cpp │ ├── catch_assertion_handler.hpp │ ├── catch_case_insensitive_comparisons.cpp │ ├── catch_case_insensitive_comparisons.hpp │ ├── catch_clara.cpp │ ├── catch_clara.hpp │ ├── catch_commandline.cpp │ ├── catch_commandline.hpp │ ├── catch_compare_traits.hpp │ ├── catch_compiler_capabilities.hpp │ ├── catch_config_android_logwrite.hpp │ ├── catch_config_counter.hpp │ ├── catch_config_prefix_messages.hpp │ ├── catch_config_static_analysis_support.hpp │ ├── catch_config_uncaught_exceptions.hpp │ ├── catch_config_wchar.hpp │ ├── catch_console_colour.cpp │ ├── catch_console_colour.hpp │ ├── catch_console_width.hpp │ ├── catch_container_nonmembers.hpp │ ├── catch_context.cpp │ ├── catch_context.hpp │ ├── catch_debug_console.cpp │ ├── catch_debug_console.hpp │ ├── catch_debugger.cpp │ ├── catch_debugger.hpp │ ├── catch_decomposer.cpp │ ├── catch_decomposer.hpp │ ├── catch_enforce.cpp │ ├── catch_enforce.hpp │ ├── catch_enum_values_registry.cpp │ ├── catch_enum_values_registry.hpp │ ├── catch_errno_guard.cpp │ ├── catch_errno_guard.hpp │ ├── catch_exception_translator_registry.cpp │ ├── catch_exception_translator_registry.hpp │ ├── catch_fatal_condition_handler.cpp │ ├── catch_fatal_condition_handler.hpp │ ├── catch_floating_point_helpers.cpp │ ├── catch_floating_point_helpers.hpp │ ├── catch_getenv.cpp │ ├── catch_getenv.hpp │ ├── catch_is_permutation.hpp │ ├── catch_istream.cpp │ ├── catch_istream.hpp │ ├── catch_jsonwriter.cpp │ ├── catch_jsonwriter.hpp │ ├── catch_lazy_expr.cpp │ ├── catch_lazy_expr.hpp │ ├── catch_leak_detector.cpp │ ├── catch_leak_detector.hpp │ ├── catch_list.cpp │ ├── catch_list.hpp │ ├── catch_logical_traits.hpp │ ├── catch_main.cpp │ ├── catch_message_info.cpp │ ├── catch_message_info.hpp │ ├── catch_meta.hpp │ ├── catch_move_and_forward.hpp │ ├── catch_noncopyable.hpp │ ├── catch_optional.hpp │ ├── catch_output_redirect.cpp │ ├── catch_output_redirect.hpp │ ├── catch_parse_numbers.cpp │ ├── catch_parse_numbers.hpp │ ├── catch_platform.hpp │ ├── catch_polyfills.cpp │ ├── catch_polyfills.hpp │ ├── catch_preprocessor.hpp │ ├── catch_preprocessor_internal_stringify.hpp │ ├── catch_preprocessor_remove_parens.hpp │ ├── catch_random_floating_point_helpers.hpp │ ├── catch_random_integer_helpers.hpp │ ├── catch_random_number_generator.cpp │ ├── catch_random_number_generator.hpp │ ├── catch_random_seed_generation.cpp │ ├── catch_random_seed_generation.hpp │ ├── catch_reporter_registry.cpp │ ├── catch_reporter_registry.hpp │ ├── catch_reporter_spec_parser.cpp │ ├── catch_reporter_spec_parser.hpp │ ├── catch_result_type.hpp │ ├── catch_reusable_string_stream.cpp │ ├── catch_reusable_string_stream.hpp │ ├── catch_run_context.cpp │ ├── catch_run_context.hpp │ ├── catch_section.cpp │ ├── catch_section.hpp │ ├── catch_sharding.hpp │ ├── catch_singletons.cpp │ ├── catch_singletons.hpp │ ├── catch_source_line_info.cpp │ ├── catch_source_line_info.hpp │ ├── catch_startup_exception_registry.cpp │ ├── catch_startup_exception_registry.hpp │ ├── catch_stdstreams.cpp │ ├── catch_stdstreams.hpp │ ├── catch_stream_end_stop.hpp │ ├── catch_string_manip.cpp │ ├── catch_string_manip.hpp │ ├── catch_stringref.cpp │ ├── catch_stringref.hpp │ ├── catch_tag_alias_registry.cpp │ ├── catch_tag_alias_registry.hpp │ ├── catch_template_test_registry.hpp │ ├── catch_test_case_info_hasher.cpp │ ├── catch_test_case_info_hasher.hpp │ ├── catch_test_case_registry_impl.cpp │ ├── catch_test_case_registry_impl.hpp │ ├── catch_test_case_tracker.cpp │ ├── catch_test_case_tracker.hpp │ ├── catch_test_failure_exception.cpp │ ├── catch_test_failure_exception.hpp │ ├── catch_test_macro_impl.hpp │ ├── catch_test_registry.cpp │ ├── catch_test_registry.hpp │ ├── catch_test_run_info.hpp │ ├── catch_test_spec_parser.cpp │ ├── catch_test_spec_parser.hpp │ ├── catch_textflow.cpp │ ├── catch_textflow.hpp │ ├── catch_to_string.hpp │ ├── catch_uncaught_exceptions.cpp │ ├── catch_uncaught_exceptions.hpp │ ├── catch_uniform_floating_point_distribution.hpp │ ├── catch_uniform_integer_distribution.hpp │ ├── catch_unique_name.hpp │ ├── catch_unique_ptr.hpp │ ├── catch_void_type.hpp │ ├── catch_wildcard_pattern.cpp │ ├── catch_wildcard_pattern.hpp │ ├── catch_windows_h_proxy.hpp │ ├── catch_xmlwriter.cpp │ └── catch_xmlwriter.hpp │ ├── matchers │ ├── catch_matchers.cpp │ ├── catch_matchers.hpp │ ├── catch_matchers_all.hpp │ ├── catch_matchers_container_properties.cpp │ ├── catch_matchers_container_properties.hpp │ ├── catch_matchers_contains.hpp │ ├── catch_matchers_exception.cpp │ ├── catch_matchers_exception.hpp │ ├── catch_matchers_floating_point.cpp │ ├── catch_matchers_floating_point.hpp │ ├── catch_matchers_predicate.cpp │ ├── catch_matchers_predicate.hpp │ ├── catch_matchers_quantifiers.cpp │ ├── catch_matchers_quantifiers.hpp │ ├── catch_matchers_range_equals.hpp │ ├── catch_matchers_string.cpp │ ├── catch_matchers_string.hpp │ ├── catch_matchers_templated.cpp │ ├── catch_matchers_templated.hpp │ ├── catch_matchers_vector.hpp │ └── internal │ │ ├── catch_matchers_impl.cpp │ │ └── catch_matchers_impl.hpp │ ├── meson.build │ └── reporters │ ├── catch_reporter_automake.cpp │ ├── catch_reporter_automake.hpp │ ├── catch_reporter_common_base.cpp │ ├── catch_reporter_common_base.hpp │ ├── catch_reporter_compact.cpp │ ├── catch_reporter_compact.hpp │ ├── catch_reporter_console.cpp │ ├── catch_reporter_console.hpp │ ├── catch_reporter_cumulative_base.cpp │ ├── catch_reporter_cumulative_base.hpp │ ├── catch_reporter_event_listener.cpp │ ├── catch_reporter_event_listener.hpp │ ├── catch_reporter_helpers.cpp │ ├── catch_reporter_helpers.hpp │ ├── catch_reporter_json.cpp │ ├── catch_reporter_json.hpp │ ├── catch_reporter_junit.cpp │ ├── catch_reporter_junit.hpp │ ├── catch_reporter_multi.cpp │ ├── catch_reporter_multi.hpp │ ├── catch_reporter_registrars.cpp │ ├── catch_reporter_registrars.hpp │ ├── catch_reporter_sonarqube.cpp │ ├── catch_reporter_sonarqube.hpp │ ├── catch_reporter_streaming_base.cpp │ ├── catch_reporter_streaming_base.hpp │ ├── catch_reporter_tap.cpp │ ├── catch_reporter_tap.hpp │ ├── catch_reporter_teamcity.cpp │ ├── catch_reporter_teamcity.hpp │ ├── catch_reporter_xml.cpp │ ├── catch_reporter_xml.hpp │ └── catch_reporters_all.hpp ├── tests ├── BUILD.bazel ├── CMakeLists.txt ├── ExtraTests │ ├── CMakeLists.txt │ ├── ToDo.txt │ ├── X01-PrefixedMacros.cpp │ ├── X02-DisabledMacros.cpp │ ├── X03-DisabledExceptions-DefaultHandler.cpp │ ├── X04-DisabledExceptions-CustomHandler.cpp │ ├── X05-DeferredStaticChecks.cpp │ ├── X10-FallbackStringifier.cpp │ ├── X11-DisableStringification.cpp │ ├── X12-CustomDebugBreakMacro.cpp │ ├── X20-AssertionStartingEventGoesBeforeAssertionIsEvaluated.cpp │ ├── X21-PartialTestCaseEvents.cpp │ ├── X22-BenchmarksInCumulativeReporter.cpp │ ├── X23-CasingInReporterNames.cpp │ ├── X24-ListenerStdoutCaptureInMultireporter.cpp │ ├── X25-ListenerCanAskForCapturedStdout.cpp │ ├── X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp │ ├── X27-CapturedStdoutInTestCaseEvents.cpp │ ├── X28-ListenersGetEventsBeforeReporters.cpp │ ├── X29-CustomArgumentsForReporters.cpp │ ├── X30-BazelReporter.cpp │ ├── X31-DuplicatedTestCases.cpp │ ├── X32-DuplicatedTestCasesDifferentTags.cpp │ ├── X33-DuplicatedTestCaseMethods.cpp │ ├── X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp │ ├── X35-DuplicatedReporterNames.cpp │ ├── X36-ReportingCrashWithJunitReporter.cpp │ ├── X90-WindowsHeaderInclusion.cpp │ ├── X91-AmalgamatedCatch.cpp │ ├── X92-NoTests.cpp │ └── X93-AllSkipped.cpp ├── SelfTest │ ├── Baselines │ │ ├── automake.std.approved.txt │ │ ├── automake.sw.approved.txt │ │ ├── automake.sw.multi.approved.txt │ │ ├── compact.sw.approved.txt │ │ ├── compact.sw.multi.approved.txt │ │ ├── console.std.approved.txt │ │ ├── console.sw.approved.txt │ │ ├── console.sw.multi.approved.txt │ │ ├── console.swa4.approved.txt │ │ ├── default.sw.multi.approved.txt │ │ ├── junit.sw.approved.txt │ │ ├── junit.sw.multi.approved.txt │ │ ├── sonarqube.sw.approved.txt │ │ ├── sonarqube.sw.multi.approved.txt │ │ ├── tap.sw.approved.txt │ │ ├── tap.sw.multi.approved.txt │ │ ├── teamcity.sw.approved.txt │ │ ├── teamcity.sw.multi.approved.txt │ │ ├── xml.sw.approved.txt │ │ └── xml.sw.multi.approved.txt │ ├── IntrospectiveTests │ │ ├── Algorithms.tests.cpp │ │ ├── AssertionHandler.tests.cpp │ │ ├── Clara.tests.cpp │ │ ├── CmdLine.tests.cpp │ │ ├── CmdLineHelpers.tests.cpp │ │ ├── ColourImpl.tests.cpp │ │ ├── Details.tests.cpp │ │ ├── FloatingPoint.tests.cpp │ │ ├── GeneratorsImpl.tests.cpp │ │ ├── Integer.tests.cpp │ │ ├── InternalBenchmark.tests.cpp │ │ ├── Json.tests.cpp │ │ ├── Parse.tests.cpp │ │ ├── PartTracker.tests.cpp │ │ ├── RandomNumberGeneration.tests.cpp │ │ ├── Reporters.tests.cpp │ │ ├── Sharding.tests.cpp │ │ ├── Stream.tests.cpp │ │ ├── String.tests.cpp │ │ ├── StringManip.tests.cpp │ │ ├── Tag.tests.cpp │ │ ├── TestCaseInfoHasher.tests.cpp │ │ ├── TestSpec.tests.cpp │ │ ├── TestSpecParser.tests.cpp │ │ ├── TextFlow.tests.cpp │ │ ├── ToString.tests.cpp │ │ ├── Traits.tests.cpp │ │ ├── UniquePtr.tests.cpp │ │ └── Xml.tests.cpp │ ├── Misc │ │ ├── invalid-test-names.input │ │ ├── plain-old-tests.input │ │ └── special-characters-in-file.input │ ├── TestRegistrations.cpp │ ├── TimingTests │ │ └── Sleep.tests.cpp │ ├── UsageTests │ │ ├── Approx.tests.cpp │ │ ├── BDD.tests.cpp │ │ ├── Benchmark.tests.cpp │ │ ├── Class.tests.cpp │ │ ├── Compilation.tests.cpp │ │ ├── Condition.tests.cpp │ │ ├── Decomposition.tests.cpp │ │ ├── EnumToString.tests.cpp │ │ ├── Exception.tests.cpp │ │ ├── Generators.tests.cpp │ │ ├── Matchers.tests.cpp │ │ ├── MatchersRanges.tests.cpp │ │ ├── Message.tests.cpp │ │ ├── Misc.tests.cpp │ │ ├── Skip.tests.cpp │ │ ├── ToStringByte.tests.cpp │ │ ├── ToStringChrono.tests.cpp │ │ ├── ToStringGeneral.tests.cpp │ │ ├── ToStringOptional.tests.cpp │ │ ├── ToStringPair.tests.cpp │ │ ├── ToStringTuple.tests.cpp │ │ ├── ToStringVariant.tests.cpp │ │ ├── ToStringVector.tests.cpp │ │ ├── ToStringWhich.tests.cpp │ │ ├── Tricky.tests.cpp │ │ └── VariadicMacros.tests.cpp │ └── helpers │ │ ├── parse_test_spec.cpp │ │ ├── parse_test_spec.hpp │ │ ├── range_test_helpers.hpp │ │ └── type_with_lit_0_comparisons.hpp ├── TestScripts │ ├── ConfigureTestsCommon.py │ ├── DiscoverTests │ │ ├── CMakeLists.txt │ │ ├── VerifyRegistration.py │ │ └── register-tests.cpp │ ├── testBazelReporter.py │ ├── testBazelSharding.py │ ├── testConfigureDefaultReporter.py │ ├── testConfigureDisable.py │ ├── testConfigureDisableStringification.py │ ├── testConfigureExperimentalRedirect.py │ ├── testPartialTestCaseEvent.py │ ├── testRandomOrder.py │ └── testSharding.py └── meson.build ├── third_party └── clara.hpp └── tools ├── misc ├── CMakeLists.txt ├── SelfTest.vcxproj.user ├── appveyorBuildConfigurationScript.bat ├── appveyorMergeCoverageScript.py ├── appveyorTestRunScript.bat ├── coverage-helper.cpp └── installOpenCppCoverage.ps1 └── scripts ├── approvalTests.py ├── approve.py ├── buildAndTest.cmd ├── buildAndTest.sh ├── checkConvenienceHeaders.py ├── checkDuplicateFilenames.py ├── checkLicense.py ├── developBuild.py ├── extractFeaturesFromReleaseNotes.py ├── fixWhitespace.py ├── generateAmalgamatedFiles.py ├── majorRelease.py ├── minorRelease.py ├── patchRelease.py ├── releaseCommon.py ├── scriptCommon.py ├── updateDocumentSnippets.py └── updateDocumentToC.py /.bazelrc: -------------------------------------------------------------------------------- 1 | build --enable_platform_specific_config 2 | 3 | build:gcc9 --cxxopt=-std=c++2a 4 | build:gcc11 --cxxopt=-std=c++2a 5 | build:gcc13 --cxxopt=-std=c++2a 6 | build:clang13 --cxxopt=-std=c++17 7 | build:vs2019 --cxxopt=/std:c++17 8 | build:vs2022 --cxxopt=/std:c++17 9 | 10 | build:windows --config=vs2022 11 | build:linux --config=gcc11 12 | build:macos --cxxopt=-std=c++2b 13 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | Standard: c++14 4 | 5 | # Note that we cannot use IncludeIsMainRegex functionality, because it 6 | # does not support includes in angle brackets (<>) 7 | SortIncludes: true 8 | IncludeBlocks: Regroup 9 | IncludeCategories: 10 | - Regex: 11 | Priority: 1 12 | - Regex: <.*/.*\.hpp> 13 | Priority: 2 14 | - Regex: <.*> 15 | Priority: 3 16 | 17 | AllowShortBlocksOnASingleLine: Always 18 | AllowShortEnumsOnASingleLine: false 19 | AllowShortFunctionsOnASingleLine: All 20 | AllowShortIfStatementsOnASingleLine: WithoutElse 21 | AllowShortLambdasOnASingleLine: Inline 22 | 23 | AccessModifierOffset: "-4" 24 | AlignEscapedNewlines: Left 25 | AllowAllConstructorInitializersOnNextLine: "true" 26 | BinPackArguments: "false" 27 | BinPackParameters: "false" 28 | BreakConstructorInitializers: AfterColon 29 | ConstructorInitializerAllOnOneLineOrOnePerLine: "true" 30 | DerivePointerAlignment: "false" 31 | FixNamespaceComments: "true" 32 | IndentCaseLabels: "false" 33 | IndentPPDirectives: AfterHash 34 | IndentWidth: "4" 35 | NamespaceIndentation: All 36 | PointerAlignment: Left 37 | SpaceBeforeCtorInitializerColon: "false" 38 | SpaceInEmptyParentheses: "false" 39 | SpacesInParentheses: "true" 40 | TabWidth: "4" 41 | UseTab: Never 42 | AlwaysBreakTemplateDeclarations: Yes 43 | SpaceAfterTemplateKeyword: true 44 | SortUsingDeclarations: true 45 | ReflowComments: true 46 | -------------------------------------------------------------------------------- /.conan/test_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(PackageTest LANGUAGES CXX) 3 | 4 | find_package(Catch2 CONFIG REQUIRED) 5 | 6 | add_executable(test_package test_package.cpp) 7 | target_link_libraries(test_package Catch2::Catch2WithMain) 8 | -------------------------------------------------------------------------------- /.conan/test_package/conanfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from conan import ConanFile 4 | from conan.tools.cmake import CMake, cmake_layout 5 | from conan.tools.build import can_run 6 | from conan.tools.files import save, load 7 | import os 8 | 9 | 10 | class TestPackageConan(ConanFile): 11 | settings = "os", "compiler", "build_type", "arch" 12 | generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" 13 | test_type = "explicit" 14 | 15 | def requirements(self): 16 | self.requires(self.tested_reference_str) 17 | 18 | def layout(self): 19 | cmake_layout(self) 20 | 21 | def generate(self): 22 | save(self, os.path.join(self.build_folder, "package_folder"), 23 | self.dependencies[self.tested_reference_str].package_folder) 24 | save(self, os.path.join(self.build_folder, "license"), 25 | self.dependencies[self.tested_reference_str].license) 26 | 27 | def build(self): 28 | cmake = CMake(self) 29 | cmake.configure() 30 | cmake.build() 31 | 32 | def test(self): 33 | if can_run(self): 34 | cmd = os.path.join(self.cpp.build.bindir, "test_package") 35 | self.run(cmd, env="conanrun") 36 | 37 | package_folder = load(self, os.path.join(self.build_folder, "package_folder")) 38 | license = load(self, os.path.join(self.build_folder, "license")) 39 | assert os.path.isfile(os.path.join(package_folder, "licenses", "LICENSE.txt")) 40 | assert license == 'BSL-1.0' 41 | -------------------------------------------------------------------------------- /.conan/test_package/test_package.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Factorial( int number ) { 4 | return number <= 1 ? 1 : Factorial( number - 1 ) * number; 5 | } 6 | 7 | TEST_CASE( "Factorial Tests", "[single-file]" ) { 8 | REQUIRE( Factorial(0) == 1 ); 9 | REQUIRE( Factorial(1) == 1 ); 10 | REQUIRE( Factorial(2) == 2 ); 11 | REQUIRE( Factorial(3) == 6 ); 12 | REQUIRE( Factorial(10) == 3628800 ); 13 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # This sets the default behaviour, overriding core.autocrlf 2 | * text=auto 3 | 4 | # All source files should have unix line-endings in the repository, 5 | # but convert to native line-endings on checkout 6 | *.cpp text 7 | *.h text 8 | *.hpp text 9 | 10 | # Windows specific files should retain windows line-endings 11 | *.sln text eol=crlf 12 | 13 | # Keep executable scripts with LFs so they can be run after being 14 | # checked out on Windows 15 | *.py text eol=lf 16 | 17 | 18 | # Keep the single include header with LFs to make sure it is uploaded, 19 | # hashed etc with LF 20 | single_include/**/*.hpp eol=lf 21 | # Also keep the LICENCE file with LFs for the same reason 22 | LICENCE.txt eol=lf 23 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: "horenmar" 2 | custom: "https://www.paypal.me/horenmar" 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create an issue that documents a bug 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **Expected behavior** 14 | A clear and concise description of what you expected to happen. 15 | 16 | **Reproduction steps** 17 | Steps to reproduce the bug. 18 | 19 | 20 | 21 | **Platform information:** 22 | 23 | - OS: **Windows NT** 24 | - Compiler+version: **GCC v2.9.5** 25 | - Catch version: **v1.2.3** 26 | 27 | 28 | **Additional context** 29 | Add any other context about the problem here. 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Create an issue that requests a feature or other improvement 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description** 11 | Describe the feature/change you request and why do you want it. 12 | 13 | **Additional context** 14 | Add any other context or screenshots about the feature request here. 15 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ## Description 12 | 18 | 19 | ## GitHub Issues 20 | 29 | -------------------------------------------------------------------------------- /.github/workflows/linux-bazel-builds.yml: -------------------------------------------------------------------------------- 1 | name: Linux Builds (Bazel) 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build_and_test_ubuntu: 7 | name: Linux Ubuntu 22.04 Bazel build 8 | runs-on: ubuntu-22.04 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | compilation_mode: [fastbuild, dbg, opt] 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - name: Mount Bazel cache 18 | uses: actions/cache@v3 19 | with: 20 | path: "/home/runner/.cache/bazel" 21 | key: bazel-ubuntu22-gcc11 22 | 23 | - name: Build 24 | run: bazelisk build --compilation_mode=${{matrix.compilation_mode}} //... 25 | -------------------------------------------------------------------------------- /.github/workflows/linux-meson-builds.yml: -------------------------------------------------------------------------------- 1 | name: Linux Builds (Meson) 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: meson ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}} 8 | runs-on: ubuntu-22.04 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | cxx: 13 | - g++-11 14 | - clang++-11 15 | build_type: [debug, release] 16 | std: [14, 17] 17 | include: 18 | - cxx: clang++-11 19 | other_pkgs: clang-11 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | 24 | - name: Prepare environment 25 | run: | 26 | sudo apt-get update 27 | sudo apt-get install -y meson ninja-build ${{matrix.other_pkgs}} 28 | 29 | - name: Configure 30 | env: 31 | CXX: ${{matrix.cxx}} 32 | CXXFLAGS: -std=c++${{matrix.std}} ${{matrix.cxxflags}} 33 | # Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}. 34 | # This is important 35 | run: | 36 | meson -Dbuildtype=${{matrix.build_type}} ${{runner.workspace}}/meson-build 37 | 38 | - name: Build 39 | working-directory: ${{runner.workspace}}/meson-build 40 | run: ninja 41 | 42 | - name: Test 43 | working-directory: ${{runner.workspace}}/meson-build 44 | run: meson test --verbose 45 | -------------------------------------------------------------------------------- /.github/workflows/mac-builds.yml: -------------------------------------------------------------------------------- 1 | name: Mac Builds 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | # From macos-14 forward, the baseline "macos-X" image is Arm based, 8 | # and not Intel based. 9 | runs-on: ${{matrix.image}} 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | image: [macos-13, macos-14, macos-15] 14 | build_type: [Debug, Release] 15 | std: [14, 17] 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Configure 21 | run: | 22 | cmake --preset basic-tests -GNinja \ 23 | -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ 24 | -DCMAKE_CXX_STANDARD=${{matrix.std}} \ 25 | -DCATCH_BUILD_EXAMPLES=ON \ 26 | -DCATCH_BUILD_EXTRA_TESTS=ON 27 | 28 | - name: Build 29 | run: cmake --build build 30 | 31 | - name: Test 32 | run: ctest --test-dir build -j --output-on-failure 33 | -------------------------------------------------------------------------------- /.github/workflows/package-manager-builds.yaml: -------------------------------------------------------------------------------- 1 | name: Package Manager Builds 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | conan_builds: 7 | name: Conan ${{matrix.conan_version}} 8 | runs-on: ubuntu-22.04 9 | strategy: 10 | matrix: 11 | conan_version: 12 | - '1.63' 13 | - '2.1' 14 | 15 | include: 16 | # Conan 1 has default profiles installed 17 | - conan_version: '1.63' 18 | profile_generate: 'false' 19 | 20 | steps: 21 | - uses: actions/checkout@v4 22 | 23 | - name: Install conan 24 | run: pip install conan==${{matrix.conan_version}} 25 | 26 | - name: Setup conan profiles 27 | if: matrix.profile_generate != 'false' 28 | run: conan profile detect 29 | 30 | - name: Run conan package create 31 | run: conan create . -tf .conan/test_package 32 | -------------------------------------------------------------------------------- /.github/workflows/validate-header-guards.yml: -------------------------------------------------------------------------------- 1 | name: Check header guards 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | # Set the type of machine to run on 8 | runs-on: ubuntu-22.04 9 | steps: 10 | 11 | - name: Checkout source code 12 | uses: actions/checkout@v4 13 | 14 | - name: Setup Dependencies 15 | uses: actions/setup-python@v2 16 | with: 17 | python-version: '3.7' 18 | - name: Install checkguard 19 | run: pip install guardonce 20 | 21 | - name: Check that include guards are properly named 22 | run: | 23 | wrong_files=$(checkguard -r src/catch2/ -p "name | append _INCLUDED | upper") 24 | if [[ $wrong_files ]]; then 25 | echo "Files with wrong header guard:" 26 | echo $wrong_files 27 | exit 1 28 | fi 29 | 30 | - name: Check that there are no duplicated filenames 31 | run: | 32 | ./tools/scripts/checkDuplicateFilenames.py 33 | 34 | - name: Check that all source files have the correct license header 35 | run: | 36 | ./tools/scripts/checkLicense.py 37 | -------------------------------------------------------------------------------- /.github/workflows/windows-simple-builds.yml: -------------------------------------------------------------------------------- 1 | name: Windows Builds (Basic) 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: ${{matrix.os}}, ${{matrix.std}}, ${{matrix.build_type}}, ${{matrix.platform}} 8 | runs-on: ${{matrix.os}} 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | os: [windows-2019, windows-2022, windows-2025] 13 | platform: [Win32, x64] 14 | build_type: [Debug, Release] 15 | std: [14, 17] 16 | steps: 17 | - uses: actions/checkout@v4 18 | 19 | - name: Configure build 20 | run: | 21 | cmake --preset all-tests ` 22 | -A ${{matrix.platform}} ` 23 | -DCMAKE_CXX_STANDARD=${{matrix.std}} ` 24 | 25 | - name: Build tests 26 | run: cmake --build build --config ${{matrix.build_type}} --parallel %NUMBER_OF_PROCESSORS% 27 | shell: cmd 28 | 29 | - name: Run tests 30 | run: ctest --test-dir build -C ${{matrix.build_type}} -j %NUMBER_OF_PROCESSORS% --output-on-failure 31 | shell: cmd 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.build 2 | !meson.build 3 | *.pbxuser 4 | *.mode1v3 5 | *.ncb 6 | *.suo 7 | Debug 8 | Release 9 | *.user 10 | *.xcuserstate 11 | .DS_Store 12 | xcuserdata 13 | CatchSelfTest.xcscheme 14 | Breakpoints.xcbkptlist 15 | UpgradeLog.XML 16 | Resources/DWARF 17 | projects/Generated 18 | *.pyc 19 | DerivedData 20 | *.xccheckout 21 | Build 22 | .idea 23 | .vs 24 | .vscode 25 | cmake-build-* 26 | benchmark-dir 27 | .conan/test_package/build 28 | **/CMakeUserPresets.json 29 | bazel-* 30 | MODULE.bazel.lock 31 | build-fuzzers 32 | debug-build 33 | .vscode 34 | msvc-sln* 35 | # Currently we use Doxygen for dep graphs and the full docs are only slowly 36 | # being filled in, so we definitely do not want git to deal with the docs. 37 | docs/doxygen 38 | *.cache 39 | compile_commands.json 40 | **/*.unapproved.txt 41 | -------------------------------------------------------------------------------- /CMake/Catch2Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | # Avoid repeatedly including the targets 4 | if(NOT TARGET Catch2::Catch2) 5 | # Provide path for scripts 6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") 7 | 8 | include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake) 9 | endif() 10 | -------------------------------------------------------------------------------- /CMake/catch2-with-main.pc.in: -------------------------------------------------------------------------------- 1 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 2 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 3 | pkg_version=@Catch2_VERSION@ 4 | 5 | Name: Catch2-With-Main 6 | Description: A modern, C++-native test framework for C++14 and above (links in default main) 7 | Version: ${pkg_version} 8 | Requires: catch2 = ${pkg_version} 9 | Cflags: -I${includedir} 10 | Libs: -L${libdir} -lCatch2Main 11 | -------------------------------------------------------------------------------- /CMake/catch2.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 4 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 5 | 6 | Name: Catch2 7 | Description: A modern, C++-native, test framework for C++14 and above 8 | URL: https://github.com/catchorg/Catch2 9 | Version: @Catch2_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lCatch2 12 | -------------------------------------------------------------------------------- /CMake/llvm-cov-wrapper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This file is part of CMake-codecov. 4 | # 5 | # Copyright (c) 6 | # 2015-2017 RWTH Aachen University, Federal Republic of Germany 7 | # 8 | # See the LICENSE file in the package base directory for details 9 | # 10 | # Written by Alexander Haase, alexander.haase@rwth-aachen.de 11 | # 12 | 13 | if [ -z "$LLVM_COV_BIN" ] 14 | then 15 | echo "LLVM_COV_BIN not set!" >& 2 16 | exit 1 17 | fi 18 | 19 | 20 | # Get LLVM version to find out. 21 | LLVM_VERSION=$($LLVM_COV_BIN -version | grep -i "LLVM version" \ 22 | | sed "s/^\([A-Za-z ]*\)\([0-9]\).\([0-9]\).*$/\2.\3/g") 23 | 24 | if [ "$1" = "-v" ] 25 | then 26 | echo "llvm-cov-wrapper $LLVM_VERSION" 27 | exit 0 28 | fi 29 | 30 | 31 | if [ -n "$LLVM_VERSION" ] 32 | then 33 | MAJOR=$(echo $LLVM_VERSION | cut -d'.' -f1) 34 | MINOR=$(echo $LLVM_VERSION | cut -d'.' -f2) 35 | 36 | if [ $MAJOR -eq 3 ] && [ $MINOR -le 4 ] 37 | then 38 | if [ -f "$1" ] 39 | then 40 | filename=$(basename "$1") 41 | extension="${filename##*.}" 42 | 43 | case "$extension" in 44 | "gcno") exec $LLVM_COV_BIN --gcno="$1" ;; 45 | "gcda") exec $LLVM_COV_BIN --gcda="$1" ;; 46 | esac 47 | fi 48 | fi 49 | 50 | if [ $MAJOR -eq 3 ] && [ $MINOR -le 5 ] 51 | then 52 | exec $LLVM_COV_BIN $@ 53 | fi 54 | fi 55 | 56 | exec $LLVM_COV_BIN gcov $@ 57 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "basic-tests", 6 | "binaryDir": "build", 7 | "installDir": "build/install", 8 | "displayName": "Basic development build", 9 | "description": "Enables development build with basic tests that are cheap to build and run", 10 | "cacheVariables": { 11 | "CMAKE_CXX_EXTENSIONS": "OFF", 12 | "CMAKE_CXX_STANDARD_REQUIRED": "ON", 13 | "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", 14 | "CATCH_DEVELOPMENT_BUILD": "ON" 15 | } 16 | }, 17 | { 18 | "name": "all-tests", 19 | "inherits": "basic-tests", 20 | "displayName": "Full development build", 21 | "description": "Enables development build with examples and ALL tests", 22 | "cacheVariables": { 23 | "CATCH_BUILD_EXAMPLES": "ON", 24 | "CATCH_BUILD_EXTRA_TESTS": "ON", 25 | "CATCH_BUILD_SURROGATES": "ON", 26 | "CATCH_ENABLE_CONFIGURE_TESTS": "ON", 27 | "CATCH_ENABLE_CMAKE_HELPER_TESTS": "ON" 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | 2 | # Catch2 Maintainers 3 | 4 | ## Current 5 | 6 | * Chris Thrasher ([@christhrasher](https://github.com/ChrisThrasher)), gpg key: 56FB686C9DFC8E2C 7 | * Martin Hořeňovský ([@horenmar](https://github.com/horenmar)), gpg key: E29C46F3B8A7502860793B7DECC9C20E314B2360 8 | 9 | ## Retired 10 | 11 | * Phil Nash ([@philsquared](https://github.com/philsquared)) 12 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | module(name = "catch2") 2 | 3 | bazel_dep(name = "bazel_skylib", version = "1.7.1") 4 | bazel_dep(name = "rules_cc", version = "0.1.1") 5 | bazel_dep(name = "rules_license", version = "1.0.0") 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | * Versions 1.x (branch Catch1.x) are no longer supported. 6 | * Versions 2.x (branch v2.x) are currently supported. 7 | * `devel` branch serves for stable-ish development and is supported, 8 | but branches `devel-*` are considered short lived and are not supported separately. 9 | 10 | 11 | ## Reporting a Vulnerability 12 | 13 | Due to its nature as a _unit_ test framework, Catch2 shouldn't interact 14 | with untrusted inputs and there shouldn't be many security vulnerabilities 15 | in it. 16 | 17 | However, if you find one you send email to martin horenovsky 18 | gmail com. If you want to encrypt the email, my pgp key is 19 | `E29C 46F3 B8A7 5028 6079 3B7D ECC9 C20E 314B 2360`. 20 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 2 3 | round: nearest 4 | range: "60...90" 5 | status: 6 | project: 7 | default: 8 | threshold: 2% 9 | patch: 10 | default: 11 | target: 80% 12 | ignore: 13 | - "**/external/clara.hpp" 14 | - "tests" 15 | 16 | 17 | codecov: 18 | branch: devel 19 | max_report_age: off 20 | 21 | comment: 22 | layout: "diff" 23 | -------------------------------------------------------------------------------- /data/artwork/catch2-c-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catchorg/Catch2/3013cb897b5706e8532507cb2b6ac33e1fc35d93/data/artwork/catch2-c-logo.png -------------------------------------------------------------------------------- /data/artwork/catch2-hand-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catchorg/Catch2/3013cb897b5706e8532507cb2b6ac33e1fc35d93/data/artwork/catch2-hand-logo.png -------------------------------------------------------------------------------- /data/artwork/catch2-logo-small-with-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catchorg/Catch2/3013cb897b5706e8532507cb2b6ac33e1fc35d93/data/artwork/catch2-logo-small-with-background.png -------------------------------------------------------------------------------- /data/artwork/catch2-logo-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catchorg/Catch2/3013cb897b5706e8532507cb2b6ac33e1fc35d93/data/artwork/catch2-logo-small.png -------------------------------------------------------------------------------- /docs/commercial-users.md: -------------------------------------------------------------------------------- 1 | 2 | # Commercial users of Catch2 3 | 4 | Catch2 is also widely used in proprietary code bases. This page contains 5 | some of them that are willing to share this information. 6 | 7 | If you want to add your organisation, please check that there is no issue 8 | with you sharing this fact. 9 | 10 | - Bloomberg 11 | - [Bloomlife](https://bloomlife.com) 12 | - [Inscopix Inc.](https://www.inscopix.com/) 13 | - Locksley.CZ 14 | - [Makimo](https://makimo.pl/) 15 | - NASA 16 | - [Nexus Software Systems](https://nexwebsites.com) 17 | - [UX3D](https://ux3d.io) 18 | - [King](https://king.com) 19 | 20 | 21 | --- 22 | 23 | [Home](Readme.md#top) 24 | -------------------------------------------------------------------------------- /examples/020-TestCase-1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | // 020-TestCase-1.cpp 10 | 11 | #include 12 | 13 | TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:1]" ) { 14 | } 15 | 16 | // ^^^ 17 | // Normally no TEST_CASEs in this file. 18 | // Here just to show there are two source files via option --list-tests. 19 | 20 | // Compile & run: 21 | // - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 020-TestCase-1.cpp 22 | // - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 020-TestCase TestCase-1.o 020-TestCase-2.cpp && 020-TestCase --success 23 | // 24 | // - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -c 020-TestCase-1.cpp 25 | // - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -Fe020-TestCase.exe 020-TestCase-1.obj 020-TestCase-2.cpp && 020-TestCase --success 26 | 27 | // Expected test case listing: 28 | // 29 | // prompt> 020-TestCase --list-tests * 30 | // Matching test cases: 31 | // 1: All test cases reside in other .cpp files (empty) 32 | // [multi-file:1] 33 | // 2: Factorial of 0 is computed (fail) 34 | // [multi-file:2] 35 | // 2: Factorials of 1 and higher are computed (pass) 36 | // [multi-file:2] 37 | // 3 matching test cases 38 | -------------------------------------------------------------------------------- /examples/020-TestCase-2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | // 020-TestCase-2.cpp 10 | 11 | // main() provided by Catch in file 020-TestCase-1.cpp. 12 | 13 | #include 14 | 15 | static int Factorial( int number ) { 16 | return number <= 1 ? number : Factorial( number - 1 ) * number; // fail 17 | // return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass 18 | } 19 | 20 | TEST_CASE( "2: Factorial of 0 is 1 (fail)", "[multi-file:2]" ) { 21 | REQUIRE( Factorial(0) == 1 ); 22 | } 23 | 24 | TEST_CASE( "2: Factorials of 1 and higher are computed (pass)", "[multi-file:2]" ) { 25 | REQUIRE( Factorial(1) == 1 ); 26 | REQUIRE( Factorial(2) == 2 ); 27 | REQUIRE( Factorial(3) == 6 ); 28 | REQUIRE( Factorial(10) == 3628800 ); 29 | } 30 | 31 | // Compile: see 020-TestCase-1.cpp 32 | 33 | // Expected compact output (all assertions): 34 | // 35 | // prompt> 020-TestCase --reporter compact --success 36 | // 020-TestCase-2.cpp:13: failed: Factorial(0) == 1 for: 0 == 1 37 | // 020-TestCase-2.cpp:17: passed: Factorial(1) == 1 for: 1 == 1 38 | // 020-TestCase-2.cpp:18: passed: Factorial(2) == 2 for: 2 == 2 39 | // 020-TestCase-2.cpp:19: passed: Factorial(3) == 6 for: 6 == 6 40 | // 020-TestCase-2.cpp:20: passed: Factorial(10) == 3628800 for: 3628800 (0x375f00) == 3628800 (0x375f00) 41 | // Failed 1 test case, failed 1 assertion. 42 | -------------------------------------------------------------------------------- /examples/232-Cfg-CustomMain.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | // 232-Cfg-CustomMain.cpp 10 | // Show how to use custom main and add a custom option to the CLI parser 11 | 12 | #include 13 | 14 | #include 15 | 16 | int main(int argc, char** argv) { 17 | Catch::Session session; // There must be exactly one instance 18 | 19 | int height = 0; // Some user variable you want to be able to set 20 | 21 | // Build a new parser on top of Catch2's 22 | using namespace Catch::Clara; 23 | auto cli 24 | = session.cli() // Get Catch2's command line parser 25 | | Opt( height, "height" ) // bind variable to a new option, with a hint string 26 | ["--height"] // the option names it will respond to 27 | ("how high?"); // description string for the help output 28 | 29 | // Now pass the new composite back to Catch2 so it uses that 30 | session.cli( cli ); 31 | 32 | // Let Catch2 (using Clara) parse the command line 33 | int returnCode = session.applyCommandLine( argc, argv ); 34 | if( returnCode != 0 ) // Indicates a command line error 35 | return returnCode; 36 | 37 | // if set on the command line then 'height' is now set at this point 38 | std::cout << "height: " << height << '\n'; 39 | 40 | return session.run(); 41 | } 42 | -------------------------------------------------------------------------------- /extras/gdbinit: -------------------------------------------------------------------------------- 1 | # 2 | # This file provides a way to skip stepping into Catch code when debugging with gdb. 3 | # 4 | # With the gdb "skip" command you can tell gdb to skip files or functions during debugging. 5 | # see https://xaizek.github.io/2016-05-26/skipping-standard-library-in-gdb/ for an example 6 | # 7 | # Basically the following line tells gdb to skip all functions containing the 8 | # regexp "Catch", which matches the complete Catch namespace. 9 | # If you want to skip just some parts of the Catch code you can modify the 10 | # regexp accordingly. 11 | # 12 | # If you want to permanently skip stepping into Catch code copy the following 13 | # line into your ~/.gdbinit file 14 | # 15 | 16 | skip -rfu Catch 17 | -------------------------------------------------------------------------------- /extras/lldbinit: -------------------------------------------------------------------------------- 1 | # 2 | # This file provides a way to skip stepping into Catch code when debugging with lldb. 3 | # 4 | # With the setting "target.process.thread.step-avoid-regexp" you can tell lldb 5 | # to skip functions matching the regexp 6 | # 7 | # Basically the following line tells lldb to skip all functions containing the 8 | # regexp "Catch", which matches the complete Catch namespace. 9 | # If you want to skip just some parts of the Catch code you can modify the 10 | # regexp accordingly. 11 | # 12 | # If you want to permanently skip stepping into Catch code copy the following 13 | # line into your ~/.lldbinit file 14 | # 15 | 16 | settings set target.process.thread.step-avoid-regexp Catch -------------------------------------------------------------------------------- /fuzzing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # License: Boost 1.0 2 | # By Paul Dreik 2020 3 | 4 | # add a library that brings in the main() function from libfuzzer 5 | # and has all the dependencies, so the individual fuzzers can be 6 | # added one line each. 7 | add_library(fuzzhelper NullOStream.h NullOStream.cpp) 8 | target_link_libraries(fuzzhelper PUBLIC Catch2::Catch2) 9 | 10 | # use C++17 so we can get string_view 11 | target_compile_features(fuzzhelper PUBLIC cxx_std_17) 12 | 13 | # This should be possible to set from the outside to be oss-fuzz compatible, 14 | # fix later. For now, target libFuzzer only. 15 | target_link_options(fuzzhelper PUBLIC "-fsanitize=fuzzer") 16 | 17 | foreach(fuzzer TestSpecParser XmlWriter textflow) 18 | add_executable(fuzz_${fuzzer} fuzz_${fuzzer}.cpp) 19 | target_link_libraries(fuzz_${fuzzer} PRIVATE fuzzhelper) 20 | endforeach() 21 | -------------------------------------------------------------------------------- /fuzzing/NullOStream.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include "NullOStream.h" 10 | 11 | void NullOStream::avoidOutOfLineVirtualCompilerWarning() 12 | { 13 | } 14 | 15 | int NullStreambuf::overflow(int c){ 16 | setp(dummyBuffer, dummyBuffer + sizeof(dummyBuffer)); 17 | return (c == traits_type::eof()) ? '\0' : c; 18 | } 19 | -------------------------------------------------------------------------------- /fuzzing/NullOStream.h: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | // from https://stackoverflow.com/a/8244052 15 | class NullStreambuf : public std::streambuf { 16 | char dummyBuffer[64]; 17 | 18 | protected: 19 | virtual int overflow(int c) override final; 20 | }; 21 | 22 | class NullOStream final : private NullStreambuf, public std::ostream { 23 | public: 24 | NullOStream() : std::ostream(this) {} 25 | NullStreambuf *rdbuf() { return this; } 26 | virtual void avoidOutOfLineVirtualCompilerWarning(); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /fuzzing/build_fuzzers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Builds the fuzzers 4 | # 5 | # By Paul Dreik 20200923 6 | set -exu 7 | 8 | CATCHROOT=$(readlink -f $(dirname $0)/..) 9 | 10 | 11 | BUILDDIR=$CATCHROOT/build-fuzzers 12 | mkdir -p $BUILDDIR 13 | cd $BUILDDIR 14 | 15 | if which /usr/lib/ccache/clang++ >/dev/null 2>&1 ; then 16 | CXX=/usr/lib/ccache/clang++ 17 | else 18 | CXX=clang++ 19 | fi 20 | 21 | cmake $CATCHROOT \ 22 | -DCMAKE_CXX_COMPILER=$CXX \ 23 | -DCMAKE_CXX_FLAGS="-fsanitize=fuzzer-no-link,address,undefined -O3 -g" \ 24 | -DCATCH_DEVELOPMENT_BUILD=On \ 25 | -DCATCH_BUILD_EXAMPLES=Off \ 26 | -DCATCH_BUILD_EXTRA_TESTS=Off \ 27 | -DCATCH_BUILD_TESTING=Off \ 28 | -DBUILD_TESTING=Off \ 29 | -DCATCH_ENABLE_WERROR=Off \ 30 | -DCATCH_BUILD_FUZZERS=On 31 | 32 | cmake --build . -j $(nproc) 33 | 34 | -------------------------------------------------------------------------------- /fuzzing/fuzz_TestSpecParser.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | //By Paul Dreik 2020 9 | 10 | #include 11 | #include 12 | 13 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 14 | 15 | Catch::TagAliasRegistry tar; 16 | Catch::TestSpecParser tsp(tar); 17 | 18 | std::string buf(Data,Data+Size); 19 | tsp.parse(buf); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /fuzzing/fuzz_XmlWriter.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | //By Paul Dreik 2020 9 | 10 | #include 11 | 12 | #include "NullOStream.h" 13 | 14 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 15 | 16 | std::string buf(Data,Data+Size); 17 | NullOStream nul; 18 | Catch::XmlEncode encode(buf); 19 | encode.encodeTo(nul); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /fuzzing/fuzz_textflow.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | //By Paul Dreik 2020 9 | 10 | #include 11 | 12 | #include "NullOStream.h" 13 | 14 | #include 15 | #include 16 | 17 | 18 | template 19 | void split(const char *Data, size_t Size, Callback callback) { 20 | 21 | using namespace std::literals; 22 | constexpr auto sep="\n~~~\n"sv; 23 | 24 | std::string_view remainder(Data,Size); 25 | for (;;) { 26 | auto pos=remainder.find(sep); 27 | if(pos==std::string_view::npos) { 28 | //not found. use the remainder and exit 29 | callback(remainder); 30 | return; 31 | } else { 32 | //found. invoke callback on the first part, then proceed with the rest. 33 | callback(remainder.substr(0,pos)); 34 | remainder=remainder.substr(pos+sep.size()); 35 | } 36 | } 37 | } 38 | 39 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { 40 | 41 | Catch::TextFlow::Columns columns; 42 | 43 | // break the input on separator 44 | split((const char*)Data,Size,[&](std::string_view word) { 45 | columns+=Catch::TextFlow::Column(std::string(word)); 46 | }); 47 | 48 | NullOStream nul; 49 | nul << columns; 50 | 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /mdsnippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "ReadOnly": false, 3 | "TocLevel": 5, 4 | "Exclude": [ 5 | "cmake-build" 6 | ], 7 | "WriteHeader": false, 8 | "Convention": "InPlaceOverwrite" 9 | } 10 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | # Copyright Catch2 Authors 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE.txt or copy at 4 | # https://www.boost.org/LICENSE_1_0.txt) 5 | 6 | # SPDX-License-Identifier: BSL-1.0 7 | 8 | project( 9 | 'catch2', 10 | 'cpp', 11 | version: '3.8.1', # CML version placeholder, don't delete 12 | license: 'BSL-1.0', 13 | meson_version: '>=0.54.1', 14 | ) 15 | 16 | subdir('src/catch2') 17 | if get_option('tests') 18 | subdir('tests') 19 | endif 20 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('tests', type: 'boolean', value: true, description: 'Build the unit tests') 2 | option('install', type: 'boolean', value: true, description: 'Install the library') 3 | -------------------------------------------------------------------------------- /src/catch2/benchmark/catch_chronometer.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | namespace Benchmark { 13 | namespace Detail { 14 | ChronometerConcept::~ChronometerConcept() = default; 15 | } // namespace Detail 16 | } // namespace Benchmark 17 | } // namespace Catch 18 | -------------------------------------------------------------------------------- /src/catch2/benchmark/catch_clock.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_CLOCK_HPP_INCLUDED 11 | #define CATCH_CLOCK_HPP_INCLUDED 12 | 13 | #include 14 | 15 | namespace Catch { 16 | namespace Benchmark { 17 | using IDuration = std::chrono::nanoseconds; 18 | using FDuration = std::chrono::duration; 19 | 20 | template 21 | using TimePoint = typename Clock::time_point; 22 | 23 | using default_clock = std::chrono::steady_clock; 24 | } // namespace Benchmark 25 | } // namespace Catch 26 | 27 | #endif // CATCH_CLOCK_HPP_INCLUDED 28 | -------------------------------------------------------------------------------- /src/catch2/benchmark/catch_environment.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_ENVIRONMENT_HPP_INCLUDED 11 | #define CATCH_ENVIRONMENT_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | 16 | namespace Catch { 17 | namespace Benchmark { 18 | struct EnvironmentEstimate { 19 | FDuration mean; 20 | OutlierClassification outliers; 21 | }; 22 | struct Environment { 23 | EnvironmentEstimate clock_resolution; 24 | EnvironmentEstimate clock_cost; 25 | }; 26 | } // namespace Benchmark 27 | } // namespace Catch 28 | 29 | #endif // CATCH_ENVIRONMENT_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/benchmark/catch_estimate.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_ESTIMATE_HPP_INCLUDED 11 | #define CATCH_ESTIMATE_HPP_INCLUDED 12 | 13 | namespace Catch { 14 | namespace Benchmark { 15 | template 16 | struct Estimate { 17 | Type point; 18 | Type lower_bound; 19 | Type upper_bound; 20 | double confidence_interval; 21 | }; 22 | } // namespace Benchmark 23 | } // namespace Catch 24 | 25 | #endif // CATCH_ESTIMATE_HPP_INCLUDED 26 | -------------------------------------------------------------------------------- /src/catch2/benchmark/catch_outlier_classification.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED 11 | #define CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED 12 | 13 | namespace Catch { 14 | namespace Benchmark { 15 | struct OutlierClassification { 16 | int samples_seen = 0; 17 | int low_severe = 0; // more than 3 times IQR below Q1 18 | int low_mild = 0; // 1.5 to 3 times IQR below Q1 19 | int high_mild = 0; // 1.5 to 3 times IQR above Q3 20 | int high_severe = 0; // more than 3 times IQR above Q3 21 | 22 | constexpr int total() const { 23 | return low_severe + low_mild + high_mild + high_severe; 24 | } 25 | }; 26 | } // namespace Benchmark 27 | } // namespace Catch 28 | 29 | #endif // CATCH_OUTLIERS_CLASSIFICATION_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/benchmark/catch_sample_analysis.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED 11 | #define CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | namespace Catch { 20 | namespace Benchmark { 21 | struct SampleAnalysis { 22 | std::vector samples; 23 | Estimate mean; 24 | Estimate standard_deviation; 25 | OutlierClassification outliers; 26 | double outlier_variance; 27 | }; 28 | } // namespace Benchmark 29 | } // namespace Catch 30 | 31 | #endif // CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED 32 | -------------------------------------------------------------------------------- /src/catch2/benchmark/detail/catch_analyse.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_ANALYSE_HPP_INCLUDED 11 | #define CATCH_ANALYSE_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | 16 | 17 | namespace Catch { 18 | class IConfig; 19 | 20 | namespace Benchmark { 21 | namespace Detail { 22 | SampleAnalysis analyse(const IConfig &cfg, FDuration* first, FDuration* last); 23 | } // namespace Detail 24 | } // namespace Benchmark 25 | } // namespace Catch 26 | 27 | #endif // CATCH_ANALYSE_HPP_INCLUDED 28 | -------------------------------------------------------------------------------- /src/catch2/benchmark/detail/catch_benchmark_function.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | namespace Benchmark { 13 | namespace Detail { 14 | struct do_nothing { 15 | void operator()() const {} 16 | }; 17 | 18 | BenchmarkFunction::callable::~callable() = default; 19 | BenchmarkFunction::BenchmarkFunction(): 20 | f( new model{ {} } ){} 21 | } // namespace Detail 22 | } // namespace Benchmark 23 | } // namespace Catch 24 | -------------------------------------------------------------------------------- /src/catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED 9 | #define CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | // We cannot forward declare the type with default template argument 16 | // multiple times, so it is split out into a separate header so that 17 | // we can prevent multiple declarations in dependees 18 | template 19 | struct BenchmarkStats; 20 | 21 | } // end namespace Catch 22 | 23 | #endif // CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED 24 | -------------------------------------------------------------------------------- /src/catch2/benchmark/detail/catch_measure.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_MEASURE_HPP_INCLUDED 11 | #define CATCH_MEASURE_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | namespace Catch { 18 | namespace Benchmark { 19 | namespace Detail { 20 | template 21 | TimingOf measure(Fun&& fun, Args&&... args) { 22 | auto start = Clock::now(); 23 | auto&& r = Detail::complete_invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...); 24 | auto end = Clock::now(); 25 | auto delta = end - start; 26 | return { delta, CATCH_FORWARD(r), 1 }; 27 | } 28 | } // namespace Detail 29 | } // namespace Benchmark 30 | } // namespace Catch 31 | 32 | #endif // CATCH_MEASURE_HPP_INCLUDED 33 | -------------------------------------------------------------------------------- /src/catch2/benchmark/detail/catch_repeat.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_REPEAT_HPP_INCLUDED 11 | #define CATCH_REPEAT_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | 16 | namespace Catch { 17 | namespace Benchmark { 18 | namespace Detail { 19 | template 20 | struct repeater { 21 | void operator()(int k) const { 22 | for (int i = 0; i < k; ++i) { 23 | fun(); 24 | } 25 | } 26 | Fun fun; 27 | }; 28 | template 29 | repeater> repeat(Fun&& fun) { 30 | return { CATCH_FORWARD(fun) }; 31 | } 32 | } // namespace Detail 33 | } // namespace Benchmark 34 | } // namespace Catch 35 | 36 | #endif // CATCH_REPEAT_HPP_INCLUDED 37 | -------------------------------------------------------------------------------- /src/catch2/benchmark/detail/catch_run_for_at_least.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace Catch { 15 | namespace Benchmark { 16 | namespace Detail { 17 | struct optimized_away_error : std::exception { 18 | const char* what() const noexcept override; 19 | }; 20 | 21 | const char* optimized_away_error::what() const noexcept { 22 | return "could not measure benchmark, maybe it was optimized away"; 23 | } 24 | 25 | void throw_optimized_away_error() { 26 | Catch::throw_exception(optimized_away_error{}); 27 | } 28 | 29 | } // namespace Detail 30 | } // namespace Benchmark 31 | } // namespace Catch 32 | -------------------------------------------------------------------------------- /src/catch2/benchmark/detail/catch_timing.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | // Adapted from donated nonius code. 9 | 10 | #ifndef CATCH_TIMING_HPP_INCLUDED 11 | #define CATCH_TIMING_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | 16 | namespace Catch { 17 | namespace Benchmark { 18 | template 19 | struct Timing { 20 | IDuration elapsed; 21 | Result result; 22 | int iterations; 23 | }; 24 | template 25 | using TimingOf = Timing>>; 26 | } // namespace Benchmark 27 | } // namespace Catch 28 | 29 | #endif // CATCH_TIMING_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/catch_assertion_info.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_ASSERTION_INFO_HPP_INCLUDED 9 | #define CATCH_ASSERTION_INFO_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Catch { 16 | 17 | struct AssertionInfo { 18 | // AssertionInfo() = delete; 19 | 20 | StringRef macroName; 21 | SourceLineInfo lineInfo; 22 | StringRef capturedExpression; 23 | ResultDisposition::Flags resultDisposition; 24 | }; 25 | 26 | } // end namespace Catch 27 | 28 | #endif // CATCH_ASSERTION_INFO_HPP_INCLUDED 29 | -------------------------------------------------------------------------------- /src/catch2/catch_case_sensitive.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_CASE_SENSITIVE_HPP_INCLUDED 9 | #define CATCH_CASE_SENSITIVE_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | 13 | enum class CaseSensitive { Yes, No }; 14 | 15 | } // namespace Catch 16 | 17 | #endif // CATCH_CASE_SENSITIVE_HPP_INCLUDED 18 | -------------------------------------------------------------------------------- /src/catch2/catch_get_random_seed.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | std::uint32_t getSeed() { 16 | return getCurrentContext().getConfig()->rngSeed(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/catch2/catch_get_random_seed.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_GET_RANDOM_SEED_HPP_INCLUDED 9 | #define CATCH_GET_RANDOM_SEED_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | //! Returns Catch2's current RNG seed. 15 | std::uint32_t getSeed(); 16 | } 17 | 18 | #endif // CATCH_GET_RANDOM_SEED_HPP_INCLUDED 19 | -------------------------------------------------------------------------------- /src/catch2/catch_section_info.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_SECTION_INFO_HPP_INCLUDED 9 | #define CATCH_SECTION_INFO_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | namespace Catch { 19 | 20 | struct SectionInfo { 21 | // The last argument is ignored, so that people can write 22 | // SECTION("ShortName", "Proper description that is long") and 23 | // still use the `-c` flag comfortably. 24 | SectionInfo( SourceLineInfo const& _lineInfo, std::string _name, 25 | const char* const = nullptr ): 26 | name(CATCH_MOVE(_name)), 27 | lineInfo(_lineInfo) 28 | {} 29 | 30 | std::string name; 31 | SourceLineInfo lineInfo; 32 | }; 33 | 34 | struct SectionEndInfo { 35 | SectionInfo sectionInfo; 36 | Counts prevAssertions; 37 | double durationInSeconds; 38 | }; 39 | 40 | } // end namespace Catch 41 | 42 | #endif // CATCH_SECTION_INFO_HPP_INCLUDED 43 | -------------------------------------------------------------------------------- /src/catch2/catch_tag_alias.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TAG_ALIAS_HPP_INCLUDED 9 | #define CATCH_TAG_ALIAS_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace Catch { 16 | 17 | struct TagAlias { 18 | TagAlias(std::string const& _tag, SourceLineInfo _lineInfo): 19 | tag(_tag), 20 | lineInfo(_lineInfo) 21 | {} 22 | 23 | std::string tag; 24 | SourceLineInfo lineInfo; 25 | }; 26 | 27 | } // end namespace Catch 28 | 29 | #endif // CATCH_TAG_ALIAS_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/catch_tag_alias_autoregistrar.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Catch { 14 | 15 | RegistrarForTagAliases::RegistrarForTagAliases(char const* alias, char const* tag, SourceLineInfo const& lineInfo) { 16 | CATCH_TRY { 17 | getMutableRegistryHub().registerTagAlias(alias, tag, lineInfo); 18 | } CATCH_CATCH_ALL { 19 | // Do not throw when constructing global objects, instead register the exception to be processed later 20 | getMutableRegistryHub().registerStartupException(); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/catch2/catch_tag_alias_autoregistrar.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED 9 | #define CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Catch { 16 | 17 | struct RegistrarForTagAliases { 18 | RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); 19 | }; 20 | 21 | } // end namespace Catch 22 | 23 | #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ 24 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ 25 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ 26 | namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ 27 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION 28 | 29 | #endif // CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/catch_timer.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | 10 | #include 11 | 12 | namespace Catch { 13 | 14 | namespace { 15 | static auto getCurrentNanosecondsSinceEpoch() -> uint64_t { 16 | return std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); 17 | } 18 | } // end unnamed namespace 19 | 20 | void Timer::start() { 21 | m_nanoseconds = getCurrentNanosecondsSinceEpoch(); 22 | } 23 | auto Timer::getElapsedNanoseconds() const -> uint64_t { 24 | return getCurrentNanosecondsSinceEpoch() - m_nanoseconds; 25 | } 26 | auto Timer::getElapsedMicroseconds() const -> uint64_t { 27 | return getElapsedNanoseconds()/1000; 28 | } 29 | auto Timer::getElapsedMilliseconds() const -> unsigned int { 30 | return static_cast(getElapsedMicroseconds()/1000); 31 | } 32 | auto Timer::getElapsedSeconds() const -> double { 33 | return static_cast(getElapsedMicroseconds())/1000000.0; 34 | } 35 | 36 | 37 | } // namespace Catch 38 | -------------------------------------------------------------------------------- /src/catch2/catch_timer.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TIMER_HPP_INCLUDED 9 | #define CATCH_TIMER_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | class Timer { 16 | uint64_t m_nanoseconds = 0; 17 | public: 18 | void start(); 19 | auto getElapsedNanoseconds() const -> uint64_t; 20 | auto getElapsedMicroseconds() const -> uint64_t; 21 | auto getElapsedMilliseconds() const -> unsigned int; 22 | auto getElapsedSeconds() const -> double; 23 | }; 24 | 25 | } // namespace Catch 26 | 27 | #endif // CATCH_TIMER_HPP_INCLUDED 28 | -------------------------------------------------------------------------------- /src/catch2/catch_totals.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TOTALS_HPP_INCLUDED 9 | #define CATCH_TOTALS_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | struct Counts { 16 | Counts operator - ( Counts const& other ) const; 17 | Counts& operator += ( Counts const& other ); 18 | 19 | std::uint64_t total() const; 20 | bool allPassed() const; 21 | bool allOk() const; 22 | 23 | std::uint64_t passed = 0; 24 | std::uint64_t failed = 0; 25 | std::uint64_t failedButOk = 0; 26 | std::uint64_t skipped = 0; 27 | }; 28 | 29 | struct Totals { 30 | 31 | Totals operator - ( Totals const& other ) const; 32 | Totals& operator += ( Totals const& other ); 33 | 34 | Totals delta( Totals const& prevTotals ) const; 35 | 36 | Counts assertions; 37 | Counts testCases; 38 | }; 39 | } 40 | 41 | #endif // CATCH_TOTALS_HPP_INCLUDED 42 | -------------------------------------------------------------------------------- /src/catch2/catch_translate_exception.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | namespace Catch { 13 | namespace Detail { 14 | void registerTranslatorImpl( 15 | Detail::unique_ptr&& translator ) { 16 | getMutableRegistryHub().registerTranslator( 17 | CATCH_MOVE( translator ) ); 18 | } 19 | } // namespace Detail 20 | } // namespace Catch 21 | -------------------------------------------------------------------------------- /src/catch2/catch_version.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | #include 10 | 11 | namespace Catch { 12 | 13 | Version::Version 14 | ( unsigned int _majorVersion, 15 | unsigned int _minorVersion, 16 | unsigned int _patchNumber, 17 | char const * const _branchName, 18 | unsigned int _buildNumber ) 19 | : majorVersion( _majorVersion ), 20 | minorVersion( _minorVersion ), 21 | patchNumber( _patchNumber ), 22 | branchName( _branchName ), 23 | buildNumber( _buildNumber ) 24 | {} 25 | 26 | std::ostream& operator << ( std::ostream& os, Version const& version ) { 27 | os << version.majorVersion << '.' 28 | << version.minorVersion << '.' 29 | << version.patchNumber; 30 | // branchName is never null -> 0th char is \0 if it is empty 31 | if (version.branchName[0]) { 32 | os << '-' << version.branchName 33 | << '.' << version.buildNumber; 34 | } 35 | return os; 36 | } 37 | 38 | Version const& libraryVersion() { 39 | static Version version( 3, 8, 1, "", 0 ); 40 | return version; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/catch2/catch_version.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_VERSION_HPP_INCLUDED 9 | #define CATCH_VERSION_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | // Versioning information 16 | struct Version { 17 | Version( Version const& ) = delete; 18 | Version& operator=( Version const& ) = delete; 19 | Version( unsigned int _majorVersion, 20 | unsigned int _minorVersion, 21 | unsigned int _patchNumber, 22 | char const * const _branchName, 23 | unsigned int _buildNumber ); 24 | 25 | unsigned int const majorVersion; 26 | unsigned int const minorVersion; 27 | unsigned int const patchNumber; 28 | 29 | // buildNumber is only used if branchName is not null 30 | char const * const branchName; 31 | unsigned int const buildNumber; 32 | 33 | friend std::ostream& operator << ( std::ostream& os, Version const& version ); 34 | }; 35 | 36 | Version const& libraryVersion(); 37 | } 38 | 39 | #endif // CATCH_VERSION_HPP_INCLUDED 40 | -------------------------------------------------------------------------------- /src/catch2/catch_version_macros.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_VERSION_MACROS_HPP_INCLUDED 9 | #define CATCH_VERSION_MACROS_HPP_INCLUDED 10 | 11 | #define CATCH_VERSION_MAJOR 3 12 | #define CATCH_VERSION_MINOR 8 13 | #define CATCH_VERSION_PATCH 1 14 | 15 | #endif // CATCH_VERSION_MACROS_HPP_INCLUDED 16 | -------------------------------------------------------------------------------- /src/catch2/generators/catch_generator_exception.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | 13 | const char* GeneratorException::what() const noexcept { 14 | return m_msg; 15 | } 16 | 17 | } // end namespace Catch 18 | -------------------------------------------------------------------------------- /src/catch2/generators/catch_generator_exception.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED 9 | #define CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | // Exception type to be thrown when a Generator runs into an error, 16 | // e.g. it cannot initialize the first return value based on 17 | // runtime information 18 | class GeneratorException : public std::exception { 19 | const char* const m_msg = ""; 20 | 21 | public: 22 | GeneratorException(const char* msg): 23 | m_msg(msg) 24 | {} 25 | 26 | const char* what() const noexcept override final; 27 | }; 28 | 29 | } // end namespace Catch 30 | 31 | #endif // CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED 32 | -------------------------------------------------------------------------------- /src/catch2/generators/catch_generators.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | 16 | IGeneratorTracker::~IGeneratorTracker() = default; 17 | 18 | namespace Generators { 19 | 20 | namespace Detail { 21 | 22 | [[noreturn]] 23 | void throw_generator_exception(char const* msg) { 24 | Catch::throw_exception(GeneratorException{ msg }); 25 | } 26 | } // end namespace Detail 27 | 28 | GeneratorUntypedBase::~GeneratorUntypedBase() = default; 29 | 30 | IGeneratorTracker* acquireGeneratorTracker(StringRef generatorName, SourceLineInfo const& lineInfo ) { 31 | return getResultCapture().acquireGeneratorTracker( generatorName, lineInfo ); 32 | } 33 | 34 | IGeneratorTracker* createGeneratorTracker( StringRef generatorName, 35 | SourceLineInfo lineInfo, 36 | GeneratorBasePtr&& generator ) { 37 | return getResultCapture().createGeneratorTracker( 38 | generatorName, lineInfo, CATCH_MOVE( generator ) ); 39 | } 40 | 41 | } // namespace Generators 42 | } // namespace Catch 43 | -------------------------------------------------------------------------------- /src/catch2/generators/catch_generators_all.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | /** \file 9 | * This is a convenience header for Catch2's Generator support. It includes 10 | * **all** of Catch2 headers related to generators. 11 | * 12 | * Generally the Catch2 users should use specific includes they need, 13 | * but this header can be used instead for ease-of-experimentation, or 14 | * just plain convenience, at the cost of (significantly) increased 15 | * compilation times. 16 | * 17 | * When a new header is added to either the `generators` folder, 18 | * or to the corresponding internal subfolder, it should be added here. 19 | */ 20 | 21 | #ifndef CATCH_GENERATORS_ALL_HPP_INCLUDED 22 | #define CATCH_GENERATORS_ALL_HPP_INCLUDED 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #endif // CATCH_GENERATORS_ALL_HPP_INCLUDED 31 | -------------------------------------------------------------------------------- /src/catch2/generators/catch_generators_random.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace Catch { 15 | namespace Generators { 16 | namespace Detail { 17 | std::uint32_t getSeed() { return sharedRng()(); } 18 | } // namespace Detail 19 | 20 | struct RandomFloatingGenerator::PImpl { 21 | PImpl( long double a, long double b, uint32_t seed ): 22 | rng( seed ), dist( a, b ) {} 23 | 24 | Catch::SimplePcg32 rng; 25 | std::uniform_real_distribution dist; 26 | }; 27 | 28 | RandomFloatingGenerator::RandomFloatingGenerator( 29 | long double a, long double b, std::uint32_t seed) : 30 | m_pimpl(Catch::Detail::make_unique(a, b, seed)) { 31 | static_cast( next() ); 32 | } 33 | 34 | RandomFloatingGenerator::~RandomFloatingGenerator() = 35 | default; 36 | bool RandomFloatingGenerator::next() { 37 | m_current_number = m_pimpl->dist( m_pimpl->rng ); 38 | return true; 39 | } 40 | } // namespace Generators 41 | } // namespace Catch 42 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_capture.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | IResultCapture::~IResultCapture() = default; 13 | } 14 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_config.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | IConfig::~IConfig() = default; 13 | } 14 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_exception.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | IExceptionTranslator::~IExceptionTranslator() = default; 13 | IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default; 14 | } 15 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_exception.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED 9 | #define CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace Catch { 17 | using exceptionTranslateFunction = std::string(*)(); 18 | 19 | class IExceptionTranslator; 20 | using ExceptionTranslators = std::vector>; 21 | 22 | class IExceptionTranslator { 23 | public: 24 | virtual ~IExceptionTranslator(); // = default 25 | virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; 26 | }; 27 | 28 | class IExceptionTranslatorRegistry { 29 | public: 30 | virtual ~IExceptionTranslatorRegistry(); // = default 31 | virtual std::string translateActiveException() const = 0; 32 | }; 33 | 34 | } // namespace Catch 35 | 36 | #endif // CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED 37 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_generatortracker.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | namespace Catch { 13 | namespace Generators { 14 | 15 | bool GeneratorUntypedBase::countedNext() { 16 | auto ret = next(); 17 | if ( ret ) { 18 | m_stringReprCache.clear(); 19 | ++m_currentElementIndex; 20 | } 21 | return ret; 22 | } 23 | 24 | StringRef GeneratorUntypedBase::currentElementAsString() const { 25 | if ( m_stringReprCache.empty() ) { 26 | m_stringReprCache = stringifyImpl(); 27 | } 28 | return m_stringReprCache; 29 | } 30 | 31 | } // namespace Generators 32 | } // namespace Catch 33 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_registry_hub.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | IRegistryHub::~IRegistryHub() = default; 13 | IMutableRegistryHub::~IMutableRegistryHub() = default; 14 | } 15 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_reporter_factory.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | IReporterFactory::~IReporterFactory() = default; 13 | EventListenerFactory::~EventListenerFactory() = default; 14 | } 15 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_tag_alias_registry.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED 9 | #define CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | struct TagAlias; 16 | 17 | class ITagAliasRegistry { 18 | public: 19 | virtual ~ITagAliasRegistry(); // = default 20 | // Nullptr if not present 21 | virtual TagAlias const* find( std::string const& alias ) const = 0; 22 | virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; 23 | 24 | static ITagAliasRegistry const& get(); 25 | }; 26 | 27 | } // end namespace Catch 28 | 29 | #endif // CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_test_invoker.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED 9 | #define CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | 13 | class ITestInvoker { 14 | public: 15 | virtual void prepareTestCase(); 16 | virtual void tearDownTestCase(); 17 | virtual void invoke() const = 0; 18 | virtual ~ITestInvoker(); // = default 19 | }; 20 | 21 | } // namespace Catch 22 | 23 | #endif // CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED 24 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_testcase.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | ITestCaseRegistry::~ITestCaseRegistry() = default; 13 | } 14 | -------------------------------------------------------------------------------- /src/catch2/interfaces/catch_interfaces_testcase.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_INTERFACES_TESTCASE_HPP_INCLUDED 9 | #define CATCH_INTERFACES_TESTCASE_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | struct TestCaseInfo; 16 | class TestCaseHandle; 17 | class IConfig; 18 | 19 | class ITestCaseRegistry { 20 | public: 21 | virtual ~ITestCaseRegistry(); // = default 22 | // TODO: this exists only for adding filenames to test cases -- let's expose this in a saner way later 23 | virtual std::vector const& getAllInfos() const = 0; 24 | virtual std::vector const& getAllTests() const = 0; 25 | virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; 26 | }; 27 | 28 | } 29 | 30 | #endif // CATCH_INTERFACES_TESTCASE_HPP_INCLUDED 31 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_case_insensitive_comparisons.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace Catch { 15 | namespace Detail { 16 | 17 | bool CaseInsensitiveLess::operator()( StringRef lhs, 18 | StringRef rhs ) const { 19 | return std::lexicographical_compare( 20 | lhs.begin(), lhs.end(), 21 | rhs.begin(), rhs.end(), 22 | []( char l, char r ) { return toLower( l ) < toLower( r ); } ); 23 | } 24 | 25 | bool 26 | CaseInsensitiveEqualTo::operator()( StringRef lhs, 27 | StringRef rhs ) const { 28 | return std::equal( 29 | lhs.begin(), lhs.end(), 30 | rhs.begin(), rhs.end(), 31 | []( char l, char r ) { return toLower( l ) == toLower( r ); } ); 32 | } 33 | 34 | } // namespace Detail 35 | } // namespace Catch 36 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_case_insensitive_comparisons.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED 9 | #define CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | namespace Detail { 15 | //! Provides case-insensitive `op<` semantics when called 16 | struct CaseInsensitiveLess { 17 | bool operator()( StringRef lhs, 18 | StringRef rhs ) const; 19 | }; 20 | 21 | //! Provides case-insensitive `op==` semantics when called 22 | struct CaseInsensitiveEqualTo { 23 | bool operator()( StringRef lhs, 24 | StringRef rhs ) const; 25 | }; 26 | 27 | } // namespace Detail 28 | } // namespace Catch 29 | 30 | #endif // CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED 31 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_commandline.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_COMMANDLINE_HPP_INCLUDED 9 | #define CATCH_COMMANDLINE_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | struct ConfigData; 16 | 17 | Clara::Parser makeCommandLineParser( ConfigData& config ); 18 | 19 | } // end namespace Catch 20 | 21 | #endif // CATCH_COMMANDLINE_HPP_INCLUDED 22 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_config_android_logwrite.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /** \file 10 | * Wrapper for ANDROID_LOGWRITE configuration option 11 | * 12 | * We want to default to enabling it when compiled for android, but 13 | * users of the library should also be able to disable it if they want 14 | * to. 15 | */ 16 | 17 | #ifndef CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED 18 | #define CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED 19 | 20 | #include 21 | 22 | #if defined(__ANDROID__) 23 | # define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE 24 | #endif 25 | 26 | 27 | #if defined( CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE ) && \ 28 | !defined( CATCH_CONFIG_NO_ANDROID_LOGWRITE ) && \ 29 | !defined( CATCH_CONFIG_ANDROID_LOGWRITE ) 30 | # define CATCH_CONFIG_ANDROID_LOGWRITE 31 | #endif 32 | 33 | #endif // CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED 34 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_config_counter.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /** \file 10 | * Wrapper for the CONFIG configuration option 11 | * 12 | * When generating internal unique names, there are two options. Either 13 | * we mix in the current line number, or mix in an incrementing number. 14 | * We prefer the latter, using `__COUNTER__`, but users might want to 15 | * use the former. 16 | */ 17 | 18 | #ifndef CATCH_CONFIG_COUNTER_HPP_INCLUDED 19 | #define CATCH_CONFIG_COUNTER_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) 24 | #define CATCH_INTERNAL_CONFIG_COUNTER 25 | #endif 26 | 27 | #if defined( CATCH_INTERNAL_CONFIG_COUNTER ) && \ 28 | !defined( CATCH_CONFIG_NO_COUNTER ) && \ 29 | !defined( CATCH_CONFIG_COUNTER ) 30 | # define CATCH_CONFIG_COUNTER 31 | #endif 32 | 33 | 34 | #endif // CATCH_CONFIG_COUNTER_HPP_INCLUDED 35 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_config_prefix_messages.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /** \file 10 | * Wrapper for the CATCH_CONFIG_PREFIX_MESSAGES configuration option 11 | * 12 | * CATCH_CONFIG_PREFIX_ALL can be used to avoid clashes with other macros 13 | * by prepending CATCH_. This may not be desirable if the only clashes are with 14 | * logger macros such as INFO and WARN. In this cases 15 | * CATCH_CONFIG_PREFIX_MESSAGES can be used to only prefix a small subset 16 | * of relevant macros. 17 | * 18 | */ 19 | 20 | #ifndef CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED 21 | #define CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED 22 | 23 | #include 24 | 25 | #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_PREFIX_MESSAGES) 26 | #define CATCH_CONFIG_PREFIX_MESSAGES 27 | #endif 28 | 29 | #endif // CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_config_static_analysis_support.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /** \file 10 | * Wrapper for the STATIC_ANALYSIS_SUPPORT configuration option 11 | * 12 | * Some of Catch2's macros can be defined differently to work better with 13 | * static analysis tools, like clang-tidy or coverity. 14 | * Currently the main use case is to show that `SECTION`s are executed 15 | * exclusively, and not all in one run of a `TEST_CASE`. 16 | */ 17 | 18 | #ifndef CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED 19 | #define CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED 20 | 21 | #include 22 | 23 | #if defined(__clang_analyzer__) || defined(__COVERITY__) 24 | #define CATCH_INTERNAL_CONFIG_STATIC_ANALYSIS_SUPPORT 25 | #endif 26 | 27 | #if defined( CATCH_INTERNAL_CONFIG_STATIC_ANALYSIS_SUPPORT ) && \ 28 | !defined( CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ) && \ 29 | !defined( CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ) 30 | # define CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT 31 | #endif 32 | 33 | 34 | #endif // CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED 35 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_config_uncaught_exceptions.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /** \file 10 | * Wrapper for UNCAUGHT_EXCEPTIONS configuration option 11 | * 12 | * For some functionality, Catch2 requires to know whether there is 13 | * an active exception. Because `std::uncaught_exception` is deprecated 14 | * in C++17, we want to use `std::uncaught_exceptions` if possible. 15 | */ 16 | 17 | #ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED 18 | #define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED 19 | 20 | #include 21 | 22 | #if defined(_MSC_VER) 23 | # if _MSC_VER >= 1900 // Visual Studio 2015 or newer 24 | # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS 25 | # endif 26 | #endif 27 | 28 | 29 | #include 30 | 31 | #if defined(__cpp_lib_uncaught_exceptions) \ 32 | && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) 33 | 34 | # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS 35 | #endif // __cpp_lib_uncaught_exceptions 36 | 37 | 38 | #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \ 39 | && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \ 40 | && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) 41 | 42 | # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS 43 | #endif 44 | 45 | 46 | #endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED 47 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_config_wchar.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /** \file 10 | * Wrapper for the WCHAR configuration option 11 | * 12 | * We want to support platforms that do not provide `wchar_t`, so we 13 | * sometimes have to disable providing wchar_t overloads through Catch2, 14 | * e.g. the StringMaker specialization for `std::wstring`. 15 | */ 16 | 17 | #ifndef CATCH_CONFIG_WCHAR_HPP_INCLUDED 18 | #define CATCH_CONFIG_WCHAR_HPP_INCLUDED 19 | 20 | #include 21 | 22 | // We assume that WCHAR should be enabled by default, and only disabled 23 | // for a shortlist (so far only DJGPP) of compilers. 24 | 25 | #if defined(__DJGPP__) 26 | # define CATCH_INTERNAL_CONFIG_NO_WCHAR 27 | #endif // __DJGPP__ 28 | 29 | #if !defined( CATCH_INTERNAL_CONFIG_NO_WCHAR ) && \ 30 | !defined( CATCH_CONFIG_NO_WCHAR ) && \ 31 | !defined( CATCH_CONFIG_WCHAR ) 32 | # define CATCH_CONFIG_WCHAR 33 | #endif 34 | 35 | #endif // CATCH_CONFIG_WCHAR_HPP_INCLUDED 36 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_console_width.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_CONSOLE_WIDTH_HPP_INCLUDED 9 | #define CATCH_CONSOLE_WIDTH_HPP_INCLUDED 10 | 11 | // This include must be kept so that user's configured value for CONSOLE_WIDTH 12 | // is used before we attempt to provide a default value 13 | #include 14 | 15 | #ifndef CATCH_CONFIG_CONSOLE_WIDTH 16 | #define CATCH_CONFIG_CONSOLE_WIDTH 80 17 | #endif 18 | 19 | #endif // CATCH_CONSOLE_WIDTH_HPP_INCLUDED 20 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_context.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Catch { 13 | 14 | Context* Context::currentContext = nullptr; 15 | 16 | void cleanUpContext() { 17 | delete Context::currentContext; 18 | Context::currentContext = nullptr; 19 | } 20 | void Context::createContext() { 21 | currentContext = new Context(); 22 | } 23 | 24 | Context& getCurrentMutableContext() { 25 | if ( !Context::currentContext ) { Context::createContext(); } 26 | // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) 27 | return *Context::currentContext; 28 | } 29 | 30 | SimplePcg32& sharedRng() { 31 | static SimplePcg32 s_rng; 32 | return s_rng; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_debug_console.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #if defined(CATCH_CONFIG_ANDROID_LOGWRITE) 20 | #include 21 | 22 | namespace Catch { 23 | void writeToDebugConsole( std::string const& text ) { 24 | __android_log_write( ANDROID_LOG_DEBUG, "Catch", text.c_str() ); 25 | } 26 | } 27 | 28 | #elif defined(CATCH_PLATFORM_WINDOWS) 29 | 30 | namespace Catch { 31 | void writeToDebugConsole( std::string const& text ) { 32 | ::OutputDebugStringA( text.c_str() ); 33 | } 34 | } 35 | 36 | #else 37 | 38 | namespace Catch { 39 | void writeToDebugConsole( std::string const& text ) { 40 | // !TBD: Need a version for Mac/ XCode and other IDEs 41 | Catch::cout() << text; 42 | } 43 | } 44 | 45 | #endif // Platform 46 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_debug_console.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_DEBUG_CONSOLE_HPP_INCLUDED 9 | #define CATCH_DEBUG_CONSOLE_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | void writeToDebugConsole( std::string const& text ); 15 | } 16 | 17 | #endif // CATCH_DEBUG_CONSOLE_HPP_INCLUDED 18 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_decomposer.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | 13 | void ITransientExpression::streamReconstructedExpression( 14 | std::ostream& os ) const { 15 | // We can't make this function pure virtual to keep ITransientExpression 16 | // constexpr, so we write error message instead 17 | os << "Some class derived from ITransientExpression without overriding streamReconstructedExpression"; 18 | } 19 | 20 | void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) { 21 | if( lhs.size() + rhs.size() < 40 && 22 | lhs.find('\n') == std::string::npos && 23 | rhs.find('\n') == std::string::npos ) 24 | os << lhs << ' ' << op << ' ' << rhs; 25 | else 26 | os << lhs << '\n' << op << '\n' << rhs; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_enforce.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | 14 | namespace Catch { 15 | #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER) 16 | [[noreturn]] 17 | void throw_exception(std::exception const& e) { 18 | Catch::cerr() << "Catch will terminate because it needed to throw an exception.\n" 19 | << "The message was: " << e.what() << '\n'; 20 | std::terminate(); 21 | } 22 | #endif 23 | 24 | [[noreturn]] 25 | void throw_logic_error(std::string const& msg) { 26 | throw_exception(std::logic_error(msg)); 27 | } 28 | 29 | [[noreturn]] 30 | void throw_domain_error(std::string const& msg) { 31 | throw_exception(std::domain_error(msg)); 32 | } 33 | 34 | [[noreturn]] 35 | void throw_runtime_error(std::string const& msg) { 36 | throw_exception(std::runtime_error(msg)); 37 | } 38 | 39 | 40 | 41 | } // namespace Catch; 42 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_enum_values_registry.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED 9 | #define CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace Catch { 18 | 19 | namespace Detail { 20 | 21 | Catch::Detail::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ); 22 | 23 | class EnumValuesRegistry : public IMutableEnumValuesRegistry { 24 | 25 | std::vector> m_enumInfos; 26 | 27 | EnumInfo const& registerEnum( StringRef enumName, StringRef allValueNames, std::vector const& values) override; 28 | }; 29 | 30 | std::vector parseEnums( StringRef enums ); 31 | 32 | } // Detail 33 | 34 | } // Catch 35 | 36 | #endif // CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED 37 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_errno_guard.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace Catch { 14 | ErrnoGuard::ErrnoGuard():m_oldErrno(errno){} 15 | ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; } 16 | } 17 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_errno_guard.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_ERRNO_GUARD_HPP_INCLUDED 9 | #define CATCH_ERRNO_GUARD_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | 13 | //! Simple RAII class that stores the value of `errno` 14 | //! at construction and restores it at destruction. 15 | class ErrnoGuard { 16 | public: 17 | // Keep these outlined to avoid dragging in macros from 18 | 19 | ErrnoGuard(); 20 | ~ErrnoGuard(); 21 | private: 22 | int m_oldErrno; 23 | }; 24 | 25 | } 26 | 27 | #endif // CATCH_ERRNO_GUARD_HPP_INCLUDED 28 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_exception_translator_registry.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED 9 | #define CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace Catch { 17 | 18 | class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { 19 | public: 20 | ~ExceptionTranslatorRegistry() override; 21 | void registerTranslator( Detail::unique_ptr&& translator ); 22 | std::string translateActiveException() const override; 23 | 24 | private: 25 | ExceptionTranslators m_translators; 26 | }; 27 | } 28 | 29 | #endif // CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_floating_point_helpers.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace Catch { 14 | namespace Detail { 15 | 16 | uint32_t convertToBits(float f) { 17 | static_assert(sizeof(float) == sizeof(uint32_t), "Important ULP matcher assumption violated"); 18 | uint32_t i; 19 | std::memcpy(&i, &f, sizeof(f)); 20 | return i; 21 | } 22 | 23 | uint64_t convertToBits(double d) { 24 | static_assert(sizeof(double) == sizeof(uint64_t), "Important ULP matcher assumption violated"); 25 | uint64_t i; 26 | std::memcpy(&i, &d, sizeof(d)); 27 | return i; 28 | } 29 | 30 | #if defined( __GNUC__ ) || defined( __clang__ ) 31 | # pragma GCC diagnostic push 32 | # pragma GCC diagnostic ignored "-Wfloat-equal" 33 | #endif 34 | bool directCompare( float lhs, float rhs ) { return lhs == rhs; } 35 | bool directCompare( double lhs, double rhs ) { return lhs == rhs; } 36 | #if defined( __GNUC__ ) || defined( __clang__ ) 37 | # pragma GCC diagnostic pop 38 | #endif 39 | 40 | 41 | } // end namespace Detail 42 | } // end namespace Catch 43 | 44 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_getenv.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace Catch { 17 | namespace Detail { 18 | 19 | #if !defined (CATCH_CONFIG_GETENV) 20 | char const* getEnv( char const* ) { return nullptr; } 21 | #else 22 | 23 | char const* getEnv( char const* varName ) { 24 | # if defined( _MSC_VER ) 25 | # pragma warning( push ) 26 | # pragma warning( disable : 4996 ) // use getenv_s instead of getenv 27 | # endif 28 | 29 | return std::getenv( varName ); 30 | 31 | # if defined( _MSC_VER ) 32 | # pragma warning( pop ) 33 | # endif 34 | } 35 | #endif 36 | } // namespace Detail 37 | } // namespace Catch 38 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_getenv.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_GETENV_HPP_INCLUDED 9 | #define CATCH_GETENV_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | namespace Detail { 13 | 14 | //! Wrapper over `std::getenv` that compiles on UWP (and always returns nullptr there) 15 | char const* getEnv(char const* varName); 16 | 17 | } 18 | } 19 | 20 | #endif // CATCH_GETENV_HPP_INCLUDED 21 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_lazy_expr.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | namespace Catch { 13 | 14 | auto operator << (std::ostream& os, LazyExpression const& lazyExpr) -> std::ostream& { 15 | if (lazyExpr.m_isNegated) 16 | os << '!'; 17 | 18 | if (lazyExpr) { 19 | if (lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression()) 20 | os << '(' << *lazyExpr.m_transientExpression << ')'; 21 | else 22 | os << *lazyExpr.m_transientExpression; 23 | } else { 24 | os << "{** error - unchecked empty expression requested **}"; 25 | } 26 | return os; 27 | } 28 | 29 | } // namespace Catch 30 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_lazy_expr.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_LAZY_EXPR_HPP_INCLUDED 9 | #define CATCH_LAZY_EXPR_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | class ITransientExpression; 16 | 17 | class LazyExpression { 18 | friend class AssertionHandler; 19 | friend struct AssertionStats; 20 | friend class RunContext; 21 | 22 | ITransientExpression const* m_transientExpression = nullptr; 23 | bool m_isNegated; 24 | public: 25 | constexpr LazyExpression( bool isNegated ): 26 | m_isNegated(isNegated) 27 | {} 28 | constexpr LazyExpression(LazyExpression const& other) = default; 29 | LazyExpression& operator = ( LazyExpression const& ) = delete; 30 | 31 | constexpr explicit operator bool() const { 32 | return m_transientExpression != nullptr; 33 | } 34 | 35 | friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&; 36 | }; 37 | 38 | } // namespace Catch 39 | 40 | #endif // CATCH_LAZY_EXPR_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_leak_detector.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef CATCH_CONFIG_WINDOWS_CRTDBG 14 | #include 15 | 16 | namespace Catch { 17 | 18 | LeakDetector::LeakDetector() { 19 | int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); 20 | flag |= _CRTDBG_LEAK_CHECK_DF; 21 | flag |= _CRTDBG_ALLOC_MEM_DF; 22 | _CrtSetDbgFlag(flag); 23 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 24 | _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); 25 | // Change this to leaking allocation's number to break there 26 | _CrtSetBreakAlloc(-1); 27 | } 28 | } 29 | 30 | #else // ^^ Windows crt debug heap enabled // Windows crt debug heap disabled vv 31 | 32 | Catch::LeakDetector::LeakDetector() = default; 33 | 34 | #endif // CATCH_CONFIG_WINDOWS_CRTDBG 35 | 36 | Catch::LeakDetector::~LeakDetector() { 37 | Catch::cleanUp(); 38 | } 39 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_leak_detector.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_LEAK_DETECTOR_HPP_INCLUDED 9 | #define CATCH_LEAK_DETECTOR_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | 13 | struct LeakDetector { 14 | LeakDetector(); 15 | ~LeakDetector(); 16 | }; 17 | 18 | } 19 | #endif // CATCH_LEAK_DETECTOR_HPP_INCLUDED 20 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_list.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_LIST_HPP_INCLUDED 9 | #define CATCH_LIST_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | 17 | namespace Catch { 18 | 19 | class IEventListener; 20 | class Config; 21 | 22 | 23 | struct ReporterDescription { 24 | std::string name, description; 25 | }; 26 | struct ListenerDescription { 27 | StringRef name; 28 | std::string description; 29 | }; 30 | 31 | struct TagInfo { 32 | void add(StringRef spelling); 33 | std::string all() const; 34 | 35 | std::set spellings; 36 | std::size_t count = 0; 37 | }; 38 | 39 | bool list( IEventListener& reporter, Config const& config ); 40 | 41 | } // end namespace Catch 42 | 43 | #endif // CATCH_LIST_HPP_INCLUDED 44 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_logical_traits.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_LOGICAL_TRAITS_HPP_INCLUDED 9 | #define CATCH_LOGICAL_TRAITS_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | namespace Detail { 15 | 16 | #if defined( __cpp_lib_logical_traits ) && __cpp_lib_logical_traits >= 201510 17 | 18 | using std::conjunction; 19 | using std::disjunction; 20 | using std::negation; 21 | 22 | #else 23 | 24 | template struct conjunction : std::true_type {}; 25 | template struct conjunction : B1 {}; 26 | template 27 | struct conjunction 28 | : std::conditional_t, B1> {}; 29 | 30 | template struct disjunction : std::false_type {}; 31 | template struct disjunction : B1 {}; 32 | template 33 | struct disjunction 34 | : std::conditional_t> {}; 35 | 36 | template 37 | struct negation : std::integral_constant {}; 38 | 39 | #endif 40 | 41 | } // namespace Detail 42 | } // namespace Catch 43 | 44 | #endif // CATCH_LOGICAL_TRAITS_HPP_INCLUDED 45 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_main.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION 16 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS 17 | static LeakDetector leakDetector; 18 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION 19 | } 20 | 21 | // Allow users of amalgamated .cpp file to remove our main and provide their own. 22 | #if !defined(CATCH_AMALGAMATED_CUSTOM_MAIN) 23 | 24 | #if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN) 25 | // Standard C/C++ Win32 Unicode wmain entry point 26 | extern "C" int __cdecl wmain (int argc, wchar_t * argv[], wchar_t * []) { 27 | #else 28 | // Standard C/C++ main entry point 29 | int main (int argc, char * argv[]) { 30 | #endif 31 | 32 | // We want to force the linker not to discard the global variable 33 | // and its constructor, as it (optionally) registers leak detector 34 | (void)&Catch::leakDetector; 35 | 36 | return Catch::Session().run( argc, argv ); 37 | } 38 | 39 | #endif // !defined(CATCH_AMALGAMATED_CUSTOM_MAIN 40 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_message_info.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | namespace Catch { 12 | 13 | MessageInfo::MessageInfo( StringRef _macroName, 14 | SourceLineInfo const& _lineInfo, 15 | ResultWas::OfType _type ) 16 | : macroName( _macroName ), 17 | lineInfo( _lineInfo ), 18 | type( _type ), 19 | sequence( ++globalCount ) 20 | {} 21 | 22 | // This may need protecting if threading support is added 23 | unsigned int MessageInfo::globalCount = 0; 24 | 25 | } // end namespace Catch 26 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_message_info.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_MESSAGE_INFO_HPP_INCLUDED 9 | #define CATCH_MESSAGE_INFO_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace Catch { 18 | 19 | struct MessageInfo { 20 | MessageInfo( StringRef _macroName, 21 | SourceLineInfo const& _lineInfo, 22 | ResultWas::OfType _type ); 23 | 24 | StringRef macroName; 25 | std::string message; 26 | SourceLineInfo lineInfo; 27 | ResultWas::OfType type; 28 | unsigned int sequence; 29 | 30 | bool operator == (MessageInfo const& other) const { 31 | return sequence == other.sequence; 32 | } 33 | bool operator < (MessageInfo const& other) const { 34 | return sequence < other.sequence; 35 | } 36 | private: 37 | static unsigned int globalCount; 38 | }; 39 | 40 | } // end namespace Catch 41 | 42 | #endif // CATCH_MESSAGE_INFO_HPP_INCLUDED 43 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_move_and_forward.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_MOVE_AND_FORWARD_HPP_INCLUDED 9 | #define CATCH_MOVE_AND_FORWARD_HPP_INCLUDED 10 | 11 | #include 12 | 13 | //! Replacement for std::move with better compile time performance 14 | #define CATCH_MOVE(...) static_cast&&>(__VA_ARGS__) 15 | 16 | //! Replacement for std::forward with better compile time performance 17 | #define CATCH_FORWARD(...) static_cast(__VA_ARGS__) 18 | 19 | #endif // CATCH_MOVE_AND_FORWARD_HPP_INCLUDED 20 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_noncopyable.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_NONCOPYABLE_HPP_INCLUDED 9 | #define CATCH_NONCOPYABLE_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | namespace Detail { 13 | 14 | //! Deriving classes become noncopyable and nonmovable 15 | class NonCopyable { 16 | NonCopyable( NonCopyable const& ) = delete; 17 | NonCopyable( NonCopyable&& ) = delete; 18 | NonCopyable& operator=( NonCopyable const& ) = delete; 19 | NonCopyable& operator=( NonCopyable&& ) = delete; 20 | 21 | protected: 22 | NonCopyable() noexcept = default; 23 | }; 24 | 25 | } // namespace Detail 26 | } // namespace Catch 27 | 28 | #endif // CATCH_NONCOPYABLE_HPP_INCLUDED 29 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_parse_numbers.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_PARSE_NUMBERS_HPP_INCLUDED 9 | #define CATCH_PARSE_NUMBERS_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace Catch { 16 | 17 | /** 18 | * Parses unsigned int from the input, using provided base 19 | * 20 | * Effectively a wrapper around std::stoul but with better error checking 21 | * e.g. "-1" is rejected, instead of being parsed as UINT_MAX. 22 | */ 23 | Optional parseUInt(std::string const& input, int base = 10); 24 | } 25 | 26 | #endif // CATCH_PARSE_NUMBERS_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_platform.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_PLATFORM_HPP_INCLUDED 9 | #define CATCH_PLATFORM_HPP_INCLUDED 10 | 11 | // See e.g.: 12 | // https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html 13 | #ifdef __APPLE__ 14 | # ifndef __has_extension 15 | # define __has_extension(x) 0 16 | # endif 17 | # include 18 | # if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \ 19 | (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1) 20 | # define CATCH_PLATFORM_MAC 21 | # elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1) 22 | # define CATCH_PLATFORM_IPHONE 23 | # endif 24 | 25 | #elif defined(linux) || defined(__linux) || defined(__linux__) 26 | # define CATCH_PLATFORM_LINUX 27 | 28 | #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) 29 | # define CATCH_PLATFORM_WINDOWS 30 | 31 | # if defined( WINAPI_FAMILY ) && ( WINAPI_FAMILY == WINAPI_FAMILY_APP ) 32 | # define CATCH_PLATFORM_WINDOWS_UWP 33 | # endif 34 | 35 | #elif defined(__ORBIS__) || defined(__PROSPERO__) 36 | # define CATCH_PLATFORM_PLAYSTATION 37 | 38 | #endif 39 | 40 | #endif // CATCH_PLATFORM_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_polyfills.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace Catch { 16 | 17 | #if !defined(CATCH_CONFIG_POLYFILL_ISNAN) 18 | bool isnan(float f) { 19 | return std::isnan(f); 20 | } 21 | bool isnan(double d) { 22 | return std::isnan(d); 23 | } 24 | #else 25 | // For now we only use this for embarcadero 26 | bool isnan(float f) { 27 | return std::_isnan(f); 28 | } 29 | bool isnan(double d) { 30 | return std::_isnan(d); 31 | } 32 | #endif 33 | 34 | #if !defined( CATCH_CONFIG_GLOBAL_NEXTAFTER ) 35 | float nextafter( float x, float y ) { return std::nextafter( x, y ); } 36 | double nextafter( double x, double y ) { return std::nextafter( x, y ); } 37 | #else 38 | float nextafter( float x, float y ) { return ::nextafterf( x, y ); } 39 | double nextafter( double x, double y ) { return ::nextafter( x, y ); } 40 | #endif 41 | 42 | } // end namespace Catch 43 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_polyfills.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_POLYFILLS_HPP_INCLUDED 9 | #define CATCH_POLYFILLS_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | 13 | bool isnan(float f); 14 | bool isnan(double d); 15 | 16 | float nextafter(float x, float y); 17 | double nextafter(double x, double y); 18 | 19 | } 20 | 21 | #endif // CATCH_POLYFILLS_HPP_INCLUDED 22 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_preprocessor_internal_stringify.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED 9 | #define CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) 14 | #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__##_catch_sr 15 | #else 16 | #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"_catch_sr 17 | #endif 18 | 19 | #endif // CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED 20 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_preprocessor_remove_parens.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED 9 | #define CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED 10 | 11 | #define INTERNAL_CATCH_EXPAND1( param ) INTERNAL_CATCH_EXPAND2( param ) 12 | #define INTERNAL_CATCH_EXPAND2( ... ) INTERNAL_CATCH_NO##__VA_ARGS__ 13 | #define INTERNAL_CATCH_DEF( ... ) INTERNAL_CATCH_DEF __VA_ARGS__ 14 | #define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF 15 | 16 | #define INTERNAL_CATCH_REMOVE_PARENS( ... ) \ 17 | INTERNAL_CATCH_EXPAND1( INTERNAL_CATCH_DEF __VA_ARGS__ ) 18 | 19 | #endif // CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED 20 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_random_seed_generation.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace Catch { 18 | 19 | std::uint32_t generateRandomSeed( GenerateFrom from ) { 20 | switch ( from ) { 21 | case GenerateFrom::Time: 22 | return static_cast( std::time( nullptr ) ); 23 | 24 | case GenerateFrom::Default: 25 | case GenerateFrom::RandomDevice: { 26 | std::random_device rd; 27 | return Detail::fillBitsFrom( rd ); 28 | } 29 | 30 | default: 31 | CATCH_ERROR("Unknown generation method"); 32 | } 33 | } 34 | 35 | } // end namespace Catch 36 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_random_seed_generation.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED 9 | #define CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | enum class GenerateFrom { 16 | Time, 17 | RandomDevice, 18 | //! Currently equivalent to RandomDevice, but can change at any point 19 | Default 20 | }; 21 | 22 | std::uint32_t generateRandomSeed(GenerateFrom from); 23 | 24 | } // end namespace Catch 25 | 26 | #endif // CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED 27 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_sharding.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_SHARDING_HPP_INCLUDED 9 | #define CATCH_SHARDING_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | 16 | template 17 | Container createShard(Container const& container, std::size_t const shardCount, std::size_t const shardIndex) { 18 | assert(shardCount > shardIndex); 19 | 20 | if (shardCount == 1) { 21 | return container; 22 | } 23 | 24 | const std::size_t totalTestCount = container.size(); 25 | 26 | const std::size_t shardSize = totalTestCount / shardCount; 27 | const std::size_t leftoverTests = totalTestCount % shardCount; 28 | 29 | const std::size_t startIndex = shardIndex * shardSize + (std::min)(shardIndex, leftoverTests); 30 | const std::size_t endIndex = (shardIndex + 1) * shardSize + (std::min)(shardIndex + 1, leftoverTests); 31 | 32 | auto startIterator = std::next(container.begin(), static_cast(startIndex)); 33 | auto endIterator = std::next(container.begin(), static_cast(endIndex)); 34 | 35 | return Container(startIterator, endIterator); 36 | } 37 | 38 | } 39 | 40 | #endif // CATCH_SHARDING_HPP_INCLUDED 41 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_singletons.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | 10 | #include 11 | 12 | namespace Catch { 13 | 14 | namespace { 15 | static auto getSingletons() -> std::vector*& { 16 | static std::vector* g_singletons = nullptr; 17 | if( !g_singletons ) 18 | g_singletons = new std::vector(); 19 | return g_singletons; 20 | } 21 | } 22 | 23 | ISingleton::~ISingleton() = default; 24 | 25 | void addSingleton(ISingleton* singleton ) { 26 | getSingletons()->push_back( singleton ); 27 | } 28 | void cleanupSingletons() { 29 | auto& singletons = getSingletons(); 30 | for( auto singleton : *singletons ) 31 | delete singleton; 32 | delete singletons; 33 | singletons = nullptr; 34 | } 35 | 36 | } // namespace Catch 37 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_singletons.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_SINGLETONS_HPP_INCLUDED 9 | #define CATCH_SINGLETONS_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | 13 | struct ISingleton { 14 | virtual ~ISingleton(); // = default 15 | }; 16 | 17 | 18 | void addSingleton( ISingleton* singleton ); 19 | void cleanupSingletons(); 20 | 21 | 22 | template 23 | class Singleton : SingletonImplT, public ISingleton { 24 | 25 | static auto getInternal() -> Singleton* { 26 | static Singleton* s_instance = nullptr; 27 | if( !s_instance ) { 28 | s_instance = new Singleton; 29 | addSingleton( s_instance ); 30 | } 31 | return s_instance; 32 | } 33 | 34 | public: 35 | static auto get() -> InterfaceT const& { 36 | return *getInternal(); 37 | } 38 | static auto getMutable() -> MutableInterfaceT& { 39 | return *getInternal(); 40 | } 41 | }; 42 | 43 | } // namespace Catch 44 | 45 | #endif // CATCH_SINGLETONS_HPP_INCLUDED 46 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_source_line_info.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace Catch { 14 | 15 | bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept { 16 | return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); 17 | } 18 | bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept { 19 | // We can assume that the same file will usually have the same pointer. 20 | // Thus, if the pointers are the same, there is no point in calling the strcmp 21 | return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0)); 22 | } 23 | 24 | std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { 25 | #ifndef __GNUG__ 26 | os << info.file << '(' << info.line << ')'; 27 | #else 28 | os << info.file << ':' << info.line; 29 | #endif 30 | return os; 31 | } 32 | 33 | } // end namespace Catch 34 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_source_line_info.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_SOURCE_LINE_INFO_HPP_INCLUDED 9 | #define CATCH_SOURCE_LINE_INFO_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | 16 | struct SourceLineInfo { 17 | 18 | SourceLineInfo() = delete; 19 | constexpr SourceLineInfo( char const* _file, std::size_t _line ) noexcept: 20 | file( _file ), 21 | line( _line ) 22 | {} 23 | 24 | bool operator == ( SourceLineInfo const& other ) const noexcept; 25 | bool operator < ( SourceLineInfo const& other ) const noexcept; 26 | 27 | char const* file; 28 | std::size_t line; 29 | 30 | friend std::ostream& operator << (std::ostream& os, SourceLineInfo const& info); 31 | }; 32 | } 33 | 34 | #define CATCH_INTERNAL_LINEINFO \ 35 | ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) 36 | 37 | #endif // CATCH_SOURCE_LINE_INFO_HPP_INCLUDED 38 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_startup_exception_registry.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Catch { 14 | #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) 15 | void StartupExceptionRegistry::add( std::exception_ptr const& exception ) noexcept { 16 | CATCH_TRY { 17 | m_exceptions.push_back(exception); 18 | } CATCH_CATCH_ALL { 19 | // If we run out of memory during start-up there's really not a lot more we can do about it 20 | std::terminate(); 21 | } 22 | } 23 | 24 | std::vector const& StartupExceptionRegistry::getExceptions() const noexcept { 25 | return m_exceptions; 26 | } 27 | #endif 28 | 29 | } // end namespace Catch 30 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_startup_exception_registry.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED 9 | #define CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED 10 | 11 | 12 | #include 13 | #include 14 | 15 | namespace Catch { 16 | 17 | class StartupExceptionRegistry { 18 | #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) 19 | public: 20 | void add(std::exception_ptr const& exception) noexcept; 21 | std::vector const& getExceptions() const noexcept; 22 | private: 23 | std::vector m_exceptions; 24 | #endif 25 | }; 26 | 27 | } // end namespace Catch 28 | 29 | #endif // CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_stdstreams.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace Catch { 16 | 17 | // If you #define this you must implement these functions 18 | #if !defined( CATCH_CONFIG_NOSTDOUT ) 19 | std::ostream& cout() { return std::cout; } 20 | std::ostream& cerr() { return std::cerr; } 21 | std::ostream& clog() { return std::clog; } 22 | #endif 23 | 24 | } // namespace Catch 25 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_stdstreams.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #ifndef CATCH_STDSTREAMS_HPP_INCLUDED 10 | #define CATCH_STDSTREAMS_HPP_INCLUDED 11 | 12 | #include 13 | 14 | namespace Catch { 15 | 16 | std::ostream& cout(); 17 | std::ostream& cerr(); 18 | std::ostream& clog(); 19 | 20 | } // namespace Catch 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_stream_end_stop.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_STREAM_END_STOP_HPP_INCLUDED 9 | #define CATCH_STREAM_END_STOP_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | // Use this in variadic streaming macros to allow 16 | // << +StreamEndStop 17 | // as well as 18 | // << stuff +StreamEndStop 19 | struct StreamEndStop { 20 | constexpr StringRef operator+() const { return StringRef(); } 21 | 22 | template 23 | constexpr friend T const& operator+( T const& value, StreamEndStop ) { 24 | return value; 25 | } 26 | }; 27 | 28 | } // namespace Catch 29 | 30 | #endif // CATCH_STREAM_END_STOP_HPP_INCLUDED 31 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_tag_alias_registry.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED 9 | #define CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace Catch { 18 | struct SourceLineInfo; 19 | 20 | class TagAliasRegistry : public ITagAliasRegistry { 21 | public: 22 | ~TagAliasRegistry() override; 23 | TagAlias const* find( std::string const& alias ) const override; 24 | std::string expandAliases( std::string const& unexpandedTestSpec ) const override; 25 | void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); 26 | 27 | private: 28 | std::map m_registry; 29 | }; 30 | 31 | } // end namespace Catch 32 | 33 | #endif // CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED 34 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_test_case_info_hasher.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | namespace Catch { 13 | TestCaseInfoHasher::TestCaseInfoHasher( hash_t seed ): m_seed( seed ) {} 14 | 15 | uint32_t TestCaseInfoHasher::operator()( TestCaseInfo const& t ) const { 16 | // FNV-1a hash algorithm that is designed for uniqueness: 17 | const hash_t prime = 1099511628211u; 18 | hash_t hash = 14695981039346656037u; 19 | for ( const char c : t.name ) { 20 | hash ^= c; 21 | hash *= prime; 22 | } 23 | for ( const char c : t.className ) { 24 | hash ^= c; 25 | hash *= prime; 26 | } 27 | for ( const Tag& tag : t.tags ) { 28 | for ( const char c : tag.original ) { 29 | hash ^= c; 30 | hash *= prime; 31 | } 32 | } 33 | hash ^= m_seed; 34 | hash *= prime; 35 | const uint32_t low{ static_cast( hash ) }; 36 | const uint32_t high{ static_cast( hash >> 32 ) }; 37 | return low * high; 38 | } 39 | } // namespace Catch 40 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_test_case_info_hasher.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED 9 | #define CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | struct TestCaseInfo; 16 | 17 | class TestCaseInfoHasher { 18 | public: 19 | using hash_t = std::uint64_t; 20 | TestCaseInfoHasher( hash_t seed ); 21 | uint32_t operator()( TestCaseInfo const& t ) const; 22 | 23 | private: 24 | hash_t m_seed; 25 | }; 26 | 27 | } // namespace Catch 28 | 29 | #endif /* CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED */ 30 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_test_failure_exception.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Catch { 14 | 15 | void throw_test_failure_exception() { 16 | #if !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) 17 | throw TestFailureException{}; 18 | #else 19 | CATCH_ERROR( "Test failure requires aborting test!" ); 20 | #endif 21 | } 22 | 23 | void throw_test_skip_exception() { 24 | #if !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) 25 | throw Catch::TestSkipException(); 26 | #else 27 | CATCH_ERROR( "Explicitly skipping tests during runtime requires exceptions" ); 28 | #endif 29 | } 30 | 31 | } // namespace Catch 32 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_test_failure_exception.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED 9 | #define CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | 13 | //! Used to signal that an assertion macro failed 14 | struct TestFailureException{}; 15 | //! Used to signal that the remainder of a test should be skipped 16 | struct TestSkipException {}; 17 | 18 | /** 19 | * Outlines throwing of `TestFailureException` into a single TU 20 | * 21 | * Also handles `CATCH_CONFIG_DISABLE_EXCEPTIONS` for callers. 22 | */ 23 | [[noreturn]] void throw_test_failure_exception(); 24 | 25 | /** 26 | * Outlines throwing of `TestSkipException` into a single TU 27 | * 28 | * Also handles `CATCH_CONFIG_DISABLE_EXCEPTIONS` for callers. 29 | */ 30 | [[noreturn]] void throw_test_skip_exception(); 31 | 32 | } // namespace Catch 33 | 34 | #endif // CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED 35 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_test_run_info.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TEST_RUN_INFO_HPP_INCLUDED 9 | #define CATCH_TEST_RUN_INFO_HPP_INCLUDED 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | struct TestRunInfo { 16 | constexpr TestRunInfo(StringRef _name) : name(_name) {} 17 | StringRef name; 18 | }; 19 | 20 | } // end namespace Catch 21 | 22 | #endif // CATCH_TEST_RUN_INFO_HPP_INCLUDED 23 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_to_string.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_TO_STRING_HPP_INCLUDED 9 | #define CATCH_TO_STRING_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace Catch { 17 | template 18 | std::string to_string(T const& t) { 19 | #if defined(CATCH_CONFIG_CPP11_TO_STRING) 20 | return std::to_string(t); 21 | #else 22 | ReusableStringStream rss; 23 | rss << t; 24 | return rss.str(); 25 | #endif 26 | } 27 | } // end namespace Catch 28 | 29 | #endif // CATCH_TO_STRING_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_uncaught_exceptions.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace Catch { 16 | bool uncaught_exceptions() { 17 | #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) 18 | return false; 19 | #elif defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) 20 | return std::uncaught_exceptions() > 0; 21 | #else 22 | return std::uncaught_exception(); 23 | #endif 24 | } 25 | } // end namespace Catch 26 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_uncaught_exceptions.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED 9 | #define CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED 10 | 11 | namespace Catch { 12 | bool uncaught_exceptions(); 13 | } // end namespace Catch 14 | 15 | #endif // CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED 16 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_unique_name.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_UNIQUE_NAME_HPP_INCLUDED 9 | #define CATCH_UNIQUE_NAME_HPP_INCLUDED 10 | 11 | #include 12 | #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line 13 | #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) 14 | #ifdef CATCH_CONFIG_COUNTER 15 | # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) 16 | #else 17 | # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) 18 | #endif 19 | 20 | #endif // CATCH_UNIQUE_NAME_HPP_INCLUDED 21 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_void_type.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_VOID_TYPE_HPP_INCLUDED 9 | #define CATCH_VOID_TYPE_HPP_INCLUDED 10 | 11 | 12 | namespace Catch { 13 | namespace Detail { 14 | 15 | template 16 | struct make_void { using type = void; }; 17 | 18 | template 19 | using void_t = typename make_void::type; 20 | 21 | } // namespace Detail 22 | } // namespace Catch 23 | 24 | 25 | #endif // CATCH_VOID_TYPE_HPP_INCLUDED 26 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_wildcard_pattern.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_WILDCARD_PATTERN_HPP_INCLUDED 9 | #define CATCH_WILDCARD_PATTERN_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace Catch 16 | { 17 | class WildcardPattern { 18 | enum WildcardPosition { 19 | NoWildcard = 0, 20 | WildcardAtStart = 1, 21 | WildcardAtEnd = 2, 22 | WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd 23 | }; 24 | 25 | public: 26 | 27 | WildcardPattern( std::string const& pattern, CaseSensitive caseSensitivity ); 28 | bool matches( std::string const& str ) const; 29 | 30 | private: 31 | std::string normaliseString( std::string const& str ) const; 32 | CaseSensitive m_caseSensitivity; 33 | WildcardPosition m_wildcard = NoWildcard; 34 | std::string m_pattern; 35 | }; 36 | } 37 | 38 | #endif // CATCH_WILDCARD_PATTERN_HPP_INCLUDED 39 | -------------------------------------------------------------------------------- /src/catch2/internal/catch_windows_h_proxy.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_WINDOWS_H_PROXY_HPP_INCLUDED 9 | #define CATCH_WINDOWS_H_PROXY_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #if defined(CATCH_PLATFORM_WINDOWS) 14 | 15 | // We might end up with the define made globally through the compiler, 16 | // and we don't want to trigger warnings for this 17 | #if !defined(NOMINMAX) 18 | # define NOMINMAX 19 | #endif 20 | #if !defined(WIN32_LEAN_AND_MEAN) 21 | # define WIN32_LEAN_AND_MEAN 22 | #endif 23 | 24 | #include 25 | 26 | #endif // defined(CATCH_PLATFORM_WINDOWS) 27 | 28 | #endif // CATCH_WINDOWS_H_PROXY_HPP_INCLUDED 29 | -------------------------------------------------------------------------------- /src/catch2/matchers/catch_matchers.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | 10 | #include 11 | 12 | namespace Catch { 13 | namespace Matchers { 14 | 15 | std::string MatcherUntypedBase::toString() const { 16 | if (m_cachedToString.empty()) { 17 | m_cachedToString = describe(); 18 | } 19 | return m_cachedToString; 20 | } 21 | 22 | MatcherUntypedBase::~MatcherUntypedBase() = default; 23 | 24 | } // namespace Matchers 25 | } // namespace Catch 26 | -------------------------------------------------------------------------------- /src/catch2/matchers/catch_matchers_container_properties.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | namespace Catch { 13 | namespace Matchers { 14 | 15 | std::string IsEmptyMatcher::describe() const { 16 | return "is empty"; 17 | } 18 | 19 | std::string HasSizeMatcher::describe() const { 20 | ReusableStringStream sstr; 21 | sstr << "has size == " << m_target_size; 22 | return sstr.str(); 23 | } 24 | 25 | IsEmptyMatcher IsEmpty() { 26 | return {}; 27 | } 28 | 29 | HasSizeMatcher SizeIs(std::size_t sz) { 30 | return HasSizeMatcher{ sz }; 31 | } 32 | 33 | } // end namespace Matchers 34 | } // end namespace Catch 35 | -------------------------------------------------------------------------------- /src/catch2/matchers/catch_matchers_exception.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | 10 | namespace Catch { 11 | namespace Matchers { 12 | 13 | bool ExceptionMessageMatcher::match(std::exception const& ex) const { 14 | return ex.what() == m_message; 15 | } 16 | 17 | std::string ExceptionMessageMatcher::describe() const { 18 | return "exception message matches \"" + m_message + '"'; 19 | } 20 | 21 | ExceptionMessageMatcher Message(std::string const& message) { 22 | return ExceptionMessageMatcher(message); 23 | } 24 | 25 | } // namespace Matchers 26 | } // namespace Catch 27 | -------------------------------------------------------------------------------- /src/catch2/matchers/catch_matchers_predicate.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | std::string Catch::Matchers::Detail::finalizeDescription(const std::string& desc) { 12 | if (desc.empty()) { 13 | return "matches undescribed predicate"; 14 | } else { 15 | return "matches predicate: \"" + desc + '"'; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/catch2/matchers/catch_matchers_quantifiers.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | 10 | namespace Catch { 11 | namespace Matchers { 12 | std::string AllTrueMatcher::describe() const { return "contains only true"; } 13 | 14 | AllTrueMatcher AllTrue() { return AllTrueMatcher{}; } 15 | 16 | std::string NoneTrueMatcher::describe() const { return "contains no true"; } 17 | 18 | NoneTrueMatcher NoneTrue() { return NoneTrueMatcher{}; } 19 | 20 | std::string AnyTrueMatcher::describe() const { return "contains at least one true"; } 21 | 22 | AnyTrueMatcher AnyTrue() { return AnyTrueMatcher{}; } 23 | } // namespace Matchers 24 | } // namespace Catch 25 | -------------------------------------------------------------------------------- /src/catch2/matchers/internal/catch_matchers_impl.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | 16 | // This is the general overload that takes a any string matcher 17 | // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers 18 | // the Equals matcher (so the header does not mention matchers) 19 | void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher ) { 20 | std::string exceptionMessage = Catch::translateActiveException(); 21 | MatchExpr expr( CATCH_MOVE(exceptionMessage), matcher ); 22 | handler.handleExpr( expr ); 23 | } 24 | 25 | } // namespace Catch 26 | -------------------------------------------------------------------------------- /src/catch2/reporters/catch_reporter_automake.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace Catch { 14 | 15 | AutomakeReporter::~AutomakeReporter() = default; 16 | 17 | void AutomakeReporter::testCaseEnded(TestCaseStats const& _testCaseStats) { 18 | // Possible values to emit are PASS, XFAIL, SKIP, FAIL, XPASS and ERROR. 19 | m_stream << ":test-result: "; 20 | if ( _testCaseStats.totals.testCases.skipped > 0 ) { 21 | m_stream << "SKIP"; 22 | } else if (_testCaseStats.totals.assertions.allPassed()) { 23 | m_stream << "PASS"; 24 | } else if (_testCaseStats.totals.assertions.allOk()) { 25 | m_stream << "XFAIL"; 26 | } else { 27 | m_stream << "FAIL"; 28 | } 29 | m_stream << ' ' << _testCaseStats.testInfo->name << '\n'; 30 | StreamingReporterBase::testCaseEnded(_testCaseStats); 31 | } 32 | 33 | void AutomakeReporter::skipTest(TestCaseInfo const& testInfo) { 34 | m_stream << ":test-result: SKIP " << testInfo.name << '\n'; 35 | } 36 | 37 | } // end namespace Catch 38 | -------------------------------------------------------------------------------- /src/catch2/reporters/catch_reporter_automake.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED 9 | #define CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace Catch { 17 | 18 | class AutomakeReporter final : public StreamingReporterBase { 19 | public: 20 | // GCC5 compat: we cannot use inherited constructor, because it 21 | // doesn't implement backport of P0136 22 | AutomakeReporter(ReporterConfig&& _config): 23 | StreamingReporterBase(CATCH_MOVE(_config)) 24 | {} 25 | ~AutomakeReporter() override; 26 | 27 | static std::string getDescription() { 28 | using namespace std::string_literals; 29 | return "Reports test results in the format of Automake .trs files"s; 30 | } 31 | 32 | void testCaseEnded(TestCaseStats const& _testCaseStats) override; 33 | void skipTest(TestCaseInfo const& testInfo) override; 34 | }; 35 | 36 | } // end namespace Catch 37 | 38 | #endif // CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED 39 | -------------------------------------------------------------------------------- /src/catch2/reporters/catch_reporter_compact.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_REPORTER_COMPACT_HPP_INCLUDED 9 | #define CATCH_REPORTER_COMPACT_HPP_INCLUDED 10 | 11 | 12 | #include 13 | 14 | 15 | namespace Catch { 16 | 17 | class CompactReporter final : public StreamingReporterBase { 18 | public: 19 | using StreamingReporterBase::StreamingReporterBase; 20 | 21 | ~CompactReporter() override; 22 | 23 | static std::string getDescription(); 24 | 25 | void noMatchingTestCases( StringRef unmatchedSpec ) override; 26 | 27 | void testRunStarting( TestRunInfo const& _testInfo ) override; 28 | 29 | void assertionEnded(AssertionStats const& _assertionStats) override; 30 | 31 | void sectionEnded(SectionStats const& _sectionStats) override; 32 | 33 | void testRunEnded(TestRunStats const& _testRunStats) override; 34 | 35 | }; 36 | 37 | } // end namespace Catch 38 | 39 | #endif // CATCH_REPORTER_COMPACT_HPP_INCLUDED 40 | -------------------------------------------------------------------------------- /src/catch2/reporters/catch_reporter_registrars.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | namespace Detail { 16 | 17 | void registerReporterImpl( std::string const& name, 18 | IReporterFactoryPtr reporterPtr ) { 19 | CATCH_TRY { 20 | getMutableRegistryHub().registerReporter( 21 | name, CATCH_MOVE( reporterPtr ) ); 22 | } 23 | CATCH_CATCH_ALL { 24 | // Do not throw when constructing global objects, instead 25 | // register the exception to be processed later 26 | getMutableRegistryHub().registerStartupException(); 27 | } 28 | } 29 | 30 | void registerListenerImpl( Detail::unique_ptr listenerFactory ) { 31 | getMutableRegistryHub().registerListener( CATCH_MOVE(listenerFactory) ); 32 | } 33 | 34 | 35 | } // namespace Detail 36 | } // namespace Catch 37 | -------------------------------------------------------------------------------- /src/catch2/reporters/catch_reporter_streaming_base.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #include 9 | 10 | namespace Catch { 11 | 12 | StreamingReporterBase::~StreamingReporterBase() = default; 13 | 14 | void 15 | StreamingReporterBase::testRunStarting( TestRunInfo const& _testRunInfo ) { 16 | currentTestRunInfo = _testRunInfo; 17 | } 18 | 19 | void StreamingReporterBase::testRunEnded( TestRunStats const& ) { 20 | currentTestCaseInfo = nullptr; 21 | } 22 | 23 | } // end namespace Catch 24 | -------------------------------------------------------------------------------- /src/catch2/reporters/catch_reporter_tap.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | #ifndef CATCH_REPORTER_TAP_HPP_INCLUDED 9 | #define CATCH_REPORTER_TAP_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | 16 | class TAPReporter final : public StreamingReporterBase { 17 | public: 18 | TAPReporter( ReporterConfig&& config ): 19 | StreamingReporterBase( CATCH_MOVE(config) ) { 20 | m_preferences.shouldReportAllAssertions = true; 21 | } 22 | 23 | static std::string getDescription() { 24 | using namespace std::string_literals; 25 | return "Reports test results in TAP format, suitable for test harnesses"s; 26 | } 27 | 28 | void testRunStarting( TestRunInfo const& testInfo ) override; 29 | 30 | void noMatchingTestCases( StringRef unmatchedSpec ) override; 31 | 32 | void assertionEnded(AssertionStats const& _assertionStats) override; 33 | 34 | void testRunEnded(TestRunStats const& _testRunStats) override; 35 | 36 | private: 37 | std::size_t counter = 0; 38 | }; 39 | 40 | } // end namespace Catch 41 | 42 | #endif // CATCH_REPORTER_TAP_HPP_INCLUDED 43 | -------------------------------------------------------------------------------- /tests/ExtraTests/ToDo.txt: -------------------------------------------------------------------------------- 1 | Configuration options that are left default and thus are not properly tested 2 | yet: 3 | 4 | CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases 5 | CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows 6 | CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed 7 | CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals 8 | CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap 9 | CATCH_CONFIG_DEFAULT_REPORTER 10 | CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS 11 | -------------------------------------------------------------------------------- /tests/ExtraTests/X03-DisabledExceptions-DefaultHandler.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | TEST_CASE("Tests that run") { 15 | // All of these should be run and be reported 16 | CHECK(1 == 2); 17 | CHECK(1 == 1); 18 | CHECK(1 != 3); 19 | CHECK(1 == 4); 20 | } 21 | 22 | 23 | 24 | TEST_CASE("Tests that abort") { 25 | // Avoid abort and other exceptional exits -- there is no way 26 | // to tell CMake that abort is the desired outcome of a test. 27 | std::set_terminate([](){exit(1);}); 28 | REQUIRE(1 == 1); 29 | REQUIRE(1 != 2); 30 | REQUIRE(1 == 3); 31 | // We should not get here, because the test above aborts 32 | REQUIRE(1 != 4); 33 | } 34 | 35 | TEST_CASE( "Misc. macros to check that they compile without exceptions" ) { 36 | BENCHMARK( "simple benchmark" ) { return 1 * 2 + 3; }; 37 | REQUIRE_THAT( 1, 38 | Catch::Matchers::Predicate( []( int i ) { return i == 1; } ) ); 39 | } 40 | -------------------------------------------------------------------------------- /tests/ExtraTests/X04-DisabledExceptions-CustomHandler.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace Catch { 14 | [[noreturn]] 15 | void throw_exception(std::exception const& e) { 16 | std::cerr << "====== CUSTOM HANDLER ====== run terminates because an exception was thrown.\n" 17 | << "The message was: " << e.what() << '\n'; 18 | // Avoid abort and other exceptional exits -- there is no way 19 | // to tell CMake that abort is the desired outcome of a test. 20 | exit(1); 21 | } 22 | } 23 | 24 | TEST_CASE("Tests that run") { 25 | // All of these should be run and be reported 26 | CHECK(1 == 2); 27 | CHECK(1 == 1); 28 | CHECK(1 != 3); 29 | CHECK(1 == 4); 30 | } 31 | 32 | 33 | 34 | TEST_CASE("Tests that abort") { 35 | REQUIRE(1 == 1); 36 | REQUIRE(1 != 2); 37 | REQUIRE(1 == 3); 38 | // We should not get here, because the test above aborts 39 | REQUIRE(1 != 4); 40 | } 41 | -------------------------------------------------------------------------------- /tests/ExtraTests/X05-DeferredStaticChecks.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Checks that when `STATIC_CHECK` is deferred to runtime and fails, it 11 | * does not abort the test case. 12 | */ 13 | 14 | #include 15 | 16 | TEST_CASE("Deferred static checks") { 17 | STATIC_CHECK(1 == 2); 18 | STATIC_CHECK_FALSE(1 != 2); 19 | // This last assertion must be executed too 20 | CHECK(1 == 2); 21 | } 22 | -------------------------------------------------------------------------------- /tests/ExtraTests/X10-FallbackStringifier.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Test that the user can define custom fallbackStringifier 11 | * 12 | * This is done by defining a custom fallback stringifier that prints 13 | * out a specific string, and then asserting (to cause stringification) 14 | * over a type without stringification support. 15 | */ 16 | 17 | #include 18 | 19 | // A catch-all stringifier 20 | template 21 | std::string fallbackStringifier(T const&) { 22 | return "{ !!! }"; 23 | } 24 | 25 | #include 26 | 27 | struct foo { 28 | explicit operator bool() const { 29 | return true; 30 | } 31 | }; 32 | 33 | TEST_CASE("aa") { 34 | REQUIRE(foo{}); 35 | } 36 | -------------------------------------------------------------------------------- /tests/ExtraTests/X11-DisableStringification.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Test that stringification of original expression can be disabled. 11 | * 12 | * This is a workaround for VS 2017, 2019 issue with Raw String literals 13 | * and preprocessor token pasting. 14 | */ 15 | 16 | 17 | #include 18 | 19 | namespace { 20 | struct Hidden {}; 21 | 22 | bool operator==(Hidden, Hidden) { return true; } 23 | } 24 | 25 | TEST_CASE("DisableStringification") { 26 | REQUIRE( Hidden{} == Hidden{} ); 27 | } 28 | -------------------------------------------------------------------------------- /tests/ExtraTests/X12-CustomDebugBreakMacro.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Test that user-defined `CATCH_BREAK_INTO_DEBUGGER` is respected and used. 11 | */ 12 | 13 | #include 14 | 15 | void custom_debug_break() { 16 | std::cerr << "Pretty please, break into debugger\n"; 17 | } 18 | 19 | #define CATCH_BREAK_INTO_DEBUGGER() custom_debug_break() 20 | 21 | #define CATCH_CONFIG_MAIN 22 | #include 23 | 24 | TEST_CASE("Failing test that breaks into debugger", "[macros]") { 25 | REQUIRE(1 == 2); 26 | } 27 | -------------------------------------------------------------------------------- /tests/ExtraTests/X23-CasingInReporterNames.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Test that reporter registration is case-preserving, selection is 11 | * case-insensitive. 12 | * 13 | * This is done by registering a custom reporter that prints out a marker 14 | * string upon construction and then invoking the binary with different 15 | * casings of the name. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | class TestReporter : public Catch::StreamingReporterBase { 25 | public: 26 | TestReporter(Catch::ReporterConfig&& _config): 27 | StreamingReporterBase(std::move(_config)) { 28 | std::cout << "TestReporter constructed\n"; 29 | } 30 | 31 | static std::string getDescription() { 32 | return "Reporter for testing casing handling in reporter registration/selection"; 33 | } 34 | 35 | ~TestReporter() override; 36 | }; 37 | 38 | TestReporter::~TestReporter() = default; 39 | 40 | CATCH_REGISTER_REPORTER("testReporterCASED", TestReporter) 41 | 42 | -------------------------------------------------------------------------------- /tests/ExtraTests/X24-ListenerStdoutCaptureInMultireporter.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Registers custom listener that does not ask for captured stdout/err 11 | * 12 | * Running the binary with this listener, and asking for multiple _capturing_ 13 | * reporters (one would be sufficient, but that would also mean depending on 14 | * implementation details inside Catch2's handling of listeners), we check that 15 | * nothing is written to stdout, because listeners should not be considered in 16 | * whether the stdout should be passed-through or not. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | namespace { 26 | class NonCapturingListener : public Catch::EventListenerBase { 27 | public: 28 | NonCapturingListener( Catch::IConfig const* config ): 29 | EventListenerBase( config ) { 30 | m_preferences.shouldRedirectStdOut = false; 31 | std::cerr << "X24 - NonCapturingListener initialized.\n"; 32 | } 33 | }; 34 | } 35 | 36 | CATCH_REGISTER_LISTENER( NonCapturingListener ) 37 | 38 | TEST_CASE( "Writes to stdout" ) { 39 | std::cout << "X24 - FooBarBaz\n"; 40 | } 41 | -------------------------------------------------------------------------------- /tests/ExtraTests/X30-BazelReporter.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Test the Bazel report functionality with a simple set 11 | * of dummy test cases. 12 | */ 13 | 14 | #include 15 | 16 | TEST_CASE( "Passing test case" ) { REQUIRE( 1 == 1 ); } 17 | TEST_CASE( "Failing test case" ) { REQUIRE( 2 == 1 ); } 18 | -------------------------------------------------------------------------------- /tests/ExtraTests/X31-DuplicatedTestCases.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Checks that test cases with identical name and tags are reported as error 11 | */ 12 | 13 | #include 14 | 15 | TEST_CASE("A test case with duplicated name and tags", "[tag1][tag2]") {} 16 | TEST_CASE("A test case with duplicated name and tags", "[tag1][tag2]") {} 17 | -------------------------------------------------------------------------------- /tests/ExtraTests/X32-DuplicatedTestCasesDifferentTags.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Checks that test cases with identical name but different tags are 11 | * not reported as an error. 12 | */ 13 | 14 | #include 15 | 16 | TEST_CASE("A test case with duplicated name but different tags", "[tag1]") {} 17 | TEST_CASE("A test case with duplicated name but different tags", "[tag2]") {} 18 | -------------------------------------------------------------------------------- /tests/ExtraTests/X33-DuplicatedTestCaseMethods.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Checks that test case methods with identical class, name and tags are 11 | * reported as error. 12 | */ 13 | 14 | #include 15 | 16 | class TestCaseFixture { 17 | public: 18 | int m_a; 19 | }; 20 | 21 | TEST_CASE_METHOD(TestCaseFixture, "A test case with duplicated name and tags", "[tag1]") {} 22 | TEST_CASE_METHOD(TestCaseFixture, "A test case with duplicated name and tags", "[tag1]") {} 23 | -------------------------------------------------------------------------------- /tests/ExtraTests/X34-DuplicatedTestCaseMethodsDifferentFixtures.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Checks that test case methods with different class, but same name and 11 | * tags name and tags are not reported as error. 12 | */ 13 | 14 | #include 15 | 16 | class TestCaseFixture1 { 17 | public: 18 | int m_a; 19 | }; 20 | 21 | class TestCaseFixture2 { 22 | public: 23 | int m_a; 24 | }; 25 | 26 | TEST_CASE_METHOD(TestCaseFixture1, "A test case with duplicated name and tags", "[tag1]") {} 27 | TEST_CASE_METHOD(TestCaseFixture2, "A test case with duplicated name and tags", "[tag1]") {} 28 | -------------------------------------------------------------------------------- /tests/ExtraTests/X35-DuplicatedReporterNames.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Checks that reporter registration errors are caught and handled as 11 | * startup errors, by causing a registration error by registering multiple 12 | * reporters with the same name. 13 | */ 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | namespace { 21 | //! Trivial custom reporter for registration 22 | class TestReporter : public Catch::StreamingReporterBase { 23 | public: 24 | using StreamingReporterBase::StreamingReporterBase; 25 | 26 | static std::string getDescription() { return "X35 test reporter"; } 27 | }; 28 | } 29 | 30 | CATCH_REGISTER_REPORTER( "test-reporter", TestReporter ) 31 | CATCH_REGISTER_REPORTER( "test-reporter", TestReporter ) 32 | -------------------------------------------------------------------------------- /tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Checks that signals/SEH within open section does not hard crash JUnit 11 | * (or similar reporter) while we are trying to report fatal error. 12 | */ 13 | 14 | #include 15 | 16 | #include 17 | 18 | // On Windows we need to send SEH and not signal to test the 19 | // RunContext::handleFatalErrorCondition code path 20 | #if defined( _MSC_VER ) 21 | # include 22 | #endif 23 | 24 | TEST_CASE( "raises signal" ) { 25 | SECTION( "section" ) { 26 | #if defined( _MSC_VER ) 27 | RaiseException( 0xC0000005, 0, 0, NULL ); 28 | #else 29 | std::raise( SIGILL ); 30 | #endif 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/ExtraTests/X90-WindowsHeaderInclusion.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Test that the Catch2 header compiles even after including windows.h 11 | * without defining NOMINMAX first. 12 | * 13 | * As an FYI, if you do that, you are wrong. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | TEST_CASE("Catch2 did survive compilation with windows.h", "[compile-test]") { 20 | SUCCEED(); 21 | } 22 | -------------------------------------------------------------------------------- /tests/ExtraTests/X91-AmalgamatedCatch.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * This file serves as a simple compilation test against the amalgamated 11 | * version of Catch2. 12 | */ 13 | 14 | #include "catch_amalgamated.hpp" 15 | 16 | TEST_CASE("Just a dummy test") { 17 | auto i = GENERATE(1, 2, 3); 18 | SECTION("a") { 19 | REQUIRE(i != 4); 20 | } 21 | SECTION("b") { 22 | CHECK(i != 5); 23 | } 24 | REQUIRE_THAT(1, 25 | Catch::Matchers::Predicate([](int i) { 26 | return i % 2 == 1; 27 | })); 28 | } 29 | 30 | TEMPLATE_TEST_CASE("Trivial template test case", "", char, short) { 31 | STATIC_REQUIRE(sizeof(TestType) <= sizeof(int)); 32 | } 33 | 34 | TEST_CASE("Benchmark test", "[!benchmark]") { 35 | BENCHMARK("Allocation benchmark") { 36 | return std::vector(10); 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /tests/ExtraTests/X92-NoTests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | /**\file 10 | * Links into executable with no tests which should fail when run 11 | */ 12 | -------------------------------------------------------------------------------- /tests/ExtraTests/X93-AllSkipped.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | TEST_CASE( "this test case is being skipped" ) { SKIP(); } 12 | 13 | TEST_CASE( "all sections in this test case are being skipped" ) { 14 | SECTION( "A" ) { SKIP(); } 15 | SECTION( "B" ) { SKIP(); } 16 | } 17 | -------------------------------------------------------------------------------- /tests/SelfTest/Baselines/default.sw.multi.approved.txt: -------------------------------------------------------------------------------- 1 | This would not be caught previously 2 | Nor would this 3 | A string sent directly to stdout 4 | A string sent directly to stderr 5 | A string sent to stderr via clog 6 | Message from section one 7 | Message from section two 8 | loose text artifact 9 | a! 10 | b1! 11 | ! 12 | -------------------------------------------------------------------------------- /tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | TEST_CASE( "Incomplete AssertionHandler", "[assertion-handler][!shouldfail]" ) { 12 | Catch::AssertionHandler catchAssertionHandler( 13 | "REQUIRE"_catch_sr, 14 | CATCH_INTERNAL_LINEINFO, 15 | "Dummy", 16 | Catch::ResultDisposition::Normal ); 17 | } 18 | -------------------------------------------------------------------------------- /tests/SelfTest/IntrospectiveTests/Parse.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | 13 | TEST_CASE("Parse uints", "[parse-numbers]") { 14 | using Catch::parseUInt; 15 | using Catch::Optional; 16 | 17 | SECTION("proper inputs") { 18 | REQUIRE( parseUInt( "0" ) == Optional{ 0 } ); 19 | REQUIRE( parseUInt( "100" ) == Optional{ 100 } ); 20 | REQUIRE( parseUInt( "4294967295" ) == 21 | Optional{ 4294967295 } ); 22 | REQUIRE( parseUInt( "0xFF", 16 ) == Optional{ 255 } ); 23 | } 24 | SECTION( "Bad inputs" ) { 25 | // empty 26 | REQUIRE_FALSE( parseUInt( "" ) ); 27 | // random noise 28 | REQUIRE_FALSE( parseUInt( "!!KJHF*#" ) ); 29 | // negative 30 | REQUIRE_FALSE( parseUInt( "-1" ) ); 31 | // too large 32 | REQUIRE_FALSE( parseUInt( "4294967296" ) ); 33 | REQUIRE_FALSE( parseUInt( "42949672964294967296429496729642949672964294967296" ) ); 34 | REQUIRE_FALSE( parseUInt( "2 4" ) ); 35 | // hex with base 10 36 | REQUIRE_FALSE( parseUInt( "0xFF", 10 ) ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/SelfTest/IntrospectiveTests/Sharding.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | TEST_CASE("Sharding Function", "[approvals]") { 18 | std::vector testContainer = { 0, 1, 2, 3, 4, 5, 6 }; 19 | std::unordered_map> expectedShardSizes = { 20 | {1, {7}}, 21 | {2, {4, 3}}, 22 | {3, {3, 2, 2}}, 23 | {4, {2, 2, 2, 1}}, 24 | {5, {2, 2, 1, 1, 1}}, 25 | {6, {2, 1, 1, 1, 1, 1}}, 26 | {7, {1, 1, 1, 1, 1, 1, 1}}, 27 | }; 28 | 29 | auto shardCount = GENERATE(range(1, 7)); 30 | auto shardIndex = GENERATE_COPY(filter([=](int i) { return i < shardCount; }, range(0, 6))); 31 | 32 | std::vector result = Catch::createShard(testContainer, shardCount, shardIndex); 33 | 34 | auto& sizes = expectedShardSizes[shardCount]; 35 | REQUIRE(result.size() == sizes[shardIndex]); 36 | 37 | std::size_t startIndex = 0; 38 | for(int i = 0; i < shardIndex; i++) { 39 | startIndex += sizes[i]; 40 | } 41 | 42 | for(std::size_t i = 0; i < sizes[shardIndex]; i++) { 43 | CHECK(result[i] == testContainer[i + startIndex]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/SelfTest/IntrospectiveTests/Stream.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | 13 | TEST_CASE( "Cout stream properly declares it writes to stdout", "[streams]" ) { 14 | REQUIRE( Catch::makeStream( "-" )->isConsole() ); 15 | } 16 | 17 | TEST_CASE( "Empty stream name opens cout stream", "[streams]" ) { 18 | REQUIRE( Catch::makeStream( "" )->isConsole() ); 19 | } 20 | 21 | TEST_CASE( "stdout and stderr streams have %-starting name", "[streams]" ) { 22 | REQUIRE( Catch::makeStream( "%stderr" )->isConsole() ); 23 | REQUIRE( Catch::makeStream( "%stdout" )->isConsole() ); 24 | } 25 | 26 | TEST_CASE( "request an unknown %-starting stream fails", "[streams]" ) { 27 | REQUIRE_THROWS( Catch::makeStream( "%somestream" ) ); 28 | } 29 | 30 | TEST_CASE( "makeStream recognizes %debug stream name", "[streams]" ) { 31 | REQUIRE_NOTHROW( Catch::makeStream( "%debug" ) ); 32 | } 33 | -------------------------------------------------------------------------------- /tests/SelfTest/Misc/invalid-test-names.input: -------------------------------------------------------------------------------- 1 | Test with special, characters in \" name 2 | -------------------------------------------------------------------------------- /tests/SelfTest/Misc/plain-old-tests.input: -------------------------------------------------------------------------------- 1 | random SECTION tests 2 | nested SECTION tests 3 | -------------------------------------------------------------------------------- /tests/SelfTest/Misc/special-characters-in-file.input: -------------------------------------------------------------------------------- 1 | Test with special\, characters \"in name 2 | -------------------------------------------------------------------------------- /tests/SelfTest/TimingTests/Sleep.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | TEST_CASE( "sleep_for_100ms", "[.min_duration_test][approvals]" ) 15 | { 16 | std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); 17 | CHECK( true ); 18 | } 19 | 20 | TEST_CASE( "sleep_for_1000ms", "[.min_duration_test][approvals]" ) 21 | { 22 | std::this_thread::sleep_for( std::chrono::milliseconds( 1'000 ) ); 23 | CHECK( true ); 24 | } 25 | -------------------------------------------------------------------------------- /tests/SelfTest/UsageTests/Decomposition.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | #include 11 | 12 | namespace { 13 | 14 | struct truthy { 15 | truthy(bool b):m_value(b){} 16 | operator bool() const { 17 | return false; 18 | } 19 | bool m_value; 20 | }; 21 | 22 | std::ostream& operator<<(std::ostream& o, truthy) { 23 | o << "Hey, its truthy!"; 24 | return o; 25 | } 26 | 27 | } // end anonymous namespace 28 | 29 | #include 30 | 31 | TEST_CASE( "Reconstruction should be based on stringification: #914" , "[Decomposition][failing][.]") { 32 | CHECK(truthy(false)); 33 | } 34 | 35 | TEST_CASE("#1005: Comparing pointer to int and long (NULL can be either on various systems)", "[Decomposition][approvals]") { 36 | FILE* fptr = nullptr; 37 | REQUIRE( fptr == 0 ); 38 | REQUIRE_FALSE( fptr != 0 ); 39 | REQUIRE( fptr == 0l ); 40 | REQUIRE_FALSE( fptr != 0l ); 41 | } 42 | -------------------------------------------------------------------------------- /tests/SelfTest/UsageTests/ToStringByte.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #if defined(CATCH_CONFIG_CPP17_BYTE) 12 | 13 | TEST_CASE( "std::byte -> toString", "[toString][byte][approvals]" ) { 14 | using type = std::byte; 15 | REQUIRE( "0" == ::Catch::Detail::stringify( type{ 0 } ) ); 16 | } 17 | 18 | TEST_CASE( "std::vector -> toString", "[toString][byte][approvals]" ) { 19 | using type = std::vector; 20 | REQUIRE( "{ 0, 1, 2 }" == ::Catch::Detail::stringify( type{ std::byte{0}, std::byte{1}, std::byte{2} } ) ); 21 | } 22 | 23 | #endif // CATCH_INTERNAL_CONFIG_CPP17_BYTE 24 | -------------------------------------------------------------------------------- /tests/SelfTest/UsageTests/ToStringOptional.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER 10 | #include 11 | 12 | #if defined(CATCH_CONFIG_CPP17_OPTIONAL) 13 | 14 | TEST_CASE( "std::optional -> toString", "[toString][optional][approvals]" ) { 15 | using type = std::optional; 16 | REQUIRE( "{ }" == ::Catch::Detail::stringify( type{} ) ); 17 | REQUIRE( "0" == ::Catch::Detail::stringify( type{ 0 } ) ); 18 | } 19 | 20 | TEST_CASE( "std::optional -> toString", "[toString][optional][approvals]" ) { 21 | using type = std::optional; 22 | REQUIRE( "{ }" == ::Catch::Detail::stringify( type{} ) ); 23 | REQUIRE( "\"abc\"" == ::Catch::Detail::stringify( type{ "abc" } ) ); 24 | } 25 | 26 | TEST_CASE( "std::vector > -> toString", "[toString][optional][approvals]" ) { 27 | using type = std::vector >; 28 | REQUIRE( "{ 0, { }, 2 }" == ::Catch::Detail::stringify( type{ 0, {}, 2 } ) ); 29 | } 30 | 31 | TEST_CASE( "std::nullopt -> toString", "[toString][optional][approvals]" ) { 32 | REQUIRE( "{ }" == ::Catch::Detail::stringify( std::nullopt ) ); 33 | } 34 | 35 | #endif // CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL 36 | -------------------------------------------------------------------------------- /tests/SelfTest/UsageTests/VariadicMacros.tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | 12 | TEST_CASE() 13 | { 14 | SUCCEED( "anonymous test case" ); 15 | } 16 | 17 | TEST_CASE( "Test case with one argument" ) 18 | { 19 | SUCCEED( "no assertions" ); 20 | } 21 | 22 | TEST_CASE( "Variadic macros", "[variadic][sections]" ) 23 | { 24 | SECTION( "Section with one argument" ) 25 | { 26 | SUCCEED( "no assertions" ); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /tests/SelfTest/helpers/parse_test_spec.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Catch { 15 | 16 | TestSpec parseTestSpec( std::string const& arg ) { 17 | return TestSpecParser( ITagAliasRegistry::get() ) 18 | .parse( arg ) 19 | .testSpec(); 20 | } 21 | 22 | } // namespace Catch 23 | -------------------------------------------------------------------------------- /tests/SelfTest/helpers/parse_test_spec.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #ifndef CATCH_TEST_HELPERS_PARSE_TEST_SPEC_HPP_INCLUDED 10 | #define CATCH_TEST_HELPERS_PARSE_TEST_SPEC_HPP_INCLUDED 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace Catch { 17 | TestSpec parseTestSpec( std::string const& arg ); 18 | } 19 | 20 | #endif // CATCH_TEST_HELPERS_PARSE_TEST_SPEC_HPP_INCLUDED 21 | -------------------------------------------------------------------------------- /tests/TestScripts/DiscoverTests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(discover-tests-test LANGUAGES CXX) 3 | 4 | add_executable(tests register-tests.cpp) 5 | add_subdirectory(${CATCH2_PATH} catch2-build) 6 | target_link_libraries(tests PRIVATE Catch2::Catch2WithMain) 7 | 8 | enable_testing() 9 | include(Catch) 10 | set(extra_args) 11 | if(CMAKE_VERSION GREATER_EQUAL 3.27) 12 | list(APPEND extra_args 13 | DL_PATHS "${CMAKE_CURRENT_LIST_DIR};${CMAKE_CURRENT_LIST_DIR}/.." 14 | ) 15 | endif() 16 | catch_discover_tests( 17 | tests 18 | ADD_TAGS_AS_LABELS 19 | DISCOVERY_MODE PRE_TEST 20 | ${extra_args} 21 | ) 22 | 23 | # DISCOVERY_MODE 24 | -------------------------------------------------------------------------------- /tests/TestScripts/DiscoverTests/register-tests.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Catch2 Authors 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE.txt or copy at 5 | // https://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // SPDX-License-Identifier: BSL-1.0 8 | 9 | #include 10 | 11 | TEST_CASE("@Script[C:\\EPM1A]=x;\"SCALA_ZERO:\"", "[script regressions]"){} 12 | TEST_CASE("Some test") {} 13 | TEST_CASE( "Let's have a test case with a long name. Longer. No, even longer. " 14 | "Really looooooooooooong. Even longer than that. Multiple lines " 15 | "worth of test name. Yep, like this." ) {} 16 | TEST_CASE( "And now a test case with weird tags.", "[tl;dr][tl;dw][foo,bar]" ) {} 17 | // Also check that we handle tests on class, which have name in output as 'class-name', not 'name'. 18 | class TestCaseFixture { 19 | public: 20 | int m_a; 21 | }; 22 | 23 | TEST_CASE_METHOD(TestCaseFixture, "A test case as method", "[tagstagstags]") {} 24 | -------------------------------------------------------------------------------- /tools/misc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(CatchCoverageHelper LANGUAGES CXX) 3 | 4 | add_executable(CoverageHelper coverage-helper.cpp) 5 | target_compile_features(CoverageHelper PRIVATE cxx_std_11) 6 | if(MSVC) 7 | target_compile_options(CoverageHelper PRIVATE /W4 /w44265 /WX /w44061 /w44062) 8 | endif() 9 | -------------------------------------------------------------------------------- /tools/misc/SelfTest.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | false 6 | 7 | 8 | 9 | 10 | false 11 | 12 | 13 | 14 | 15 | false 16 | 17 | 18 | 19 | 20 | false 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tools/misc/appveyorBuildConfigurationScript.bat: -------------------------------------------------------------------------------- 1 | SETLOCAL EnableDelayedExpansion 2 | 3 | @REM # Possibilities: 4 | @REM # Debug build + coverage 5 | @REM # Debug build + examples 6 | @REM # Debug build + --- 7 | @REM # Release build 8 | if "%CONFIGURATION%"=="Debug" ( 9 | if "%coverage%"=="1" ( 10 | @REM # coverage needs to build the special helper as well as the main 11 | cmake -Stools/misc -Bbuild-misc -A%PLATFORM% || exit /b !ERRORLEVEL! 12 | cmake --build build-misc || exit /b !ERRORLEVEL! 13 | cmake -S. -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_ENABLE_CONFIGURE_TESTS=%configure_tests% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! 14 | ) else ( 15 | @REM # We know that coverage is 0 16 | cmake -S. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_BUILD_SURROGATES=%surrogates% -DCATCH_DEVELOPMENT_BUILD=ON -DCATCH_ENABLE_CONFIGURE_TESTS=%configure_tests% || exit /b !ERRORLEVEL! 17 | ) 18 | ) 19 | if "%CONFIGURATION%"=="Release" ( 20 | cmake -S. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! 21 | ) 22 | -------------------------------------------------------------------------------- /tools/misc/appveyorMergeCoverageScript.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import glob 4 | import subprocess 5 | 6 | if __name__ == '__main__': 7 | cov_files = list(glob.glob('tests/cov-report*.bin')) 8 | base_cmd = ['OpenCppCoverage', '--quiet', '--export_type=cobertura:cobertura.xml'] + ['--input_coverage={}'.format(f) for f in cov_files] 9 | subprocess.check_call(base_cmd) 10 | -------------------------------------------------------------------------------- /tools/misc/appveyorTestRunScript.bat: -------------------------------------------------------------------------------- 1 | SETLOCAL EnableDelayedExpansion 2 | 3 | rem Disable launching the JIT debugger for ctest.exe 4 | reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList" /v "ctest.ext" /t REG_DWORD /d 1 5 | cd Build 6 | if "%CONFIGURATION%"=="Debug" ( 7 | if "%coverage%"=="1" ( 8 | ctest -j 2 -C %CONFIGURATION% -D ExperimentalMemCheck -LE uses-signals || exit /b !ERRORLEVEL! 9 | python ..\tools\misc\appveyorMergeCoverageScript.py || exit /b !ERRORLEVEL! 10 | codecov --root .. --no-color --disable gcov -f cobertura.xml -t %CODECOV_TOKEN% || exit /b !ERRORLEVEL! 11 | ) else ( 12 | ctest -j 2 -C %CONFIGURATION% || exit /b !ERRORLEVEL! 13 | ) 14 | ) 15 | if "%CONFIGURATION%"=="Release" ( 16 | ctest -j 2 -C %CONFIGURATION% || exit /b !ERRORLEVEL! 17 | ) 18 | -------------------------------------------------------------------------------- /tools/misc/installOpenCppCoverage.ps1: -------------------------------------------------------------------------------- 1 | # Downloads are done from the official github release page links 2 | $downloadUrl = "https://github.com/OpenCppCoverage/OpenCppCoverage/releases/download/release-0.9.9.0/OpenCppCoverageSetup-x64-0.9.9.0.exe" 3 | $installerPath = [System.IO.Path]::Combine($Env:USERPROFILE, "Downloads", "OpenCppCoverageSetup.exe") 4 | 5 | if(-Not (Test-Path $installerPath)) { 6 | Write-Host -ForegroundColor White ("Downloading OpenCppCoverage from: " + $downloadUrl) 7 | Start-BitsTransfer $downloadUrl -Destination $installerPath 8 | } 9 | 10 | Write-Host -ForegroundColor White "About to install OpenCppCoverage..." 11 | 12 | $installProcess = (Start-Process $installerPath -ArgumentList '/VERYSILENT' -PassThru -Wait) 13 | if($installProcess.ExitCode -ne 0) { 14 | throw [System.String]::Format("Failed to install OpenCppCoverage, ExitCode: {0}.", $installProcess.ExitCode) 15 | } 16 | 17 | # Assume standard, boring, installation path of ".../Program Files/OpenCppCoverage" 18 | $installPath = [System.IO.Path]::Combine(${Env:ProgramFiles}, "OpenCppCoverage") 19 | $env:Path="$env:Path;$installPath" 20 | -------------------------------------------------------------------------------- /tools/scripts/approve.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import sys 5 | import shutil 6 | import glob 7 | from scriptCommon import catchPath 8 | 9 | rootPath = os.path.join( catchPath, 'tests/SelfTest/Baselines' ) 10 | 11 | if len(sys.argv) > 1: 12 | files = [os.path.join( rootPath, f ) for f in sys.argv[1:]] 13 | else: 14 | files = glob.glob( os.path.join( rootPath, "*.unapproved.txt" ) ) 15 | 16 | 17 | def approveFile( approvedFile, unapprovedFile ): 18 | justFilename = unapprovedFile[len(rootPath)+1:] 19 | if os.path.exists( unapprovedFile ): 20 | if os.path.exists( approvedFile ): 21 | os.remove( approvedFile ) 22 | os.rename( unapprovedFile, approvedFile ) 23 | print( "approved " + justFilename ) 24 | else: 25 | print( "approval file " + justFilename + " does not exist" ) 26 | 27 | if files: 28 | for unapprovedFile in files: 29 | approveFile( unapprovedFile.replace( "unapproved.txt", "approved.txt" ), unapprovedFile ) 30 | else: 31 | print( "no files to approve" ) 32 | -------------------------------------------------------------------------------- /tools/scripts/buildAndTest.cmd: -------------------------------------------------------------------------------- 1 | rem Start at the root of the Catch project directory, for example: 2 | rem cd Catch2 3 | 4 | rem begin-snippet: catch2-build-and-test-win 5 | rem 1. Regenerate the amalgamated distribution 6 | python tools\scripts\generateAmalgamatedFiles.py 7 | 8 | rem 2. Configure the full test build 9 | cmake -B debug-build -S . -DCMAKE_BUILD_TYPE=Debug --preset all-tests 10 | 11 | rem 3. Run the actual build 12 | cmake --build debug-build 13 | 14 | rem 4. Run the tests using CTest 15 | ctest -j 4 --output-on-failure -C Debug --test-dir debug-build 16 | rem end-snippet 17 | -------------------------------------------------------------------------------- /tools/scripts/buildAndTest.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Start at the root of the Catch project directory, for example: 4 | # cd Catch2 5 | 6 | # begin-snippet: catch2-build-and-test 7 | # 1. Regenerate the amalgamated distribution 8 | ./tools/scripts/generateAmalgamatedFiles.py 9 | 10 | # 2. Configure the full test build 11 | cmake -B debug-build -S . -DCMAKE_BUILD_TYPE=Debug --preset all-tests 12 | 13 | # 3. Run the actual build 14 | cmake --build debug-build 15 | 16 | # 4. Run the tests using CTest 17 | ctest -j 4 --output-on-failure -C Debug --test-dir debug-build 18 | # end-snippet 19 | -------------------------------------------------------------------------------- /tools/scripts/checkDuplicateFilenames.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import sys 5 | 6 | files_set = set() 7 | 8 | for root, dir, files in os.walk("src/catch2"): 9 | for file in files: 10 | if file not in files_set: 11 | files_set.add(file) 12 | else: 13 | print("File %s is duplicate" % file) 14 | sys.exit(1) 15 | -------------------------------------------------------------------------------- /tools/scripts/checkLicense.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import glob 5 | 6 | correct_licence = """\ 7 | 8 | // Copyright Catch2 Authors 9 | // Distributed under the Boost Software License, Version 1.0. 10 | // (See accompanying file LICENSE.txt or copy at 11 | // https://www.boost.org/LICENSE_1_0.txt) 12 | 13 | // SPDX-License-Identifier: BSL-1.0 14 | """ 15 | 16 | def check_licence_in_file(filename: str) -> bool: 17 | with open(filename, 'r') as f: 18 | file_preamble = ''.join(f.readlines()[:7]) 19 | 20 | if correct_licence != file_preamble: 21 | print('File {} does not have proper licence'.format(filename)) 22 | return False 23 | return True 24 | 25 | def check_licences_in_path(path: str) -> int: 26 | failed = 0 27 | files_to_check = glob.glob(path + '/**/*.cpp', recursive=True) \ 28 | + glob.glob(path + '/**/*.hpp', recursive=True) 29 | for file in files_to_check: 30 | if not check_licence_in_file(file): 31 | failed += 1 32 | return failed 33 | 34 | def check_licences(): 35 | failed = 0 36 | # Add 'extras' after the amalgamted files are regenerated with the new script (past 3.4.0) 37 | roots = ['src/catch2', 'tests', 'examples', 'fuzzing'] 38 | for root in roots: 39 | failed += check_licences_in_path(root) 40 | 41 | if failed: 42 | print('{} files are missing licence'.format(failed)) 43 | sys.exit(1) 44 | 45 | if __name__ == "__main__": 46 | check_licences() 47 | -------------------------------------------------------------------------------- /tools/scripts/developBuild.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import releaseCommon 4 | 5 | v = releaseCommon.Version() 6 | v.incrementBuildNumber() 7 | releaseCommon.performUpdates(v) 8 | 9 | print( "Updated files to v{0}".format( v.getVersionString() ) ) 10 | -------------------------------------------------------------------------------- /tools/scripts/majorRelease.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import releaseCommon 4 | 5 | v = releaseCommon.Version() 6 | v.incrementMajorVersion() 7 | releaseCommon.performUpdates(v) 8 | 9 | print( "Updated files to v{0}".format( v.getVersionString() ) ) 10 | -------------------------------------------------------------------------------- /tools/scripts/minorRelease.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import releaseCommon 4 | 5 | v = releaseCommon.Version() 6 | v.incrementMinorVersion() 7 | releaseCommon.performUpdates(v) 8 | 9 | print( "Updated files to v{0}".format( v.getVersionString() ) ) 10 | -------------------------------------------------------------------------------- /tools/scripts/patchRelease.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import releaseCommon 4 | 5 | v = releaseCommon.Version() 6 | v.incrementPatchNumber() 7 | releaseCommon.performUpdates(v) 8 | 9 | print( "Updated files to v{0}".format( v.getVersionString() ) ) 10 | -------------------------------------------------------------------------------- /tools/scripts/scriptCommon.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | catchPath = os.path.dirname(os.path.dirname(os.path.realpath( os.path.dirname(sys.argv[0])))) 5 | -------------------------------------------------------------------------------- /tools/scripts/updateDocumentSnippets.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from scriptCommon import catchPath 4 | import os 5 | import subprocess 6 | 7 | # --------------------------------------------------- 8 | # Update code examples 9 | # --------------------------------------------------- 10 | # For info on mdsnippets, see https://github.com/SimonCropp/MarkdownSnippets 11 | 12 | # install dotnet SDK from http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409 13 | # Then install MarkdownSnippets.Tool with 14 | # dotnet tool install -g MarkdownSnippets.Tool 15 | # To update: 16 | # dotnet tool update -g MarkdownSnippets.Tool 17 | # To uninstall (e.g. to downgrade to a lower version) 18 | # dotnet tool uninstall -g MarkdownSnippets.Tool 19 | 20 | os.chdir(catchPath) 21 | 22 | subprocess.run('dotnet tool update -g MarkdownSnippets.Tool --version 21.2.0', shell=True, check=True) 23 | subprocess.run('mdsnippets', shell=True, check=True) 24 | --------------------------------------------------------------------------------