Skip to content

Commit f6e1c09

Browse files
committed
Migrate examples to standalone tests
1 parent 74b8c4a commit f6e1c09

File tree

23 files changed

+356
-182
lines changed

23 files changed

+356
-182
lines changed

cmake/FortunoTestHelpers.cmake

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This file is part of Fortuno.
2+
# Licensed under the BSD-2-Clause Plus Patent license.
3+
# SPDX-License-Identifier: BSD-2-Clause-Patent
4+
5+
function(Fortuno_add_test test)
6+
#[===[.md
7+
# Fortuno_add_test
8+
9+
Internal helper for adding functional tests testing whole CMake projects.
10+
11+
## Synopsis
12+
```cmake
13+
Template_add_test(<name>
14+
[TEST_NAME <test_name>]
15+
)
16+
```
17+
18+
## Options
19+
20+
`<name>`
21+
: Path to the CMake project to be executed relative to `${CMAKE_CURRENT_SOURCE_DIR}`
22+
23+
`TEST_NAME` [Default: `<name>`]
24+
: Name for the test to be used as the ctest name
25+
]===]
26+
27+
set(ARGS_Options)
28+
set(ARGS_OneValue
29+
TEST_NAME
30+
)
31+
set(ARGS_MultiValue)
32+
cmake_parse_arguments(PARSE_ARGV 1 ARGS "${ARGS_Options}" "${ARGS_OneValue}" "${ARGS_MultiValue}")
33+
34+
# Check required/optional arguments
35+
if (ARGC LESS 1)
36+
message(FATAL_ERROR "Missing test name")
37+
endif ()
38+
if (NOT DEFINED ARGS_TEST_NAME)
39+
set(ARGS_TEST_NAME ${test})
40+
endif ()
41+
42+
set(configure_args
43+
-DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER}
44+
)
45+
if (Fortuno_IS_TOP_LEVEL)
46+
list(APPEND configure_args
47+
# Generated Config file point to binary targets until it is installed
48+
-DFortuno_ROOT=${Fortuno_BINARY_DIR}
49+
-DFETCHCONTENT_SOURCE_DIR_FORTUNO=${Template_SOURCE_DIR}
50+
)
51+
endif ()
52+
53+
add_test(NAME ${ARGS_TEST_NAME}
54+
COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/${test}
55+
${CMAKE_CURRENT_BINARY_DIR}/${test}
56+
# Use the same build environment as the current runner
57+
--build-generator "${CMAKE_GENERATOR}"
58+
--build-options ${configure_args}
59+
--test-command ${CMAKE_CTEST_COMMAND}
60+
--test-dir ${CMAKE_CURRENT_BINARY_DIR}/${test}
61+
--output-on-failure
62+
)
63+
endfunction()

config.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ option(FORTUNO_WITH_COARRAY "Fortuno: whether library with coarray interface sho
1515

1616
option(FORTUNO_WITH_TESTS "Fortuno: whether to build test suite" ${PROJECT_IS_TOP_LEVEL})
1717

18-
option(FORTUNO_WITH_EXAMPLES "Fortuno: whether to build example apps" ${PROJECT_IS_TOP_LEVEL})
18+
if (FORTUNO_WITH_EXAMPLES)
19+
message(WARNING
20+
"FORTUNO_WITH_EXAMPLES is deprecated and has no effect. "
21+
"This is now part of the tests"
22+
)
23+
endif ()
1924

2025
option(FORTUNO_INSTALL "Fortuno: Install project" ${PROJECT_IS_TOP_LEVEL})
2126

example/CMakeLists.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.

example/coarray-fpp/CMakeLists.txt

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,44 @@
22
# Licensed under the BSD-2-Clause Plus Patent license.
33
# SPDX-License-Identifier: BSD-2-Clause-Patent
44

5-
list(APPEND CMAKE_MESSAGE_CONTEXT CoarrayFpp)
5+
cmake_minimum_required(VERSION 3.22...3.31)
66

7-
add_library(fortuno_example_coarray_fpp_mylib)
8-
set_target_properties(
9-
fortuno_example_coarray_fpp_mylib PROPERTIES
10-
OUTPUT_NAME mylib
7+
project(coarray-fpp-example
8+
LANGUAGES Fortran
119
)
10+
11+
find_package(Fortuno CONFIG REQUIRED)
12+
13+
# TODO: decouple this from config.cmake setup
14+
# TODO: Do not hardcode the path dependence
15+
# Get the absolute path of the Fortuno repo
16+
cmake_path(SET Fortuno_Source_Dir NORMALIZE "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
17+
include(${Fortuno_Source_Dir}/config.cmake)
18+
19+
add_library(mylib)
1220
target_sources(
13-
fortuno_example_coarray_fpp_mylib PRIVATE
21+
mylib PRIVATE
1422
mylib.f90
1523
)
16-
target_compile_options(fortuno_example_coarray_fpp_mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
17-
target_link_options(fortuno_example_coarray_fpp_mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
24+
target_compile_options(mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
25+
target_link_options(mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
1826

19-
add_executable(fortuno_example_coarray_fpp_testapp)
20-
set_target_properties(
21-
fortuno_example_coarray_fpp_testapp PROPERTIES
22-
OUTPUT_NAME testapp
23-
)
27+
add_executable(testapp)
2428
target_sources(
25-
fortuno_example_coarray_fpp_testapp PRIVATE
29+
testapp PRIVATE
2630
test_simple_fpp.F90
2731
testapp.f90
2832
)
29-
target_compile_options(fortuno_example_coarray_fpp_testapp PRIVATE ${FORTUNO_FFLAGS_FPP})
33+
target_compile_options(testapp PRIVATE ${FORTUNO_FFLAGS_FPP})
3034
target_link_libraries(
31-
fortuno_example_coarray_fpp_testapp PRIVATE
32-
fortuno_example_coarray_fpp_mylib
35+
testapp PRIVATE
36+
mylib
3337
Fortuno::fortuno_coarray
3438
)
35-
target_compile_options(fortuno_example_coarray_fpp_testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
36-
target_link_options(fortuno_example_coarray_fpp_testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
39+
target_compile_options(testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
40+
target_link_options(testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
41+
42+
enable_testing()
43+
add_test(NAME fortuno_test
44+
COMMAND testapp
45+
)

example/coarray-fypp/CMakeLists.txt

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@
22
# Licensed under the BSD-2-Clause Plus Patent license.
33
# SPDX-License-Identifier: BSD-2-Clause-Patent
44

5-
list(APPEND CMAKE_MESSAGE_CONTEXT CoarrayFypp)
5+
cmake_minimum_required(VERSION 3.22...3.31)
66

7-
add_library(fortuno_example_coarray_fypp_mylib)
8-
set_target_properties(
9-
fortuno_example_coarray_fypp_mylib PROPERTIES
10-
OUTPUT_NAME mylib
7+
project(coarray-fypp-example
8+
LANGUAGES Fortran
119
)
10+
11+
find_package(Fortuno CONFIG REQUIRED)
12+
13+
find_program(FYPP fypp)
14+
15+
# TODO: decouple this from config.cmake setup
16+
# TODO: Do not hardcode the path dependence
17+
# Get the absolute path of the Fortuno repo
18+
cmake_path(SET Fortuno_Source_Dir NORMALIZE "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
19+
include(${Fortuno_Source_Dir}/config.cmake)
20+
include(${Fortuno_Source_Dir}/cmake/FortunoHelpers.cmake)
21+
22+
add_library(mylib)
1223
target_sources(
13-
fortuno_example_coarray_fypp_mylib PRIVATE
24+
mylib PRIVATE
1425
mylib.f90
1526
)
16-
target_compile_options(fortuno_example_coarray_fypp_mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
17-
target_link_options(fortuno_example_coarray_fypp_mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
27+
target_compile_options(mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
28+
target_link_options(mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
1829

19-
add_executable(fortuno_example_coarray_fypp_testapp)
20-
set_target_properties(
21-
fortuno_example_coarray_fypp_testapp PROPERTIES
22-
OUTPUT_NAME testapp
23-
)
30+
add_executable(testapp)
2431

2532
set(
2633
fypp-sources
@@ -33,20 +40,25 @@ get_target_property(
3340
INTERFACE_INCLUDE_DIRECTORIES
3441
)
3542
fortuno_preprocess(
36-
${FYPP} "-I${_fortuno_incdir};--file-var-root=${CMAKE_SOURCE_DIR}"
43+
${FYPP} "-I${_fortuno_incdir};--file-var-root=${Fortuno_Source_Dir}"
3744
.fypp .f90
3845
"${fypp-sources}" fypp-f90-sources
3946
)
4047

4148
target_sources(
42-
fortuno_example_coarray_fypp_testapp PRIVATE
49+
testapp PRIVATE
4350
${fypp-f90-sources}
4451
testapp.f90
4552
)
4653
target_link_libraries(
47-
fortuno_example_coarray_fypp_testapp
54+
testapp
4855
PRIVATE
49-
fortuno_example_coarray_fypp_mylib Fortuno::fortuno_coarray
56+
mylib Fortuno::fortuno_coarray
57+
)
58+
target_compile_options(testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
59+
target_link_options(testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
60+
61+
enable_testing()
62+
add_test(NAME fortuno_test
63+
COMMAND testapp
5064
)
51-
target_compile_options(fortuno_example_coarray_fypp_testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
52-
target_link_options(fortuno_example_coarray_fypp_testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})

example/coarray/CMakeLists.txt

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,42 @@
22
# Licensed under the BSD-2-Clause Plus Patent license.
33
# SPDX-License-Identifier: BSD-2-Clause-Patent
44

5-
list(APPEND CMAKE_MESSAGE_CONTEXT Coarray)
5+
cmake_minimum_required(VERSION 3.22...3.31)
66

7-
add_library(fortuno_example_coarray_mylib)
8-
set_target_properties(
9-
fortuno_example_coarray_mylib PROPERTIES
10-
OUTPUT_NAME mylib
7+
project(coarray-example
8+
LANGUAGES Fortran
119
)
10+
11+
find_package(Fortuno CONFIG REQUIRED)
12+
13+
# TODO: decouple this from config.cmake setup
14+
# TODO: Do not hardcode the path dependence
15+
# Get the absolute path of the Fortuno repo
16+
cmake_path(SET Fortuno_Source_Dir NORMALIZE "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
17+
include(${Fortuno_Source_Dir}/config.cmake)
18+
19+
add_library(mylib)
1220
target_sources(
13-
fortuno_example_coarray_mylib PRIVATE
21+
mylib PRIVATE
1422
mylib.f90
1523
)
16-
target_compile_options(fortuno_example_coarray_mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
17-
target_link_options(fortuno_example_coarray_mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
24+
target_compile_options(mylib PRIVATE ${FORTUNO_FFLAGS_COARRAY})
25+
target_link_options(mylib PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
1826

19-
add_executable(fortuno_example_coarray_testapp)
20-
set_target_properties(
21-
fortuno_example_coarray_testapp PROPERTIES
22-
OUTPUT_NAME testapp
23-
)
27+
add_executable(testapp)
2428
target_sources(
25-
fortuno_example_coarray_testapp PRIVATE
29+
testapp PRIVATE
2630
test_simple.f90
2731
testapp.f90
2832
)
2933
target_link_libraries(
30-
fortuno_example_coarray_testapp PRIVATE
31-
fortuno_example_coarray_mylib Fortuno::fortuno_coarray
34+
testapp PRIVATE
35+
mylib Fortuno::fortuno_coarray
36+
)
37+
target_compile_options(testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
38+
target_link_options(testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})
39+
40+
enable_testing()
41+
add_test(NAME fortuno_test
42+
COMMAND testapp
3243
)
33-
target_compile_options(fortuno_example_coarray_testapp PRIVATE ${FORTUNO_FFLAGS_COARRAY})
34-
target_link_options(fortuno_example_coarray_testapp PRIVATE ${FORTUNO_LDFLAGS_COARRAY})

example/mpi-fpp/CMakeLists.txt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,44 @@
22
# Licensed under the BSD-2-Clause Plus Patent license.
33
# SPDX-License-Identifier: BSD-2-Clause-Patent
44

5-
list(APPEND CMAKE_MESSAGE_CONTEXT MpiFpp)
5+
cmake_minimum_required(VERSION 3.22...3.31)
66

7-
add_library(fortuno_example_mpi_fpp_mylib)
8-
set_target_properties(
9-
fortuno_example_mpi_fpp_mylib PROPERTIES
10-
OUTPUT_NAME mylib
7+
project(mpi-fpp-example
8+
LANGUAGES Fortran
119
)
10+
11+
find_package(MPI MODULE COMPONENTS Fortran)
12+
find_package(Fortuno CONFIG REQUIRED)
13+
14+
# TODO: decouple this from config.cmake setup
15+
# TODO: Do not hardcode the path dependence
16+
# Get the absolute path of the Fortuno repo
17+
cmake_path(SET Fortuno_Source_Dir NORMALIZE "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
18+
include(${Fortuno_Source_Dir}/config.cmake)
19+
20+
add_library(mylib)
1221
target_sources(
13-
fortuno_example_mpi_fpp_mylib PRIVATE
22+
mylib PRIVATE
1423
mylib.f90
1524
)
16-
target_link_libraries(fortuno_example_mpi_fpp_mylib PRIVATE MPI::MPI_Fortran)
25+
target_link_libraries(mylib PRIVATE MPI::MPI_Fortran)
1726

18-
add_executable(fortuno_example_mpi_fpp_testapp)
19-
set_target_properties(
20-
fortuno_example_mpi_fpp_testapp PROPERTIES
21-
OUTPUT_NAME testapp
22-
)
27+
add_executable(testapp)
2328
target_sources(
24-
fortuno_example_mpi_fpp_testapp PRIVATE
29+
testapp PRIVATE
2530
test_simple_fpp.F90
2631
testapp.f90
2732
)
28-
target_compile_options(fortuno_example_mpi_fpp_testapp PRIVATE ${FORTUNO_FFLAGS_FPP})
33+
target_compile_options(testapp PRIVATE ${FORTUNO_FFLAGS_FPP})
2934
target_link_libraries(
30-
fortuno_example_mpi_fpp_testapp
35+
testapp
3136
PRIVATE
32-
fortuno_example_mpi_fpp_mylib
37+
mylib
3338
Fortuno::fortuno_mpi
3439
MPI::MPI_Fortran
3540
)
41+
42+
enable_testing()
43+
add_test(NAME fortuno_test
44+
COMMAND testapp
45+
)

0 commit comments

Comments
 (0)