| 1 |
!> Define tests for the `fpm_manifest` modules |
| 2 |
module test_manifest |
| 3 |
use fpm_filesystem, only: get_temp_filename |
| 4 |
use testsuite, only : new_unittest, unittest_t, error_t, test_failed, check_string |
| 5 |
use fpm_manifest |
| 6 |
use fpm_manifest_profile, only: profile_config_t |
| 7 |
use fpm_manifest_platform, only: platform_config_t |
| 8 |
use fpm_compiler, only: id_gcc, id_intel_classic_nix |
| 9 |
use fpm_environment, only: OS_LINUX |
| 10 |
use fpm_manifest_feature, only: feature_config_t |
| 11 |
use fpm_strings, only: operator(.in.), string_t |
| 12 |
use fpm_error, only: fatal_error, error_t |
| 13 |
use tomlf, only : new_table, toml_table, toml_array |
| 14 |
use fpm_toml, only : add_table, add_array, get_value, get_list, set_value, set_list |
| 15 |
implicit none |
| 16 |
private |
| 17 |
public :: collect_manifest |
| 18 |
|
| 19 |
contains |
| 20 |
|
| 21 |
!> Collect all exported unit tests |
| 22 |
subroutine collect_manifest(testsuite) |
| 23 |
|
| 24 |
!> Collection of tests |
| 25 |
type(unittest_t), allocatable, intent(out) :: testsuite(:) |
| 26 |
|
| 27 |
testsuite = [ & |
| 28 |
& new_unittest("valid-manifest", test_valid_manifest), & |
| 29 |
& new_unittest("invalid-manifest", test_invalid_manifest, should_fail=.true.), & |
| 30 |
& new_unittest("default-library", test_default_library), & |
| 31 |
& new_unittest("default-library-type", test_default_library_type), & |
| 32 |
& new_unittest("default-executable", test_default_executable), & |
| 33 |
& new_unittest("dependency-empty", test_dependency_empty, should_fail=.true.), & |
| 34 |
& new_unittest("dependency-pathtag", test_dependency_pathtag, should_fail=.true.), & |
| 35 |
& new_unittest("dependency-gitpath", test_dependency_gitpath, should_fail=.true.), & |
| 36 |
& new_unittest("dependency-nourl", test_dependency_nourl, should_fail=.true.), & |
| 37 |
& new_unittest("dependency-gitconflict", test_dependency_gitconflict, should_fail=.true.), & |
| 38 |
& new_unittest("dependency-invalid-git", test_dependency_invalid_git, should_fail=.true.), & |
| 39 |
& new_unittest("dependency-no-namespace", test_dependency_no_namespace, should_fail=.true.), & |
| 40 |
& new_unittest("dependency-redundant-v", test_dependency_redundant_v, should_fail=.true.), & |
| 41 |
& new_unittest("dependency-features-present", test_dependency_features_present), & |
| 42 |
& new_unittest("dependency-features-absent", test_dependency_features_absent), & |
| 43 |
& new_unittest("dependency-features-empty", test_dependency_features_empty), & |
| 44 |
& new_unittest("dependency-profile-present", test_dependency_profile_present), & |
| 45 |
& new_unittest("dependency-profile-absent", test_dependency_profile_absent), & |
| 46 |
& new_unittest("dependency-profile-features-conflict", & |
| 47 |
& test_dependency_profile_features_conflict, should_fail=.true.), & |
| 48 |
& new_unittest("dependency-wrongkey", test_dependency_wrongkey, should_fail=.true.), & |
| 49 |
& new_unittest("dependencies-empty", test_dependencies_empty), & |
| 50 |
& new_unittest("dependencies-typeerror", test_dependencies_typeerror, should_fail=.true.), & |
| 51 |
& new_unittest("profiles", test_profiles), & |
| 52 |
& new_unittest("profiles-invalid", test_profiles_invalid, should_fail=.true.), & |
| 53 |
& new_unittest("executable-empty", test_executable_empty, should_fail=.true.), & |
| 54 |
& new_unittest("executable-typeerror", test_executable_typeerror, should_fail=.true.), & |
| 55 |
& new_unittest("executable-noname", test_executable_noname, should_fail=.true.), & |
| 56 |
& new_unittest("executable-wrongkey", test_executable_wrongkey, should_fail=.true.), & |
| 57 |
& new_unittest("build-config-valid", test_build_valid), & |
| 58 |
& new_unittest("build-config-empty", test_build_empty), & |
| 59 |
& new_unittest("build-config-invalid-values", test_build_invalid_values, should_fail=.true.), & |
| 60 |
& new_unittest("build-key-invalid", test_build_invalid_key), & |
| 61 |
& new_unittest("library-empty", test_library_empty), & |
| 62 |
& new_unittest("library-wrongkey", test_library_wrongkey, should_fail=.true.), & |
| 63 |
& new_unittest("library-list", test_library_list, should_fail=.true.), & |
| 64 |
& new_unittest("package-simple", test_package_simple), & |
| 65 |
& new_unittest("package-empty", test_package_empty, should_fail=.true.), & |
| 66 |
& new_unittest("package-typeerror", test_package_typeerror, should_fail=.true.), & |
| 67 |
& new_unittest("package-noname", test_package_noname, should_fail=.true.), & |
| 68 |
& new_unittest("package-wrongexe", test_package_wrongexe, should_fail=.true.), & |
| 69 |
& new_unittest("package-wrongtest", test_package_wrongtest, should_fail=.true.), & |
| 70 |
& new_unittest("package-duplicate", test_package_duplicate, should_fail=.true.), & |
| 71 |
& new_unittest("test-simple", test_test_simple), & |
| 72 |
& new_unittest("test-empty", test_test_empty, should_fail=.true.), & |
| 73 |
& new_unittest("test-typeerror", test_test_typeerror, should_fail=.true.), & |
| 74 |
& new_unittest("test-noname", test_test_noname, should_fail=.true.), & |
| 75 |
& new_unittest("test-wrongkey", test_test_wrongkey, should_fail=.true.), & |
| 76 |
& new_unittest("link-string", test_link_string), & |
| 77 |
& new_unittest("link-array", test_link_array), & |
| 78 |
& new_unittest("link-error", test_invalid_link, should_fail=.true.), & |
| 79 |
& new_unittest("example-simple", test_example_simple), & |
| 80 |
& new_unittest("example-empty", test_example_empty, should_fail=.true.), & |
| 81 |
& new_unittest("install-library", test_install_library), & |
| 82 |
& new_unittest("install-empty", test_install_empty), & |
| 83 |
& new_unittest("install-module-dir", test_install_module_dir), & |
| 84 |
& new_unittest("install-wrongkey", test_install_wrongkey, should_fail=.true.), & |
| 85 |
& new_unittest("preprocess-empty", test_preprocess_empty), & |
| 86 |
& new_unittest("preprocess-wrongkey", test_preprocess_wrongkey, should_fail=.true.), & |
| 87 |
& new_unittest("preprocessors-empty", test_preprocessors_empty, should_fail=.true.), & |
| 88 |
& new_unittest("macro-parsing", test_macro_parsing, should_fail=.false.), & |
| 89 |
& new_unittest("macro-parsing-dependency", & |
| 90 |
& test_macro_parsing_dependency, should_fail=.false.), & |
| 91 |
& new_unittest("features-demo-serialization", test_features_demo_serialization) & |
| 92 |
& ] |
| 93 |
|
| 94 |
end subroutine collect_manifest |
| 95 |
|
| 96 |
|
| 97 |
!> Try to read some unnecessary obscure and convoluted but not invalid package file |
| 98 |
subroutine test_valid_manifest(error) |
| 99 |
|
| 100 |
!> Error handling |
| 101 |
type(error_t), allocatable, intent(out) :: error |
| 102 |
|
| 103 |
type(package_config_t) :: package |
| 104 |
character(len=*), parameter :: manifest = 'fpm-valid-manifest.toml' |
| 105 |
integer :: unit |
| 106 |
|
| 107 |
open(file=manifest, newunit=unit) |
| 108 |
write(unit, '(a)') & |
| 109 |
& 'name = "example"', & |
| 110 |
& '[build]', & |
| 111 |
& 'auto-executables = false', & |
| 112 |
& 'auto-tests = false', & |
| 113 |
& 'module-naming = false', & |
| 114 |
& '[dependencies.fpm]', & |
| 115 |
& 'git = "https://github.com/fortran-lang/fpm"', & |
| 116 |
& '[[executable]]', & |
| 117 |
& 'name = "example-1" # comment', & |
| 118 |
& 'source-dir = "prog"', & |
| 119 |
& '[dependencies]', & |
| 120 |
& 'toml-f.git = "[email protected]:toml-f/toml-f.git"', & |
| 121 |
& '"toml..f" = { path = ".." }', & |
| 122 |
& '[["executable"]]', & |
| 123 |
& 'name = "example-2"', & |
| 124 |
& 'source-dir = "prog"', & |
| 125 |
& '[executable.dependencies]', & |
| 126 |
& '[''library'']', & |
| 127 |
& 'source-dir = """', & |
| 128 |
& 'lib""" # comment', & |
| 129 |
& '[preprocess]', & |
| 130 |
& '[preprocess.cpp]', & |
| 131 |
& 'suffixes = ["F90", "f90"]', & |
| 132 |
& 'directories = ["src/feature1", "src/models"]', & |
| 133 |
& 'macros = ["FOO", "BAR"]' |
| 134 |
close(unit) |
| 135 |
|
| 136 |
call get_package_data(package, manifest, error) |
| 137 |
|
| 138 |
open(file=manifest, newunit=unit) |
| 139 |
close(unit, status='delete') |
| 140 |
|
| 141 |
if (allocated(error)) return |
| 142 |
|
| 143 |
if (package%name /= "example") then |
| 144 |
call test_failed(error, "Package name is "//package%name//" but should be example") |
| 145 |
return |
| 146 |
end if |
| 147 |
|
| 148 |
if (.not.allocated(package%library)) then |
| 149 |
call test_failed(error, "library is not present in package data") |
| 150 |
return |
| 151 |
end if |
| 152 |
|
| 153 |
if (.not.allocated(package%executable)) then |
| 154 |
call test_failed(error, "executable is not present in package data") |
| 155 |
return |
| 156 |
end if |
| 157 |
|
| 158 |
if (size(package%executable) /= 2) then |
| 159 |
call test_failed(error, "Number of executables in package is not two") |
| 160 |
return |
| 161 |
end if |
| 162 |
|
| 163 |
if (.not.allocated(package%dependency)) then |
| 164 |
call test_failed(error, "dependency is not present in package data") |
| 165 |
return |
| 166 |
end if |
| 167 |
|
| 168 |
if (size(package%dependency) /= 3) then |
| 169 |
call test_failed(error, "Number of dependencies in package is not three") |
| 170 |
return |
| 171 |
end if |
| 172 |
|
| 173 |
if (allocated(package%test)) then |
| 174 |
call test_failed(error, "test is present in package but not in package file") |
| 175 |
return |
| 176 |
end if |
| 177 |
|
| 178 |
if (.not.allocated(package%preprocess)) then |
| 179 |
call test_failed(error, "Preprocessor is not present in package data") |
| 180 |
return |
| 181 |
end if |
| 182 |
|
| 183 |
if (size(package%preprocess) /= 1) then |
| 184 |
call test_failed(error, "Number of preprocessors in package is not one") |
| 185 |
return |
| 186 |
end if |
| 187 |
|
| 188 |
! Test package serialization |
| 189 |
call package%test_serialization('test_valid_manifest',error) |
| 190 |
if (allocated(error)) return |
| 191 |
|
| 192 |
end subroutine test_valid_manifest |
| 193 |
|
| 194 |
|
| 195 |
!> Try to read a valid TOML document which represent an invalid package file |
| 196 |
subroutine test_invalid_manifest(error) |
| 197 |
|
| 198 |
!> Error handling |
| 199 |
type(error_t), allocatable, intent(out) :: error |
| 200 |
|
| 201 |
type(package_config_t) :: package |
| 202 |
character(len=*), parameter :: manifest = 'fpm-invalid-manifest.toml' |
| 203 |
integer :: unit |
| 204 |
|
| 205 |
open(file=manifest, newunit=unit) |
| 206 |
write(unit, '(a)') & |
| 207 |
& '[package]', & |
| 208 |
& 'name = "example"', & |
| 209 |
& 'version = "0.1.0"' |
| 210 |
close(unit) |
| 211 |
|
| 212 |
call get_package_data(package, manifest, error) |
| 213 |
|
| 214 |
open(file=manifest, newunit=unit) |
| 215 |
close(unit, status='delete') |
| 216 |
|
| 217 |
end subroutine test_invalid_manifest |
| 218 |
|
| 219 |
|
| 220 |
!> Create a default library |
| 221 |
subroutine test_default_library(error) |
| 222 |
|
| 223 |
!> Error handling |
| 224 |
type(error_t), allocatable, intent(out) :: error |
| 225 |
|
| 226 |
type(package_config_t) :: package |
| 227 |
|
| 228 |
allocate(package%library) |
| 229 |
call default_library(package%library) |
| 230 |
|
| 231 |
call check_string(error, package%library%source_dir, "src", & |
| 232 |
& "Default library source-dir") |
| 233 |
if (allocated(error)) return |
| 234 |
|
| 235 |
if (.not.allocated(package%library%include_dir)) then |
| 236 |
call test_failed(error,"Default include-dir list not allocated") |
| 237 |
return |
| 238 |
end if |
| 239 |
|
| 240 |
if (.not.("include".in.package%library%include_dir)) then |
| 241 |
call test_failed(error,"'include' not in default include-dir list") |
| 242 |
return |
| 243 |
end if |
| 244 |
|
| 245 |
call package%test_serialization('test_default_library',error) |
| 246 |
if (allocated(error)) return |
| 247 |
|
| 248 |
end subroutine test_default_library |
| 249 |
|
| 250 |
|
| 251 |
!> Test that a package with non-specified library returns monolithic and not shared/static |
| 252 |
subroutine test_default_library_type(error) |
| 253 |
|
| 254 |
!> Error handling |
| 255 |
type(error_t), allocatable, intent(out) :: error |
| 256 |
|
| 257 |
type(package_config_t) :: package |
| 258 |
character(len=*), parameter :: manifest = 'fpm-default-library-type.toml' |
| 259 |
integer :: unit |
| 260 |
|
| 261 |
open(file=manifest, newunit=unit) |
| 262 |
write(unit, '(a)') & |
| 263 |
& 'name = "example"', & |
| 264 |
& '[library]' |
| 265 |
close(unit) |
| 266 |
|
| 267 |
call get_package_data(package, manifest, error) |
| 268 |
|
| 269 |
open(file=manifest, newunit=unit) |
| 270 |
close(unit, status='delete') |
| 271 |
|
| 272 |
if (allocated(error)) return |
| 273 |
|
| 274 |
if (.not.allocated(package%library)) then |
| 275 |
call test_failed(error, "Default library is not present in package data") |
| 276 |
return |
| 277 |
end if |
| 278 |
|
| 279 |
if (.not.package%library%monolithic()) then |
| 280 |
call test_failed(error, "Default library should be monolithic") |
| 281 |
return |
| 282 |
end if |
| 283 |
|
| 284 |
if (package%library%shared()) then |
| 285 |
call test_failed(error, "Default library should not be shared") |
| 286 |
return |
| 287 |
end if |
| 288 |
|
| 289 |
if (package%library%static()) then |
| 290 |
call test_failed(error, "Default library should not be static") |
| 291 |
return |
| 292 |
end if |
| 293 |
|
| 294 |
call package%test_serialization('test_default_library_type',error) |
| 295 |
if (allocated(error)) return |
| 296 |
|
| 297 |
end subroutine test_default_library_type |
| 298 |
|
| 299 |
|
| 300 |
!> Create a default executable |
| 301 |
subroutine test_default_executable(error) |
| 302 |
|
| 303 |
!> Error handling |
| 304 |
type(error_t), allocatable, intent(out) :: error |
| 305 |
|
| 306 |
type(package_config_t) :: package |
| 307 |
character(len=*), parameter :: name = "default" |
| 308 |
|
| 309 |
allocate(package%executable(1)) |
| 310 |
call default_executable(package%executable(1), name) |
| 311 |
|
| 312 |
call check_string(error, package%executable(1)%source_dir, "app", & |
| 313 |
& "Default executable source-dir") |
| 314 |
if (allocated(error)) return |
| 315 |
|
| 316 |
call check_string(error, package%executable(1)%name, name, & |
| 317 |
& "Default executable name") |
| 318 |
if (allocated(error)) return |
| 319 |
|
| 320 |
call package%feature_config_t%test_serialization('test_default_executable (feature only)',error) |
| 321 |
if (allocated(error)) return |
| 322 |
|
| 323 |
call package%test_serialization('test_default_executable',error) |
| 324 |
if (allocated(error)) return |
| 325 |
|
| 326 |
end subroutine test_default_executable |
| 327 |
|
| 328 |
!> Dependencies cannot be created from empty tables |
| 329 |
subroutine test_dependency_empty(error) |
| 330 |
use fpm_manifest_dependency |
| 331 |
|
| 332 |
!> Error handling |
| 333 |
type(error_t), allocatable, intent(out) :: error |
| 334 |
|
| 335 |
type(toml_table) :: table |
| 336 |
type(dependency_config_t) :: dependency |
| 337 |
|
| 338 |
call new_table(table) |
| 339 |
table%key = "example" |
| 340 |
|
| 341 |
call new_dependency(dependency, table, error=error) |
| 342 |
|
| 343 |
end subroutine test_dependency_empty |
| 344 |
|
| 345 |
|
| 346 |
!> Try to create a dependency with conflicting entries |
| 347 |
subroutine test_dependency_pathtag(error) |
| 348 |
use fpm_manifest_dependency |
| 349 |
|
| 350 |
!> Error handling |
| 351 |
type(error_t), allocatable, intent(out) :: error |
| 352 |
|
| 353 |
type(toml_table) :: table |
| 354 |
integer :: stat |
| 355 |
type(dependency_config_t) :: dependency |
| 356 |
|
| 357 |
call new_table(table) |
| 358 |
table%key = 'example' |
| 359 |
call set_value(table, 'path', 'package', stat) |
| 360 |
call set_value(table, 'tag', 'v20.1', stat) |
| 361 |
|
| 362 |
call new_dependency(dependency, table, error=error) |
| 363 |
|
| 364 |
end subroutine test_dependency_pathtag |
| 365 |
|
| 366 |
|
| 367 |
!> Try to create a dependency with conflicting entries |
| 368 |
subroutine test_dependency_nourl(error) |
| 369 |
use fpm_manifest_dependency |
| 370 |
|
| 371 |
!> Error handling |
| 372 |
type(error_t), allocatable, intent(out) :: error |
| 373 |
|
| 374 |
type(toml_table) :: table |
| 375 |
integer :: stat |
| 376 |
type(dependency_config_t) :: dependency |
| 377 |
|
| 378 |
call new_table(table) |
| 379 |
table%key = 'example' |
| 380 |
call set_value(table, 'tag', 'v20.1', stat) |
| 381 |
|
| 382 |
call new_dependency(dependency, table, error=error) |
| 383 |
|
| 384 |
end subroutine test_dependency_nourl |
| 385 |
|
| 386 |
|
| 387 |
!> Try to create a dependency with conflicting entries |
| 388 |
subroutine test_dependency_gitpath(error) |
| 389 |
use fpm_manifest_dependency |
| 390 |
|
| 391 |
!> Error handling |
| 392 |
type(error_t), allocatable, intent(out) :: error |
| 393 |
|
| 394 |
type(toml_table) :: table |
| 395 |
integer :: stat |
| 396 |
type(dependency_config_t) :: dependency |
| 397 |
|
| 398 |
call new_table(table) |
| 399 |
table%key = 'example' |
| 400 |
call set_value(table, 'path', 'package', stat) |
| 401 |
call set_value(table, 'git', 'https://gitea.com/fortran-lang/pack', stat) |
| 402 |
|
| 403 |
call new_dependency(dependency, table, error=error) |
| 404 |
|
| 405 |
end subroutine test_dependency_gitpath |
| 406 |
|
| 407 |
|
| 408 |
!> Try to create a dependency with conflicting entries |
| 409 |
subroutine test_dependency_gitconflict(error) |
| 410 |
use fpm_manifest_dependency |
| 411 |
|
| 412 |
!> Error handling |
| 413 |
type(error_t), allocatable, intent(out) :: error |
| 414 |
|
| 415 |
type(toml_table) :: table |
| 416 |
integer :: stat |
| 417 |
type(dependency_config_t) :: dependency |
| 418 |
|
| 419 |
call new_table(table) |
| 420 |
table%key = 'example' |
| 421 |
call set_value(table, 'git', 'https://gitea.com/fortran-lang/pack', stat) |
| 422 |
call set_value(table, 'branch', 'latest', stat) |
| 423 |
call set_value(table, 'tag', 'v20.1', stat) |
| 424 |
|
| 425 |
call new_dependency(dependency, table, error=error) |
| 426 |
|
| 427 |
end subroutine test_dependency_gitconflict |
| 428 |
|
| 429 |
|
| 430 |
!> Try to create a git dependency with an invalid source format. |
| 431 |
subroutine test_dependency_invalid_git(error) |
| 432 |
use fpm_manifest_dependency |
| 433 |
|
| 434 |
!> Error handling |
| 435 |
type(error_t), allocatable, intent(out) :: error |
| 436 |
|
| 437 |
type(toml_table) :: table |
| 438 |
type(dependency_config_t) :: dependency |
| 439 |
|
| 440 |
call new_table(table) |
| 441 |
table%key = 'example' |
| 442 |
call set_value(table, 'git', 123) ! Not a string |
| 443 |
|
| 444 |
call new_dependency(dependency, table, error=error) |
| 445 |
|
| 446 |
end subroutine test_dependency_invalid_git |
| 447 |
|
| 448 |
!> Namespace is necessary if a dependency is not a git or path dependency |
| 449 |
subroutine test_dependency_no_namespace(error) |
| 450 |
use fpm_manifest_dependency |
| 451 |
|
| 452 |
type(error_t), allocatable, intent(out) :: error |
| 453 |
|
| 454 |
type(toml_table) :: table |
| 455 |
type(dependency_config_t) :: dependency |
| 456 |
|
| 457 |
call new_table(table) |
| 458 |
table%key = 'example' |
| 459 |
call set_value(table, 'v', 'abc') |
| 460 |
|
| 461 |
call new_dependency(dependency, table, error=error) |
| 462 |
|
| 463 |
end subroutine test_dependency_no_namespace |
| 464 |
|
| 465 |
!> Do not specify version with a git or path dependency |
| 466 |
subroutine test_dependency_redundant_v(error) |
| 467 |
use fpm_manifest_dependency |
| 468 |
|
| 469 |
type(error_t), allocatable, intent(out) :: error |
| 470 |
|
| 471 |
type(toml_table) :: table |
| 472 |
type(dependency_config_t) :: dependency |
| 473 |
|
| 474 |
call new_table(table) |
| 475 |
table%key = 'example' |
| 476 |
call set_value(table, 'v', '0.0.0') |
| 477 |
call set_value(table, 'path', 'abc') |
| 478 |
|
| 479 |
call new_dependency(dependency, table, error=error) |
| 480 |
|
| 481 |
end subroutine test_dependency_redundant_v |
| 482 |
|
| 483 |
|
| 484 |
!> Try to create a dependency with conflicting entries |
| 485 |
subroutine test_dependency_wrongkey(error) |
| 486 |
use fpm_manifest_dependency |
| 487 |
|
| 488 |
!> Error handling |
| 489 |
type(error_t), allocatable, intent(out) :: error |
| 490 |
|
| 491 |
type(toml_table) :: table |
| 492 |
integer :: stat |
| 493 |
type(dependency_config_t) :: dependency |
| 494 |
|
| 495 |
call new_table(table) |
| 496 |
table%key = 'example' |
| 497 |
call set_value(table, 'not-available', 'anywhere', stat) |
| 498 |
|
| 499 |
call new_dependency(dependency, table, error=error) |
| 500 |
|
| 501 |
end subroutine test_dependency_wrongkey |
| 502 |
|
| 503 |
|
| 504 |
!> Dependency tables can be empty |
| 505 |
subroutine test_dependencies_empty(error) |
| 506 |
use fpm_manifest_dependency |
| 507 |
|
| 508 |
!> Error handling |
| 509 |
type(error_t), allocatable, intent(out) :: error |
| 510 |
|
| 511 |
type(toml_table) :: table |
| 512 |
type(dependency_config_t), allocatable :: dependencies(:) |
| 513 |
|
| 514 |
call new_table(table) |
| 515 |
|
| 516 |
call new_dependencies(dependencies, table, error=error) |
| 517 |
if (allocated(error)) return |
| 518 |
|
| 519 |
if (allocated(dependencies)) then |
| 520 |
call test_failed(error, "Found dependencies in empty table") |
| 521 |
end if |
| 522 |
|
| 523 |
end subroutine test_dependencies_empty |
| 524 |
|
| 525 |
|
| 526 |
!> Add a dependency as an array, which is not supported |
| 527 |
subroutine test_dependencies_typeerror(error) |
| 528 |
use fpm_manifest_dependency |
| 529 |
|
| 530 |
!> Error handling |
| 531 |
type(error_t), allocatable, intent(out) :: error |
| 532 |
|
| 533 |
type(toml_table) :: table |
| 534 |
type(toml_array), pointer :: children |
| 535 |
integer :: stat |
| 536 |
type(dependency_config_t), allocatable :: dependencies(:) |
| 537 |
|
| 538 |
call new_table(table) |
| 539 |
call add_array(table, 'dep1', children, stat) |
| 540 |
|
| 541 |
call new_dependencies(dependencies, table, error=error) |
| 542 |
|
| 543 |
end subroutine test_dependencies_typeerror |
| 544 |
|
| 545 |
!> Test profile parsing and storage in package |
| 546 |
subroutine test_profiles(error) |
| 547 |
|
| 548 |
!> Error handling |
| 549 |
type(error_t), allocatable, intent(out) :: error |
| 550 |
|
| 551 |
type(package_config_t) :: package |
| 552 |
character(len=*), parameter :: manifest = 'fpm-profiles.toml' |
| 553 |
integer :: unit |
| 554 |
|
| 555 |
open(file=manifest, newunit=unit) |
| 556 |
write(unit, '(a)') & |
| 557 |
& 'name = "example"', & |
| 558 |
& '[profiles]', & |
| 559 |
& 'development = ["debug", "testing"]', & |
| 560 |
& 'release = ["optimized"]', & |
| 561 |
& 'full-test = ["debug", "testing", "benchmarks"]', & |
| 562 |
& '[features]', & |
| 563 |
& 'testing.flags = " -g"', & |
| 564 |
& 'optimized.flags = " -O2"', & |
| 565 |
& 'benchmarks.flags = " -O3"' |
| 566 |
close(unit) |
| 567 |
|
| 568 |
call get_package_data(package, manifest, error) |
| 569 |
|
| 570 |
open(file=manifest, newunit=unit) |
| 571 |
close(unit, status='delete') |
| 572 |
|
| 573 |
if (allocated(error)) return |
| 574 |
|
| 575 |
! Check that profiles were parsed correctly |
| 576 |
if (.not. allocated(package%profiles)) then |
| 577 |
call test_failed(error, "No profiles found in package") |
| 578 |
return |
| 579 |
end if |
| 580 |
|
| 581 |
! debug, release, development, full-test |
| 582 |
if (size(package%profiles) /= 4) then |
| 583 |
call test_failed(error, "Unexpected number of profiles, should be 4") |
| 584 |
return |
| 585 |
end if |
| 586 |
|
| 587 |
! Check development profile |
| 588 |
if (package%profiles(1)%name /= "development") then |
| 589 |
call test_failed(error, "Expected profile name 'development', got '" // package%profiles(1)%name // "'") |
| 590 |
return |
| 591 |
end if |
| 592 |
|
| 593 |
if (size(package%profiles(1)%features) /= 2) then |
| 594 |
call test_failed(error, "Unexpected number of features, should be 2") |
| 595 |
return |
| 596 |
end if |
| 597 |
|
| 598 |
if (package%profiles(1)%features(1)%s /= "debug" .or. & |
| 599 |
package%profiles(1)%features(2)%s /= "testing") then |
| 600 |
call test_failed(error, "Incorrect features in development profile") |
| 601 |
return |
| 602 |
end if |
| 603 |
|
| 604 |
end subroutine test_profiles |
| 605 |
|
| 606 |
!> Test invalid profile configuration should fail |
| 607 |
subroutine test_profiles_invalid(error) |
| 608 |
|
| 609 |
!> Error handling |
| 610 |
type(error_t), allocatable, intent(out) :: error |
| 611 |
|
| 612 |
type(package_config_t) :: package |
| 613 |
character(len=*), parameter :: manifest = 'fpm-profiles-error.toml' |
| 614 |
integer :: unit |
| 615 |
|
| 616 |
open(file=manifest, newunit=unit) |
| 617 |
write(unit, '(a)') & |
| 618 |
& 'name = "example"', & |
| 619 |
& '[profiles]', & |
| 620 |
& 'development = "not_an_array"' |
| 621 |
close(unit) |
| 622 |
|
| 623 |
call get_package_data(package, manifest, error) |
| 624 |
|
| 625 |
open(file=manifest, newunit=unit) |
| 626 |
close(unit, status='delete') |
| 627 |
end subroutine test_profiles_invalid |
| 628 |
|
| 629 |
!> Executables cannot be created from empty tables |
| 630 |
subroutine test_executable_empty(error) |
| 631 |
use fpm_manifest_executable |
| 632 |
|
| 633 |
!> Error handling |
| 634 |
type(error_t), allocatable, intent(out) :: error |
| 635 |
|
| 636 |
type(toml_table) :: table |
| 637 |
type(executable_config_t) :: executable |
| 638 |
|
| 639 |
call new_table(table) |
| 640 |
|
| 641 |
call new_executable(executable, table, error) |
| 642 |
|
| 643 |
end subroutine test_executable_empty |
| 644 |
|
| 645 |
|
| 646 |
!> Pass a wrong TOML type to the name field of the executable |
| 647 |
subroutine test_executable_typeerror(error) |
| 648 |
use fpm_manifest_executable |
| 649 |
|
| 650 |
!> Error handling |
| 651 |
type(error_t), allocatable, intent(out) :: error |
| 652 |
|
| 653 |
type(toml_table) :: table |
| 654 |
type(toml_table), pointer :: child |
| 655 |
integer :: stat |
| 656 |
type(executable_config_t) :: executable |
| 657 |
|
| 658 |
call new_table(table) |
| 659 |
call add_table(table, 'name', child, stat) |
| 660 |
|
| 661 |
call new_executable(executable, table, error) |
| 662 |
|
| 663 |
end subroutine test_executable_typeerror |
| 664 |
|
| 665 |
|
| 666 |
!> Pass a TOML table with insufficient entries to the executable constructor |
| 667 |
subroutine test_executable_noname(error) |
| 668 |
use fpm_manifest_executable |
| 669 |
|
| 670 |
!> Error handling |
| 671 |
type(error_t), allocatable, intent(out) :: error |
| 672 |
|
| 673 |
type(toml_table) :: table |
| 674 |
type(toml_table), pointer :: child |
| 675 |
integer :: stat |
| 676 |
type(executable_config_t) :: executable |
| 677 |
|
| 678 |
call new_table(table) |
| 679 |
call add_table(table, 'dependencies', child, stat) |
| 680 |
|
| 681 |
call new_executable(executable, table, error) |
| 682 |
|
| 683 |
end subroutine test_executable_noname |
| 684 |
|
| 685 |
|
| 686 |
!> Pass a TOML table with not allowed keys |
| 687 |
subroutine test_executable_wrongkey(error) |
| 688 |
use fpm_manifest_executable |
| 689 |
|
| 690 |
!> Error handling |
| 691 |
type(error_t), allocatable, intent(out) :: error |
| 692 |
|
| 693 |
type(toml_table) :: table |
| 694 |
type(toml_table), pointer :: child |
| 695 |
integer :: stat |
| 696 |
type(executable_config_t) :: executable |
| 697 |
|
| 698 |
call new_table(table) |
| 699 |
call add_table(table, 'wrong-field', child, stat) |
| 700 |
|
| 701 |
call new_executable(executable, table, error) |
| 702 |
|
| 703 |
end subroutine test_executable_wrongkey |
| 704 |
|
| 705 |
|
| 706 |
!> Try to read values from the [build] table |
| 707 |
subroutine test_build_valid(error) |
| 708 |
|
| 709 |
!> Error handling |
| 710 |
type(error_t), allocatable, intent(out) :: error |
| 711 |
|
| 712 |
type(package_config_t) :: package |
| 713 |
character(:), allocatable :: temp_file |
| 714 |
integer :: unit |
| 715 |
|
| 716 |
allocate(temp_file, source=get_temp_filename()) |
| 717 |
|
| 718 |
open(file=temp_file, newunit=unit) |
| 719 |
write(unit, '(a)') & |
| 720 |
& 'name = "example"', & |
| 721 |
& '[build]', & |
| 722 |
& 'auto-executables = false', & |
| 723 |
& 'auto-tests = false', & |
| 724 |
& 'module-naming = true' |
| 725 |
close(unit) |
| 726 |
|
| 727 |
call get_package_data(package, temp_file, error) |
| 728 |
|
| 729 |
if (allocated(error)) return |
| 730 |
|
| 731 |
if (package%build%auto_executables) then |
| 732 |
call test_failed(error, "Wrong value of 'auto-executables' read, expecting .false.") |
| 733 |
return |
| 734 |
end if |
| 735 |
|
| 736 |
if (package%build%auto_tests) then |
| 737 |
call test_failed(error, "Wrong value of 'auto-tests' read, expecting .false.") |
| 738 |
return |
| 739 |
end if |
| 740 |
|
| 741 |
if (.not. package%build%module_naming) then |
| 742 |
call test_failed(error, "Wrong value of 'module-naming' read, expecting .true.") |
| 743 |
return |
| 744 |
end if |
| 745 |
|
| 746 |
end subroutine test_build_valid |
| 747 |
|
| 748 |
|
| 749 |
!> Try to read values from the [build] table |
| 750 |
subroutine test_build_invalid_key(error) |
| 751 |
|
| 752 |
!> Error handling |
| 753 |
type(error_t), allocatable, intent(out) :: error |
| 754 |
|
| 755 |
type(package_config_t) :: package |
| 756 |
character(:), allocatable :: temp_file |
| 757 |
integer :: unit |
| 758 |
type(error_t), allocatable :: build_error |
| 759 |
|
| 760 |
allocate(temp_file, source=get_temp_filename()) |
| 761 |
|
| 762 |
open(file=temp_file, newunit=unit) |
| 763 |
write(unit, '(a)') & |
| 764 |
& 'name = "example"', & |
| 765 |
& '[build]', & |
| 766 |
& 'auto-executables = false', & |
| 767 |
& 'auto-tests = false ', & |
| 768 |
& 'module-naming = true ', & |
| 769 |
& 'this-will-fail = true ' |
| 770 |
close(unit) |
| 771 |
|
| 772 |
call get_package_data(package, temp_file, build_error) |
| 773 |
|
| 774 |
! Error message should contain both package name and key name |
| 775 |
if (allocated(build_error)) then |
| 776 |
|
| 777 |
if (.not.index(build_error%message,'this-will-fail')>0) then |
| 778 |
call fatal_error(error, 'no invalid key name is printed to output') |
| 779 |
return |
| 780 |
end if |
| 781 |
|
| 782 |
if (.not.index(build_error%message,'example')>0) then |
| 783 |
call fatal_error(error, 'no package name is printed to output') |
| 784 |
return |
| 785 |
end if |
| 786 |
|
| 787 |
else |
| 788 |
call fatal_error(error, 'no error allocated on invalid [build] section key ') |
| 789 |
return |
| 790 |
end if |
| 791 |
|
| 792 |
end subroutine test_build_invalid_key |
| 793 |
|
| 794 |
|
| 795 |
!> Try to read values from an empty [build] table |
| 796 |
subroutine test_build_empty(error) |
| 797 |
|
| 798 |
!> Error handling |
| 799 |
type(error_t), allocatable, intent(out) :: error |
| 800 |
|
| 801 |
type(package_config_t) :: package |
| 802 |
character(:), allocatable :: temp_file |
| 803 |
integer :: unit |
| 804 |
|
| 805 |
allocate(temp_file, source=get_temp_filename()) |
| 806 |
|
| 807 |
open(file=temp_file, newunit=unit) |
| 808 |
write(unit, '(a)') & |
| 809 |
& 'name = "example"', & |
| 810 |
& '[build]', & |
| 811 |
& '[library]' |
| 812 |
close(unit) |
| 813 |
|
| 814 |
call get_package_data(package, temp_file, error) |
| 815 |
|
| 816 |
if (allocated(error)) return |
| 817 |
|
| 818 |
if (.not.package%build%auto_executables) then |
| 819 |
call test_failed(error, "Wrong default value of 'auto-executables' read, expecting .true.") |
| 820 |
return |
| 821 |
end if |
| 822 |
|
| 823 |
if (.not.package%build%auto_tests) then |
| 824 |
call test_failed(error, "Wrong default value of 'auto-tests' read, expecting .true.") |
| 825 |
return |
| 826 |
end if |
| 827 |
|
| 828 |
if (package%build%module_naming) then |
| 829 |
call test_failed(error, "Wrong default value of 'module-naming' read, expecting .false.") |
| 830 |
return |
| 831 |
end if |
| 832 |
|
| 833 |
end subroutine test_build_empty |
| 834 |
|
| 835 |
|
| 836 |
!> Try to read values from a [build] table with invalid values |
| 837 |
subroutine test_build_invalid_values(error) |
| 838 |
|
| 839 |
!> Error handling |
| 840 |
type(error_t), allocatable, intent(out) :: error |
| 841 |
|
| 842 |
type(package_config_t) :: package |
| 843 |
character(:), allocatable :: temp_file |
| 844 |
integer :: unit |
| 845 |
|
| 846 |
allocate(temp_file, source=get_temp_filename()) |
| 847 |
|
| 848 |
open(file=temp_file, newunit=unit) |
| 849 |
write(unit, '(a)') & |
| 850 |
& 'name = "example"', & |
| 851 |
& '[build]', & |
| 852 |
& 'auto-executables = "false"' |
| 853 |
close(unit) |
| 854 |
|
| 855 |
call get_package_data(package, temp_file, error) |
| 856 |
|
| 857 |
end subroutine test_build_invalid_values |
| 858 |
|
| 859 |
|
| 860 |
!> Libraries can be created from empty tables |
| 861 |
subroutine test_library_empty(error) |
| 862 |
use fpm_manifest_library |
| 863 |
|
| 864 |
!> Error handling |
| 865 |
type(error_t), allocatable, intent(out) :: error |
| 866 |
|
| 867 |
type(toml_table) :: table |
| 868 |
type(library_config_t) :: library |
| 869 |
|
| 870 |
call new_table(table) |
| 871 |
|
| 872 |
call new_library(library, table, error) |
| 873 |
if (allocated(error)) return |
| 874 |
|
| 875 |
call check_string(error, library%source_dir, "src", & |
| 876 |
& "Default library source-dir") |
| 877 |
if (allocated(error)) return |
| 878 |
|
| 879 |
if (.not.allocated(library%include_dir)) then |
| 880 |
call test_failed(error,"Default include-dir list not allocated") |
| 881 |
return |
| 882 |
end if |
| 883 |
|
| 884 |
if (.not.("include".in.library%include_dir)) then |
| 885 |
call test_failed(error,"'include' not in default include-dir list") |
| 886 |
return |
| 887 |
end if |
| 888 |
|
| 889 |
end subroutine test_library_empty |
| 890 |
|
| 891 |
|
| 892 |
!> Pass a TOML table with not allowed keys |
| 893 |
subroutine test_library_wrongkey(error) |
| 894 |
use fpm_manifest_library |
| 895 |
|
| 896 |
!> Error handling |
| 897 |
type(error_t), allocatable, intent(out) :: error |
| 898 |
|
| 899 |
type(toml_table) :: table |
| 900 |
type(toml_table), pointer :: child |
| 901 |
integer :: stat |
| 902 |
type(library_config_t) :: library |
| 903 |
|
| 904 |
call new_table(table) |
| 905 |
call add_table(table, 'not-allowed', child, stat) |
| 906 |
|
| 907 |
call new_library(library, table, error) |
| 908 |
|
| 909 |
end subroutine test_library_wrongkey |
| 910 |
|
| 911 |
!> Pass a TOML table with not allowed source dirs |
| 912 |
subroutine test_library_list(error) |
| 913 |
use fpm_manifest_library |
| 914 |
|
| 915 |
!> Error handling |
| 916 |
type(error_t), allocatable, intent(out) :: error |
| 917 |
|
| 918 |
type(string_t), allocatable :: source_dirs(:) |
| 919 |
type(toml_table) :: table |
| 920 |
type(library_config_t) :: library |
| 921 |
|
| 922 |
source_dirs = [string_t("src1"),string_t("src2")] |
| 923 |
call new_table (table) |
| 924 |
call set_list (table, "source-dir", source_dirs, error) |
| 925 |
call new_library(library, table, error) |
| 926 |
|
| 927 |
end subroutine test_library_list |
| 928 |
|
| 929 |
!> Pass a TOML table with a 1-sized source dir list |
| 930 |
subroutine test_library_listone(error) |
| 931 |
use fpm_manifest_library |
| 932 |
|
| 933 |
!> Error handling |
| 934 |
type(error_t), allocatable, intent(out) :: error |
| 935 |
|
| 936 |
type(package_config_t) :: package |
| 937 |
character(:), allocatable :: temp_file |
| 938 |
integer :: unit |
| 939 |
|
| 940 |
open(file=temp_file, newunit=unit) |
| 941 |
write(unit, '(a)') & |
| 942 |
& 'name = "example"', & |
| 943 |
& '[library]', & |
| 944 |
& 'source-dir = ["my-src"]' |
| 945 |
close(unit) |
| 946 |
|
| 947 |
call get_package_data(package, temp_file, error) |
| 948 |
|
| 949 |
end subroutine test_library_listone |
| 950 |
|
| 951 |
!> Packages cannot be created from empty tables |
| 952 |
subroutine test_package_simple(error) |
| 953 |
use fpm_manifest_package |
| 954 |
|
| 955 |
!> Error handling |
| 956 |
type(error_t), allocatable, intent(out) :: error |
| 957 |
|
| 958 |
type(toml_table) :: table |
| 959 |
type(toml_table), pointer :: child, child2 |
| 960 |
type(toml_array), pointer :: children |
| 961 |
integer :: stat |
| 962 |
type(package_config_t) :: package |
| 963 |
|
| 964 |
call new_table(table) |
| 965 |
call set_value(table, 'name', 'example', stat) |
| 966 |
call set_value(table, 'license', 'MIT', stat) |
| 967 |
call add_table(table, 'dev-dependencies', child, stat) |
| 968 |
call add_table(child, 'pkg1', child2, stat) |
| 969 |
call set_value(child2, 'git', 'https://github.com/fortran-lang/pkg1', stat) |
| 970 |
call add_table(child, 'pkg2', child2) |
| 971 |
call set_value(child2, 'git', 'https://gitlab.com/fortran-lang/pkg2', stat) |
| 972 |
call set_value(child2, 'branch', 'devel', stat) |
| 973 |
call add_table(child, 'pkg3', child2) |
| 974 |
call set_value(child2, 'git', 'https://bitbucket.org/fortran-lang/pkg3', stat) |
| 975 |
call set_value(child2, 'rev', '9fceb02d0ae598e95dc970b74767f19372d61af8', stat) |
| 976 |
call add_table(child, 'pkg4', child2) |
| 977 |
call set_value(child2, 'git', 'https://gitea.com/fortran-lang/pkg4', stat) |
| 978 |
call set_value(child2, 'tag', 'v1.8.5-rc3', stat) |
| 979 |
call add_array(table, 'test', children, stat) |
| 980 |
call add_table(children, child, stat) |
| 981 |
call set_value(child, 'name', 'tester', stat) |
| 982 |
|
| 983 |
call new_package(package, table, error=error) |
| 984 |
|
| 985 |
end subroutine test_package_simple |
| 986 |
|
| 987 |
|
| 988 |
!> Packages cannot be created from empty tables |
| 989 |
subroutine test_package_empty(error) |
| 990 |
use fpm_manifest_package |
| 991 |
|
| 992 |
!> Error handling |
| 993 |
type(error_t), allocatable, intent(out) :: error |
| 994 |
|
| 995 |
type(toml_table) :: table |
| 996 |
type(package_config_t) :: package |
| 997 |
|
| 998 |
call new_table(table) |
| 999 |
|
| 1000 |
call new_package(package, table, error=error) |
| 1001 |
|
| 1002 |
end subroutine test_package_empty |
| 1003 |
|
| 1004 |
|
| 1005 |
!> Create an array in the package name, which should cause an error |
| 1006 |
subroutine test_package_typeerror(error) |
| 1007 |
use fpm_manifest_package |
| 1008 |
|
| 1009 |
!> Error handling |
| 1010 |
type(error_t), allocatable, intent(out) :: error |
| 1011 |
|
| 1012 |
type(toml_table) :: table |
| 1013 |
type(toml_array), pointer :: child |
| 1014 |
integer :: stat |
| 1015 |
type(package_config_t) :: package |
| 1016 |
|
| 1017 |
call new_table(table) |
| 1018 |
call add_array(table, "name", child, stat) |
| 1019 |
|
| 1020 |
call new_package(package, table, error=error) |
| 1021 |
|
| 1022 |
end subroutine test_package_typeerror |
| 1023 |
|
| 1024 |
|
| 1025 |
!> Try to create a new package without a name field |
| 1026 |
subroutine test_package_noname(error) |
| 1027 |
use fpm_manifest_package |
| 1028 |
|
| 1029 |
!> Error handling |
| 1030 |
type(error_t), allocatable, intent(out) :: error |
| 1031 |
|
| 1032 |
type(toml_table) :: table |
| 1033 |
type(toml_table), pointer :: child |
| 1034 |
integer :: stat |
| 1035 |
type(package_config_t) :: package |
| 1036 |
|
| 1037 |
call new_table(table) |
| 1038 |
call add_table(table, "library", child, stat) |
| 1039 |
call add_table(table, "dev-dependencies", child, stat) |
| 1040 |
call add_table(table, "dependencies", child, stat) |
| 1041 |
|
| 1042 |
call new_package(package, table, error=error) |
| 1043 |
|
| 1044 |
end subroutine test_package_noname |
| 1045 |
|
| 1046 |
|
| 1047 |
!> Try to read executables from a mixed type array |
| 1048 |
subroutine test_package_wrongexe(error) |
| 1049 |
use fpm_manifest_package |
| 1050 |
|
| 1051 |
!> Error handling |
| 1052 |
type(error_t), allocatable, intent(out) :: error |
| 1053 |
|
| 1054 |
type(toml_table) :: table |
| 1055 |
type(toml_array), pointer :: children, children2 |
| 1056 |
integer :: stat |
| 1057 |
type(package_config_t) :: package |
| 1058 |
|
| 1059 |
call new_table(table) |
| 1060 |
call set_value(table, 'name', 'example', stat) |
| 1061 |
call add_array(table, 'executable', children, stat) |
| 1062 |
call add_array(children, children2, stat) |
| 1063 |
|
| 1064 |
call new_package(package, table, error=error) |
| 1065 |
|
| 1066 |
end subroutine test_package_wrongexe |
| 1067 |
|
| 1068 |
|
| 1069 |
!> Try to read tests from a mixed type array |
| 1070 |
subroutine test_package_wrongtest(error) |
| 1071 |
use fpm_manifest_package |
| 1072 |
|
| 1073 |
!> Error handling |
| 1074 |
type(error_t), allocatable, intent(out) :: error |
| 1075 |
|
| 1076 |
type(toml_table) :: table |
| 1077 |
type(toml_array), pointer :: children, children2 |
| 1078 |
integer :: stat |
| 1079 |
type(package_config_t) :: package |
| 1080 |
|
| 1081 |
call new_table(table) |
| 1082 |
call set_value(table, 'name', 'example', stat) |
| 1083 |
call add_array(table, 'test', children, stat) |
| 1084 |
call add_array(children, children2, stat) |
| 1085 |
|
| 1086 |
call new_package(package, table, error=error) |
| 1087 |
|
| 1088 |
end subroutine test_package_wrongtest |
| 1089 |
|
| 1090 |
|
| 1091 |
!> Try to read tests from a mixed type array |
| 1092 |
subroutine test_package_duplicate(error) |
| 1093 |
use fpm_manifest_package |
| 1094 |
|
| 1095 |
!> Error handling |
| 1096 |
type(error_t), allocatable, intent(out) :: error |
| 1097 |
|
| 1098 |
type(toml_table) :: table |
| 1099 |
type(toml_table), pointer :: child |
| 1100 |
type(toml_array), pointer :: children |
| 1101 |
integer :: stat |
| 1102 |
type(package_config_t) :: package |
| 1103 |
|
| 1104 |
table = toml_table() |
| 1105 |
call set_value(table, 'name', 'example', stat) |
| 1106 |
call add_array(table, 'test', children, stat) |
| 1107 |
call add_table(children, child, stat) |
| 1108 |
call set_value(child, 'name', 'prog', stat) |
| 1109 |
call add_table(children, child, stat) |
| 1110 |
call set_value(child, 'name', 'prog', stat) |
| 1111 |
|
| 1112 |
call new_package(package, table, error=error) |
| 1113 |
|
| 1114 |
end subroutine test_package_duplicate |
| 1115 |
|
| 1116 |
|
| 1117 |
!> Tests cannot be created from empty tables |
| 1118 |
subroutine test_test_simple(error) |
| 1119 |
use fpm_manifest_test |
| 1120 |
|
| 1121 |
!> Error handling |
| 1122 |
type(error_t), allocatable, intent(out) :: error |
| 1123 |
|
| 1124 |
type(toml_table) :: table |
| 1125 |
type(toml_table), pointer :: child |
| 1126 |
integer :: stat |
| 1127 |
type(test_config_t) :: test |
| 1128 |
|
| 1129 |
call new_table(table) |
| 1130 |
call set_value(table, 'name', 'example', stat) |
| 1131 |
call set_value(table, 'source-dir', 'tests', stat) |
| 1132 |
call set_value(table, 'main', 'tester.f90', stat) |
| 1133 |
call add_table(table, 'dependencies', child, stat) |
| 1134 |
|
| 1135 |
call new_test(test, table, error) |
| 1136 |
if (allocated(error)) return |
| 1137 |
|
| 1138 |
call check_string(error, test%main, "tester.f90", "Test main") |
| 1139 |
if (allocated(error)) return |
| 1140 |
|
| 1141 |
end subroutine test_test_simple |
| 1142 |
|
| 1143 |
|
| 1144 |
!> Tests cannot be created from empty tables |
| 1145 |
subroutine test_test_empty(error) |
| 1146 |
use fpm_manifest_test |
| 1147 |
|
| 1148 |
!> Error handling |
| 1149 |
type(error_t), allocatable, intent(out) :: error |
| 1150 |
|
| 1151 |
type(toml_table) :: table |
| 1152 |
type(test_config_t) :: test |
| 1153 |
|
| 1154 |
call new_table(table) |
| 1155 |
|
| 1156 |
call new_test(test, table, error) |
| 1157 |
|
| 1158 |
end subroutine test_test_empty |
| 1159 |
|
| 1160 |
|
| 1161 |
!> Pass a wrong TOML type to the name field of the test |
| 1162 |
subroutine test_test_typeerror(error) |
| 1163 |
use fpm_manifest_test |
| 1164 |
|
| 1165 |
!> Error handling |
| 1166 |
type(error_t), allocatable, intent(out) :: error |
| 1167 |
|
| 1168 |
type(toml_table) :: table |
| 1169 |
type(toml_table), pointer :: child |
| 1170 |
integer :: stat |
| 1171 |
type(test_config_t) :: test |
| 1172 |
|
| 1173 |
call new_table(table) |
| 1174 |
call add_table(table, 'name', child, stat) |
| 1175 |
|
| 1176 |
call new_test(test, table, error) |
| 1177 |
|
| 1178 |
end subroutine test_test_typeerror |
| 1179 |
|
| 1180 |
|
| 1181 |
!> Pass a TOML table with insufficient entries to the test constructor |
| 1182 |
subroutine test_test_noname(error) |
| 1183 |
use fpm_manifest_test |
| 1184 |
|
| 1185 |
!> Error handling |
| 1186 |
type(error_t), allocatable, intent(out) :: error |
| 1187 |
|
| 1188 |
type(toml_table) :: table |
| 1189 |
type(toml_table), pointer :: child |
| 1190 |
integer :: stat |
| 1191 |
type(test_config_t) :: test |
| 1192 |
|
| 1193 |
call new_table(table) |
| 1194 |
call add_table(table, 'dependencies', child, stat) |
| 1195 |
|
| 1196 |
call new_test(test, table, error) |
| 1197 |
|
| 1198 |
end subroutine test_test_noname |
| 1199 |
|
| 1200 |
|
| 1201 |
!> Pass a TOML table with not allowed keys |
| 1202 |
subroutine test_test_wrongkey(error) |
| 1203 |
use fpm_manifest_test |
| 1204 |
|
| 1205 |
!> Error handling |
| 1206 |
type(error_t), allocatable, intent(out) :: error |
| 1207 |
|
| 1208 |
type(toml_table) :: table |
| 1209 |
type(toml_table), pointer :: child |
| 1210 |
integer :: stat |
| 1211 |
type(test_config_t) :: test |
| 1212 |
|
| 1213 |
call new_table(table) |
| 1214 |
call add_table(table, 'not-supported', child, stat) |
| 1215 |
|
| 1216 |
call new_test(test, table, error) |
| 1217 |
|
| 1218 |
end subroutine test_test_wrongkey |
| 1219 |
|
| 1220 |
|
| 1221 |
!> Create a simple example entry |
| 1222 |
subroutine test_example_simple(error) |
| 1223 |
use fpm_manifest_example |
| 1224 |
|
| 1225 |
!> Error handling |
| 1226 |
type(error_t), allocatable, intent(out) :: error |
| 1227 |
|
| 1228 |
type(toml_table) :: table |
| 1229 |
type(toml_table), pointer :: child |
| 1230 |
integer :: stat |
| 1231 |
type(example_config_t) :: example |
| 1232 |
|
| 1233 |
call new_table(table) |
| 1234 |
call set_value(table, 'name', 'example', stat) |
| 1235 |
call set_value(table, 'source-dir', 'demos', stat) |
| 1236 |
call set_value(table, 'main', 'demo.f90', stat) |
| 1237 |
call add_table(table, 'dependencies', child, stat) |
| 1238 |
|
| 1239 |
call new_example(example, table, error) |
| 1240 |
if (allocated(error)) return |
| 1241 |
|
| 1242 |
call check_string(error, example%main, "demo.f90", "Example main") |
| 1243 |
if (allocated(error)) return |
| 1244 |
|
| 1245 |
end subroutine test_example_simple |
| 1246 |
|
| 1247 |
|
| 1248 |
!> Examples cannot be created from empty tables |
| 1249 |
subroutine test_example_empty(error) |
| 1250 |
use fpm_manifest_example |
| 1251 |
|
| 1252 |
!> Error handling |
| 1253 |
type(error_t), allocatable, intent(out) :: error |
| 1254 |
|
| 1255 |
type(toml_table) :: table |
| 1256 |
type(example_config_t) :: example |
| 1257 |
|
| 1258 |
call new_table(table) |
| 1259 |
|
| 1260 |
call new_example(example, table, error) |
| 1261 |
|
| 1262 |
end subroutine test_example_empty |
| 1263 |
|
| 1264 |
|
| 1265 |
!> Test link options |
| 1266 |
subroutine test_link_string(error) |
| 1267 |
use fpm_manifest_build |
| 1268 |
|
| 1269 |
!> Error handling |
| 1270 |
type(error_t), allocatable, intent(out) :: error |
| 1271 |
|
| 1272 |
type(toml_table) :: table |
| 1273 |
integer :: stat |
| 1274 |
type(build_config_t) :: build |
| 1275 |
|
| 1276 |
table = toml_table() |
| 1277 |
call set_value(table, "link", "z", stat=stat) |
| 1278 |
|
| 1279 |
call new_build_config(build, table, 'test_link_string', error) |
| 1280 |
if (allocated(error)) return |
| 1281 |
|
| 1282 |
!> Test serialization roundtrip |
| 1283 |
call build%test_serialization('test_link_string', error) |
| 1284 |
if (allocated(error)) return |
| 1285 |
|
| 1286 |
end subroutine test_link_string |
| 1287 |
|
| 1288 |
|
| 1289 |
!> Test link options |
| 1290 |
subroutine test_link_array(error) |
| 1291 |
use fpm_manifest_build |
| 1292 |
|
| 1293 |
!> Error handling |
| 1294 |
type(error_t), allocatable, intent(out) :: error |
| 1295 |
|
| 1296 |
type(toml_table) :: table |
| 1297 |
type(toml_array), pointer :: children |
| 1298 |
integer :: stat |
| 1299 |
type(build_config_t) :: build |
| 1300 |
|
| 1301 |
table = toml_table() |
| 1302 |
call add_array(table, "link", children, stat=stat) |
| 1303 |
call set_value(children, 1, "blas", stat=stat) |
| 1304 |
call set_value(children, 2, "lapack", stat=stat) |
| 1305 |
|
| 1306 |
call new_build_config(build, table, 'test_link_array', error) |
| 1307 |
if (allocated(error)) return |
| 1308 |
|
| 1309 |
!> Test serialization roundtrip |
| 1310 |
call build%test_serialization('test_link_array', error) |
| 1311 |
if (allocated(error)) return |
| 1312 |
|
| 1313 |
end subroutine test_link_array |
| 1314 |
|
| 1315 |
|
| 1316 |
!> Test link options |
| 1317 |
subroutine test_invalid_link(error) |
| 1318 |
use fpm_manifest_build |
| 1319 |
|
| 1320 |
!> Error handling |
| 1321 |
type(error_t), allocatable, intent(out) :: error |
| 1322 |
|
| 1323 |
type(toml_table) :: table |
| 1324 |
type(toml_table), pointer :: child |
| 1325 |
integer :: stat |
| 1326 |
type(build_config_t) :: build |
| 1327 |
|
| 1328 |
table = toml_table() |
| 1329 |
call add_table(table, "link", child, stat=stat) |
| 1330 |
|
| 1331 |
call new_build_config(build, table, 'test_invalid_link', error) |
| 1332 |
|
| 1333 |
end subroutine test_invalid_link |
| 1334 |
|
| 1335 |
|
| 1336 |
subroutine test_install_library(error) |
| 1337 |
use fpm_manifest_install |
| 1338 |
|
| 1339 |
!> Error handling |
| 1340 |
type(error_t), allocatable, intent(out) :: error |
| 1341 |
|
| 1342 |
type(toml_table) :: table |
| 1343 |
type(install_config_t) :: install |
| 1344 |
|
| 1345 |
table = toml_table() |
| 1346 |
call set_value(table, "library", .true.) |
| 1347 |
|
| 1348 |
call new_install_config(install, table, error) |
| 1349 |
if (allocated(error)) return |
| 1350 |
|
| 1351 |
if (.not.install%library) then |
| 1352 |
call test_failed(error, "Library entry should be true") |
| 1353 |
return |
| 1354 |
end if |
| 1355 |
|
| 1356 |
end subroutine test_install_library |
| 1357 |
|
| 1358 |
|
| 1359 |
subroutine test_install_empty(error) |
| 1360 |
use fpm_manifest_install |
| 1361 |
|
| 1362 |
!> Error handling |
| 1363 |
type(error_t), allocatable, intent(out) :: error |
| 1364 |
|
| 1365 |
type(toml_table) :: table |
| 1366 |
type(install_config_t) :: install |
| 1367 |
|
| 1368 |
table = toml_table() |
| 1369 |
|
| 1370 |
call new_install_config(install, table, error) |
| 1371 |
if (allocated(error)) return |
| 1372 |
|
| 1373 |
if (install%library) then |
| 1374 |
call test_failed(error, "Library default should be false") |
| 1375 |
return |
| 1376 |
end if |
| 1377 |
|
| 1378 |
end subroutine test_install_empty |
| 1379 |
|
| 1380 |
|
| 1381 |
subroutine test_install_wrongkey(error) |
| 1382 |
use fpm_manifest_install |
| 1383 |
|
| 1384 |
!> Error handling |
| 1385 |
type(error_t), allocatable, intent(out) :: error |
| 1386 |
|
| 1387 |
type(toml_table) :: table |
| 1388 |
type(install_config_t) :: install |
| 1389 |
|
| 1390 |
table = toml_table() |
| 1391 |
call set_value(table, "prefix", "/some/install/path") |
| 1392 |
|
| 1393 |
call new_install_config(install, table, error) |
| 1394 |
|
| 1395 |
end subroutine test_install_wrongkey |
| 1396 |
|
| 1397 |
|
| 1398 |
subroutine test_install_module_dir(error) |
| 1399 |
use fpm_manifest_install |
| 1400 |
|
| 1401 |
!> Error handling |
| 1402 |
type(error_t), allocatable, intent(out) :: error |
| 1403 |
|
| 1404 |
type(toml_table) :: table |
| 1405 |
type(install_config_t) :: install |
| 1406 |
|
| 1407 |
table = toml_table() |
| 1408 |
call set_value(table, "module-dir", "custom_modules") |
| 1409 |
|
| 1410 |
call new_install_config(install, table, error) |
| 1411 |
if (allocated(error)) return |
| 1412 |
|
| 1413 |
if (.not.allocated(install%module_dir)) then |
| 1414 |
call test_failed(error, "Module directory should be allocated") |
| 1415 |
return |
| 1416 |
end if |
| 1417 |
|
| 1418 |
if (install%module_dir /= "custom_modules") then |
| 1419 |
call test_failed(error, "Module directory should match input") |
| 1420 |
return |
| 1421 |
end if |
| 1422 |
|
| 1423 |
end subroutine test_install_module_dir |
| 1424 |
|
| 1425 |
subroutine test_preprocess_empty(error) |
| 1426 |
use fpm_manifest_preprocess |
| 1427 |
|
| 1428 |
!> Error handling |
| 1429 |
type(error_t), allocatable, intent(out) :: error |
| 1430 |
|
| 1431 |
type(toml_table) :: table |
| 1432 |
type(preprocess_config_t) :: preprocess |
| 1433 |
|
| 1434 |
call new_table(table) |
| 1435 |
table%key = "example" |
| 1436 |
|
| 1437 |
call preprocess%new(table, error) |
| 1438 |
|
| 1439 |
end subroutine test_preprocess_empty |
| 1440 |
|
| 1441 |
!> Pass a TOML table with not allowed keys |
| 1442 |
subroutine test_preprocess_wrongkey(error) |
| 1443 |
use fpm_manifest_preprocess |
| 1444 |
|
| 1445 |
!> Error handling |
| 1446 |
type(error_t), allocatable, intent(out) :: error |
| 1447 |
|
| 1448 |
type(toml_table) :: table |
| 1449 |
type(toml_table), pointer :: child |
| 1450 |
integer :: stat |
| 1451 |
type(preprocess_config_t) :: preprocess |
| 1452 |
|
| 1453 |
call new_table(table) |
| 1454 |
table%key = 'example' |
| 1455 |
call add_table(table, 'wrong-field', child, stat) |
| 1456 |
|
| 1457 |
call preprocess%new(table, error) |
| 1458 |
|
| 1459 |
end subroutine test_preprocess_wrongkey |
| 1460 |
|
| 1461 |
!> Preprocess table cannot be empty. |
| 1462 |
subroutine test_preprocessors_empty(error) |
| 1463 |
use fpm_manifest_preprocess |
| 1464 |
|
| 1465 |
!> Error handling |
| 1466 |
type(error_t), allocatable, intent(out) :: error |
| 1467 |
|
| 1468 |
type(toml_table) :: table |
| 1469 |
type(preprocess_config_t), allocatable :: preprocessors(:) |
| 1470 |
|
| 1471 |
call new_table(table) |
| 1472 |
|
| 1473 |
call new_preprocessors(preprocessors, table, error) |
| 1474 |
if (allocated(error)) return |
| 1475 |
|
| 1476 |
end subroutine test_preprocessors_empty |
| 1477 |
|
| 1478 |
!> Test macro parsing function get_macros_from_manifest |
| 1479 |
subroutine test_macro_parsing(error) |
| 1480 |
use fpm_compiler, only: get_macros, compiler_enum, id_gcc |
| 1481 |
|
| 1482 |
!> Error handling |
| 1483 |
type(error_t), allocatable, intent(out) :: error |
| 1484 |
|
| 1485 |
type(package_config_t) :: package |
| 1486 |
character(:), allocatable :: temp_file |
| 1487 |
integer :: unit |
| 1488 |
integer(compiler_enum) :: id |
| 1489 |
|
| 1490 |
id = id_gcc |
| 1491 |
|
| 1492 |
allocate(temp_file, source=get_temp_filename()) |
| 1493 |
|
| 1494 |
open(file=temp_file, newunit=unit) |
| 1495 |
write(unit, '(a)') & |
| 1496 |
& 'name = "example"', & |
| 1497 |
& 'version = "0.1.0"', & |
| 1498 |
& '[preprocess]', & |
| 1499 |
& '[preprocess.cpp]', & |
| 1500 |
& 'macros = ["FOO", "BAR=2", "VERSION={version}"]' |
| 1501 |
close(unit) |
| 1502 |
|
| 1503 |
call get_package_data(package, temp_file, error) |
| 1504 |
|
| 1505 |
if (allocated(error)) return |
| 1506 |
|
| 1507 |
if (get_macros(id, package%preprocess(1)%macros, package%version) /= " -DFOO -DBAR=2 -DVERSION=0.1.0") then |
| 1508 |
call test_failed(error, "Macros were not parsed correctly") |
| 1509 |
end if |
| 1510 |
|
| 1511 |
end subroutine test_macro_parsing |
| 1512 |
|
| 1513 |
!> Test macro parsing of the package and its dependency. |
| 1514 |
subroutine test_macro_parsing_dependency(error) |
| 1515 |
use fpm_compiler, only: get_macros, compiler_enum |
| 1516 |
|
| 1517 |
!> Error handling |
| 1518 |
type(error_t), allocatable, intent(out) :: error |
| 1519 |
|
| 1520 |
character(len=:), allocatable :: macros_package, macros_dependency |
| 1521 |
|
| 1522 |
type(package_config_t) :: package, dependency |
| 1523 |
|
| 1524 |
character(:), allocatable :: toml_file_package |
| 1525 |
character(:), allocatable :: toml_file_dependency |
| 1526 |
|
| 1527 |
integer :: unit |
| 1528 |
integer(compiler_enum) :: id |
| 1529 |
|
| 1530 |
allocate(toml_file_package, source=get_temp_filename()) |
| 1531 |
allocate(toml_file_dependency, source=get_temp_filename()) |
| 1532 |
|
| 1533 |
open(file=toml_file_package, newunit=unit) |
| 1534 |
write(unit, '(a)') & |
| 1535 |
& 'name = "example"', & |
| 1536 |
& 'version = "0.1.0"', & |
| 1537 |
& '[dependencies]', & |
| 1538 |
& '[dependencies.dependency-name]', & |
| 1539 |
& 'git = "https://github.com/fortran-lang/dependency-name"', & |
| 1540 |
& '[preprocess]', & |
| 1541 |
& '[preprocess.cpp]', & |
| 1542 |
& 'macros = ["FOO", "BAR=2", "VERSION={version}"]' |
| 1543 |
close(unit) |
| 1544 |
|
| 1545 |
open(file=toml_file_dependency, newunit=unit) |
| 1546 |
write(unit, '(a)') & |
| 1547 |
& 'name = "dependency-name"', & |
| 1548 |
& 'version = "0.2.0"', & |
| 1549 |
& '[preprocess]', & |
| 1550 |
& '[preprocess.cpp]', & |
| 1551 |
& 'macros = ["FOO1", "BAR2=2", "VERSION={version}"]' |
| 1552 |
close(unit) |
| 1553 |
|
| 1554 |
call get_package_data(package, toml_file_package, error) |
| 1555 |
|
| 1556 |
if (allocated(error)) return |
| 1557 |
|
| 1558 |
call get_package_data(dependency, toml_file_dependency, error) |
| 1559 |
|
| 1560 |
if (allocated(error)) return |
| 1561 |
|
| 1562 |
macros_package = get_macros(id, package%preprocess(1)%macros, package%version) |
| 1563 |
macros_dependency = get_macros(id, dependency%preprocess(1)%macros, dependency%version) |
| 1564 |
if (macros_package == macros_dependency) then |
| 1565 |
call test_failed(error, "Macros of package and dependency should not be equal") |
| 1566 |
end if |
| 1567 |
|
| 1568 |
end subroutine test_macro_parsing_dependency |
| 1569 |
|
| 1570 |
!> Ensure dependency "features" array is correctly parsed when present |
| 1571 |
subroutine test_dependency_features_present(error) |
| 1572 |
!> Error handling |
| 1573 |
type(error_t), allocatable, intent(out) :: error |
| 1574 |
|
| 1575 |
type(package_config_t) :: package |
| 1576 |
character(:), allocatable :: temp_file |
| 1577 |
integer :: unit, i, idx_dep0, idx_dep1, idx_dep2 |
| 1578 |
|
| 1579 |
allocate(temp_file, source=get_temp_filename()) |
| 1580 |
|
| 1581 |
open(file=temp_file, newunit=unit) |
| 1582 |
write(unit, '(a)') & |
| 1583 |
& 'name = "example"', & |
| 1584 |
& 'version = "0.1.0"', & |
| 1585 |
& '[dependencies]', & |
| 1586 |
& '"dep0" = { path = "local/dep0", features = ["featA", "featB"] }', & |
| 1587 |
& '"dep1" = { git = "https://example.com/repo.git", tag = "v1.2.3", features = ["only"] }', & |
| 1588 |
& '"dep2" = { path = "other/dep2" }' |
| 1589 |
close(unit) |
| 1590 |
|
| 1591 |
call get_package_data(package, temp_file, error) |
| 1592 |
if (allocated(error)) return |
| 1593 |
|
| 1594 |
if (.not.allocated(package%dependency)) then |
| 1595 |
call test_failed(error, 'No dependencies parsed from manifest') |
| 1596 |
return |
| 1597 |
end if |
| 1598 |
|
| 1599 |
idx_dep0 = 0; idx_dep1 = 0; idx_dep2 = 0 |
| 1600 |
do i = 1, size(package%dependency) |
| 1601 |
select case (package%dependency(i)%name) |
| 1602 |
case ('dep0'); idx_dep0 = i |
| 1603 |
case ('dep1'); idx_dep1 = i |
| 1604 |
case ('dep2'); idx_dep2 = i |
| 1605 |
end select |
| 1606 |
end do |
| 1607 |
|
| 1608 |
if (idx_dep0 == 0 .or. idx_dep1 == 0 .or. idx_dep2 == 0) then |
| 1609 |
call test_failed(error, 'Expected dependencies dep0/dep1/dep2 not found') |
| 1610 |
return |
| 1611 |
end if |
| 1612 |
|
| 1613 |
! dep0: features = ["featA","featB"] |
| 1614 |
if (.not.allocated(package%dependency(idx_dep0)%features)) then |
| 1615 |
call test_failed(error, 'dep0 features not allocated') |
| 1616 |
return |
| 1617 |
end if |
| 1618 |
if (size(package%dependency(idx_dep0)%features) /= 2) then |
| 1619 |
call test_failed(error, 'dep0 features size /= 2') |
| 1620 |
return |
| 1621 |
end if |
| 1622 |
if (package%dependency(idx_dep0)%features(1)%s /= 'featA' .or. & |
| 1623 |
& package%dependency(idx_dep0)%features(2)%s /= 'featB') then |
| 1624 |
call test_failed(error, 'dep0 features values mismatch') |
| 1625 |
return |
| 1626 |
end if |
| 1627 |
|
| 1628 |
! dep1: features = ["only"] |
| 1629 |
if (.not.allocated(package%dependency(idx_dep1)%features)) then |
| 1630 |
call test_failed(error, 'dep1 features not allocated') |
| 1631 |
return |
| 1632 |
end if |
| 1633 |
if (size(package%dependency(idx_dep1)%features) /= 1) then |
| 1634 |
call test_failed(error, 'dep1 features size /= 1') |
| 1635 |
return |
| 1636 |
end if |
| 1637 |
if (package%dependency(idx_dep1)%features(1)%s /= 'only') then |
| 1638 |
call test_failed(error, 'dep1 features value mismatch') |
| 1639 |
return |
| 1640 |
end if |
| 1641 |
|
| 1642 |
! dep2: no features key -> should be NOT allocated |
| 1643 |
if (allocated(package%dependency(idx_dep2)%features)) then |
| 1644 |
call test_failed(error, 'dep2 features should be unallocated when key is absent') |
| 1645 |
return |
| 1646 |
end if |
| 1647 |
end subroutine test_dependency_features_present |
| 1648 |
|
| 1649 |
|
| 1650 |
!> Ensure a dependency without "features" key is accepted (no allocation) |
| 1651 |
subroutine test_dependency_features_absent(error) |
| 1652 |
!> Error handling |
| 1653 |
type(error_t), allocatable, intent(out) :: error |
| 1654 |
|
| 1655 |
type(package_config_t) :: package |
| 1656 |
character(:), allocatable :: temp_file |
| 1657 |
integer :: unit, i |
| 1658 |
|
| 1659 |
allocate(temp_file, source=get_temp_filename()) |
| 1660 |
|
| 1661 |
open(file=temp_file, newunit=unit) |
| 1662 |
write(unit, '(a)') & |
| 1663 |
& 'name = "example"', & |
| 1664 |
& '[dependencies]', & |
| 1665 |
& '"a" = { path = "a" }', & |
| 1666 |
& '"b" = { git = "https://example.org/b.git", branch = "main" }' |
| 1667 |
close(unit) |
| 1668 |
|
| 1669 |
call get_package_data(package, temp_file, error) |
| 1670 |
if (allocated(error)) return |
| 1671 |
|
| 1672 |
if (.not.allocated(package%dependency)) then |
| 1673 |
call test_failed(error, 'No dependencies parsed from manifest') |
| 1674 |
return |
| 1675 |
end if |
| 1676 |
|
| 1677 |
do i = 1, size(package%dependency) |
| 1678 |
if (allocated(package%dependency(i)%features)) then |
| 1679 |
call test_failed(error, 'features should be unallocated when not specified') |
| 1680 |
return |
| 1681 |
end if |
| 1682 |
end do |
| 1683 |
end subroutine test_dependency_features_absent |
| 1684 |
|
| 1685 |
|
| 1686 |
!> Accept an explicit empty "features = []" list |
| 1687 |
subroutine test_dependency_features_empty(error) |
| 1688 |
!> Error handling |
| 1689 |
type(error_t), allocatable, intent(out) :: error |
| 1690 |
|
| 1691 |
type(package_config_t) :: package |
| 1692 |
character(:), allocatable :: temp_file |
| 1693 |
integer :: unit, i, idx |
| 1694 |
|
| 1695 |
allocate(temp_file, source=get_temp_filename()) |
| 1696 |
|
| 1697 |
open(file=temp_file, newunit=unit) |
| 1698 |
write(unit, '(a)') & |
| 1699 |
& 'name = "example"', & |
| 1700 |
& '[dependencies]', & |
| 1701 |
& '"empty" = { path = "local/empty", features = [] }' |
| 1702 |
close(unit) |
| 1703 |
|
| 1704 |
call get_package_data(package, temp_file, error) |
| 1705 |
if (allocated(error)) return |
| 1706 |
|
| 1707 |
idx = -1 |
| 1708 |
if (.not.allocated(package%dependency)) then |
| 1709 |
call test_failed(error, 'No dependencies parsed from manifest') |
| 1710 |
return |
| 1711 |
end if |
| 1712 |
|
| 1713 |
do i = 1, size(package%dependency) |
| 1714 |
if (package%dependency(i)%name == 'empty') then |
| 1715 |
idx = i |
| 1716 |
exit |
| 1717 |
end if |
| 1718 |
end do |
| 1719 |
|
| 1720 |
if (idx < 1) then |
| 1721 |
call test_failed(error, 'Dependency "empty" not found') |
| 1722 |
return |
| 1723 |
end if |
| 1724 |
|
| 1725 |
if (.not.allocated(package%dependency(idx)%features)) then |
| 1726 |
call test_failed(error, 'features should be allocated (size=0) for empty list') |
| 1727 |
return |
| 1728 |
end if |
| 1729 |
if (size(package%dependency(idx)%features) /= 0) then |
| 1730 |
call test_failed(error, 'features size should be zero for empty list') |
| 1731 |
return |
| 1732 |
end if |
| 1733 |
end subroutine test_dependency_features_empty |
| 1734 |
|
| 1735 |
!> Test features demo manifest serialization (from example_packages/features_demo/fpm.toml) |
| 1736 |
subroutine test_features_demo_serialization(error) |
| 1737 |
!> Error handling |
| 1738 |
type(error_t), allocatable, intent(out) :: error |
| 1739 |
|
| 1740 |
type(package_config_t) :: package |
| 1741 |
character(:), allocatable :: temp_file |
| 1742 |
integer :: unit |
| 1743 |
|
| 1744 |
allocate(temp_file, source=get_temp_filename()) |
| 1745 |
|
| 1746 |
open(file=temp_file, newunit=unit) |
| 1747 |
write(unit, '(a)') & |
| 1748 |
& 'name = "features_demo"', & |
| 1749 |
& 'version = "0.1.0"', & |
| 1750 |
& 'license = "MIT"', & |
| 1751 |
& 'description = "Demo package for FPM features functionality"', & |
| 1752 |
& '', & |
| 1753 |
& '[[executable]]', & |
| 1754 |
& 'name = "features_demo"', & |
| 1755 |
& 'source-dir = "app"', & |
| 1756 |
& 'main = "main.f90"', & |
| 1757 |
& '', & |
| 1758 |
& '[features]', & |
| 1759 |
& '# Base debug feature', & |
| 1760 |
& 'debug.flags = "-g"', & |
| 1761 |
& 'debug.preprocess.cpp.macros = "DEBUG"', & |
| 1762 |
& '', & |
| 1763 |
& '# Release feature', & |
| 1764 |
& 'release.flags = "-O3"', & |
| 1765 |
& 'release.preprocess.cpp.macros = "RELEASE"', & |
| 1766 |
& '', & |
| 1767 |
& '# Compiler-specific features', & |
| 1768 |
& 'debug.gfortran.flags = "-Wall -fcheck=bounds"', & |
| 1769 |
& 'release.gfortran.flags = "-mtune=generic -funroll-loops"', & |
| 1770 |
& '', & |
| 1771 |
& '# Platform-specific features', & |
| 1772 |
& 'linux.preprocess.cpp.macros = "LINUX_BUILD"', & |
| 1773 |
& '', & |
| 1774 |
& '# Parallel features', & |
| 1775 |
& 'mpi.preprocess.cpp.macros = "USE_MPI"', & |
| 1776 |
& 'mpi.dependencies.mpi = "*"', & |
| 1777 |
& 'openmp.preprocess.cpp.macros = "USE_OPENMP"', & |
| 1778 |
& 'openmp.dependencies.openmp = "*"', & |
| 1779 |
& '', & |
| 1780 |
& '[profiles]', & |
| 1781 |
& 'development = ["debug"]', & |
| 1782 |
& 'production = ["release", "openmp"]' |
| 1783 |
close(unit) |
| 1784 |
|
| 1785 |
call get_package_data(package, temp_file, error) |
| 1786 |
if (allocated(error)) return |
| 1787 |
|
| 1788 |
! Verify basic package structure |
| 1789 |
if (package%name /= "features_demo") then |
| 1790 |
call test_failed(error, "Package name should be 'features_demo'") |
| 1791 |
return |
| 1792 |
end if |
| 1793 |
|
| 1794 |
if (.not. allocated(package%features)) then |
| 1795 |
call test_failed(error, "Features should be allocated") |
| 1796 |
return |
| 1797 |
end if |
| 1798 |
|
| 1799 |
if (.not. allocated(package%profiles)) then |
| 1800 |
call test_failed(error, "Profiles should be allocated") |
| 1801 |
return |
| 1802 |
end if |
| 1803 |
|
| 1804 |
if (.not. allocated(package%executable)) then |
| 1805 |
call test_failed(error, "Executables should be allocated") |
| 1806 |
return |
| 1807 |
end if |
| 1808 |
|
| 1809 |
! Test package serialization roundtrip |
| 1810 |
call package%test_serialization('test_features_demo_serialization', error) |
| 1811 |
if (allocated(error)) return |
| 1812 |
|
| 1813 |
end subroutine test_features_demo_serialization |
| 1814 |
|
| 1815 |
|
| 1816 |
!> Test that a dependency with "profile" key is parsed correctly |
| 1817 |
subroutine test_dependency_profile_present(error) |
| 1818 |
!> Error handling |
| 1819 |
type(error_t), allocatable, intent(out) :: error |
| 1820 |
|
| 1821 |
type(package_config_t) :: package |
| 1822 |
character(:), allocatable :: temp_file |
| 1823 |
integer :: unit, i, idx_dep0, idx_dep1 |
| 1824 |
|
| 1825 |
allocate(temp_file, source=get_temp_filename()) |
| 1826 |
|
| 1827 |
open(file=temp_file, newunit=unit) |
| 1828 |
write(unit, '(a)') & |
| 1829 |
& 'name = "example"', & |
| 1830 |
& 'version = "0.1.0"', & |
| 1831 |
& '[dependencies]', & |
| 1832 |
& '"dep0" = { path = "local/dep0", profile = "release" }', & |
| 1833 |
& '"dep1" = { path = "local/dep1" }' |
| 1834 |
close(unit) |
| 1835 |
|
| 1836 |
call get_package_data(package, temp_file, error) |
| 1837 |
if (allocated(error)) return |
| 1838 |
|
| 1839 |
if (.not.allocated(package%dependency)) then |
| 1840 |
call test_failed(error, 'No dependencies parsed from manifest') |
| 1841 |
return |
| 1842 |
end if |
| 1843 |
|
| 1844 |
idx_dep0 = 0; idx_dep1 = 0 |
| 1845 |
do i = 1, size(package%dependency) |
| 1846 |
select case (package%dependency(i)%name) |
| 1847 |
case ('dep0'); idx_dep0 = i |
| 1848 |
case ('dep1'); idx_dep1 = i |
| 1849 |
end select |
| 1850 |
end do |
| 1851 |
|
| 1852 |
if (idx_dep0 == 0 .or. idx_dep1 == 0) then |
| 1853 |
call test_failed(error, 'Expected dependencies dep0/dep1 not found') |
| 1854 |
return |
| 1855 |
end if |
| 1856 |
|
| 1857 |
! dep0: profile = "release" |
| 1858 |
if (.not.allocated(package%dependency(idx_dep0)%profile)) then |
| 1859 |
call test_failed(error, 'dep0 profile not allocated') |
| 1860 |
return |
| 1861 |
end if |
| 1862 |
if (package%dependency(idx_dep0)%profile /= 'release') then |
| 1863 |
call test_failed(error, 'dep0 profile value mismatch, expected "release"') |
| 1864 |
return |
| 1865 |
end if |
| 1866 |
! dep0 should NOT have features allocated |
| 1867 |
if (allocated(package%dependency(idx_dep0)%features)) then |
| 1868 |
if (size(package%dependency(idx_dep0)%features) > 0) then |
| 1869 |
call test_failed(error, 'dep0 features should not be present when profile is used') |
| 1870 |
return |
| 1871 |
end if |
| 1872 |
end if |
| 1873 |
|
| 1874 |
! dep1: no profile key -> should be NOT allocated |
| 1875 |
if (allocated(package%dependency(idx_dep1)%profile)) then |
| 1876 |
call test_failed(error, 'dep1 profile should be unallocated when key is absent') |
| 1877 |
return |
| 1878 |
end if |
| 1879 |
end subroutine test_dependency_profile_present |
| 1880 |
|
| 1881 |
|
| 1882 |
!> Ensure a dependency without "profile" key leaves it unallocated |
| 1883 |
subroutine test_dependency_profile_absent(error) |
| 1884 |
!> Error handling |
| 1885 |
type(error_t), allocatable, intent(out) :: error |
| 1886 |
|
| 1887 |
type(package_config_t) :: package |
| 1888 |
character(:), allocatable :: temp_file |
| 1889 |
integer :: unit, i |
| 1890 |
|
| 1891 |
allocate(temp_file, source=get_temp_filename()) |
| 1892 |
|
| 1893 |
open(file=temp_file, newunit=unit) |
| 1894 |
write(unit, '(a)') & |
| 1895 |
& 'name = "example"', & |
| 1896 |
& '[dependencies]', & |
| 1897 |
& '"a" = { path = "a" }', & |
| 1898 |
& '"b" = { git = "https://example.org/b.git", branch = "main" }' |
| 1899 |
close(unit) |
| 1900 |
|
| 1901 |
call get_package_data(package, temp_file, error) |
| 1902 |
if (allocated(error)) return |
| 1903 |
|
| 1904 |
if (.not.allocated(package%dependency)) then |
| 1905 |
call test_failed(error, 'No dependencies parsed from manifest') |
| 1906 |
return |
| 1907 |
end if |
| 1908 |
|
| 1909 |
do i = 1, size(package%dependency) |
| 1910 |
if (allocated(package%dependency(i)%profile)) then |
| 1911 |
call test_failed(error, 'profile should be unallocated when not specified') |
| 1912 |
return |
| 1913 |
end if |
| 1914 |
end do |
| 1915 |
end subroutine test_dependency_profile_absent |
| 1916 |
|
| 1917 |
|
| 1918 |
!> Specifying both "features" and "profile" should be an error |
| 1919 |
subroutine test_dependency_profile_features_conflict(error) |
| 1920 |
!> Error handling |
| 1921 |
type(error_t), allocatable, intent(out) :: error |
| 1922 |
|
| 1923 |
type(package_config_t) :: package |
| 1924 |
character(:), allocatable :: temp_file |
| 1925 |
integer :: unit |
| 1926 |
|
| 1927 |
allocate(temp_file, source=get_temp_filename()) |
| 1928 |
|
| 1929 |
open(file=temp_file, newunit=unit) |
| 1930 |
write(unit, '(a)') & |
| 1931 |
& 'name = "example"', & |
| 1932 |
& '[dependencies]', & |
| 1933 |
& '"bad" = { path = "bad", features = ["f1"], profile = "release" }' |
| 1934 |
close(unit) |
| 1935 |
|
| 1936 |
call get_package_data(package, temp_file, error) |
| 1937 |
|
| 1938 |
end subroutine test_dependency_profile_features_conflict |
| 1939 |
|
| 1940 |
|
| 1941 |
end module test_manifest |