diff --git a/bs/setup.cmake b/bs/setup.cmake index 064791f548695ab5afe803735651b23c5413d1d8..0e843612f54aa8e58e69dbd5d5bcbaf562d14e8a 100644 --- a/bs/setup.cmake +++ b/bs/setup.cmake @@ -110,7 +110,7 @@ endif() # Dev : Setup Targets for Linting # -------------------------------------------------------------------------------------------------- if(DIAGNOSTIC_LINTING) - set(TORA_CLANG_TIDY_PASSTHROUGH "-DZELL_RUN_CLANG_TIDY") + set(TORA_CLANG_TIDY_PASSTHROUGH "-DMOL_COMPILE_TEST_DISABLE") find_package(tora REQUIRED COMPONENTS clang-tidy) add_custom_target(diagnostic.linting) add_dependencies(diagnostic.linting tora.clang-tidy) diff --git a/src/cpp/include/mol/compile_test.hpp b/src/cpp/include/mol/compile_test.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fc9fd4beda523e99d413884942e6a2328e78c007 --- /dev/null +++ b/src/cpp/include/mol/compile_test.hpp @@ -0,0 +1,22 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#ifndef MOL_COMPILE_TEST_HPP +#define MOL_COMPILE_TEST_HPP + +#include <mol/detail/compile_test.hpp> +#include <mol/detail/test_name.hpp> +#include <type_traits> + +#ifndef MOL_COMPILE_TEST_DISABLE +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_COMPILE_TEST(condition) \ + MOL_DETAIL_COMPILE_TEST_IMPL(MOL_DETAIL_TEST_NAME(__COUNTER__), condition) +#else +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_COMPILE_TEST(condition) \ + MOL_DETAIL_COMPILE_TEST_DUMMY_IMPL(MOL_DETAIL_TEST_NAME(__COUNTER__), condition) +#endif +#endif // MOL_COMPILE_TEST_HPP diff --git a/src/cpp/include/mol/dependent_false.hpp b/src/cpp/include/mol/dependent_false.hpp new file mode 100644 index 0000000000000000000000000000000000000000..098f86fca5dff625c59df6df0b61bd00d12b4fec --- /dev/null +++ b/src/cpp/include/mol/dependent_false.hpp @@ -0,0 +1,23 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#ifndef MOL_DEPENDENT_FALSE_HPP +#define MOL_DEPENDENT_FALSE_HPP + +#include <mol/detail/dependent_false.hpp> +#include <utility> + +namespace mol { +template <class T> +struct dependent_false : std::false_type {}; + +template <> +struct dependent_false<detail::dependent_false_dummy_class> : std::true_type {}; + +template <typename T> +constexpr inline auto dependent_false_v = dependent_false<T>::value; +} // namespace mol + +#endif // MOL_DEPENDENT_FALSE_HPP diff --git a/src/cpp/include/mol/detail/compile_test.hpp b/src/cpp/include/mol/detail/compile_test.hpp new file mode 100644 index 0000000000000000000000000000000000000000..06db49d5ec967c6b8cef8a8648cda3614afa4feb --- /dev/null +++ b/src/cpp/include/mol/detail/compile_test.hpp @@ -0,0 +1,32 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#ifndef MOL_DETAIL_COMPILE_TEST_HPP +#define MOL_DETAIL_COMPILE_TEST_HPP + +#include <mol/detail/test_name.hpp> + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_DETAIL_COMPILE_TEST_IMPL(test_name, condition) \ + template <typename T, bool b, typename std::enable_if_t<!b>* = nullptr> \ + void test_name() \ + { \ + } \ + template <typename T, bool b, typename std::enable_if_t<b>* = nullptr> \ + void test_name(); \ + void test_name_##instantiate(); \ + void test_name_##instantiate() \ + { \ + MOL_DETAIL_TEST_ID(test_name)<int, condition>(); \ + } \ + template <typename T, bool b, typename std::enable_if_t<b>*> \ + void test_name() + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_DETAIL_COMPILE_TEST_DUMMY_IMPL(test_name, condition) \ + template <typename T, bool b, typename std::enable_if_t<b>* = nullptr> \ + void test_name() + +#endif // MOL_DETAIL_COMPILE_TEST_HPP diff --git a/src/cpp/include/mol/detail/dependent_false.hpp b/src/cpp/include/mol/detail/dependent_false.hpp new file mode 100644 index 0000000000000000000000000000000000000000..952211fcb93b52db2ef25e6a4e08d81948f1d952 --- /dev/null +++ b/src/cpp/include/mol/detail/dependent_false.hpp @@ -0,0 +1,13 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#ifndef MOL_DETAIL_DEPENDENT_FALSE_HPP +#define MOL_DETAIL_DEPENDENT_FALSE_HPP + +namespace mol::detail { +class dependent_false_dummy_class {}; +} // namespace mol::detail + +#endif // MOL_DETAIL_DEPENDENT_FALSE_HPP diff --git a/src/cpp/include/mol/detail/test_name.hpp b/src/cpp/include/mol/detail/test_name.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f9e0ed0204cfb40612ebf3102faf4735ef141416 --- /dev/null +++ b/src/cpp/include/mol/detail/test_name.hpp @@ -0,0 +1,18 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#ifndef MOL_DETAIL_TEST_NAME_HPP +#define MOL_DETAIL_TEST_NAME_HPP + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_DETAIL_TEST_ID(s) s +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_DETAIL_TEST_NAME_IMPL(s) testzell_compile_test_##s +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_DETAIL_TEST_NAME_PREMACRO(s) MOL_DETAIL_TEST_NAME_IMPL(s) +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define MOL_DETAIL_TEST_NAME(s) MOL_DETAIL_TEST_NAME_PREMACRO(__COUNTER__) + +#endif // MOL_DETAIL_TEST_NAME_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2fe19124b4568d7a8b9fc4094f1adc6806fea9b6..b8e321c520b91b6d1d1c1ed2e84e6025e2dc4aba 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,15 +13,22 @@ target_link_libraries(libtestzell PUBLIC zell::libzell) add_subdirectory(common) # ------------------------------------------------------------------------------ -# Adding Tests +# Add Compile Tests # ------------------------------------------------------------------------------ - tora_surrogate_check(libtestzell) if(BUILD_SOURCE) tora_surrogate_check(libzell) endif() +add_subdirectory(compile) + + + +# ------------------------------------------------------------------------------ +# Adding Runtime Tests +# ------------------------------------------------------------------------------ + add_subdirectory(smoke) add_subdirectory(unit) add_subdirectory(integration) diff --git a/test/compile/CMakeLists.txt b/test/compile/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec3565accbcfb65535e1b6be6af8215b162315c7 --- /dev/null +++ b/test/compile/CMakeLists.txt @@ -0,0 +1,6 @@ +# -------------------------------------------------------------------------------------------------- +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +# -------------------------------------------------------------------------------------------------- + +add_subdirectory(cpp) diff --git a/test/compile/cpp/CMakeLists.txt b/test/compile/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0a6b57edcbd835b147079c29839f94545994fd7 --- /dev/null +++ b/test/compile/cpp/CMakeLists.txt @@ -0,0 +1,6 @@ +# -------------------------------------------------------------------------------------------------- +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de> +# -------------------------------------------------------------------------------------------------- + +add_compile_test_directory(mol libtestzell cpp unit_test) diff --git a/test/compile/cpp/mol/false_false.t.cpp b/test/compile/cpp/mol/false_false.t.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4913ea5be83c59315d8110e7de8378e2b9db9a85 --- /dev/null +++ b/test/compile/cpp/mol/false_false.t.cpp @@ -0,0 +1,27 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2023 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#include <mol/compile_test.hpp> +#include <mol/dependent_false.hpp> + +template <typename T, bool b, typename std::enable_if<b>::type* = nullptr> +void foo() +{ +} + +template <typename T, bool b, typename std::enable_if<!b>::type* = nullptr> +void foo() +{ + static_assert(mol::dependent_false_v<T>, "Not integral"); +} + +MOL_COMPILE_TEST(false) +{ + foo<int, false>(); +} + +auto main() -> int +{ +} diff --git a/test/compile/cpp/mol/false_true.t.cpp b/test/compile/cpp/mol/false_true.t.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93b4ee9b277cac7fd702b7fcae32b0408334ead0 --- /dev/null +++ b/test/compile/cpp/mol/false_true.t.cpp @@ -0,0 +1,27 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2023 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- + +#include <mol/compile_test.hpp> +#include <mol/dependent_false.hpp> + +template <typename T, bool b, typename std::enable_if<b>::type* = nullptr> +void foo() +{ +} + +template <typename T, bool b, typename std::enable_if<!b>::type* = nullptr> +void foo() +{ + static_assert(mol::dependent_false_v<T>, "Not integral"); +} + +MOL_COMPILE_TEST(false) +{ + foo<int, true>(); +} + +auto main() -> int +{ +} diff --git a/test/compile/cpp/mol/true_false.fail.t.cpp b/test/compile/cpp/mol/true_false.fail.t.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ad90307593ba1f75f2fe3d0289775dcf9afc7a3 --- /dev/null +++ b/test/compile/cpp/mol/true_false.fail.t.cpp @@ -0,0 +1,26 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2023 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- +#include <mol/compile_test.hpp> +#include <mol/dependent_false.hpp> + +template <typename T, bool b, typename std::enable_if<b>::type* = nullptr> +void foo() +{ +} + +template <typename T, bool b, typename std::enable_if<!b>::type* = nullptr> +void foo() +{ + static_assert(mol::dependent_false_v<T>, "Not integral"); +} + +MOL_COMPILE_TEST(true) +{ + foo<int, false>(); +} + +auto main() -> int +{ +} diff --git a/test/compile/cpp/mol/true_true.t.cpp b/test/compile/cpp/mol/true_true.t.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30194011d969740cf957fc0574037e7e75380f98 --- /dev/null +++ b/test/compile/cpp/mol/true_true.t.cpp @@ -0,0 +1,26 @@ +// ------------------------------------------------------------------------------------------------- +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: (C) 2023 Jayesh Badwaik <j.badwaik@fz-juelich.de> +// ------------------------------------------------------------------------------------------------- +#include <mol/compile_test.hpp> +#include <mol/dependent_false.hpp> + +template <typename T, bool b, typename std::enable_if<b>::type* = nullptr> +void foo() +{ +} + +template <typename T, bool b, typename std::enable_if<!b>::type* = nullptr> +void foo() +{ + static_assert(mol::dependent_false_v<T>, "Not integral"); +} + +MOL_COMPILE_TEST(true) +{ + foo<int, true>(); +} + +auto main() -> int +{ +}