mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
e1e6872c4c
This is both a really big and a really small commit. It is small in that it only contains renaming, moving and modification of include directives caused by this. It is really big in the obvious way of touching something like 200 files. The new rules for naming files is simple: headers use the `.hpp` extension. The rules for physical file layout is still kinda in progress, but the basics are also simple: * Significant parts of functionality get their own subfolder * Benchmarking is in `catch2/benchmark` * Matchers are in `catch2/matchers` * Generators are in `catch2/generators` * Reporters are in `catch2/reporters` * Baseline testing facilities are in `catch2/` * Various top level folders also contain `internal` subfolder, with files that users probably do not want to include directly, at least not until they have to write something like their own reporter. * The exact files in these subfolders is likely to change later on Note that while some includes were cleaned up in this commit, it is only the low hanging fruit and further cleanup using automatic tooling will happen later. Also note that various include guards, copyright notices and file headers will also be standardized later, rather than in this commit.
85 lines
3.2 KiB
C++
85 lines
3.2 KiB
C++
// X11-DisableStringification.cpp
|
|
// Test that Catch's prefixed macros compile and run properly.
|
|
|
|
#include <catch2/internal/catch_default_main.hpp>
|
|
// This won't provide full coverage, but it might be worth checking
|
|
// the other branch as well
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/matchers/catch_matchers_predicate.hpp>
|
|
#include <catch2/matchers/catch_matchers_string.hpp>
|
|
|
|
#include <type_traits>
|
|
#include <stdexcept>
|
|
|
|
namespace {
|
|
[[noreturn]]
|
|
void this_throws() {
|
|
throw std::runtime_error("Some msg");
|
|
}
|
|
void this_doesnt_throw() {}
|
|
}
|
|
|
|
CATCH_TEST_CASE("PrefixedMacros") {
|
|
using namespace Catch::Matchers;
|
|
|
|
CATCH_REQUIRE( 1 == 1 );
|
|
CATCH_REQUIRE_FALSE( 1 != 1 );
|
|
|
|
CATCH_REQUIRE_THROWS(this_throws());
|
|
CATCH_REQUIRE_THROWS_AS(this_throws(), std::runtime_error);
|
|
CATCH_REQUIRE_THROWS_WITH(this_throws(), "Some msg");
|
|
CATCH_REQUIRE_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; }));
|
|
CATCH_REQUIRE_NOTHROW(this_doesnt_throw());
|
|
|
|
CATCH_CHECK( 1 == 1 );
|
|
CATCH_CHECK_FALSE( 1 != 1 );
|
|
CATCH_CHECKED_IF( 1 == 1 ) {
|
|
CATCH_SUCCEED("don't care");
|
|
} CATCH_CHECKED_ELSE ( 1 == 1 ) {
|
|
CATCH_SUCCEED("don't care");
|
|
}
|
|
|
|
CATCH_CHECK_NOFAIL(1 == 2);
|
|
|
|
CATCH_CHECK_THROWS(this_throws());
|
|
CATCH_CHECK_THROWS_AS(this_throws(), std::runtime_error);
|
|
CATCH_CHECK_THROWS_WITH(this_throws(), "Some msg");
|
|
CATCH_CHECK_THROWS_MATCHES(this_throws(), std::runtime_error, Predicate<std::runtime_error>([](std::runtime_error const&) { return true; }));
|
|
CATCH_CHECK_NOTHROW(this_doesnt_throw());
|
|
|
|
CATCH_REQUIRE_THAT("abcd", Equals("abcd"));
|
|
CATCH_CHECK_THAT("bdef", Equals("bdef"));
|
|
|
|
CATCH_INFO( "some info" );
|
|
CATCH_UNSCOPED_INFO( "some info" );
|
|
CATCH_WARN( "some warn" );
|
|
CATCH_SECTION("some section") {
|
|
int i = 1;
|
|
CATCH_CAPTURE( i );
|
|
CATCH_DYNAMIC_SECTION("Dynamic section: " << i) {
|
|
CATCH_FAIL_CHECK( "failure" );
|
|
}
|
|
}
|
|
|
|
CATCH_STATIC_REQUIRE( std::is_void<void>::value );
|
|
CATCH_STATIC_REQUIRE_FALSE( std::is_void<int>::value );
|
|
CATCH_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 )
|
|
//
|