Add test for CATCH_CONFIG_PREFIX_ALL

This commit is contained in:
Martin Hořeňovský 2018-09-01 15:01:51 +02:00
parent f3972f0695
commit 9c3cc4a076
3 changed files with 93 additions and 0 deletions

View File

@ -16,6 +16,21 @@ set( TESTS_DIR ${CATCH_DIR}/projects/ExtraTests )
set( SINGLE_INCLUDE_PATH ${CATCH_DIR}/single_include )
add_executable(PrefixedMacros ${TESTS_DIR}/X01-PrefixedMacros.cpp)
target_compile_definitions( PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL )
add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s)
set_tests_properties(
CATCH_CONFIG_PREFIX_ALL
PROPERTIES
PASS_REGULAR_EXPRESSION "CATCH_"
FAIL_REGULAR_EXPRESSION
# The spaces are important -> They disambiguate between CATCH_REQUIRE
# and REQUIRE without prefix.
" REQUIRE; REQUIRE_FALSE; REQUIRE_THROWS; REQUIRE_THROWS_AS; REQUIRE_THROWS_WITH; REQUIRE_THROWS_MATCHES; REQUIRE_NOTHROW; CHECK; CHECK_FALSE; CHECKED_IF; CHECKED_ELSE; CHECK_NOFAIL; CHECK_THROWS; CHECK_THROWS_AS; CHECK_THROWS_WITH; CHECK_THROWS_MATCHES; CHECK_NOTHROW; REQUIRE_THAT; CHECK_THAT"
)
add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp)
target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier )
@ -39,6 +54,7 @@ set_tests_properties(
set( EXTRA_TEST_BINARIES
PrefixedMacros
FallbackStringifier
DisableStringification
)

View File

@ -9,3 +9,4 @@ yet:
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
CATCH_CONFIG_DEFAULT_REPORTER
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS

View File

@ -0,0 +1,76 @@
// X11-DisableStringification.cpp
// Test that Catch's prefixed macros compile and run properly.
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <stdexcept>
[[noreturn]]
void this_throws() {
throw std::runtime_error("Some msg");
}
void this_doesnt_throw() {}
CATCH_TEST_CASE("PrefixedMacros") {
using namespace Catch::Matchers;
CATCH_REQUIRE( 1 == 1 );
CATCH_REQUIRE_FALSE( 1 != 1 );
CATCH_REQUIRE_THROWS(this_throws());
CATCH_REQUIRE_THROWS_AS(this_throws(), std::runtime_error);
CATCH_REQUIRE_THROWS_WITH(this_throws(), "Some msg");
CATCH_REQUIRE_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; }));
CATCH_REQUIRE_NOTHROW(this_doesnt_throw());
CATCH_CHECK( 1 == 1 );
CATCH_CHECK_FALSE( 1 != 1 );
CATCH_CHECKED_IF( 1 == 1 ) {
CATCH_SUCCEED("don't care");
} CATCH_CHECKED_ELSE ( 1 == 1 ) {
CATCH_SUCCEED("don't care");
}
CATCH_CHECK_NOFAIL(1 == 2);
CATCH_CHECK_THROWS(this_throws());
CATCH_CHECK_THROWS_AS(this_throws(), std::runtime_error);
CATCH_CHECK_THROWS_WITH(this_throws(), "Some msg");
CATCH_CHECK_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; }));
CATCH_CHECK_NOTHROW(this_doesnt_throw());
CATCH_REQUIRE_THAT("abcd", Equals("abcd"));
CATCH_CHECK_THAT("bdef", Equals("bdef"));
CATCH_INFO( "some info" );
CATCH_WARN( "some warn" );
CATCH_SECTION("some section") {
int i = 1;
CATCH_CAPTURE( i );
CATCH_DYNAMIC_SECTION("Dynamic section: " << i) {
CATCH_FAIL_CHECK( "failure" );
}
}
}
CATCH_ANON_TEST_CASE() {
CATCH_FAIL("");
}
// Missing:
//
// #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
// #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
// #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
//
// // "BDD-style" convenience wrappers
// #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
// #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
// #define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
// #define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
// #define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And when: " << desc )
// #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
// #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
//