Skip to content

Commit 42344ba

Browse files
committed
different tests for different standard versions
1 parent ac3d088 commit 42344ba

File tree

6 files changed

+65
-31
lines changed

6 files changed

+65
-31
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ if (PROJECT_IS_TOP_LEVEL)
2626
endif ()
2727
endif ()
2828

29-
set(CMAKE_CXX_STANDARD 20)
3029
set(CMAKE_CXX_EXTENSIONS OFF)
3130
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
3231
add_subdirectory(tests)
Submodule demangle updated from 09fd439 to abd0f94

tests/CMakeLists.txt

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
include(compiler_warnings.cmake)
2+
find_package(Catch2 3 REQUIRED)
3+
include(CTest)
4+
include(Catch)
25

3-
set(TEST_FILES
6+
set(cxx_17_files
47
${CMAKE_CURRENT_SOURCE_DIR}/add_noexcept.cpp
5-
${CMAKE_CURRENT_SOURCE_DIR}/change_observer.cpp
68
${CMAKE_CURRENT_SOURCE_DIR}/check.cpp
79
${CMAKE_CURRENT_SOURCE_DIR}/constexpr_hash.cpp
8-
${CMAKE_CURRENT_SOURCE_DIR}/copy_traits.cpp
910
${CMAKE_CURRENT_SOURCE_DIR}/defer.cpp
11+
${CMAKE_CURRENT_SOURCE_DIR}/pack_loops.cpp
12+
)
13+
set(cxx_20_files
14+
${cxx_17_files}
15+
${CMAKE_CURRENT_SOURCE_DIR}/change_observer.cpp
16+
${CMAKE_CURRENT_SOURCE_DIR}/copy_traits.cpp
1017
${CMAKE_CURRENT_SOURCE_DIR}/demangle.cpp
1118
${CMAKE_CURRENT_SOURCE_DIR}/mt_queue.cpp
1219
${CMAKE_CURRENT_SOURCE_DIR}/ownptrvec.cpp
13-
${CMAKE_CURRENT_SOURCE_DIR}/pack_loops.cpp
1420
${CMAKE_CURRENT_SOURCE_DIR}/pair.cpp
1521
${CMAKE_CURRENT_SOURCE_DIR}/ptrvecview.cpp
1622
${CMAKE_CURRENT_SOURCE_DIR}/resource.cpp
@@ -19,23 +25,35 @@ set(TEST_FILES
1925
${CMAKE_CURRENT_SOURCE_DIR}/template_helpers.cpp
2026
${CMAKE_CURRENT_SOURCE_DIR}/trim.cpp
2127
${CMAKE_CURRENT_SOURCE_DIR}/valueptr.cpp
28+
)
29+
30+
set(cxx_23_files
31+
${cxx_20_files}
2232
${CMAKE_CURRENT_SOURCE_DIR}/err.cpp
2333
)
24-
add_executable(libut_tests ${TEST_FILES})
25-
target_link_libraries(libut_tests PRIVATE UT::all)
26-
set_target_warnings(libut_tests)
2734

28-
find_package(Catch2 3 REQUIRED)
29-
target_link_libraries(libut_tests PRIVATE Catch2::Catch2WithMain)
30-
target_precompile_headers(libut_tests PRIVATE <catch.hpp>)
35+
function(setup_target target)
36+
target_link_libraries(${target} PRIVATE UT::all)
37+
set_target_warnings(${target})
38+
target_link_libraries(${target} PRIVATE Catch2::Catch2WithMain)
39+
target_precompile_headers(${target} PRIVATE <catch.hpp>)
40+
if(NOT MSVC)
41+
target_compile_options(${target} PUBLIC "-fsanitize=address" "-Og" "-g")
42+
target_link_options(${target} PUBLIC "-fsanitize=address" "-lg")
43+
else()
44+
target_compile_options(${target} PUBLIC "/Zc:__cplusplus")
45+
endif()
46+
catch_discover_tests(${target})
47+
endfunction()
3148

32-
if(NOT MSVC)
33-
target_compile_options(libut_tests PUBLIC "-fsanitize=address" "-Og" "-g")
34-
target_link_options(libut_tests PUBLIC "-fsanitize=address" "-lg")
35-
else()
36-
target_compile_options(libut_tests PUBLIC "/Zc:__cplusplus")
37-
endif()
49+
add_executable(libut_tests_17 ${cxx_17_files})
50+
add_executable(libut_tests_20 ${cxx_20_files})
51+
add_executable(libut_tests_23 ${cxx_23_files})
3852

39-
include(CTest)
40-
include(Catch)
41-
catch_discover_tests(libut_tests)
53+
target_compile_features(libut_tests_17 PUBLIC cxx_std_17)
54+
target_compile_features(libut_tests_20 PUBLIC cxx_std_20)
55+
target_compile_features(libut_tests_23 PUBLIC cxx_std_23)
56+
57+
setup_target(libut_tests_17)
58+
setup_target(libut_tests_20)
59+
setup_target(libut_tests_23)

tests/check.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include <string_view>
88
#include <vector>
99

10+
bool startsWith(std::string_view str, std::string_view with) {
11+
if (str.size() < with.size()) return false;
12+
return str.substr(0, with.size()) == with;
13+
}
14+
1015
#define DFLT_CTOR(name) \
1116
name() noexcept { }
1217
#define DTOR(name) \
@@ -156,13 +161,13 @@ TEST_CASE("Check functionality", "[check]") {
156161

157162

158163
REQUIRE(vec.size() == 8);
159-
// Using starts_with (instead of ==) because Check uses typeid name to identify objects
160-
REQUIRE(vec.at(0).starts_with("Check();"));
161-
REQUIRE(vec.at(1).starts_with("Check(const Check &);"));
162-
REQUIRE(vec.at(2).starts_with("Check(Check &&);"));
163-
REQUIRE(vec.at(3).starts_with("Check &operator=(Check);"));
164-
REQUIRE(vec.at(4).starts_with("Check &operator=(Check &&);"));
165-
REQUIRE(vec.at(5).starts_with("~Check();"));
166-
REQUIRE(vec.at(6).starts_with("~Check();"));
167-
REQUIRE(vec.at(7).starts_with("~Check();"));
164+
// Using startsWith (instead of ==) because Check uses typeid name to identify objects
165+
REQUIRE(startsWith(vec.at(0), "Check();"));
166+
REQUIRE(startsWith(vec.at(1), "Check(const Check &);"));
167+
REQUIRE(startsWith(vec.at(2), "Check(Check &&);"));
168+
REQUIRE(startsWith(vec.at(3), "Check &operator=(Check);"));
169+
REQUIRE(startsWith(vec.at(4), "Check &operator=(Check &&);"));
170+
REQUIRE(startsWith(vec.at(5), "~Check();"));
171+
REQUIRE(startsWith(vec.at(6), "~Check();"));
172+
REQUIRE(startsWith(vec.at(7), "~Check();"));
168173
}

tests/constexpr_hash.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ constexpr auto len(char const *str) {
2020
return std::char_traits<char>::length(str);
2121
}
2222

23+
constexpr char *copy(char *to, char const *from, std::size_t size) {
24+
for (auto i = size_t(0); i < size; ++i)
25+
to[i] = from[i];
26+
return to;
27+
}
28+
2329
template<std::size_t size>
2430
constexpr auto makeCopy(char const *str) {
2531
std::array<char, size + 1> arr {};
26-
std::char_traits<char>::copy(arr.data(), str, arr.size());
32+
copy(arr.data(), str, arr.size());
2733
arr[size] = 0;
2834
return arr;
2935
}

tests/pack_loops.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void loopOverParameterPackContinue() {
6767
REQUIRE(count == 4);
6868
}
6969

70+
#if __cplusplus >= 202'002
71+
7072
template<typename... Ts>
7173
void loopOverTypes() {
7274
int count = 0;
@@ -113,6 +115,8 @@ void loopOverTypesContinue() {
113115
REQUIRE(float_count == 2);
114116
}
115117

118+
#endif
119+
116120
template<typename... T>
117121
int indexArgs(T... args) {
118122
return UT_PACK_IDX(args, 2);
@@ -138,11 +142,13 @@ TEST_CASE("pack for loop", "[pack_loops]") {
138142
loopOverParameterPackContinue<0, -100, 1, -100, 2, -100, 3>();
139143
}
140144

145+
#if __cplusplus >= 202'002
141146
TEST_CASE("type pack for loop", "[pack_loops]") {
142147
loopOverTypes<int, float, double, float>();
143148
loopOverTypesBreak<int, float, float, double, float, int>();
144149
loopOverTypesContinue<int, float, double, float, int>();
145150
}
151+
#endif
146152

147153
TEST_CASE("pack index", "[pack_loops]") {
148154
REQUIRE(indexArgs(0, 0, 3, 0) == 3);

0 commit comments

Comments
 (0)