Skip to content

Commit

Permalink
Add a simple ctest
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Sep 8, 2023
1 parent 6c4ce2c commit 0a1bf9f
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Basic tests
add_test(NAME version
COMMAND ${CMAKE_Fypp_COMPILER} --version)

# Integration tests
add_subdirectory(cmake)
73 changes: 73 additions & 0 deletions test/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_dir>
[TEST_NAME <name>]
[TEST_COMMAND <args> ...]
[BUILD_OPTIONS <args> ...])
```

## Options
`<test_dir>`
Path to the test CMake project

`TEST_NAME` [Default `<test_dir>`]
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
- <inv:cmake:std:label:build and test mode>

]===]


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 ()
13 changes: 13 additions & 0 deletions test/cmake/module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 ()
15 changes: 15 additions & 0 deletions test/cmake/module/fypp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 $<TARGET_FILE:exec>)
1 change: 1 addition & 0 deletions test/cmake/module/fypp/src
3 changes: 3 additions & 0 deletions test/cmake/src/test_bare.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module test_bare_m
integer :: a
end module test_bare_m
3 changes: 3 additions & 0 deletions test/cmake/src/test_exec.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
program test
print *, "hello"
end program test
3 changes: 3 additions & 0 deletions test/cmake/src/test_obj.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module test_obj_m
integer :: a
end module test_obj_m
3 changes: 3 additions & 0 deletions test/cmake/src/test_shared.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module test_shared_m
integer :: a
end module test_shared_m
3 changes: 3 additions & 0 deletions test/cmake/src/test_static.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module test_static_m
integer :: a
end module test_static_m

0 comments on commit 0a1bf9f

Please sign in to comment.