From 44351756e5e76fca0ece9b8e9744a702ee56ca21 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Wed, 9 May 2018 21:36:59 +0200 Subject: [PATCH] plugging Catch2 examples within CMake --- CMakeLists.txt | 12 ++++++++++++ tests/CMakeLists.txt | 22 ++++++++++++++++++++++ tests/example.cpp | 19 +++++++++++++++++++ tests/example2.cpp | 19 +++++++++++++++++++ tests/main.cpp | 9 +++++++++ 5 files changed, 81 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/example.cpp create mode 100644 tests/example2.cpp create mode 100644 tests/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d90ab4a1..8d76b3f97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,18 @@ include_directories(src/scheme) include_directories(src/experimental) + +# Pastis tests + +set(CATCH_MODULE_PATH "${PASTIS_SOURCE_DIR}/packages/Catch2") +set(CATCH_INCLUDE_PATH "${CATCH_MODULE_PATH}/single_include") + +include("${CATCH_MODULE_PATH}/contrib/ParseAndAddCatchTests.cmake") +add_subdirectory("${CATCH_MODULE_PATH}") + +add_subdirectory(tests) +enable_testing() + # ----------------------------------------------------- link_libraries("-rdynamic") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..f62f6d02e --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,22 @@ +include_directories("${CATCH_INCLUDE_PATH}") + +#set(EXECUTABLE_OUTPUT_PATH ${PASTIS_BINARY_DIR}) +add_executable (unit_tests + main.cpp + example.cpp + example2.cpp) + +target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) +target_link_libraries (unit_tests Catch) + +enable_testing() + +#parse catch tests +ParseAndAddCatchTests (unit_tests) + +#add_dependencies(check +# DEPENDS exec_tests) + +add_custom_target(check + COMMAND unit_tests + DEPENDS unit_tests) diff --git a/tests/example.cpp b/tests/example.cpp new file mode 100644 index 000000000..0cbc903b5 --- /dev/null +++ b/tests/example.cpp @@ -0,0 +1,19 @@ +#include <catch.hpp> + +TEST_CASE("Test1", "[unit]") { + int a = 1; + int b = 2; + REQUIRE(a == b); +} + +TEST_CASE("Test2") { + int a = 2; + int b = 2; + REQUIRE(a == b); +} + +TEST_CASE("Test3", "[a][b][c]") { + int a = 1; + int b = 2; + REQUIRE(a != b); +} diff --git a/tests/example2.cpp b/tests/example2.cpp new file mode 100644 index 000000000..076fa5840 --- /dev/null +++ b/tests/example2.cpp @@ -0,0 +1,19 @@ +#include <catch.hpp> + +TEST_CASE("Test5", "[unit]") { + int a = 1; + int b = 2; + REQUIRE(a+1 == b); +} + +TEST_CASE("Test6", "[a]") { + int a = 2; + int b = 2; + REQUIRE(a == b); +} + +TEST_CASE("Test7", "[a][b][c]") { + int a = 1; + int b = 2; + REQUIRE(a != b); +} diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 000000000..7253fe66f --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,9 @@ +#define CATCH_CONFIG_MAIN +#include <catch.hpp> +// #define CATCH_CONFIG_RUNNER +// #include <catch.hpp> + +// int main(int argc, char* argv[]) { +// auto result = Catch::Session().run(argc, argv); +// return (result < 0xff ? result : 0xff); +// } -- GitLab