| 1 |
!> Implementation of the meta data for a test. |
| 2 |
!> |
| 3 |
!> The test data structure is effectively a decorated version of an executable |
| 4 |
!> and shares most of its properties, except for the defaults and can be |
| 5 |
!> handled under most circumstances just like any other executable. |
| 6 |
!> |
| 7 |
!> A test table can currently have the following fields |
| 8 |
!> |
| 9 |
!>```toml |
| 10 |
!>[[ test ]] |
| 11 |
!>name = "string" |
| 12 |
!>source-dir = "path" |
| 13 |
!>main = "file" |
| 14 |
!>link = ["lib"] |
| 15 |
!>[test.dependencies] |
| 16 |
!>``` |
| 17 |
module fpm_manifest_test |
| 18 |
use fpm_manifest_dependency, only : new_dependencies |
| 19 |
use fpm_manifest_executable, only : executable_config_t |
| 20 |
use fpm_error, only : error_t, syntax_error, bad_name_error |
| 21 |
use tomlf, only : toml_table, toml_key, toml_stat |
| 22 |
use fpm_toml, only : get_value, get_list |
| 23 |
implicit none |
| 24 |
private |
| 25 |
|
| 26 |
public :: test_config_t, new_test |
| 27 |
|
| 28 |
|
| 29 |
!> Configuation meta data for an test |
| 30 |
type, extends(executable_config_t) :: test_config_t |
| 31 |
|
| 32 |
contains |
| 33 |
|
| 34 |
!> Print information on this instance |
| 35 |
procedure :: info |
| 36 |
|
| 37 |
end type test_config_t |
| 38 |
|
| 39 |
|
| 40 |
contains |
| 41 |
|
| 42 |
|
| 43 |
!> Construct a new test configuration from a TOML data structure |
| 44 |
subroutine new_test(self, table, error) |
| 45 |
|
| 46 |
!> Instance of the test configuration |
| 47 |
type(test_config_t), intent(out) :: self |
| 48 |
|
| 49 |
!> Instance of the TOML data structure |
| 50 |
type(toml_table), intent(inout) :: table |
| 51 |
|
| 52 |
!> Error handling |
| 53 |
type(error_t), allocatable, intent(out) :: error |
| 54 |
|
| 55 |
type(toml_table), pointer :: child |
| 56 |
|
| 57 |
call check(table, error) |
| 58 |
if (allocated(error)) return |
| 59 |
|
| 60 |
call get_value(table, "name", self%name) |
| 61 |
if (.not.allocated(self%name)) then |
| 62 |
call syntax_error(error, "Could not retrieve test name") |
| 63 |
return |
| 64 |
end if |
| 65 |
if (bad_name_error(error,'test',self%name))then |
| 66 |
return |
| 67 |
endif |
| 68 |
call get_value(table, "source-dir", self%source_dir, "test") |
| 69 |
call get_value(table, "main", self%main, "main.f90") |
| 70 |
|
| 71 |
call get_value(table, "dependencies", child, requested=.false.) |
| 72 |
if (associated(child)) then |
| 73 |
call new_dependencies(self%dependency, child, error=error) |
| 74 |
if (allocated(error)) return |
| 75 |
end if |
| 76 |
|
| 77 |
call get_list(table, "link", self%link, error) |
| 78 |
if (allocated(error)) return |
| 79 |
|
| 80 |
end subroutine new_test |
| 81 |
|
| 82 |
|
| 83 |
!> Check local schema for allowed entries |
| 84 |
subroutine check(table, error) |
| 85 |
|
| 86 |
!> Instance of the TOML data structure |
| 87 |
type(toml_table), intent(inout) :: table |
| 88 |
|
| 89 |
!> Error handling |
| 90 |
type(error_t), allocatable, intent(out) :: error |
| 91 |
|
| 92 |
type(toml_key), allocatable :: list(:) |
| 93 |
logical :: name_present |
| 94 |
integer :: ikey |
| 95 |
|
| 96 |
name_present = .false. |
| 97 |
|
| 98 |
call table%get_keys(list) |
| 99 |
|
| 100 |
if (size(list) < 1) then |
| 101 |
call syntax_error(error, "Test section does not provide sufficient entries") |
| 102 |
return |
| 103 |
end if |
| 104 |
|
| 105 |
do ikey = 1, size(list) |
| 106 |
select case(list(ikey)%key) |
| 107 |
case default |
| 108 |
call syntax_error(error, "Key "//list(ikey)%key//" is not allowed in test entry") |
| 109 |
exit |
| 110 |
|
| 111 |
case("name") |
| 112 |
name_present = .true. |
| 113 |
|
| 114 |
case("source-dir", "main", "dependencies", "link") |
| 115 |
continue |
| 116 |
|
| 117 |
end select |
| 118 |
end do |
| 119 |
if (allocated(error)) return |
| 120 |
|
| 121 |
if (.not.name_present) then |
| 122 |
call syntax_error(error, "Test name is not provided, please add a name entry") |
| 123 |
end if |
| 124 |
|
| 125 |
end subroutine check |
| 126 |
|
| 127 |
|
| 128 |
!> Write information on instance |
| 129 |
subroutine info(self, unit, verbosity) |
| 130 |
|
| 131 |
!> Instance of the test configuration |
| 132 |
class(test_config_t), intent(in) :: self |
| 133 |
|
| 134 |
!> Unit for IO |
| 135 |
integer, intent(in) :: unit |
| 136 |
|
| 137 |
!> Verbosity of the printout |
| 138 |
integer, intent(in), optional :: verbosity |
| 139 |
|
| 140 |
integer :: pr, ii |
| 141 |
character(len=*), parameter :: fmt = '("#", 1x, a, t30, a)', & |
| 142 |
& fmti = '("#", 1x, a, t30, i0)' |
| 143 |
|
| 144 |
if (present(verbosity)) then |
| 145 |
pr = verbosity |
| 146 |
else |
| 147 |
pr = 1 |
| 148 |
end if |
| 149 |
|
| 150 |
if (pr < 1) return |
| 151 |
|
| 152 |
write(unit, fmt) "Test target" |
| 153 |
if (allocated(self%name)) then |
| 154 |
write(unit, fmt) "- name", self%name |
| 155 |
end if |
| 156 |
if (allocated(self%source_dir)) then |
| 157 |
if (self%source_dir /= "test" .or. pr > 2) then |
| 158 |
write(unit, fmt) "- source directory", self%source_dir |
| 159 |
end if |
| 160 |
end if |
| 161 |
if (allocated(self%main)) then |
| 162 |
if (self%main /= "main.f90" .or. pr > 2) then |
| 163 |
write(unit, fmt) "- test source", self%main |
| 164 |
end if |
| 165 |
end if |
| 166 |
|
| 167 |
if (allocated(self%dependency)) then |
| 168 |
if (size(self%dependency) > 1 .or. pr > 2) then |
| 169 |
write(unit, fmti) "- dependencies", size(self%dependency) |
| 170 |
end if |
| 171 |
do ii = 1, size(self%dependency) |
| 172 |
call self%dependency(ii)%info(unit, pr - 1) |
| 173 |
end do |
| 174 |
end if |
| 175 |
|
| 176 |
end subroutine info |
| 177 |
|
| 178 |
|
| 179 |
end module fpm_manifest_test |