update test

This commit is contained in:
neargye 2019-04-10 18:48:14 +05:00
parent a631f84520
commit fcdf72a0d7
2 changed files with 23 additions and 22 deletions

View file

@ -13,10 +13,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(HAS_PERMISSIVE_FLAG) if(HAS_PERMISSIVE_FLAG)
set(OPTIONS ${OPTIONS} /permissive-) set(OPTIONS ${OPTIONS} /permissive-)
endif() endif()
set(OPTIONS ${OPTIONS} /wd4702) # Disable warning C4702: unreachable code
set(HAS_CPP11_FLAG TRUE)
check_cxx_compiler_flag(/std:c++14 HAS_CPP14_FLAG)
check_cxx_compiler_flag(/std:c++17 HAS_CPP17_FLAG) check_cxx_compiler_flag(/std:c++17 HAS_CPP17_FLAG)
check_cxx_compiler_flag(/std:c++20 HAS_CPP20_FLAG) check_cxx_compiler_flag(/std:c++20 HAS_CPP20_FLAG)
check_cxx_compiler_flag(/std:c++latest HAS_CPPLATEST_FLAG) check_cxx_compiler_flag(/std:c++latest HAS_CPPLATEST_FLAG)
@ -24,8 +21,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
set(OPTIONS -Wall -Wextra -pedantic-errors) set(OPTIONS -Wall -Wextra -pedantic-errors)
check_cxx_compiler_flag(-std=c++11 HAS_CPP11_FLAG)
check_cxx_compiler_flag(-std=c++14 HAS_CPP14_FLAG)
check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG) check_cxx_compiler_flag(-std=c++17 HAS_CPP17_FLAG)
check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG) check_cxx_compiler_flag(-std=c++20 HAS_CPP20_FLAG)
endif() endif()

View file

@ -84,7 +84,8 @@ const Directions directions = Directions::Right;
TEST_CASE("NAMEOF") { TEST_CASE("NAMEOF") {
SECTION("variable") { SECTION("variable") {
REQUIRE(NAMEOF(othervar) == "othervar"); constexpr auto name = NAMEOF(othervar);
REQUIRE(name == "othervar");
REQUIRE(NAMEOF(struct_var) == "struct_var"); REQUIRE(NAMEOF(struct_var) == "struct_var");
REQUIRE(NAMEOF(::struct_var) == "struct_var"); REQUIRE(NAMEOF(::struct_var) == "struct_var");
REQUIRE(NAMEOF(ptr_s) == "ptr_s"); REQUIRE(NAMEOF(ptr_s) == "ptr_s");
@ -119,7 +120,8 @@ TEST_CASE("NAMEOF") {
TEST_CASE("NAMEOF_FULL") { TEST_CASE("NAMEOF_FULL") {
SECTION("variable") { SECTION("variable") {
REQUIRE(NAMEOF_FULL(othervar) == "othervar"); constexpr auto full_name = NAMEOF_FULL(othervar);
REQUIRE(full_name == "othervar");
REQUIRE(NAMEOF_FULL(struct_var) == "struct_var"); REQUIRE(NAMEOF_FULL(struct_var) == "struct_var");
REQUIRE(NAMEOF_FULL(::struct_var) == "struct_var"); REQUIRE(NAMEOF_FULL(::struct_var) == "struct_var");
REQUIRE(NAMEOF_FULL(ptr_s) == "ptr_s"); REQUIRE(NAMEOF_FULL(ptr_s) == "ptr_s");
@ -154,7 +156,8 @@ TEST_CASE("NAMEOF_FULL") {
TEST_CASE("NAMEOF_RAW") { TEST_CASE("NAMEOF_RAW") {
SECTION("variable") { SECTION("variable") {
REQUIRE(NAMEOF_RAW(othervar) == "othervar"); constexpr auto raw_name = NAMEOF_RAW(othervar);
REQUIRE(raw_name == "othervar");
REQUIRE(NAMEOF_RAW(struct_var) == "struct_var"); REQUIRE(NAMEOF_RAW(struct_var) == "struct_var");
REQUIRE(NAMEOF_RAW(&struct_var) == "&struct_var"); REQUIRE(NAMEOF_RAW(&struct_var) == "&struct_var");
REQUIRE(NAMEOF_RAW(::struct_var) == "::struct_var"); REQUIRE(NAMEOF_RAW(::struct_var) == "::struct_var");
@ -210,8 +213,8 @@ TEST_CASE("NAMEOF_ENUM") {
REQUIRE(NAMEOF_ENUM(Color::RED) == "RED"); REQUIRE(NAMEOF_ENUM(Color::RED) == "RED");
REQUIRE(NAMEOF_ENUM(color) == "RED"); REQUIRE(NAMEOF_ENUM(color) == "RED");
constexpr auto color_name = NAMEOF_ENUM(color_); constexpr auto enum_name = NAMEOF_ENUM(color_);
REQUIRE(color_name == "BLUE"); REQUIRE(enum_name == "BLUE");
REQUIRE(NAMEOF_ENUM(Color::BLUE) == "BLUE"); REQUIRE(NAMEOF_ENUM(Color::BLUE) == "BLUE");
REQUIRE(NAMEOF_ENUM(color_) == "BLUE"); REQUIRE(NAMEOF_ENUM(color_) == "BLUE");
@ -235,8 +238,8 @@ TEST_CASE("nameof::nameof_enum") {
REQUIRE(nameof::nameof_enum(Color::RED) == "RED"); REQUIRE(nameof::nameof_enum(Color::RED) == "RED");
REQUIRE(nameof::nameof_enum(color) == "RED"); REQUIRE(nameof::nameof_enum(color) == "RED");
constexpr auto color_name = nameof::nameof_enum(color_); constexpr auto enum_name = nameof::nameof_enum(color_);
REQUIRE(color_name == "BLUE"); REQUIRE(enum_name == "BLUE");
REQUIRE(nameof::nameof_enum(Color::BLUE) == "BLUE"); REQUIRE(nameof::nameof_enum(Color::BLUE) == "BLUE");
REQUIRE(nameof::nameof_enum(color_) == "BLUE"); REQUIRE(nameof::nameof_enum(color_) == "BLUE");
@ -253,8 +256,9 @@ TEST_CASE("nameof::nameof_enum") {
} }
TEST_CASE("NAMEOF_VAR_TYPE") { TEST_CASE("NAMEOF_VAR_TYPE") {
constexpr auto type_name = NAMEOF_VAR_TYPE(struct_var);
#if defined(__clang__) #if defined(__clang__)
REQUIRE(NAMEOF_VAR_TYPE(struct_var) == "SomeStruct"); REQUIRE(type_name == "SomeStruct");
REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "SomeStruct *"); REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "SomeStruct *");
REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "SomeStruct &"); REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "SomeStruct &");
@ -268,7 +272,7 @@ TEST_CASE("NAMEOF_VAR_TYPE") {
REQUIRE(NAMEOF_VAR_TYPE(std::declval<const SomeClass<int>>()) == "const SomeClass<int> &&"); REQUIRE(NAMEOF_VAR_TYPE(std::declval<const SomeClass<int>>()) == "const SomeClass<int> &&");
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
REQUIRE(NAMEOF_VAR_TYPE(struct_var) == "struct SomeStruct"); REQUIRE(type_name == "struct SomeStruct");
REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "struct SomeStruct *"); REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "struct SomeStruct *");
REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "struct SomeStruct &"); REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "struct SomeStruct &");
@ -282,7 +286,7 @@ TEST_CASE("NAMEOF_VAR_TYPE") {
REQUIRE(NAMEOF_VAR_TYPE(std::declval<const SomeClass<int>>()) == "class SomeClass<int> const &&"); REQUIRE(NAMEOF_VAR_TYPE(std::declval<const SomeClass<int>>()) == "class SomeClass<int> const &&");
#elif defined(__GNUC__) #elif defined(__GNUC__)
REQUIRE(NAMEOF_VAR_TYPE(struct_var) == "SomeStruct"); REQUIRE(type_name == "SomeStruct");
REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "SomeStruct*"); REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "SomeStruct*");
REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "SomeStruct&"); REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "SomeStruct&");
@ -299,8 +303,9 @@ TEST_CASE("NAMEOF_VAR_TYPE") {
} }
TEST_CASE("NAMEOF_TYPE") { TEST_CASE("NAMEOF_TYPE") {
constexpr auto type_name = NAMEOF_TYPE(decltype(struct_var));
#if defined(__clang__) #if defined(__clang__)
REQUIRE(NAMEOF_TYPE(decltype(struct_var)) == "SomeStruct"); REQUIRE(type_name == "SomeStruct");
REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct *"); REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct *");
REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct &"); REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct &");
REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct");
@ -317,7 +322,7 @@ TEST_CASE("NAMEOF_TYPE") {
REQUIRE(NAMEOF_TYPE(Color) == "Color"); REQUIRE(NAMEOF_TYPE(Color) == "Color");
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
REQUIRE(NAMEOF_TYPE(decltype(struct_var)) == "struct SomeStruct"); REQUIRE(type_name == "struct SomeStruct");
REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "struct SomeStruct *"); REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "struct SomeStruct *");
REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "struct SomeStruct &"); REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "struct SomeStruct &");
REQUIRE(NAMEOF_TYPE(SomeStruct) == "struct SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct) == "struct SomeStruct");
@ -334,7 +339,7 @@ TEST_CASE("NAMEOF_TYPE") {
REQUIRE(NAMEOF_TYPE(Color) == "enum Color"); REQUIRE(NAMEOF_TYPE(Color) == "enum Color");
#elif defined(__GNUC__) #elif defined(__GNUC__)
REQUIRE(NAMEOF_TYPE(decltype(struct_var)) == "SomeStruct"); REQUIRE(type_name == "SomeStruct");
REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct*"); REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct*");
REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct&"); REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct&");
REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct");
@ -354,8 +359,9 @@ TEST_CASE("NAMEOF_TYPE") {
} }
TEST_CASE("nameof::nameof_type") { TEST_CASE("nameof::nameof_type") {
constexpr auto type_name = nameof::nameof_type<decltype(struct_var)>();
#if defined(__clang__) #if defined(__clang__)
REQUIRE(nameof::nameof_type<decltype(struct_var)>() == "SomeStruct"); REQUIRE(type_name == "SomeStruct");
REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "SomeStruct *"); REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "SomeStruct *");
REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "SomeStruct &"); REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "SomeStruct &");
REQUIRE(nameof::nameof_type<SomeStruct>() == "SomeStruct"); REQUIRE(nameof::nameof_type<SomeStruct>() == "SomeStruct");
@ -372,7 +378,7 @@ TEST_CASE("nameof::nameof_type"){
REQUIRE(nameof::nameof_type<Color>() == "Color"); REQUIRE(nameof::nameof_type<Color>() == "Color");
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
REQUIRE(nameof::nameof_type<decltype(struct_var)>() == "struct SomeStruct"); REQUIRE(type_name == "struct SomeStruct");
REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "struct SomeStruct *"); REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "struct SomeStruct *");
REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "struct SomeStruct &"); REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "struct SomeStruct &");
REQUIRE(nameof::nameof_type<SomeStruct>() == "struct SomeStruct"); REQUIRE(nameof::nameof_type<SomeStruct>() == "struct SomeStruct");
@ -389,7 +395,7 @@ TEST_CASE("nameof::nameof_type"){
REQUIRE(nameof::nameof_type<Color>() == "enum Color"); REQUIRE(nameof::nameof_type<Color>() == "enum Color");
#elif defined(__GNUC__) #elif defined(__GNUC__)
REQUIRE(nameof::nameof_type<decltype(struct_var)>() == "SomeStruct"); REQUIRE(type_name == "SomeStruct");
REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "SomeStruct*"); REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "SomeStruct*");
REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "SomeStruct&"); REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "SomeStruct&");
REQUIRE(nameof::nameof_type<SomeStruct>() == "SomeStruct"); REQUIRE(nameof::nameof_type<SomeStruct>() == "SomeStruct");