Skip to content

Commit 496cadb

Browse files
committed
add coverage test
1 parent dc98525 commit 496cadb

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

cmake/compilers.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ add_compile_options(
2727
"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:RelWithDebInfo>>:-Wno-maybe-uninitialized>"
2828
)
2929
endif()
30+
31+
# --- code coverage
32+
if(ENABLE_COVERAGE)
33+
include(CodeCoverage)
34+
append_coverage_compiler_flags()
35+
set(COVERAGE_EXCLUDES ${PROJECT_SOURCE_DIR}/src/tests)
36+
endif()

src/tests/CMakeLists.txt

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
set_directory_properties(PROPERTIES LABELS h5fortran)
2+
3+
# --- fundamental HDF5 library check
4+
15
add_executable(test_minimal test_minimal.f90)
26
# even though we're not using h5fortran, we're testing that HDF5 was linked
37
# as part of h5fortran
48
target_link_libraries(test_minimal PRIVATE h5fortran::h5fortran)
59
set_target_properties(test_minimal PROPERTIES LABELS unit)
6-
add_test(NAME h5fortran:minimal COMMAND test_minimal)
7-
set_tests_properties(h5fortran:minimal PROPERTIES
10+
add_test(NAME minimal COMMAND test_minimal)
11+
set_tests_properties(minimal PROPERTIES
812
FIXTURES_SETUP h5lib
913
TIMEOUT 5
1014
LABELS core
1115
)
1216

17+
# --- h5fortran unit tests
1318

1419
function(setup_test names)
1520

@@ -22,24 +27,23 @@ target_link_libraries(test_${name} PRIVATE h5fortran::h5fortran)
2227
target_compile_options(test_${name} PRIVATE "$<$<Fortran_COMPILER_ID:GNU>:-Wno-compare-reals;-Wno-conversion>")
2328
set_target_properties(test_${name} PROPERTIES LABELS unit)
2429

25-
add_test(NAME h5fortran:${name}
30+
add_test(NAME ${name}
2631
COMMAND test_${name}
2732
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
2833
)
29-
set_tests_properties(h5fortran:${name} PROPERTIES
34+
set_tests_properties(${name} PROPERTIES
3035
FIXTURES_REQUIRED h5lib
3136
TIMEOUT 10
3237
)
3338

34-
3539
if(${name} MATCHES ".*fail.*")
36-
set_tests_properties(h5fortran:${name} PROPERTIES
40+
set_tests_properties(${name} PROPERTIES
3741
WILL_FAIL true
3842
LABELS shaky
3943
DISABLED $<OR:$<BOOL:${CI}>,$<NOT:$<BOOL:test_shaky>>>
4044
)
4145
else()
42-
set_tests_properties(h5fortran:${name} PROPERTIES
46+
set_tests_properties(${name} PROPERTIES
4347
LABELS unit
4448
)
4549
endif()
@@ -48,18 +52,25 @@ endforeach()
4852

4953
endfunction(setup_test)
5054

51-
# --- all other tests
55+
# --- setup unit tests
5256
set(testnames array attributes deflate destructor error exist module layout lt scalar shape string
5357
fail_read_size_mismatch fail_read_rank_mismatch fail_nonexist_variable)
5458

5559
setup_test("${testnames}")
5660

57-
set_tests_properties(h5fortran:shape PROPERTIES
61+
set_tests_properties(shape PROPERTIES
5862
FIXTURES_SETUP h5shape
5963
)
6064

6165
set(shape_file ${CMAKE_CURRENT_BINARY_DIR}/test_shape.h5)
6266

67+
if(ENABLE_COVERAGE)
68+
setup_target_for_coverage_gcovr_html(
69+
NAME coverage
70+
EXECUTABLE ${CMAKE_CTEST_COMMAND}
71+
)
72+
endif()
73+
6374
# --- Windows shared DLLs
6475
if(WIN32 AND BUILD_SHARED_LIBS AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.21)
6576
add_custom_command(TARGET test_shape POST_BUILD
@@ -83,11 +94,11 @@ if(NOT DEFINED h5py_ok)
8394
endif()
8495
endif()
8596

86-
add_test(NAME h5fortran:PythonShape
97+
add_test(NAME PythonShape
8798
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_shape.py ${shape_file}
8899
)
89100

90-
set_tests_properties(h5fortran:PythonShape PROPERTIES
101+
set_tests_properties(PythonShape PROPERTIES
91102
REQUIRED_FILES ${shape_file}
92103
FIXTURES_REQUIRED "h5lib;h5shape"
93104
TIMEOUT 15
@@ -101,12 +112,12 @@ find_package(Matlab COMPONENTS MAIN_PROGRAM)
101112
if(Matlab_FOUND)
102113
set(matlab_cmd "i=h5info('${shape_file}', '/d7').Dataspace.Size; assert(all(i == [2, 1, 3, 4, 7, 6, 5]))")
103114

104-
add_test(NAME h5fortran:MatlabShape COMMAND ${Matlab_MAIN_PROGRAM} -batch ${matlab_cmd})
115+
add_test(NAME MatlabShape COMMAND ${Matlab_MAIN_PROGRAM} -batch ${matlab_cmd})
105116

106-
set_tests_properties(h5fortran:MatlabShape PROPERTIES
117+
set_tests_properties(MatlabShape PROPERTIES
107118
TIMEOUT 90
108119
LABELS shaky
109-
DEPENDS h5fortran:shape
120+
DEPENDS shape
110121
REQUIRED_FILES ${shape_file}
111122
FIXTURES_REQUIRED h5lib
112123
)
@@ -117,13 +128,13 @@ endif(matlab)
117128
# --- h5ls
118129

119130
find_program(h5ls NAMES h5ls)
120-
add_test(NAME h5fortran:h5ls COMMAND ${h5ls} ${shape_file}/d7)
131+
add_test(NAME h5ls COMMAND ${h5ls} ${shape_file}/d7)
121132

122-
set_tests_properties(h5fortran:h5ls PROPERTIES
133+
set_tests_properties(h5ls PROPERTIES
123134
TIMEOUT 10
124135
REQUIRED_FILES ${shape_file}
125136
FIXTURES_REQUIRED h5lib
126-
DEPENDS h5fortran:shape
137+
DEPENDS shape
127138
PASS_REGULAR_EXPRESSION "{5, 6, 7, 4, 3, 1, 2}"
128139
DISABLED $<NOT:$<BOOL:${h5ls}>>
129140
)

0 commit comments

Comments
 (0)