Skip to content

Commit 4ad99df

Browse files
authored
Merge pull request #17 from iris-cpp/update-test-sources
Organize test sources
2 parents 7670a27 + b78298e commit 4ad99df

16 files changed

Lines changed: 124 additions & 130 deletions

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ endif()
88

99
project(iris VERSION 0.0.1 LANGUAGES CXX)
1010

11+
if(NOT DEFINED IRIS_ROOT)
12+
set(IRIS_ROOT "${CMAKE_CURRENT_LIST_DIR}")
13+
endif()
1114

1215
# -----------------------------------------------------------------
1316
# Global settings
@@ -45,8 +48,8 @@ if(MSVC)
4548
target_sources(
4649
iris
4750
PRIVATE
48-
"${PROJECT_SOURCE_DIR}/cpp.hint"
49-
"${PROJECT_SOURCE_DIR}/iris.natvis"
51+
"${CMAKE_CURRENT_LIST_DIR}/cpp.hint"
52+
"${CMAKE_CURRENT_LIST_DIR}/iris.natvis"
5053
)
5154

5255
target_link_libraries(iris PUBLIC _iris_cxx_common)

iris.natvis

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<AutoVisualizer
44
xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6-
xsi:schemaLocation="http://schemas.microsoft.com/vstudio/debugger/natvis/2010 file:///C:/Program%20Files/Microsoft%20Visual%20Studio/2022/Community/Xml/Schemas/1033/natvis.xsd"
6+
xsi:schemaLocation="http://schemas.microsoft.com/vstudio/debugger/natvis/2010 file:///C:/Program%20Files/Microsoft%20Visual%20Studio/18/Community/Xml/Schemas/1033/natvis.xsd"
77
>
8-
<Type Name="iris::indirect&lt;*&gt;">
8+
<Type Name="iris::detail::indirect_base&lt;*&gt;">
99
<SmartPointer Usage="Minimal">ptr_</SmartPointer>
1010
<DisplayString Condition="ptr_ == 0">[valueless_after_move]</DisplayString>
1111
<DisplayString Condition="ptr_ != 0">{*ptr_}</DisplayString>

test/CMakeLists.txt

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,70 @@
11
# SPDX-License-Identifier: MIT
22

3-
# For Iris-specific tests.
3+
# -----------------------------------------------------------------
4+
# Setup the basic targets
5+
6+
# For internal common settings
7+
add_library(_iris_cxx_test_common INTERFACE)
8+
set_target_properties(_iris_cxx_test_common PROPERTIES CXX_EXTENSIONS OFF)
9+
target_link_libraries(_iris_cxx_test_common INTERFACE _iris_cxx_common)
10+
11+
12+
# For Iris-specific tests
413
add_library(iris_cxx_test INTERFACE)
514
set_target_properties(iris_cxx_test PROPERTIES CXX_EXTENSIONS OFF)
6-
target_link_libraries(iris_cxx_test INTERFACE _iris_cxx_common)
15+
target_link_libraries(iris_cxx_test INTERFACE _iris_cxx_test_common)
716

817
# For external libraries. Excludes strict warning, etc.
918
add_library(iris_cxx_test_external INTERFACE)
1019
set_target_properties(iris_cxx_test_external PROPERTIES CXX_EXTENSIONS OFF)
11-
target_link_libraries(iris_cxx_test_external INTERFACE _iris_cxx_common)
20+
target_link_libraries(iris_cxx_test_external INTERFACE _iris_cxx_test_common)
1221

1322
if(MSVC)
23+
target_compile_options(
24+
_iris_cxx_test_common
25+
INTERFACE
26+
/wd5072 # ASan intentionally enabled on Release build
27+
/fsanitize=address
28+
)
29+
target_link_options(
30+
_iris_cxx_test_common
31+
INTERFACE
32+
/ignore:4302 # ASan intentionally enabled on Release build
33+
/INCREMENTAL:NO # required for ASan
34+
)
35+
1436
target_compile_options(
1537
iris_cxx_test
1638
INTERFACE /W4 /analyze /analyze:external-
1739
)
40+
1841
target_compile_options(
1942
iris_cxx_test_external
2043
INTERFACE /analyze-
2144
)
2245

2346
else() # non-MSVC
47+
target_compile_options(
48+
_iris_cxx_test_common
49+
INTERFACE
50+
-fsanitize=undefined,address
51+
)
52+
target_link_options(
53+
_iris_cxx_test_common
54+
INTERFACE
55+
-fsanitize=undefined,address
56+
)
57+
2458
target_compile_options(
2559
iris_cxx_test
2660
INTERFACE
2761
-Wall -Wextra -pedantic
2862
)
2963
endif()
3064

31-
# --------------------------------------------
65+
66+
# -----------------------------------------------------------------
67+
# Catch2
3268

3369
# https://github.com/catchorg/Catch2/blob/devel/docs/configuration.md
3470
set(CATCH_CONFIG_FAST_COMPILE ON)
@@ -44,28 +80,32 @@ FetchContent_Declare(
4480
FetchContent_MakeAvailable(Catch2)
4581

4682
set_target_properties(Catch2 PROPERTIES CXX_EXTENSIONS OFF)
83+
set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "_deps")
84+
4785
target_compile_definitions(Catch2 PUBLIC DO_NOT_USE_WMAIN)
4886
target_link_libraries(Catch2 PRIVATE iris_cxx_test_external)
4987
target_link_libraries(Catch2WithMain PRIVATE iris_cxx_test_external)
5088

5189
target_link_libraries(iris_cxx_test INTERFACE Catch2::Catch2WithMain)
5290

53-
# --------------------------------------------
91+
92+
# -----------------------------------------------------------------
93+
# Common CMake utilities for testing
5494

5595
function(iris_define_test_headers test_name)
5696
target_sources(${test_name}_test PRIVATE FILE_SET HEADERS FILES ${ARGN})
5797
endfunction()
5898

5999
function(iris_define_test test_name)
60100
add_executable(${test_name}_test ${ARGN})
101+
target_include_directories(${test_name}_test PRIVATE ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
61102
target_include_directories(${test_name}_test PRIVATE ${CMAKE_CURRENT_LIST_DIR})
62-
iris_define_test_headers(${test_name} test.hpp)
63103
set_target_properties(${test_name}_test PROPERTIES CXX_EXTENSIONS OFF)
64104

65105
if(MSVC)
66106
# Prevent "Warning: Conflicting <Type> entries detected" error
67107
set_source_files_properties(
68-
"${PROJECT_SOURCE_DIR}/iris.natvis"
108+
"${IRIS_ROOT}/iris.natvis"
69109
TARGET_DIRECTORY ${test_name}_test
70110
PROPERTIES VS_SETTINGS "ExcludedFromBuild=true"
71111
)
@@ -83,12 +123,30 @@ function(iris_define_tests)
83123
endforeach()
84124
endfunction()
85125

86-
# --------------------------------------------
126+
function(iris_define_sub_tests prefix)
127+
foreach(test_name IN LISTS ARGN)
128+
iris_define_test(${prefix}_${test_name} ${test_name}.cpp)
129+
set_target_properties(${prefix}_${test_name}_test PROPERTIES FOLDER "test/${prefix}")
130+
endforeach()
131+
endfunction()
132+
133+
134+
# -----------------------------------------------------------------
135+
# Iris tests
87136

88137
if(PROJECT_IS_TOP_LEVEL)
89138
add_subdirectory(rvariant)
90139

91-
iris_define_tests(
140+
set(
141+
IRIS_TEST_IRIS_TESTS
92142
type_traits
143+
core
144+
indirect
93145
)
146+
147+
iris_define_sub_tests(iris ${IRIS_TEST_IRIS_TESTS})
148+
149+
foreach(test_name IN LISTS IRIS_TEST_IRIS_TESTS)
150+
iris_define_test_headers(iris_${test_name} iris_test.hpp)
151+
endforeach()
94152
endif()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: MIT
22

3+
#include "iris_test.hpp"
4+
35
#include <iris/type_traits.hpp>
46
#include <iris/requirements.hpp>
57
#include <iris/compare.hpp>
68

7-
#include <catch2/catch_test_macros.hpp>
8-
99
#include <concepts>
1010
#include <utility>
1111
#include <type_traits>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT
22

3-
#include "iris/indirect.hpp"
3+
#include "iris_test.hpp"
44

5-
#include <catch2/catch_test_macros.hpp>
5+
#include <iris/indirect.hpp>
66

77
namespace unit_test {
88

test/test.hpp renamed to test/iris_test.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef IRIS_TEST_TEST_HPP
2-
#define IRIS_TEST_TEST_HPP
1+
#ifndef IRIS_TEST_IRIS_TEST_HPP
2+
#define IRIS_TEST_IRIS_TEST_HPP
33

44
// SPDX-License-Identifier: MIT
55

test/rvariant/CMakeLists.txt

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,18 @@
11
# SPDX-License-Identifier: MIT
22

3-
add_executable(
4-
iris_rvariant_test
5-
6-
# Independent Polyfill
7-
indirect_test.cpp
8-
9-
# Independent language core / exposition-only utils
10-
core_test.cpp
11-
12-
# Main library
13-
rvariant_test.cpp
14-
many_alternatives_32_test.cpp
15-
get_visit_test.cpp
16-
flexible_test.cpp
17-
recursive_wrapper_test.cpp
18-
truly_recursive_test.cpp
19-
io_test.cpp
20-
)
21-
22-
if(MSVC)
23-
target_sources(iris_rvariant_test PRIVATE ../cpp.hint)
24-
endif()
25-
26-
target_sources(
27-
iris_rvariant_test
28-
PRIVATE FILE_SET HEADERS FILES
29-
rvariant_test.hpp
3+
set(
4+
IRIS_TEST_RVARIANT_TESTS
5+
rvariant
6+
many_alternatives_32
7+
get_visit
8+
flexible
9+
recursive_wrapper
10+
truly_recursive
11+
io
3012
)
3113

32-
set_target_properties(
33-
iris_rvariant_test
34-
PROPERTIES CXX_EXTENSIONS OFF
35-
)
36-
37-
if(MSVC)
38-
target_compile_options(
39-
Catch2
40-
PUBLIC
41-
/wd5072 # ASan intentionally enabled on Release build
42-
/fsanitize=address
43-
PRIVATE
44-
/analyze-
45-
)
46-
target_link_options(
47-
Catch2
48-
PUBLIC
49-
/ignore:4302 # ASan intentionally enabled on Release build
50-
/INCREMENTAL:NO # required for ASan
51-
)
52-
53-
target_compile_options(
54-
iris_rvariant_test
55-
PUBLIC
56-
/W4 /analyze /analyze:external-
57-
/fsanitize=address
58-
)
59-
else()
60-
target_compile_options(
61-
iris_rvariant_test
62-
PUBLIC
63-
-fsanitize=undefined,address
64-
)
65-
target_link_options(
66-
iris_rvariant_test
67-
PUBLIC
68-
-fsanitize=undefined,address
69-
)
70-
endif()
71-
72-
target_link_libraries(
73-
iris_rvariant_test
74-
PRIVATE Iris::Iris Catch2::Catch2WithMain
75-
)
14+
iris_define_sub_tests(rvariant ${IRIS_TEST_RVARIANT_TESTS})
7615

77-
add_test(NAME iris_rvariant_test COMMAND iris_rvariant_test)
16+
foreach(test_name IN LISTS IRIS_TEST_RVARIANT_TESTS)
17+
iris_define_test_headers(rvariant_${test_name} iris_rvariant_test.hpp)
18+
endforeach()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT
22

3-
#include "rvariant_test.hpp"
3+
#include "iris_rvariant_test.hpp"
44

5-
#include "iris/rvariant.hpp"
5+
#include <iris/rvariant.hpp>
66

77
#include <type_traits>
88
#include <utility>
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// SPDX-License-Identifier: MIT
1+
// SPDX-License-Identifier: MIT
22

3-
#include "rvariant_test.hpp"
3+
#include "iris_rvariant_test.hpp"
44

5-
#include "iris/rvariant.hpp"
6-
7-
#include "iris/type_traits.hpp"
8-
9-
#include <catch2/catch_test_macros.hpp>
5+
#include <iris/rvariant.hpp>
6+
#include <iris/type_traits.hpp>
107

118
#include <concepts>
129
#include <string_view>
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// SPDX-License-Identifier: MIT
1+
// SPDX-License-Identifier: MIT
2+
3+
#include "iris_rvariant_test.hpp"
24

35
#include <iostream>
46

@@ -37,15 +39,11 @@ struct NonStreamable {};
3739

3840
} // anonymous global
3941

40-
#include "iris/io_fwd.hpp" // this finds `operator<<` in the global ns
41-
42-
#include "rvariant_test.hpp"
43-
44-
#include "iris/rvariant/rvariant.hpp"
45-
#include "iris/rvariant/rvariant_io.hpp"
46-
#include "iris/rvariant/recursive_wrapper.hpp"
42+
#include <iris/io_fwd.hpp> // this finds `operator<<` in the global ns
4743

48-
#include <catch2/catch_test_macros.hpp>
44+
#include <iris/rvariant/rvariant.hpp>
45+
#include <iris/rvariant/rvariant_io.hpp>
46+
#include <iris/rvariant/recursive_wrapper.hpp>
4947

5048
#include <string>
5149
#include <sstream>

0 commit comments

Comments
 (0)