From 0a1bf9f38aa81226d39b51008dc940e25eacfff8 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Wed, 5 Jul 2023 21:37:41 +0200 Subject: [PATCH] Add a simple ctest Signed-off-by: Cristian Le --- test/CMakeLists.txt | 4 ++ test/cmake/CMakeLists.txt | 73 +++++++++++++++++++++++++++ test/cmake/module/CMakeLists.txt | 13 +++++ test/cmake/module/fypp/CMakeLists.txt | 15 ++++++ test/cmake/module/fypp/src | 1 + test/cmake/src/test_bare.f90 | 3 ++ test/cmake/src/test_exec.fypp | 3 ++ test/cmake/src/test_obj.fypp | 3 ++ test/cmake/src/test_shared.fypp | 3 ++ test/cmake/src/test_static.fypp | 3 ++ 10 files changed, 121 insertions(+) create mode 100644 test/cmake/CMakeLists.txt create mode 100644 test/cmake/module/CMakeLists.txt create mode 100644 test/cmake/module/fypp/CMakeLists.txt create mode 120000 test/cmake/module/fypp/src create mode 100644 test/cmake/src/test_bare.f90 create mode 100644 test/cmake/src/test_exec.fypp create mode 100644 test/cmake/src/test_obj.fypp create mode 100644 test/cmake/src/test_shared.fypp create mode 100644 test/cmake/src/test_static.fypp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0c099b7..2a2a702 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,2 +1,6 @@ +# Basic tests add_test(NAME version COMMAND ${CMAKE_Fypp_COMPILER} --version) + +# Integration tests +add_subdirectory(cmake) diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt new file mode 100644 index 0000000..26f63b8 --- /dev/null +++ b/test/cmake/CMakeLists.txt @@ -0,0 +1,73 @@ +function(Fypp_add_test test_dir) + #[===[.md: + # Fypp_add_test + + Internal function for adding Fypp cmake tests + + ## Synopsis + ```cmake + Main interface + Fypp_add_test( + [TEST_NAME ] + [TEST_COMMAND ...] + [BUILD_OPTIONS ...]) + ``` + + ## Options + `` + Path to the test CMake project + + `TEST_NAME` [Default ``] + Name of the test + + `TEST_COMMAND` + Additional test commands passed to `ctest --test-command` + + `BUILD_OPTIONS` + CMake configure options passed to the testing cmake + + ## See also + - + + ]===] + + + set(ARGS_Options + ) + set(ARGS_OneValue + TEST_NAME + ) + set(ARGS_MultiValue + BUILD_OPTIONS + TEST_COMMAND + ) + + cmake_parse_arguments(PARSE_ARGV 1 ARGS "${ARGS_Options}" "${ARGS_OneValue}" "${ARGS_MultiValue}") + + # Resolve default options + if (NOT DEFINED ARGS_TEST_NAME) + set(ARGS_TEST_NAME ${test_dir}) + endif () + + add_test(NAME ${ARGS_TEST_NAME} COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${test_dir} + ${CMAKE_CURRENT_BINARY_DIR}/${test_dir} + --build-generator "${CMAKE_GENERATOR}" + --build-options + ${ARGS_BUILD_OPTIONS} + --test-command ${CMAKE_CTEST_COMMAND} --test-dir=${CMAKE_CURRENT_BINARY_DIR}/${test_dir} --no-tests=ignore ${ARGS_TEST_COMMAND} + ) +endfunction() + +set(build_options) +set(test_command) +set(test_dir_rel) +foreach (test_dir IN ITEMS + module +) + block() + cmake_path(APPEND test_dir_rel ${test_dir}) + add_subdirectory(${test_dir}) + endblock() +endforeach () diff --git a/test/cmake/module/CMakeLists.txt b/test/cmake/module/CMakeLists.txt new file mode 100644 index 0000000..eada8c2 --- /dev/null +++ b/test/cmake/module/CMakeLists.txt @@ -0,0 +1,13 @@ +list(APPEND build_options + "-DCMAKE_MODULE_PATH=${PROJECT_SOURCE_DIR}/cmake" +) +foreach (test IN ITEMS fypp) + set(args) + if (build_options) + list(APPEND args BUILD_OPTIONS ${build_options}) + endif () + if (test_command) + list(APPEND args TEST_COMMAND ${test_command}) + endif () + Fypp_add_test(${test_dir_rel}/${test} ${args}) +endforeach () diff --git a/test/cmake/module/fypp/CMakeLists.txt b/test/cmake/module/fypp/CMakeLists.txt new file mode 100644 index 0000000..1bc609b --- /dev/null +++ b/test/cmake/module/fypp/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.15) + +project(test_fypp LANGUAGES Fortran) +include(Fypp) + +Fypp_add_executable(exec src/test_exec.fypp) +#Fypp_add_library(test_obj OBJECT src/test_obj.fypp src/test_bare.f90) +Fypp_add_library(test_static STATIC src/test_static.fypp) +Fypp_add_library(test_shared SHARED src/test_shared.fypp) +add_library(test_obj_other OBJECT) +target_compile_definitions(test_obj_other PRIVATE FOO BAR=some_value) +Fypp_target_sources(test_obj_other PRIVATE src/test_obj.fypp src/test_bare.f90) + +enable_testing() +add_test(NAME test_exec COMMAND $) diff --git a/test/cmake/module/fypp/src b/test/cmake/module/fypp/src new file mode 120000 index 0000000..929cb3d --- /dev/null +++ b/test/cmake/module/fypp/src @@ -0,0 +1 @@ +../../src \ No newline at end of file diff --git a/test/cmake/src/test_bare.f90 b/test/cmake/src/test_bare.f90 new file mode 100644 index 0000000..ee494d3 --- /dev/null +++ b/test/cmake/src/test_bare.f90 @@ -0,0 +1,3 @@ +module test_bare_m + integer :: a +end module test_bare_m diff --git a/test/cmake/src/test_exec.fypp b/test/cmake/src/test_exec.fypp new file mode 100644 index 0000000..64b945e --- /dev/null +++ b/test/cmake/src/test_exec.fypp @@ -0,0 +1,3 @@ +program test + print *, "hello" +end program test diff --git a/test/cmake/src/test_obj.fypp b/test/cmake/src/test_obj.fypp new file mode 100644 index 0000000..e68fd75 --- /dev/null +++ b/test/cmake/src/test_obj.fypp @@ -0,0 +1,3 @@ +module test_obj_m + integer :: a +end module test_obj_m diff --git a/test/cmake/src/test_shared.fypp b/test/cmake/src/test_shared.fypp new file mode 100644 index 0000000..f4f1639 --- /dev/null +++ b/test/cmake/src/test_shared.fypp @@ -0,0 +1,3 @@ +module test_shared_m + integer :: a +end module test_shared_m diff --git a/test/cmake/src/test_static.fypp b/test/cmake/src/test_static.fypp new file mode 100644 index 0000000..c1a546b --- /dev/null +++ b/test/cmake/src/test_static.fypp @@ -0,0 +1,3 @@ +module test_static_m + integer :: a +end module test_static_m