| 1 |
!> Driver for unit testing |
| 2 |
program fpm_testing |
| 3 |
use, intrinsic :: iso_fortran_env, only : error_unit |
| 4 |
use testsuite, only : run_testsuite, new_testsuite, testsuite_t, select_suite, run_selected |
| 5 |
use test_toml, only : collect_toml |
| 6 |
use test_compiler, only : collect_compiler |
| 7 |
use test_manifest, only : collect_manifest |
| 8 |
use test_filesystem, only : collect_filesystem |
| 9 |
use test_source_parsing, only : collect_source_parsing |
| 10 |
use test_module_dependencies, only : collect_module_dependencies |
| 11 |
use test_package_dependencies, only : collect_package_dependencies |
| 12 |
use test_backend, only: collect_backend |
| 13 |
use test_installer, only : collect_installer |
| 14 |
use test_versioning, only : collect_versioning |
| 15 |
use test_settings, only : collect_settings |
| 16 |
use test_os, only: collect_os |
| 17 |
use test_features, only : collect_features |
| 18 |
|
| 19 |
implicit none |
| 20 |
integer :: stat, is |
| 21 |
character(len=:), allocatable :: suite_name, test_name |
| 22 |
type(testsuite_t), allocatable :: suite(:) |
| 23 |
character(len=*), parameter :: fmt = '("#", *(1x, a))' |
| 24 |
|
| 25 |
stat = 0 |
| 26 |
|
| 27 |
suite = [ & |
| 28 |
& new_testsuite("fpm_toml", collect_toml), & |
| 29 |
& new_testsuite("fpm_manifest", collect_manifest), & |
| 30 |
& new_testsuite("fpm_features", collect_features), & |
| 31 |
& new_testsuite("fpm_filesystem", collect_filesystem), & |
| 32 |
& new_testsuite("fpm_source_parsing", collect_source_parsing), & |
| 33 |
& new_testsuite("fpm_module_dependencies", collect_module_dependencies), & |
| 34 |
& new_testsuite("fpm_package_dependencies", collect_package_dependencies), & |
| 35 |
& new_testsuite("fpm_test_backend", collect_backend), & |
| 36 |
& new_testsuite("fpm_installer", collect_installer), & |
| 37 |
& new_testsuite("fpm_versioning", collect_versioning), & |
| 38 |
& new_testsuite("fpm_settings", collect_settings), & |
| 39 |
& new_testsuite("fpm_os", collect_os), & |
| 40 |
& new_testsuite("fpm_compiler", collect_compiler) & |
| 41 |
& ] |
| 42 |
|
| 43 |
call get_argument(1, suite_name) |
| 44 |
call get_argument(2, test_name) |
| 45 |
|
| 46 |
if (allocated(suite_name)) then |
| 47 |
is = select_suite(suite, suite_name) |
| 48 |
if (is > 0 .and. is <= size(suite)) then |
| 49 |
if (allocated(test_name)) then |
| 50 |
write(error_unit, fmt) "Suite:", suite(is)%name |
| 51 |
call run_selected(suite(is)%collect, test_name, error_unit, stat) |
| 52 |
if (stat < 0) then |
| 53 |
error stop 1 |
| 54 |
end if |
| 55 |
else |
| 56 |
write(error_unit, fmt) "Testing:", suite(is)%name |
| 57 |
call run_testsuite(suite(is)%collect, error_unit, stat) |
| 58 |
end if |
| 59 |
else |
| 60 |
write(error_unit, fmt) "Available testsuites" |
| 61 |
do is = 1, size(suite) |
| 62 |
write(error_unit, fmt) "-", suite(is)%name |
| 63 |
end do |
| 64 |
error stop 1 |
| 65 |
end if |
| 66 |
else |
| 67 |
do is = 1, size(suite) |
| 68 |
write(error_unit, fmt) "Testing:", suite(is)%name |
| 69 |
call run_testsuite(suite(is)%collect, error_unit, stat) |
| 70 |
end do |
| 71 |
end if |
| 72 |
|
| 73 |
if (stat > 0) then |
| 74 |
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!" |
| 75 |
error stop 1 |
| 76 |
end if |
| 77 |
|
| 78 |
|
| 79 |
contains |
| 80 |
|
| 81 |
|
| 82 |
!> Obtain the command line argument at a given index |
| 83 |
subroutine get_argument(idx, arg) |
| 84 |
|
| 85 |
!> Index of command line argument, range [0:command_argument_count()] |
| 86 |
integer, intent(in) :: idx |
| 87 |
|
| 88 |
!> Command line argument |
| 89 |
character(len=:), allocatable, intent(out) :: arg |
| 90 |
|
| 91 |
integer :: length, arg_stat |
| 92 |
|
| 93 |
call get_command_argument(idx, length=length, status=arg_stat) |
| 94 |
if (arg_stat /= 0) then |
| 95 |
return |
| 96 |
endif |
| 97 |
|
| 98 |
allocate(character(len=length) :: arg, stat=arg_stat) |
| 99 |
if (arg_stat /= 0) then |
| 100 |
return |
| 101 |
endif |
| 102 |
|
| 103 |
if (length > 0) then |
| 104 |
call get_command_argument(idx, arg, status=arg_stat) |
| 105 |
if (arg_stat /= 0) then |
| 106 |
deallocate(arg) |
| 107 |
return |
| 108 |
end if |
| 109 |
end if |
| 110 |
|
| 111 |
end subroutine get_argument |
| 112 |
|
| 113 |
|
| 114 |
end program fpm_testing |