File tree Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Original file line number Diff line number Diff line change 11macro (ADDTEST name )
22 add_executable (test_${name} test_${name} .f90)
3- target_link_libraries (test_${name} ${PROJECT_NAME} )
3+ target_link_libraries (test_${name} PRIVATE ${PROJECT_NAME} )
44 add_test (NAME ${name}
55 COMMAND $<TARGET_FILE:test_${name} > ${CMAKE_CURRENT_BINARY_DIR}
66 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
@@ -19,7 +19,14 @@ add_subdirectory(system)
1919add_subdirectory (quadrature)
2020add_subdirectory (math)
2121
22- ADDTEST(always_skip)
23- set_tests_properties (always_skip PROPERTIES SKIP_RETURN_CODE 77)
24- ADDTEST(always_fail)
25- set_tests_properties (always_fail PROPERTIES WILL_FAIL true )
22+ add_executable (test_error_handling test_error_driver.f90)
23+
24+ add_executable (test_always_77 test_always_77.f90)
25+ target_link_libraries (test_always_77 PRIVATE ${PROJECT_NAME} )
26+ add_test (NAME test_error_77
27+ COMMAND $<TARGET_FILE:test_error_handling> $<TARGET_FILE:test_always_77> 77)
28+
29+ add_executable (test_always_1 test_always_fail.f90)
30+ target_link_libraries (test_always_1 PRIVATE ${PROJECT_NAME} )
31+ add_test (NAME test_error_1
32+ COMMAND $<TARGET_FILE:test_error_handling> $<TARGET_FILE:test_always_1> 1)
Original file line number Diff line number Diff line change 1- program test_always_skip
1+ program test_always_77
22
33use stdlib_error, only: check
44implicit none
Original file line number Diff line number Diff line change 1+ program test_driver
2+ ! ! tests return codes from programs.
3+ ! ! useful for checking "error stop" return codes.
4+ ! !
5+ ! ! Arguments:
6+ ! ! prog: program to run and catch return code
7+
8+ implicit none
9+
10+ integer :: ierr, ok_code, cmderr
11+ character (1024 ) :: prog
12+ character (3 ) :: ok, actual
13+
14+ call get_command_argument(1 , prog, status= ierr)
15+ if (ierr/= 0 ) error stop " please specify a program to catch return codes from"
16+
17+ call get_command_argument(2 , ok, status= ierr)
18+ if (ierr/= 0 ) error stop " please specify the expected return code"
19+
20+ read (ok, ' (i3)' ) ok_code
21+
22+ call execute_command_line(trim (prog), exitstat= ierr, cmdstat= cmderr)
23+ if (cmderr/= 0 ) error stop " test_driver had problem running always-fail program"
24+
25+ write (actual, ' (i3)' ) ierr
26+ if (ierr /= ok_code) error stop " expected return code " // ok// " , got " // actual// " instead"
27+
28+ end program
You can’t perform that action at this time.
0 commit comments