Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ endif()

project(iris VERSION 0.0.1 LANGUAGES CXX)

if(NOT DEFINED IRIS_ROOT)
set(IRIS_ROOT "${CMAKE_CURRENT_LIST_DIR}")
endif()

# -----------------------------------------------------------------
# Global settings
Expand Down Expand Up @@ -45,8 +48,8 @@ if(MSVC)
target_sources(
iris
PRIVATE
"${PROJECT_SOURCE_DIR}/cpp.hint"
"${PROJECT_SOURCE_DIR}/iris.natvis"
"${CMAKE_CURRENT_LIST_DIR}/cpp.hint"
"${CMAKE_CURRENT_LIST_DIR}/iris.natvis"
)

target_link_libraries(iris PUBLIC _iris_cxx_common)
Expand Down
4 changes: 2 additions & 2 deletions iris.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<AutoVisualizer
xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.microsoft.com/vstudio/debugger/natvis/2010 file:///C:/Program%20Files/Microsoft%20Visual%20Studio/2022/Community/Xml/Schemas/1033/natvis.xsd"
xsi:schemaLocation="http://schemas.microsoft.com/vstudio/debugger/natvis/2010 file:///C:/Program%20Files/Microsoft%20Visual%20Studio/18/Community/Xml/Schemas/1033/natvis.xsd"
>
<Type Name="iris::indirect&lt;*&gt;">
<Type Name="iris::detail::indirect_base&lt;*&gt;">
<SmartPointer Usage="Minimal">ptr_</SmartPointer>
<DisplayString Condition="ptr_ == 0">[valueless_after_move]</DisplayString>
<DisplayString Condition="ptr_ != 0">{*ptr_}</DisplayString>
Expand Down
76 changes: 67 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,70 @@
# SPDX-License-Identifier: MIT

# For Iris-specific tests.
# -----------------------------------------------------------------
# Setup the basic targets

# For internal common settings
add_library(_iris_cxx_test_common INTERFACE)
set_target_properties(_iris_cxx_test_common PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(_iris_cxx_test_common INTERFACE _iris_cxx_common)


# For Iris-specific tests
add_library(iris_cxx_test INTERFACE)
set_target_properties(iris_cxx_test PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(iris_cxx_test INTERFACE _iris_cxx_common)
target_link_libraries(iris_cxx_test INTERFACE _iris_cxx_test_common)

# For external libraries. Excludes strict warning, etc.
add_library(iris_cxx_test_external INTERFACE)
set_target_properties(iris_cxx_test_external PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(iris_cxx_test_external INTERFACE _iris_cxx_common)
target_link_libraries(iris_cxx_test_external INTERFACE _iris_cxx_test_common)

if(MSVC)
target_compile_options(
_iris_cxx_test_common
INTERFACE
/wd5072 # ASan intentionally enabled on Release build
/fsanitize=address
)
target_link_options(
_iris_cxx_test_common
INTERFACE
/ignore:4302 # ASan intentionally enabled on Release build
/INCREMENTAL:NO # required for ASan
)

target_compile_options(
iris_cxx_test
INTERFACE /W4 /analyze /analyze:external-
)

target_compile_options(
iris_cxx_test_external
INTERFACE /analyze-
)

else() # non-MSVC
target_compile_options(
_iris_cxx_test_common
INTERFACE
-fsanitize=undefined,address
)
target_link_options(
_iris_cxx_test_common
INTERFACE
-fsanitize=undefined,address
)

target_compile_options(
iris_cxx_test
INTERFACE
-Wall -Wextra -pedantic
)
endif()

# --------------------------------------------

# -----------------------------------------------------------------
# Catch2

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

set_target_properties(Catch2 PROPERTIES CXX_EXTENSIONS OFF)
set_target_properties(Catch2 Catch2WithMain PROPERTIES FOLDER "_deps")

target_compile_definitions(Catch2 PUBLIC DO_NOT_USE_WMAIN)
target_link_libraries(Catch2 PRIVATE iris_cxx_test_external)
target_link_libraries(Catch2WithMain PRIVATE iris_cxx_test_external)

target_link_libraries(iris_cxx_test INTERFACE Catch2::Catch2WithMain)

# --------------------------------------------

# -----------------------------------------------------------------
# Common CMake utilities for testing

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

function(iris_define_test test_name)
add_executable(${test_name}_test ${ARGN})
target_include_directories(${test_name}_test PRIVATE ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
target_include_directories(${test_name}_test PRIVATE ${CMAKE_CURRENT_LIST_DIR})
iris_define_test_headers(${test_name} test.hpp)
set_target_properties(${test_name}_test PROPERTIES CXX_EXTENSIONS OFF)

if(MSVC)
# Prevent "Warning: Conflicting <Type> entries detected" error
set_source_files_properties(
"${PROJECT_SOURCE_DIR}/iris.natvis"
"${IRIS_ROOT}/iris.natvis"
TARGET_DIRECTORY ${test_name}_test
PROPERTIES VS_SETTINGS "ExcludedFromBuild=true"
)
Expand All @@ -83,12 +123,30 @@ function(iris_define_tests)
endforeach()
endfunction()

# --------------------------------------------
function(iris_define_sub_tests prefix)
foreach(test_name IN LISTS ARGN)
iris_define_test(${prefix}_${test_name} ${test_name}.cpp)
set_target_properties(${prefix}_${test_name}_test PROPERTIES FOLDER "test/${prefix}")
endforeach()
endfunction()


# -----------------------------------------------------------------
# Iris tests

if(PROJECT_IS_TOP_LEVEL)
add_subdirectory(rvariant)

iris_define_tests(
set(
IRIS_TEST_IRIS_TESTS
type_traits
core
indirect
)

iris_define_sub_tests(iris ${IRIS_TEST_IRIS_TESTS})

foreach(test_name IN LISTS IRIS_TEST_IRIS_TESTS)
iris_define_test_headers(iris_${test_name} iris_test.hpp)
endforeach()
endif()
4 changes: 2 additions & 2 deletions test/rvariant/core_test.cpp → test/core.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT

#include "iris_test.hpp"

#include <iris/type_traits.hpp>
#include <iris/requirements.hpp>
#include <iris/compare.hpp>

#include <catch2/catch_test_macros.hpp>

#include <concepts>
#include <utility>
#include <type_traits>
Expand Down
4 changes: 2 additions & 2 deletions test/rvariant/indirect_test.cpp → test/indirect.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

#include "iris/indirect.hpp"
#include "iris_test.hpp"

#include <catch2/catch_test_macros.hpp>
#include <iris/indirect.hpp>

namespace unit_test {

Expand Down
4 changes: 2 additions & 2 deletions test/test.hpp → test/iris_test.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef IRIS_TEST_TEST_HPP
#define IRIS_TEST_TEST_HPP
#ifndef IRIS_TEST_IRIS_TEST_HPP
#define IRIS_TEST_IRIS_TEST_HPP

// SPDX-License-Identifier: MIT

Expand Down
85 changes: 13 additions & 72 deletions test/rvariant/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,77 +1,18 @@
# SPDX-License-Identifier: MIT

add_executable(
iris_rvariant_test

# Independent Polyfill
indirect_test.cpp

# Independent language core / exposition-only utils
core_test.cpp

# Main library
rvariant_test.cpp
many_alternatives_32_test.cpp
get_visit_test.cpp
flexible_test.cpp
recursive_wrapper_test.cpp
truly_recursive_test.cpp
io_test.cpp
)

if(MSVC)
target_sources(iris_rvariant_test PRIVATE ../cpp.hint)
endif()

target_sources(
iris_rvariant_test
PRIVATE FILE_SET HEADERS FILES
rvariant_test.hpp
set(
IRIS_TEST_RVARIANT_TESTS
rvariant
many_alternatives_32
get_visit
flexible
recursive_wrapper
truly_recursive
io
)

set_target_properties(
iris_rvariant_test
PROPERTIES CXX_EXTENSIONS OFF
)

if(MSVC)
target_compile_options(
Catch2
PUBLIC
/wd5072 # ASan intentionally enabled on Release build
/fsanitize=address
PRIVATE
/analyze-
)
target_link_options(
Catch2
PUBLIC
/ignore:4302 # ASan intentionally enabled on Release build
/INCREMENTAL:NO # required for ASan
)

target_compile_options(
iris_rvariant_test
PUBLIC
/W4 /analyze /analyze:external-
/fsanitize=address
)
else()
target_compile_options(
iris_rvariant_test
PUBLIC
-fsanitize=undefined,address
)
target_link_options(
iris_rvariant_test
PUBLIC
-fsanitize=undefined,address
)
endif()

target_link_libraries(
iris_rvariant_test
PRIVATE Iris::Iris Catch2::Catch2WithMain
)
iris_define_sub_tests(rvariant ${IRIS_TEST_RVARIANT_TESTS})

add_test(NAME iris_rvariant_test COMMAND iris_rvariant_test)
foreach(test_name IN LISTS IRIS_TEST_RVARIANT_TESTS)
iris_define_test_headers(rvariant_${test_name} iris_rvariant_test.hpp)
endforeach()
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

#include "rvariant_test.hpp"
#include "iris_rvariant_test.hpp"

#include "iris/rvariant.hpp"
#include <iris/rvariant.hpp>

#include <type_traits>
#include <utility>
Expand Down
11 changes: 4 additions & 7 deletions test/rvariant/get_visit_test.cpp → test/rvariant/get_visit.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT

#include "rvariant_test.hpp"
#include "iris_rvariant_test.hpp"

#include "iris/rvariant.hpp"

#include "iris/type_traits.hpp"

#include <catch2/catch_test_macros.hpp>
#include <iris/rvariant.hpp>
#include <iris/type_traits.hpp>

#include <concepts>
#include <string_view>
Expand Down
16 changes: 7 additions & 9 deletions test/rvariant/io_test.cpp → test/rvariant/io.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT

#include "iris_rvariant_test.hpp"

#include <iostream>

Expand Down Expand Up @@ -37,15 +39,11 @@ struct NonStreamable {};

} // anonymous global

#include "iris/io_fwd.hpp" // this finds `operator<<` in the global ns

#include "rvariant_test.hpp"

#include "iris/rvariant/rvariant.hpp"
#include "iris/rvariant/rvariant_io.hpp"
#include "iris/rvariant/recursive_wrapper.hpp"
#include <iris/io_fwd.hpp> // this finds `operator<<` in the global ns

#include <catch2/catch_test_macros.hpp>
#include <iris/rvariant/rvariant.hpp>
#include <iris/rvariant/rvariant_io.hpp>
#include <iris/rvariant/recursive_wrapper.hpp>

#include <string>
#include <sstream>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef IRIS_RVARIANT_TEST_HPP
#define IRIS_RVARIANT_TEST_HPP
#ifndef IRIS_TEST_IRIS_RVARIANT_TEST_HPP
#define IRIS_TEST_IRIS_RVARIANT_TEST_HPP

// SPDX-License-Identifier: MIT

#include "iris/rvariant/rvariant.hpp" // IWYU pragma: export
#include "iris/format_traits.hpp" // IWYU pragma: export
#include "iris_test.hpp"

#include <catch2/catch_test_macros.hpp> // IWYU pragma: export
#include <iris/rvariant/rvariant.hpp> // IWYU pragma: export
#include <iris/format_traits.hpp> // IWYU pragma: export

#include <iosfwd>
#include <string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT

#if IRIS_CI
#include "rvariant_test.hpp"
#include "iris_rvariant_test.hpp"


namespace unit_test {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT

#include "iris/rvariant/recursive_wrapper.hpp"
#include "iris/rvariant/rvariant.hpp"
#include "iris_rvariant_test.hpp"

#include <catch2/catch_test_macros.hpp>
#include <iris/rvariant/recursive_wrapper.hpp>
#include <iris/rvariant/rvariant.hpp>

#include <string>
#include <string_view>
Expand Down
Loading