|
| 1 | +module test_shared_lib |
| 2 | + use testdrive, only : new_unittest, unittest_type, error_type, check |
| 3 | + use shared_lib, only: test_something |
| 4 | + |
| 5 | + implicit none |
| 6 | + |
| 7 | + public :: collect |
| 8 | + |
| 9 | + |
| 10 | +contains |
| 11 | + |
| 12 | + !> Collect all exported unit tests |
| 13 | + subroutine collect(testsuite) |
| 14 | + !> Collection of tests |
| 15 | + type(unittest_type), allocatable, intent(out) :: testsuite(:) |
| 16 | + |
| 17 | + testsuite = [ new_unittest("shared_lib", test_shared) ] |
| 18 | + |
| 19 | + end subroutine collect |
| 20 | + |
| 21 | + subroutine test_shared(error) |
| 22 | + type(error_type), allocatable, intent(out) :: error |
| 23 | + |
| 24 | + call check(error, test_something(), 123, "Should be test_something==123") |
| 25 | + |
| 26 | + end subroutine test_shared |
| 27 | + |
| 28 | +end module test_shared_lib |
| 29 | + |
| 30 | +program tester |
| 31 | + use, intrinsic :: iso_fortran_env, only : error_unit |
| 32 | + use testdrive, only : run_testsuite, new_testsuite, testsuite_type |
| 33 | + use test_shared_lib, only : collect |
| 34 | + implicit none |
| 35 | + integer :: stat |
| 36 | + type(testsuite_type), allocatable :: testsuite |
| 37 | + character(len=*), parameter :: fmt = '("#", *(1x, a))' |
| 38 | + |
| 39 | + stat = 0 |
| 40 | + |
| 41 | + testsuite = new_testsuite("shared_lib", collect) |
| 42 | + |
| 43 | + write(error_unit, fmt) "Testing:", testsuite%name |
| 44 | + call run_testsuite(testsuite%collect, error_unit, stat) |
| 45 | + |
| 46 | + if (stat > 0) then |
| 47 | + write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!" |
| 48 | + error stop |
| 49 | + end if |
| 50 | +end program tester |
0 commit comments