| 1 |
!> Unit tests for FPM feature and feature collection functionality |
| 2 |
module test_features |
| 3 |
use testsuite, only : new_unittest, unittest_t, error_t, test_failed |
| 4 |
use fpm_manifest, only: package_config_t, get_package_data |
| 5 |
use fpm_manifest_feature, only: feature_config_t |
| 6 |
use fpm_manifest_feature_collection, only: feature_collection_t |
| 7 |
use fpm_manifest_platform, only: platform_config_t |
| 8 |
use fpm_environment, only: OS_ALL, OS_LINUX, OS_MACOS, OS_WINDOWS |
| 9 |
use fpm_compiler, only: id_all, id_gcc, id_intel_classic_nix, id_intel_classic_windows, id_intel_llvm_nix, & |
| 10 |
match_compiler_type |
| 11 |
use fpm_strings, only: string_t |
| 12 |
use fpm_filesystem, only: get_temp_filename |
| 13 |
implicit none |
| 14 |
private |
| 15 |
|
| 16 |
public :: collect_features |
| 17 |
|
| 18 |
contains |
| 19 |
|
| 20 |
!> Collect all feature tests |
| 21 |
subroutine collect_features(testsuite) |
| 22 |
!> Collection of tests |
| 23 |
type(unittest_t), allocatable, intent(out) :: testsuite(:) |
| 24 |
|
| 25 |
testsuite = [ & |
| 26 |
& new_unittest("feature-collection-basic", test_feature_collection_basic), & |
| 27 |
& new_unittest("feature-collection-flexible", test_feature_collection_flexible), & |
| 28 |
& new_unittest("feature-collection-invalid", test_feature_collection_invalid, should_fail=.true.), & |
| 29 |
& new_unittest("feature-collection-duplicates", test_feature_collection_duplicates, should_fail=.true.), & |
| 30 |
& new_unittest("feature-collection-extract", test_feature_collection_extract), & |
| 31 |
& new_unittest("feature-collection-platform-validation", test_feature_collection_platform_validation, & |
| 32 |
& should_fail=.true.), & |
| 33 |
& new_unittest("feature-collection-complex", test_feature_collection_complex), & |
| 34 |
& new_unittest("feature-allocatable-conflict", test_feature_allocatable_conflict, should_fail=.true.), & |
| 35 |
& new_unittest("feature-flag-addition", test_feature_flag_addition), & |
| 36 |
& new_unittest("feature-metapackage-addition", test_feature_metapackage_addition), & |
| 37 |
& new_unittest("feature-extract-gfortran-linux", test_feature_extract_gfortran_linux), & |
| 38 |
& new_unittest("feature-extract-ifort-windows", test_feature_extract_ifort_windows), & |
| 39 |
& new_unittest("feature-extract-dependencies-examples", test_feature_extract_dependencies_examples), & |
| 40 |
& new_unittest("feature-extract-build-configs", test_feature_extract_build_configs), & |
| 41 |
& new_unittest("feature-extract-test-configs", test_feature_extract_test_configs), & |
| 42 |
& new_unittest("feature-extract-example-configs", test_feature_extract_example_configs), & |
| 43 |
& new_unittest("dependency-feature-propagation", test_dependency_feature_propagation), & |
| 44 |
& new_unittest("dependency-features-specification", test_dependency_features_specification), & |
| 45 |
& new_unittest("feature-chained-os-commands", test_feature_chained_os_commands, should_fail=.true.), & |
| 46 |
& new_unittest("feature-chained-compiler-commands", & |
| 47 |
& test_feature_chained_compiler_commands, should_fail=.true.), & |
| 48 |
& new_unittest("feature-complex-chain-compiler-os-compiler", & |
| 49 |
& test_feature_complex_chain_compiler_os_compiler, should_fail=.true.), & |
| 50 |
& new_unittest("feature-complex-chain-os-compiler-os", & |
| 51 |
& test_feature_complex_chain_os_compiler_os, should_fail=.true.), & |
| 52 |
& new_unittest("feature-mixed-valid-chains", test_feature_mixed_valid_chains), & |
| 53 |
& new_unittest("feature-compiler-flags-integration", test_feature_compiler_flags_integration), & |
| 54 |
& new_unittest("default-profile-with-debug", test_default_profile_with_debug), & |
| 55 |
& new_unittest("default-profile-with-release", test_default_profile_with_release), & |
| 56 |
& new_unittest("default-profile-implicit-debug", test_default_profile_implicit_debug), & |
| 57 |
& new_unittest("default-profile-skipped-custom", test_default_profile_skipped_custom) & |
| 58 |
& ] |
| 59 |
|
| 60 |
end subroutine collect_features |
| 61 |
|
| 62 |
!> Test basic feature collection functionality |
| 63 |
!> This should create two variants: gfortran+OS_ALL and ifort+OS_ALL (NOT duplicates) |
| 64 |
subroutine test_feature_collection_basic(error) |
| 65 |
|
| 66 |
!> Error handling |
| 67 |
type(error_t), allocatable, intent(out) :: error |
| 68 |
|
| 69 |
type(package_config_t) :: package |
| 70 |
character(:), allocatable :: temp_file |
| 71 |
integer :: unit,i |
| 72 |
|
| 73 |
allocate(temp_file, source=get_temp_filename()) |
| 74 |
|
| 75 |
open(file=temp_file, newunit=unit) |
| 76 |
write(unit, '(a)') & |
| 77 |
& 'name = "feature-test"', & |
| 78 |
& 'version = "0.1.0"', & |
| 79 |
& '[features]', & |
| 80 |
& 'debug.gfortran.flags = "-Wall -g -fcheck=bounds"', & |
| 81 |
& 'debug.ifort.flags = "/warn:all /check:all /traceback"', & |
| 82 |
& 'release.flags = "-O3"' |
| 83 |
close(unit) |
| 84 |
|
| 85 |
call get_package_data(package, temp_file, error) |
| 86 |
|
| 87 |
if (allocated(error)) return |
| 88 |
|
| 89 |
! Check that feature collections were created |
| 90 |
if (.not. allocated(package%features)) then |
| 91 |
call test_failed(error, "Feature collections were not created") |
| 92 |
return |
| 93 |
end if |
| 94 |
|
| 95 |
! Verify we have at least one collection |
| 96 |
if (size(package%features) /= 2) then |
| 97 |
call test_failed(error, "Invalid feature collections found, should be 2") |
| 98 |
return |
| 99 |
end if |
| 100 |
|
| 101 |
! Check that the debug collection has variants |
| 102 |
do i=1,2 |
| 103 |
|
| 104 |
if (package%features(i)%base%name=="debug") then |
| 105 |
|
| 106 |
if (.not. allocated(package%features(i)%variants)) then |
| 107 |
call test_failed(error, "Debug collection variants were not created") |
| 108 |
return |
| 109 |
end if |
| 110 |
|
| 111 |
! Should have exactly 2 variants: gfortran and ifort |
| 112 |
if (size(package%features(i)%variants) /= 2) then |
| 113 |
call test_failed(error, "Debug collection should have exactly 2 variants") |
| 114 |
return |
| 115 |
end if |
| 116 |
|
| 117 |
! Check that variants have different platform configurations |
| 118 |
if (package%features(i)%variants(1)%platform == package%features(i)%variants(2)%platform) then |
| 119 |
call test_failed(error, "Variants should have different platform configurations: " & |
| 120 |
//"variant1.compiler="//package%features(i)%variants(1)%platform%compiler_name() & |
| 121 |
//" variant1.os="//package%features(i)%variants(1)%platform%os_name() & |
| 122 |
//" variant2.compiler="//package%features(i)%variants(2)%platform%compiler_name() & |
| 123 |
//" variant2.os="//package%features(i)%variants(2)%platform%os_name()) |
| 124 |
return |
| 125 |
end if |
| 126 |
|
| 127 |
else |
| 128 |
|
| 129 |
if (allocated(package%features(i)%variants)) then |
| 130 |
if (size(package%features(i)%variants) > 0) then |
| 131 |
call test_failed(error, "Release collection variants should not be created") |
| 132 |
return |
| 133 |
endif |
| 134 |
end if |
| 135 |
endif |
| 136 |
|
| 137 |
end do |
| 138 |
|
| 139 |
end subroutine test_feature_collection_basic |
| 140 |
|
| 141 |
!> Test flexible feature collection parsing with OS and compiler constraints |
| 142 |
subroutine test_feature_collection_flexible(error) |
| 143 |
|
| 144 |
!> Error handling |
| 145 |
type(error_t), allocatable, intent(out) :: error |
| 146 |
|
| 147 |
type(package_config_t) :: package |
| 148 |
character(:), allocatable :: temp_file |
| 149 |
integer :: unit |
| 150 |
|
| 151 |
allocate(temp_file, source=get_temp_filename()) |
| 152 |
|
| 153 |
open(file=temp_file, newunit=unit) |
| 154 |
write(unit, '(a)') & |
| 155 |
& 'name = "flexible-test"', & |
| 156 |
& 'version = "0.1.0"', & |
| 157 |
& '[features]', & |
| 158 |
& 'myfeature.linux.gfortran.flags = "-fPIC -Wall"', & |
| 159 |
& 'myfeature.windows.ifort.flags = "/fPIC /warn:all"', & |
| 160 |
& 'myfeature.macos.flags = "-framework CoreFoundation"', & |
| 161 |
& 'myfeature.preprocess.cpp.macros = ["-DMYFEATURE"]' |
| 162 |
close(unit) |
| 163 |
|
| 164 |
call get_package_data(package, temp_file, error) |
| 165 |
|
| 166 |
if (allocated(error)) return |
| 167 |
|
| 168 |
! Check that feature collections were created |
| 169 |
if (.not. allocated(package%features)) then |
| 170 |
call test_failed(error, "Feature collections were not created for flexible test") |
| 171 |
return |
| 172 |
end if |
| 173 |
|
| 174 |
! Verify we have at least one collection |
| 175 |
if (size(package%features) < 1) then |
| 176 |
call test_failed(error, "No feature collections found in flexible test") |
| 177 |
return |
| 178 |
end if |
| 179 |
|
| 180 |
! Check that base feature has been set |
| 181 |
if (.not. allocated(package%features(1)%base%name)) then |
| 182 |
call test_failed(error, "Base feature name not set in flexible test") |
| 183 |
return |
| 184 |
end if |
| 185 |
|
| 186 |
|
| 187 |
end subroutine test_feature_collection_flexible |
| 188 |
|
| 189 |
!> Test invalid feature collection configuration (should fail) |
| 190 |
subroutine test_feature_collection_invalid(error) |
| 191 |
|
| 192 |
!> Error handling |
| 193 |
type(error_t), allocatable, intent(out) :: error |
| 194 |
|
| 195 |
type(package_config_t) :: package |
| 196 |
character(:), allocatable :: temp_file |
| 197 |
integer :: unit |
| 198 |
|
| 199 |
allocate(temp_file, source=get_temp_filename()) |
| 200 |
|
| 201 |
open(file=temp_file, newunit=unit) |
| 202 |
write(unit, '(a)') & |
| 203 |
& 'name = "invalid-test"', & |
| 204 |
& 'version = "0.1.0"', & |
| 205 |
& '[features]', & |
| 206 |
& 'badfeature.unknownos.badcompiler.flags = "-invalid"', & |
| 207 |
& 'badfeature.invalid-key-format = "should fail"' |
| 208 |
close(unit) |
| 209 |
|
| 210 |
call get_package_data(package, temp_file, error) |
| 211 |
|
| 212 |
end subroutine test_feature_collection_invalid |
| 213 |
|
| 214 |
!> Test feature collection duplicate platform detection |
| 215 |
subroutine test_feature_collection_duplicates(error) |
| 216 |
|
| 217 |
!> Error handling |
| 218 |
type(error_t), allocatable, intent(out) :: error |
| 219 |
|
| 220 |
type(package_config_t) :: package |
| 221 |
character(:), allocatable :: temp_file |
| 222 |
integer :: unit |
| 223 |
|
| 224 |
allocate(temp_file, source=get_temp_filename()) |
| 225 |
|
| 226 |
open(file=temp_file, newunit=unit) |
| 227 |
write(unit, '(a)') & |
| 228 |
& 'name = "duplicate-test"', & |
| 229 |
& 'version = "0.1.0"', & |
| 230 |
& '[features]', & |
| 231 |
& 'debug.gfortran.flags = "-g"', & |
| 232 |
& 'debug.gfortran.c-flags = "-DDEBUG"' ! Duplicate gfortran platform |
| 233 |
close(unit) |
| 234 |
|
| 235 |
call get_package_data(package, temp_file, error) |
| 236 |
|
| 237 |
! This should fail due to duplicate gfortran platform |
| 238 |
if (.not. allocated(error)) then |
| 239 |
call test_failed(error, "Expected error for duplicate platform configurations was not generated") |
| 240 |
return |
| 241 |
end if |
| 242 |
|
| 243 |
! Clear the expected error |
| 244 |
deallocate(error) |
| 245 |
|
| 246 |
end subroutine test_feature_collection_duplicates |
| 247 |
|
| 248 |
!> Test feature collection extract_for_target functionality |
| 249 |
subroutine test_feature_collection_extract(error) |
| 250 |
|
| 251 |
!> Error handling |
| 252 |
type(error_t), allocatable, intent(out) :: error |
| 253 |
|
| 254 |
type(package_config_t) :: package |
| 255 |
character(:), allocatable :: temp_file |
| 256 |
integer :: unit |
| 257 |
type(feature_config_t) :: extracted_feature |
| 258 |
type(platform_config_t) :: target_platform |
| 259 |
integer :: i |
| 260 |
|
| 261 |
allocate(temp_file, source=get_temp_filename()) |
| 262 |
|
| 263 |
open(file=temp_file, newunit=unit) |
| 264 |
write(unit, '(a)') & |
| 265 |
& 'name = "extract-test"', & |
| 266 |
& 'version = "0.1.0"', & |
| 267 |
& '[features]', & |
| 268 |
& 'debug.flags = "-g"', & |
| 269 |
& 'debug.gfortran.flags = "-Wall"', & |
| 270 |
& 'debug.ifort.flags = "/debug"' |
| 271 |
close(unit) |
| 272 |
|
| 273 |
call get_package_data(package, temp_file, error) |
| 274 |
if (allocated(error)) return |
| 275 |
|
| 276 |
! Should have debug feature collection |
| 277 |
if (.not. allocated(package%features) .or. size(package%features) < 1) then |
| 278 |
call test_failed(error, "No feature collections found for extract test") |
| 279 |
return |
| 280 |
end if |
| 281 |
|
| 282 |
! Find debug feature collection |
| 283 |
do i = 1, size(package%features) |
| 284 |
if (package%features(i)%base%name == "debug") then |
| 285 |
|
| 286 |
! Test extraction for gfortran on linux |
| 287 |
target_platform%compiler = id_gcc |
| 288 |
target_platform%os_type = OS_LINUX |
| 289 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 290 |
if (allocated(error)) return |
| 291 |
|
| 292 |
! Should have both base and gfortran-specific flags |
| 293 |
if (.not. allocated(extracted_feature%flags)) then |
| 294 |
call test_failed(error, "Extracted feature missing flags") |
| 295 |
return |
| 296 |
end if |
| 297 |
|
| 298 |
! The extracted flags should contain both base and gfortran flags |
| 299 |
! (implementation details may vary but should have both -g and -Wall) |
| 300 |
if (index(extracted_feature%flags, "-g") == 0) then |
| 301 |
call test_failed(error, "Extracted feature missing base flags (-g)") |
| 302 |
return |
| 303 |
end if |
| 304 |
|
| 305 |
! Test extraction for ifort |
| 306 |
target_platform%compiler = id_intel_classic_nix |
| 307 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 308 |
if (allocated(error)) return |
| 309 |
|
| 310 |
if (.not. allocated(extracted_feature%flags)) then |
| 311 |
call test_failed(error, "Extracted ifort feature missing flags") |
| 312 |
return |
| 313 |
end if |
| 314 |
|
| 315 |
return ! Test passed |
| 316 |
end if |
| 317 |
end do |
| 318 |
|
| 319 |
call test_failed(error, "Debug feature collection not found for extract test") |
| 320 |
|
| 321 |
end subroutine test_feature_collection_extract |
| 322 |
|
| 323 |
!> Test feature collection platform validation |
| 324 |
subroutine test_feature_collection_platform_validation(error) |
| 325 |
|
| 326 |
!> Error handling |
| 327 |
type(error_t), allocatable, intent(out) :: error |
| 328 |
|
| 329 |
type(package_config_t) :: package |
| 330 |
character(:), allocatable :: temp_file |
| 331 |
integer :: unit |
| 332 |
|
| 333 |
allocate(temp_file, source=get_temp_filename()) |
| 334 |
|
| 335 |
open(file=temp_file, newunit=unit) |
| 336 |
write(unit, '(a)') & |
| 337 |
& 'name = "validation-test"', & |
| 338 |
& 'version = "0.1.0"', & |
| 339 |
& '[features]', & |
| 340 |
& 'test.invalidcompiler.flags = "-test"' ! Invalid compiler name |
| 341 |
close(unit) |
| 342 |
|
| 343 |
! Should return error |
| 344 |
call get_package_data(package, temp_file, error) |
| 345 |
|
| 346 |
end subroutine test_feature_collection_platform_validation |
| 347 |
|
| 348 |
!> Test complex feature collection hierarchy |
| 349 |
subroutine test_feature_collection_complex(error) |
| 350 |
|
| 351 |
!> Error handling |
| 352 |
type(error_t), allocatable, intent(out) :: error |
| 353 |
|
| 354 |
type(package_config_t) :: package |
| 355 |
character(:), allocatable :: temp_file |
| 356 |
integer :: unit |
| 357 |
integer :: i, debug_variants, release_variants |
| 358 |
|
| 359 |
allocate(temp_file, source=get_temp_filename()) |
| 360 |
|
| 361 |
open(file=temp_file, newunit=unit) |
| 362 |
write(unit, '(a)') & |
| 363 |
& 'name = "complex-test"', & |
| 364 |
& 'version = "0.1.0"', & |
| 365 |
& '[features]', & |
| 366 |
& 'debug.flags = "-g"', & |
| 367 |
& 'debug.gfortran.flags = "-Wall"', & |
| 368 |
& 'debug.ifort.flags = "/debug"', & |
| 369 |
& 'debug.linux.flags = "-DLINUX"', & |
| 370 |
& 'debug.windows.ifort.flags = "/DEBUG:FULL"', & |
| 371 |
& 'release.flags = "-O3"', & |
| 372 |
& 'release.gfortran.flags = "-mtune=generic -funroll-loops"' |
| 373 |
close(unit) |
| 374 |
|
| 375 |
call get_package_data(package, temp_file, error) |
| 376 |
if (allocated(error)) return |
| 377 |
|
| 378 |
! Should have 2 feature collections (debug and release) |
| 379 |
if (.not. allocated(package%features) .or. size(package%features) /= 2) then |
| 380 |
call test_failed(error, "Expected 2 feature collections for complex test") |
| 381 |
return |
| 382 |
end if |
| 383 |
|
| 384 |
debug_variants = 0 |
| 385 |
release_variants = 0 |
| 386 |
|
| 387 |
do i = 1, size(package%features) |
| 388 |
if (package%features(i)%base%name == "debug") then |
| 389 |
if (allocated(package%features(i)%variants)) then |
| 390 |
debug_variants = size(package%features(i)%variants) |
| 391 |
end if |
| 392 |
else if (package%features(i)%base%name == "release") then |
| 393 |
if (allocated(package%features(i)%variants)) then |
| 394 |
release_variants = size(package%features(i)%variants) |
| 395 |
end if |
| 396 |
end if |
| 397 |
end do |
| 398 |
|
| 399 |
! Debug should have multiple variants (gfortran, ifort, linux, windows+ifort) |
| 400 |
if (debug_variants < 3) then |
| 401 |
call test_failed(error, "Debug feature should have at least 3 variants in complex test") |
| 402 |
return |
| 403 |
end if |
| 404 |
|
| 405 |
! Release should have 1 variant (gfortran) |
| 406 |
if (release_variants /= 1) then |
| 407 |
call test_failed(error, "Release feature should have exactly 1 variant in complex test") |
| 408 |
return |
| 409 |
end if |
| 410 |
|
| 411 |
end subroutine test_feature_collection_complex |
| 412 |
|
| 413 |
!> Test that allocatable configurations cannot appear in multiple variants (should fail) |
| 414 |
subroutine test_feature_allocatable_conflict(error) |
| 415 |
!> Error handling |
| 416 |
type(error_t), allocatable, intent(out) :: error |
| 417 |
|
| 418 |
type(package_config_t) :: package |
| 419 |
character(:), allocatable :: temp_file |
| 420 |
integer :: unit |
| 421 |
|
| 422 |
allocate(temp_file, source=get_temp_filename()) |
| 423 |
|
| 424 |
open(file=temp_file, newunit=unit) |
| 425 |
write(unit, '(a)') & |
| 426 |
& 'name = "conflict-test"', & |
| 427 |
& 'version = "0.1.0"', & |
| 428 |
& '[features]', & |
| 429 |
& 'myfeature.gfortran.fortran.source-dir = "src/gfortran"', & |
| 430 |
& 'myfeature.linux.fortran.source-dir = "src/linux"' |
| 431 |
close(unit) |
| 432 |
|
| 433 |
! Conflict: both would apply to gfortran+linux |
| 434 |
call get_package_data(package, temp_file, error) |
| 435 |
|
| 436 |
end subroutine test_feature_allocatable_conflict |
| 437 |
|
| 438 |
!> Test that flags are properly added together (additive) |
| 439 |
subroutine test_feature_flag_addition(error) |
| 440 |
!> Error handling |
| 441 |
type(error_t), allocatable, intent(out) :: error |
| 442 |
|
| 443 |
type(package_config_t) :: package |
| 444 |
character(:), allocatable :: temp_file |
| 445 |
integer :: unit |
| 446 |
type(feature_config_t) :: extracted_feature |
| 447 |
type(platform_config_t) :: target_platform |
| 448 |
integer :: i |
| 449 |
|
| 450 |
allocate(temp_file, source=get_temp_filename()) |
| 451 |
|
| 452 |
open(file=temp_file, newunit=unit) |
| 453 |
write(unit, '(a)') & |
| 454 |
& 'name = "addition-test"', & |
| 455 |
& 'version = "0.1.0"', & |
| 456 |
& '[features]', & |
| 457 |
& 'myfeature.flags = "-DBASE"', & |
| 458 |
& 'myfeature.gfortran.flags = "-DGFORTRAN"', & |
| 459 |
& 'myfeature.linux.flags = "-DLINUX"' |
| 460 |
close(unit) |
| 461 |
|
| 462 |
call get_package_data(package, temp_file, error) |
| 463 |
if (allocated(error)) return |
| 464 |
|
| 465 |
! Should have feature collection |
| 466 |
if (.not. allocated(package%features) .or. size(package%features) < 1) then |
| 467 |
call test_failed(error, "No feature collections found for addition test") |
| 468 |
return |
| 469 |
end if |
| 470 |
|
| 471 |
! Find myfeature collection |
| 472 |
do i = 1, size(package%features) |
| 473 |
if (package%features(i)%base%name == "myfeature") then |
| 474 |
|
| 475 |
! Test extraction for gfortran on linux (should get all three flags) |
| 476 |
target_platform%compiler = id_gcc |
| 477 |
target_platform%os_type = OS_LINUX |
| 478 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 479 |
if (allocated(error)) return |
| 480 |
|
| 481 |
! Should have flags from base, gfortran, and linux variants |
| 482 |
if (.not. allocated(extracted_feature%flags)) then |
| 483 |
call test_failed(error, "Extracted feature missing flags") |
| 484 |
return |
| 485 |
end if |
| 486 |
|
| 487 |
! Should contain all three flags (additive behavior) |
| 488 |
if (index(extracted_feature%flags, "-DBASE") == 0) then |
| 489 |
call test_failed(error, "Missing base flags (-DBASE)") |
| 490 |
return |
| 491 |
end if |
| 492 |
|
| 493 |
if (index(extracted_feature%flags, "-DGFORTRAN") == 0) then |
| 494 |
call test_failed(error, "Missing compiler-specific flags (-DGFORTRAN)") |
| 495 |
return |
| 496 |
end if |
| 497 |
|
| 498 |
if (index(extracted_feature%flags, "-DLINUX") == 0) then |
| 499 |
call test_failed(error, "Missing OS-specific flags (-DLINUX)") |
| 500 |
return |
| 501 |
end if |
| 502 |
|
| 503 |
return ! Test passed |
| 504 |
end if |
| 505 |
end do |
| 506 |
|
| 507 |
call test_failed(error, "myfeature collection not found for addition test") |
| 508 |
|
| 509 |
end subroutine test_feature_flag_addition |
| 510 |
|
| 511 |
!> Test that metapackages are properly combined with OR logic (additive) |
| 512 |
subroutine test_feature_metapackage_addition(error) |
| 513 |
!> Error handling |
| 514 |
type(error_t), allocatable, intent(out) :: error |
| 515 |
|
| 516 |
type(package_config_t) :: package |
| 517 |
character(:), allocatable :: temp_file |
| 518 |
integer :: unit |
| 519 |
type(feature_config_t) :: extracted_feature |
| 520 |
type(platform_config_t) :: target_platform |
| 521 |
integer :: i |
| 522 |
|
| 523 |
allocate(temp_file, source=get_temp_filename()) |
| 524 |
|
| 525 |
open(file=temp_file, newunit=unit) |
| 526 |
write(unit, '(a)') & |
| 527 |
& 'name = "meta-test"', & |
| 528 |
& 'version = "0.1.0"', & |
| 529 |
& '[features]', & |
| 530 |
& 'myfeature.dependencies.openmp = "*"', & |
| 531 |
& 'myfeature.gfortran.dependencies.stdlib = "*"', & |
| 532 |
& 'myfeature.linux.dependencies.mpi = "*"' |
| 533 |
close(unit) |
| 534 |
|
| 535 |
call get_package_data(package, temp_file, error) |
| 536 |
if (allocated(error)) return |
| 537 |
|
| 538 |
! Should have feature collection |
| 539 |
if (.not. allocated(package%features) .or. size(package%features) < 1) then |
| 540 |
call test_failed(error, "No feature collections found for metapackage test") |
| 541 |
return |
| 542 |
end if |
| 543 |
|
| 544 |
! Find myfeature collection |
| 545 |
do i = 1, size(package%features) |
| 546 |
if (package%features(i)%base%name == "myfeature") then |
| 547 |
|
| 548 |
! Test extraction for gfortran on linux (should get all three metapackages) |
| 549 |
target_platform%compiler = id_gcc |
| 550 |
target_platform%os_type = OS_LINUX |
| 551 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 552 |
if (allocated(error)) return |
| 553 |
|
| 554 |
if (.not. package%features(i)%base%meta%openmp%on) then |
| 555 |
call test_failed(error, "Missing base openmp metapackage") |
| 556 |
return |
| 557 |
end if |
| 558 |
|
| 559 |
! Should have all three metapackages enabled (OR logic) |
| 560 |
if (.not. extracted_feature%meta%openmp%on) then |
| 561 |
call test_failed(error, "Missing openmp metapackage") |
| 562 |
return |
| 563 |
end if |
| 564 |
|
| 565 |
if (.not. extracted_feature%meta%stdlib%on) then |
| 566 |
call test_failed(error, "Missing stdlib metapackage") |
| 567 |
return |
| 568 |
end if |
| 569 |
|
| 570 |
if (.not. extracted_feature%meta%mpi%on) then |
| 571 |
call test_failed(error, "Missing mpi metapackage") |
| 572 |
return |
| 573 |
end if |
| 574 |
|
| 575 |
return ! Test passed |
| 576 |
end if |
| 577 |
end do |
| 578 |
|
| 579 |
call test_failed(error, "myfeature collection not found for metapackage test") |
| 580 |
|
| 581 |
end subroutine test_feature_metapackage_addition |
| 582 |
|
| 583 |
!> Test comprehensive feature extraction for gfortran+Linux target (flags + executables + build) |
| 584 |
subroutine test_feature_extract_gfortran_linux(error) |
| 585 |
!> Error handling |
| 586 |
type(error_t), allocatable, intent(out) :: error |
| 587 |
|
| 588 |
type(package_config_t) :: package |
| 589 |
character(:), allocatable :: temp_file |
| 590 |
integer :: unit |
| 591 |
type(feature_config_t) :: extracted_feature |
| 592 |
type(platform_config_t) :: target_platform |
| 593 |
integer :: i |
| 594 |
|
| 595 |
allocate(temp_file, source=get_temp_filename()) |
| 596 |
|
| 597 |
open(file=temp_file, newunit=unit) |
| 598 |
write(unit, '(a)') & |
| 599 |
& 'name = "extract-test"', & |
| 600 |
& 'version = "0.1.0"', & |
| 601 |
& '[features]', & |
| 602 |
& 'debug.flags = "-g"', & |
| 603 |
& 'debug.gfortran.flags = "-Wall -fcheck=bounds"', & |
| 604 |
& 'debug.linux.flags = "-DLINUX"', & |
| 605 |
& 'debug.linux.gfortran.flags = "-fbacktrace"', & |
| 606 |
& '[[features.debug.executable]]', & |
| 607 |
& 'name = "base_prog"', & |
| 608 |
& 'source-dir = "app"', & |
| 609 |
& '[[features.debug.gfortran.executable]]', & |
| 610 |
& 'name = "gfortran_prog"', & |
| 611 |
& 'source-dir = "app/gfortran"', & |
| 612 |
& '[[features.debug.linux.executable]]', & |
| 613 |
& 'name = "linux_prog"', & |
| 614 |
& 'source-dir = "app/linux"', & |
| 615 |
& '[features.debug.gfortran.build]', & |
| 616 |
& 'auto-executables = false' |
| 617 |
close(unit) |
| 618 |
|
| 619 |
call get_package_data(package, temp_file, error) |
| 620 |
if (allocated(error)) return |
| 621 |
|
| 622 |
! Find debug collection and extract for gfortran+Linux |
| 623 |
do i = 1, size(package%features) |
| 624 |
if (package%features(i)%base%name == "debug") then |
| 625 |
target_platform = platform_config_t(id_gcc, OS_LINUX) |
| 626 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 627 |
if (allocated(error)) return |
| 628 |
|
| 629 |
! Check flags are combined correctly |
| 630 |
if (.not. allocated(extracted_feature%flags)) then |
| 631 |
call test_failed(error, "No flags in extracted gfortran+Linux feature") |
| 632 |
return |
| 633 |
end if |
| 634 |
|
| 635 |
if (index(extracted_feature%flags, "-g") == 0 .or. & |
| 636 |
index(extracted_feature%flags, "-Wall") == 0 .or. & |
| 637 |
index(extracted_feature%flags, "-DLINUX") == 0 .or. & |
| 638 |
index(extracted_feature%flags, "-fbacktrace") == 0) then |
| 639 |
call test_failed(error, "Missing expected flags in gfortran+Linux extraction") |
| 640 |
return |
| 641 |
end if |
| 642 |
|
| 643 |
! Check that all executables are combined (base + gfortran + linux) |
| 644 |
if (.not. allocated(extracted_feature%executable) .or. size(extracted_feature%executable) < 3) then |
| 645 |
call test_failed(error, "Wrong number of executables in gfortran+Linux (expected 3)") |
| 646 |
return |
| 647 |
end if |
| 648 |
|
| 649 |
! Check that build config is set (only gfortran variant has it) |
| 650 |
if (.not. allocated(extracted_feature%build)) then |
| 651 |
call test_failed(error, "Missing build config in gfortran+Linux extraction") |
| 652 |
return |
| 653 |
end if |
| 654 |
|
| 655 |
if (extracted_feature%build%auto_executables) then |
| 656 |
call test_failed(error, "Build config not applied correctly") |
| 657 |
return |
| 658 |
end if |
| 659 |
|
| 660 |
return ! Test passed |
| 661 |
end if |
| 662 |
end do |
| 663 |
|
| 664 |
call test_failed(error, "debug collection not found") |
| 665 |
|
| 666 |
end subroutine test_feature_extract_gfortran_linux |
| 667 |
|
| 668 |
!> Test comprehensive feature extraction for ifort+Windows target (flags + tests + library) |
| 669 |
subroutine test_feature_extract_ifort_windows(error) |
| 670 |
!> Error handling |
| 671 |
type(error_t), allocatable, intent(out) :: error |
| 672 |
|
| 673 |
type(package_config_t) :: package |
| 674 |
character(:), allocatable :: temp_file |
| 675 |
integer :: unit |
| 676 |
type(feature_config_t) :: extracted_feature |
| 677 |
type(platform_config_t) :: target_platform |
| 678 |
integer :: i |
| 679 |
|
| 680 |
allocate(temp_file, source=get_temp_filename()) |
| 681 |
|
| 682 |
open(file=temp_file, newunit=unit) |
| 683 |
write(unit, '(a)') & |
| 684 |
& 'name = "extract-test"', & |
| 685 |
& 'version = "0.1.0"', & |
| 686 |
& '[features]', & |
| 687 |
& 'debug.flags = "/debug"', & |
| 688 |
& 'debug.ifort.flags = "/warn:all"', & |
| 689 |
& 'debug.windows.flags = "/DWINDOWS"', & |
| 690 |
& 'debug.linux.flags = "-DLINUX"', & ! Should not be included for Windows target |
| 691 |
& '[[features.debug.test]]', & |
| 692 |
& 'name = "base_test"', & |
| 693 |
& 'source-dir = "test"', & |
| 694 |
& '[[features.debug.ifort.test]]', & |
| 695 |
& 'name = "ifort_test"', & |
| 696 |
& 'source-dir = "test/ifort"', & |
| 697 |
& '[[features.debug.windows.test]]', & |
| 698 |
& 'name = "windows_test"', & |
| 699 |
& 'source-dir = "test/windows"', & |
| 700 |
& '[features.debug.windows.library]', & |
| 701 |
& 'source-dir = "src/windows"' |
| 702 |
close(unit) |
| 703 |
|
| 704 |
call get_package_data(package, temp_file, error) |
| 705 |
if (allocated(error)) return |
| 706 |
|
| 707 |
! Find debug collection and extract for gfortran+Windows |
| 708 |
do i = 1, size(package%features) |
| 709 |
if (package%features(i)%base%name == "debug") then |
| 710 |
target_platform = platform_config_t("ifort", OS_WINDOWS) |
| 711 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 712 |
if (allocated(error)) return |
| 713 |
|
| 714 |
! Check flags: should have base + ifort + windows (but NOT linux) |
| 715 |
if (.not. allocated(extracted_feature%flags)) then |
| 716 |
call test_failed(error, "No flags in extracted ifort+Windows feature") |
| 717 |
return |
| 718 |
end if |
| 719 |
|
| 720 |
if (index(extracted_feature%flags, "/debug") == 0 .or. & |
| 721 |
index(extracted_feature%flags, "/warn:all") == 0 .or. & |
| 722 |
index(extracted_feature%flags, "/DWINDOWS") == 0) then |
| 723 |
call test_failed(error, "Missing expected flags in ifort+Windows extraction. Got: '" & |
| 724 |
//extracted_feature%flags//"'") |
| 725 |
return |
| 726 |
end if |
| 727 |
|
| 728 |
! Should NOT have linux-specific flag |
| 729 |
if (index(extracted_feature%flags, "-DLINUX") > 0) then |
| 730 |
call test_failed(error, "Incorrectly included Linux flag -DLINUX in ifort+Windows") |
| 731 |
return |
| 732 |
end if |
| 733 |
|
| 734 |
! Check that all tests are combined (base + ifort + windows) |
| 735 |
if (.not. allocated(extracted_feature%test) .or. size(extracted_feature%test) < 3) then |
| 736 |
call test_failed(error, "Wrong number of tests in ifort+Windows (expected 3)") |
| 737 |
return |
| 738 |
end if |
| 739 |
|
| 740 |
! Check that library config is set (only windows variant has it) |
| 741 |
if (.not. allocated(extracted_feature%library)) then |
| 742 |
call test_failed(error, "Missing library config in ifort+Windows extraction") |
| 743 |
return |
| 744 |
end if |
| 745 |
|
| 746 |
if (extracted_feature%library%source_dir /= "src/windows") then |
| 747 |
call test_failed(error, "Library config not applied correctly") |
| 748 |
return |
| 749 |
end if |
| 750 |
|
| 751 |
return ! Test passed |
| 752 |
end if |
| 753 |
end do |
| 754 |
|
| 755 |
call test_failed(error, "debug collection not found") |
| 756 |
|
| 757 |
end subroutine test_feature_extract_ifort_windows |
| 758 |
|
| 759 |
!> Test feature extraction with dependencies and examples for gfortran+macOS target |
| 760 |
subroutine test_feature_extract_dependencies_examples(error) |
| 761 |
!> Error handling |
| 762 |
type(error_t), allocatable, intent(out) :: error |
| 763 |
|
| 764 |
type(package_config_t) :: package |
| 765 |
character(:), allocatable :: temp_file |
| 766 |
integer :: unit |
| 767 |
type(feature_config_t) :: extracted_feature |
| 768 |
type(platform_config_t) :: target_platform |
| 769 |
integer :: i, j |
| 770 |
logical :: has_gfortran_dep, has_macos_dep |
| 771 |
|
| 772 |
allocate(temp_file, source=get_temp_filename()) |
| 773 |
|
| 774 |
open(file=temp_file, newunit=unit) |
| 775 |
write(unit, '(a)') & |
| 776 |
& 'name = "deps-test"', & |
| 777 |
& 'version = "0.1.0"', & |
| 778 |
& '[features]', & |
| 779 |
& '[features.testing.dependencies]', & |
| 780 |
& 'base_dep.git = "https://github.com/example/base"', & |
| 781 |
& '[features.testing.gfortran.dependencies]', & |
| 782 |
& 'gfortran_dep.git = "https://github.com/example/gfortran"', & |
| 783 |
& '[features.testing.macos.dependencies]', & |
| 784 |
& 'macos_dep.git = "https://github.com/example/macos"', & |
| 785 |
& '[[features.testing.example]]', & |
| 786 |
& 'name = "base_example"', & |
| 787 |
& 'source-dir = "example"', & |
| 788 |
& '[[features.testing.gfortran.example]]', & |
| 789 |
& 'name = "gfortran_example"', & |
| 790 |
& 'source-dir = "example/gfortran"', & |
| 791 |
& '[[features.testing.macos.example]]', & |
| 792 |
& 'name = "macos_example"', & |
| 793 |
& 'source-dir = "example/macos"', & |
| 794 |
& '[features.testing.macos.fortran]', & |
| 795 |
& 'implicit-typing = false' |
| 796 |
close(unit) |
| 797 |
|
| 798 |
call get_package_data(package, temp_file, error) |
| 799 |
if (allocated(error)) return |
| 800 |
|
| 801 |
! Find testing collection and extract for gfortran+macOS |
| 802 |
do i = 1, size(package%features) |
| 803 |
if (package%features(i)%base%name == "testing") then |
| 804 |
target_platform = platform_config_t(id_gcc, OS_MACOS) |
| 805 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 806 |
if (allocated(error)) return |
| 807 |
|
| 808 |
! Check that all dependencies are combined (base + gfortran + macos) |
| 809 |
if (.not. allocated(extracted_feature%dependency)) then |
| 810 |
call test_failed(error, "Missing dependencies in gfortran+macOS extraction") |
| 811 |
return |
| 812 |
end if |
| 813 |
|
| 814 |
! Verify that specific dependencies are present by checking names |
| 815 |
has_gfortran_dep = .false. |
| 816 |
has_macos_dep = .false. |
| 817 |
|
| 818 |
do j = 1, size(extracted_feature%dependency) |
| 819 |
if (extracted_feature%dependency(j)%name == "gfortran_dep") then |
| 820 |
has_gfortran_dep = .true. |
| 821 |
end if |
| 822 |
if (extracted_feature%dependency(j)%name == "macos_dep") then |
| 823 |
has_macos_dep = .true. |
| 824 |
end if |
| 825 |
end do |
| 826 |
|
| 827 |
if (.not. has_gfortran_dep) then |
| 828 |
call test_failed(error, "Missing gfortran_dep dependency in gfortran+macOS extraction") |
| 829 |
return |
| 830 |
end if |
| 831 |
if (.not. has_macos_dep) then |
| 832 |
call test_failed(error, "Missing macos_dep dependency in gfortran+macOS extraction") |
| 833 |
return |
| 834 |
end if |
| 835 |
|
| 836 |
! Check that all examples are combined (base + gfortran + macos) |
| 837 |
if (.not. allocated(extracted_feature%example) .or. size(extracted_feature%example) < 3) then |
| 838 |
call test_failed(error, "Wrong number of examples in gfortran+macOS (expected 3)") |
| 839 |
return |
| 840 |
end if |
| 841 |
|
| 842 |
! Check that fortran config is set (only macOS variant has it) |
| 843 |
if (.not. allocated(extracted_feature%fortran)) then |
| 844 |
call test_failed(error, "Missing fortran config in gfortran+macOS extraction") |
| 845 |
return |
| 846 |
end if |
| 847 |
|
| 848 |
if (extracted_feature%fortran%implicit_typing) then |
| 849 |
call test_failed(error, "Fortran config not applied correctly - "// & |
| 850 |
" implicit typing should be false") |
| 851 |
return |
| 852 |
end if |
| 853 |
|
| 854 |
return ! Test passed |
| 855 |
end if |
| 856 |
end do |
| 857 |
|
| 858 |
call test_failed(error, "testing collection not found") |
| 859 |
|
| 860 |
end subroutine test_feature_extract_dependencies_examples |
| 861 |
|
| 862 |
!> Test feature extraction with build configurations for ifort+Linux target |
| 863 |
subroutine test_feature_extract_build_configs(error) |
| 864 |
!> Error handling |
| 865 |
type(error_t), allocatable, intent(out) :: error |
| 866 |
|
| 867 |
type(package_config_t) :: package |
| 868 |
character(:), allocatable :: temp_file |
| 869 |
integer :: unit |
| 870 |
type(feature_config_t) :: extracted_feature |
| 871 |
type(platform_config_t) :: target_platform |
| 872 |
integer :: i |
| 873 |
|
| 874 |
allocate(temp_file, source=get_temp_filename()) |
| 875 |
|
| 876 |
open(file=temp_file, newunit=unit) |
| 877 |
write(unit, '(a)') & |
| 878 |
& 'name = "build-test"', & |
| 879 |
& 'version = "0.1.0"', & |
| 880 |
& '[features]', & |
| 881 |
& '[features.optimization.ifort.linux.build]', & |
| 882 |
& 'auto-executables = false', & |
| 883 |
& 'auto-tests = false', & |
| 884 |
& 'link = ["mylib"]', & |
| 885 |
& 'external-modules = ["external_mod"]' |
| 886 |
close(unit) |
| 887 |
|
| 888 |
call get_package_data(package, temp_file, error) |
| 889 |
if (allocated(error)) return |
| 890 |
|
| 891 |
! Find optimization collection and extract for ifort+Linux |
| 892 |
do i = 1, size(package%features) |
| 893 |
if (package%features(i)%base%name == "optimization") then |
| 894 |
target_platform = platform_config_t(id_intel_classic_nix, OS_LINUX) |
| 895 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 896 |
if (allocated(error)) return |
| 897 |
|
| 898 |
! Check that build config is present |
| 899 |
if (.not. allocated(extracted_feature%build)) then |
| 900 |
call test_failed(error, "Missing build config in ifort+Linux extraction") |
| 901 |
return |
| 902 |
end if |
| 903 |
|
| 904 |
! Check that auto-executables is set correctly |
| 905 |
if (extracted_feature%build%auto_executables) then |
| 906 |
call test_failed(error, "Build config auto-executables should be false") |
| 907 |
return |
| 908 |
end if |
| 909 |
|
| 910 |
! Check that auto-tests is set correctly |
| 911 |
if (extracted_feature%build%auto_tests) then |
| 912 |
call test_failed(error, "Build config auto-tests should be false") |
| 913 |
return |
| 914 |
end if |
| 915 |
|
| 916 |
! Check that link libraries are present |
| 917 |
if (.not. allocated(extracted_feature%build%link) .or. size(extracted_feature%build%link) < 1) then |
| 918 |
call test_failed(error, "Missing link libraries in ifort+Linux build config") |
| 919 |
return |
| 920 |
end if |
| 921 |
|
| 922 |
! Check that external modules are present |
| 923 |
if (.not. allocated(extracted_feature%build%external_modules) & |
| 924 |
.or. size(extracted_feature%build%external_modules) < 1) then |
| 925 |
call test_failed(error, "Missing external modules in ifort+Linux build config") |
| 926 |
return |
| 927 |
end if |
| 928 |
|
| 929 |
return ! Test passed |
| 930 |
end if |
| 931 |
end do |
| 932 |
|
| 933 |
call test_failed(error, "optimization collection not found") |
| 934 |
|
| 935 |
end subroutine test_feature_extract_build_configs |
| 936 |
|
| 937 |
!> Test feature extraction with test configurations for gfortran+Windows target |
| 938 |
subroutine test_feature_extract_test_configs(error) |
| 939 |
!> Error handling |
| 940 |
type(error_t), allocatable, intent(out) :: error |
| 941 |
|
| 942 |
type(package_config_t) :: package |
| 943 |
character(:), allocatable :: temp_file |
| 944 |
integer :: unit |
| 945 |
type(feature_config_t) :: extracted_feature |
| 946 |
type(platform_config_t) :: target_platform |
| 947 |
integer :: i, j |
| 948 |
logical :: has_base, has_gfortran, has_windows, has_specific |
| 949 |
|
| 950 |
allocate(temp_file, source=get_temp_filename()) |
| 951 |
|
| 952 |
open(file=temp_file, newunit=unit) |
| 953 |
write(unit, '(a)') & |
| 954 |
& 'name = "test-configs"', & |
| 955 |
& 'version = "0.1.0"', & |
| 956 |
& '[features]', & |
| 957 |
& '[[features.testing.test]]', & |
| 958 |
& 'name = "base_test"', & |
| 959 |
& 'source-dir = "test"', & |
| 960 |
& '[[features.testing.gfortran.test]]', & |
| 961 |
& 'name = "gfortran_test"', & |
| 962 |
& 'source-dir = "test/gfortran"', & |
| 963 |
& '[[features.testing.windows.test]]', & |
| 964 |
& 'name = "windows_test"', & |
| 965 |
& 'source-dir = "test/windows"', & |
| 966 |
& '[[features.testing.gfortran.windows.test]]', & |
| 967 |
& 'name = "gfortran_windows_test"', & |
| 968 |
& 'source-dir = "test/gfortran_windows"' |
| 969 |
close(unit) |
| 970 |
|
| 971 |
call get_package_data(package, temp_file, error) |
| 972 |
if (allocated(error)) return |
| 973 |
|
| 974 |
! Find testing collection and extract for gfortran+Windows |
| 975 |
do i = 1, size(package%features) |
| 976 |
if (package%features(i)%base%name == "testing") then |
| 977 |
target_platform = platform_config_t(id_gcc, OS_WINDOWS) |
| 978 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 979 |
if (allocated(error)) return |
| 980 |
|
| 981 |
! Check that all test configs are combined (base + gfortran + windows + gfortran.windows) |
| 982 |
if (.not. allocated(extracted_feature%test) .or. size(extracted_feature%test) < 4) then |
| 983 |
call test_failed(error, "Wrong number of test configs in gfortran+Windows (expected 4)") |
| 984 |
return |
| 985 |
end if |
| 986 |
|
| 987 |
! Verify that specific test configs are present by checking names |
| 988 |
has_base = .false. |
| 989 |
has_gfortran = .false. |
| 990 |
has_windows = .false. |
| 991 |
has_specific = .false. |
| 992 |
|
| 993 |
do j = 1, size(extracted_feature%test) |
| 994 |
select case (extracted_feature%test(j)%name) |
| 995 |
case ("base_test") |
| 996 |
has_base = .true. |
| 997 |
case ("gfortran_test") |
| 998 |
has_gfortran = .true. |
| 999 |
case ("windows_test") |
| 1000 |
has_windows = .true. |
| 1001 |
case ("gfortran_windows_test") |
| 1002 |
has_specific = .true. |
| 1003 |
end select |
| 1004 |
end do |
| 1005 |
|
| 1006 |
if (.not. has_base) then |
| 1007 |
call test_failed(error, "Missing base_test in gfortran+Windows extraction") |
| 1008 |
return |
| 1009 |
end if |
| 1010 |
if (.not. has_gfortran) then |
| 1011 |
call test_failed(error, "Missing gfortran_test in gfortran+Windows extraction") |
| 1012 |
return |
| 1013 |
end if |
| 1014 |
if (.not. has_windows) then |
| 1015 |
call test_failed(error, "Missing windows_test in gfortran+Windows extraction") |
| 1016 |
return |
| 1017 |
end if |
| 1018 |
if (.not. has_specific) then |
| 1019 |
call test_failed(error, "Missing gfortran_windows_test in gfortran+Windows extraction") |
| 1020 |
return |
| 1021 |
end if |
| 1022 |
|
| 1023 |
return ! Test passed |
| 1024 |
end if |
| 1025 |
end do |
| 1026 |
|
| 1027 |
call test_failed(error, "testing collection not found") |
| 1028 |
|
| 1029 |
end subroutine test_feature_extract_test_configs |
| 1030 |
|
| 1031 |
!> Test feature extraction with example configurations for ifx+macOS target |
| 1032 |
subroutine test_feature_extract_example_configs(error) |
| 1033 |
!> Error handling |
| 1034 |
type(error_t), allocatable, intent(out) :: error |
| 1035 |
|
| 1036 |
type(package_config_t) :: package |
| 1037 |
character(:), allocatable :: temp_file |
| 1038 |
integer :: unit |
| 1039 |
type(feature_config_t) :: extracted_feature |
| 1040 |
type(platform_config_t) :: target_platform |
| 1041 |
integer :: i, j |
| 1042 |
logical :: has_base, has_ifx, has_macos, has_specific |
| 1043 |
|
| 1044 |
allocate(temp_file, source=get_temp_filename()) |
| 1045 |
|
| 1046 |
open(file=temp_file, newunit=unit) |
| 1047 |
write(unit, '(a)') & |
| 1048 |
& 'name = "example-configs"', & |
| 1049 |
& 'version = "0.1.0"', & |
| 1050 |
& '[features]', & |
| 1051 |
& '[[features.showcase.example]]', & |
| 1052 |
& 'name = "base_example"', & |
| 1053 |
& 'source-dir = "examples"', & |
| 1054 |
& '[[features.showcase.ifx.example]]', & |
| 1055 |
& 'name = "ifx_example"', & |
| 1056 |
& 'source-dir = "examples/ifx"', & |
| 1057 |
& '[[features.showcase.macos.example]]', & |
| 1058 |
& 'name = "macos_example"', & |
| 1059 |
& 'source-dir = "examples/macos"', & |
| 1060 |
& '[[features.showcase.ifx.macos.example]]', & |
| 1061 |
& 'name = "ifx_macos_example"', & |
| 1062 |
& 'source-dir = "examples/ifx_macos"' |
| 1063 |
close(unit) |
| 1064 |
|
| 1065 |
call get_package_data(package, temp_file, error) |
| 1066 |
if (allocated(error)) return |
| 1067 |
|
| 1068 |
! Find showcase collection and extract for ifx+macOS |
| 1069 |
do i = 1, size(package%features) |
| 1070 |
if (package%features(i)%base%name == "showcase") then |
| 1071 |
target_platform = platform_config_t(id_intel_llvm_nix, OS_MACOS) |
| 1072 |
extracted_feature = package%features(i)%extract_for_target(target_platform, error=error) |
| 1073 |
if (allocated(error)) return |
| 1074 |
|
| 1075 |
! Check that all example configs are combined (base + ifx + macos + ifx.macos) |
| 1076 |
if (.not. allocated(extracted_feature%example) .or. size(extracted_feature%example) < 4) then |
| 1077 |
call test_failed(error, "Wrong number of example configs in ifx+macOS (expected 4)") |
| 1078 |
return |
| 1079 |
end if |
| 1080 |
|
| 1081 |
! Verify that specific example configs are present by checking names |
| 1082 |
has_base = .false. |
| 1083 |
has_ifx = .false. |
| 1084 |
has_macos = .false. |
| 1085 |
has_specific = .false. |
| 1086 |
|
| 1087 |
do j = 1, size(extracted_feature%example) |
| 1088 |
select case (extracted_feature%example(j)%name) |
| 1089 |
case ("base_example") |
| 1090 |
has_base = .true. |
| 1091 |
case ("ifx_example") |
| 1092 |
has_ifx = .true. |
| 1093 |
case ("macos_example") |
| 1094 |
has_macos = .true. |
| 1095 |
case ("ifx_macos_example") |
| 1096 |
has_specific = .true. |
| 1097 |
end select |
| 1098 |
end do |
| 1099 |
|
| 1100 |
if (.not. has_base) then |
| 1101 |
call test_failed(error, "Missing base_example in ifx+macOS extraction") |
| 1102 |
return |
| 1103 |
end if |
| 1104 |
if (.not. has_ifx) then |
| 1105 |
call test_failed(error, "Missing ifx_example in ifx+macOS extraction") |
| 1106 |
return |
| 1107 |
end if |
| 1108 |
if (.not. has_macos) then |
| 1109 |
call test_failed(error, "Missing macos_example in ifx+macOS extraction") |
| 1110 |
return |
| 1111 |
end if |
| 1112 |
if (.not. has_specific) then |
| 1113 |
call test_failed(error, "Missing ifx_macos_example in ifx+macOS extraction") |
| 1114 |
return |
| 1115 |
end if |
| 1116 |
|
| 1117 |
return ! Test passed |
| 1118 |
end if |
| 1119 |
end do |
| 1120 |
|
| 1121 |
call test_failed(error, "showcase collection not found") |
| 1122 |
|
| 1123 |
end subroutine test_feature_extract_example_configs |
| 1124 |
|
| 1125 |
!> Test that dependency features are correctly propagated and applied |
| 1126 |
subroutine test_dependency_feature_propagation(error) |
| 1127 |
!> Error handling |
| 1128 |
type(error_t), allocatable, intent(out) :: error |
| 1129 |
|
| 1130 |
type(package_config_t) :: dependency_config, exported_config |
| 1131 |
character(:), allocatable :: temp_file |
| 1132 |
integer :: unit |
| 1133 |
type(platform_config_t) :: target_platform |
| 1134 |
type(string_t), allocatable :: test_features(:) |
| 1135 |
|
| 1136 |
allocate(temp_file, source=get_temp_filename()) |
| 1137 |
|
| 1138 |
! Create a dependency manifest with features |
| 1139 |
open(file=temp_file, newunit=unit) |
| 1140 |
write(unit, '(a)') & |
| 1141 |
& 'name = "test-dependency"', & |
| 1142 |
& 'version = "0.1.0"', & |
| 1143 |
& '[features]', & |
| 1144 |
& 'debug.flags = "-g -DDEBUG"', & |
| 1145 |
& 'debug.gfortran.flags = "-fcheck=bounds"', & |
| 1146 |
& 'mpi.flags = "-DUSE_MPI"', & |
| 1147 |
& 'mpi.dependencies.mpi = "*"', & |
| 1148 |
& '[[features.debug.executable]]', & |
| 1149 |
& 'name = "debug_tool"', & |
| 1150 |
& 'source-dir = "debug_tools"' |
| 1151 |
close(unit) |
| 1152 |
|
| 1153 |
! Load the dependency configuration |
| 1154 |
call get_package_data(dependency_config, temp_file, error) |
| 1155 |
if (allocated(error)) return |
| 1156 |
|
| 1157 |
! Simulate dependency requesting specific features (like dep%features from build_model) |
| 1158 |
allocate(test_features(2)) |
| 1159 |
test_features(1)%s = "debug" |
| 1160 |
test_features(2)%s = "mpi" |
| 1161 |
|
| 1162 |
! Test export_config with these features (mimics line 132-133 in fpm.f90) |
| 1163 |
target_platform = platform_config_t(id_gcc, OS_LINUX) |
| 1164 |
exported_config = dependency_config%export_config(target_platform, test_features, verbose=.false., error=error) |
| 1165 |
if (allocated(error)) return |
| 1166 |
|
| 1167 |
! Verify that debug feature flags were applied |
| 1168 |
if (.not. allocated(exported_config%flags)) then |
| 1169 |
call test_failed(error, "Dependency export_config missing flags from debug feature") |
| 1170 |
return |
| 1171 |
end if |
| 1172 |
|
| 1173 |
if (index(exported_config%flags, "-g") == 0 .or. & |
| 1174 |
index(exported_config%flags, "-DDEBUG") == 0) then |
| 1175 |
call test_failed(error, "Dependency missing debug flags: got '" // exported_config%flags // "'") |
| 1176 |
return |
| 1177 |
end if |
| 1178 |
|
| 1179 |
if (index(exported_config%flags, "-fcheck=bounds") == 0) then |
| 1180 |
call test_failed(error, "Dependency missing gfortran-specific debug flags") |
| 1181 |
return |
| 1182 |
end if |
| 1183 |
|
| 1184 |
! Verify that mpi feature flags were applied |
| 1185 |
if (index(exported_config%flags, "-DUSE_MPI") == 0) then |
| 1186 |
call test_failed(error, "Dependency missing mpi flags") |
| 1187 |
return |
| 1188 |
end if |
| 1189 |
|
| 1190 |
! Verify that mpi metapackage was enabled |
| 1191 |
if (.not. exported_config%meta%mpi%on) then |
| 1192 |
call test_failed(error, "Dependency mpi metapackage not enabled") |
| 1193 |
return |
| 1194 |
end if |
| 1195 |
|
| 1196 |
! Verify that debug executable was included |
| 1197 |
if (.not. allocated(exported_config%executable)) then |
| 1198 |
call test_failed(error, "Dependency debug executable not included") |
| 1199 |
return |
| 1200 |
end if |
| 1201 |
|
| 1202 |
if (size(exported_config%executable) < 1) then |
| 1203 |
call test_failed(error, "Dependency should have debug executable") |
| 1204 |
return |
| 1205 |
end if |
| 1206 |
|
| 1207 |
if (exported_config%executable(1)%name /= "debug_tool") then |
| 1208 |
call test_failed(error, "Dependency debug executable has wrong name") |
| 1209 |
return |
| 1210 |
end if |
| 1211 |
|
| 1212 |
end subroutine test_dependency_feature_propagation |
| 1213 |
|
| 1214 |
!> Test that main package can specify features for its dependencies |
| 1215 |
subroutine test_dependency_features_specification(error) |
| 1216 |
!> Error handling |
| 1217 |
type(error_t), allocatable, intent(out) :: error |
| 1218 |
|
| 1219 |
type(package_config_t) :: main_package |
| 1220 |
character(:), allocatable :: temp_file |
| 1221 |
integer :: unit, i |
| 1222 |
logical :: found_tomlf_dep |
| 1223 |
|
| 1224 |
allocate(temp_file, source=get_temp_filename()) |
| 1225 |
|
| 1226 |
! Create a main package manifest that specifies features for dependencies |
| 1227 |
open(file=temp_file, newunit=unit) |
| 1228 |
write(unit, '(a)') & |
| 1229 |
& 'name = "main-package"', & |
| 1230 |
& 'version = "0.1.0"', & |
| 1231 |
& '[dependencies]', & |
| 1232 |
& '"dep-a" = { path = "../dep-a", features = ["openmp", "json"] }', & |
| 1233 |
& '"dep-b" = { path = "../dep-b", features = ["debug"] }' |
| 1234 |
close(unit) |
| 1235 |
|
| 1236 |
! Load the main package configuration |
| 1237 |
call get_package_data(main_package, temp_file, error) |
| 1238 |
if (allocated(error)) return |
| 1239 |
|
| 1240 |
! Verify dependencies were parsed correctly |
| 1241 |
if (.not. allocated(main_package%dependency)) then |
| 1242 |
call test_failed(error, "Main package dependencies not allocated") |
| 1243 |
return |
| 1244 |
end if |
| 1245 |
|
| 1246 |
if (size(main_package%dependency) /= 2) then |
| 1247 |
call test_failed(error, "Expected 2 dependencies, got " // & |
| 1248 |
char(size(main_package%dependency) + ichar('0'))) |
| 1249 |
return |
| 1250 |
end if |
| 1251 |
|
| 1252 |
! Find and verify dep-a dependency with features |
| 1253 |
found_tomlf_dep = .false. |
| 1254 |
do i = 1, size(main_package%dependency) |
| 1255 |
if (main_package%dependency(i)%name == "dep-a") then |
| 1256 |
found_tomlf_dep = .true. |
| 1257 |
|
| 1258 |
! Verify path configuration exists |
| 1259 |
if (.not. allocated(main_package%dependency(i)%path)) then |
| 1260 |
call test_failed(error, "dep-a dependency missing path configuration") |
| 1261 |
return |
| 1262 |
end if |
| 1263 |
|
| 1264 |
! Path gets canonicalized, so just check it ends with the relative path |
| 1265 |
if (index(main_package%dependency(i)%path, "dep-a") == 0) then |
| 1266 |
call test_failed(error, "dep-a dependency path should contain 'dep-a', got: '" // & |
| 1267 |
main_package%dependency(i)%path // "'") |
| 1268 |
return |
| 1269 |
end if |
| 1270 |
|
| 1271 |
! Verify features array - this is the key test |
| 1272 |
if (.not. allocated(main_package%dependency(i)%features)) then |
| 1273 |
call test_failed(error, "dep-a dependency features not allocated") |
| 1274 |
return |
| 1275 |
end if |
| 1276 |
|
| 1277 |
if (size(main_package%dependency(i)%features) /= 2) then |
| 1278 |
call test_failed(error, "dep-a dependency should have 2 features") |
| 1279 |
return |
| 1280 |
end if |
| 1281 |
|
| 1282 |
if (main_package%dependency(i)%features(1)%s /= "openmp" .or. & |
| 1283 |
main_package%dependency(i)%features(2)%s /= "json") then |
| 1284 |
call test_failed(error, "dep-a dependency has wrong feature names") |
| 1285 |
return |
| 1286 |
end if |
| 1287 |
exit |
| 1288 |
end if |
| 1289 |
end do |
| 1290 |
|
| 1291 |
if (.not. found_tomlf_dep) then |
| 1292 |
call test_failed(error, "dep-a dependency not found") |
| 1293 |
return |
| 1294 |
end if |
| 1295 |
|
| 1296 |
! Verify dep-b dependency has features |
| 1297 |
do i = 1, size(main_package%dependency) |
| 1298 |
if (main_package%dependency(i)%name == "dep-b") then |
| 1299 |
if (.not. allocated(main_package%dependency(i)%features)) then |
| 1300 |
call test_failed(error, "dep-b dependency features not allocated") |
| 1301 |
return |
| 1302 |
end if |
| 1303 |
|
| 1304 |
if (size(main_package%dependency(i)%features) /= 1) then |
| 1305 |
call test_failed(error, "dep-b dependency should have 1 feature") |
| 1306 |
return |
| 1307 |
end if |
| 1308 |
|
| 1309 |
if (main_package%dependency(i)%features(1)%s /= "debug") then |
| 1310 |
call test_failed(error, "dep-b dependency has wrong feature name") |
| 1311 |
return |
| 1312 |
end if |
| 1313 |
exit |
| 1314 |
end if |
| 1315 |
end do |
| 1316 |
|
| 1317 |
end subroutine test_dependency_features_specification |
| 1318 |
|
| 1319 |
!> Test that chained OS commands are rejected (should fail) |
| 1320 |
subroutine test_feature_chained_os_commands(error) |
| 1321 |
!> Error handling |
| 1322 |
type(error_t), allocatable, intent(out) :: error |
| 1323 |
|
| 1324 |
type(package_config_t) :: package |
| 1325 |
character(:), allocatable :: temp_file |
| 1326 |
integer :: unit |
| 1327 |
|
| 1328 |
allocate(temp_file, source=get_temp_filename()) |
| 1329 |
|
| 1330 |
open(file=temp_file, newunit=unit) |
| 1331 |
write(unit, '(a)') & |
| 1332 |
& 'name = "chained-os-test"', & |
| 1333 |
& 'version = "0.1.0"', & |
| 1334 |
& '[features]', & |
| 1335 |
& 'myfeature.windows.linux.flags = "-invalid"' ! Chained OS: windows.linux |
| 1336 |
close(unit) |
| 1337 |
|
| 1338 |
call get_package_data(package, temp_file, error) |
| 1339 |
|
| 1340 |
! This should fail due to chained OS commands |
| 1341 |
|
| 1342 |
end subroutine test_feature_chained_os_commands |
| 1343 |
|
| 1344 |
!> Test that chained compiler commands are rejected (should fail) |
| 1345 |
subroutine test_feature_chained_compiler_commands(error) |
| 1346 |
!> Error handling |
| 1347 |
type(error_t), allocatable, intent(out) :: error |
| 1348 |
|
| 1349 |
type(package_config_t) :: package |
| 1350 |
character(:), allocatable :: temp_file |
| 1351 |
integer :: unit |
| 1352 |
|
| 1353 |
allocate(temp_file, source=get_temp_filename()) |
| 1354 |
|
| 1355 |
open(file=temp_file, newunit=unit) |
| 1356 |
write(unit, '(a)') & |
| 1357 |
& 'name = "chained-compiler-test"', & |
| 1358 |
& 'version = "0.1.0"', & |
| 1359 |
& '[features]', & |
| 1360 |
& 'myfeature.gfortran.ifort.flags = "-invalid"' ! Chained compiler: gfortran.ifort |
| 1361 |
close(unit) |
| 1362 |
|
| 1363 |
call get_package_data(package, temp_file, error) |
| 1364 |
|
| 1365 |
! This should fail due to chained compiler commands |
| 1366 |
|
| 1367 |
end subroutine test_feature_chained_compiler_commands |
| 1368 |
|
| 1369 |
!> Test complex chaining: compiler.os.compiler (should fail) |
| 1370 |
subroutine test_feature_complex_chain_compiler_os_compiler(error) |
| 1371 |
!> Error handling |
| 1372 |
type(error_t), allocatable, intent(out) :: error |
| 1373 |
|
| 1374 |
type(package_config_t) :: package |
| 1375 |
character(:), allocatable :: temp_file |
| 1376 |
integer :: unit |
| 1377 |
|
| 1378 |
allocate(temp_file, source=get_temp_filename()) |
| 1379 |
|
| 1380 |
open(file=temp_file, newunit=unit) |
| 1381 |
write(unit, '(a)') & |
| 1382 |
& 'name = "complex-chain-test"', & |
| 1383 |
& 'version = "0.1.0"', & |
| 1384 |
& '[features]', & |
| 1385 |
& 'myfeature.gfortran.windows.ifort.flags = "-invalid"' ! gfortran.windows.ifort chain |
| 1386 |
close(unit) |
| 1387 |
|
| 1388 |
call get_package_data(package, temp_file, error) |
| 1389 |
|
| 1390 |
! This should fail due to chained compiler constraints: gfortran -> windows (OK) -> ifort (ERROR) |
| 1391 |
|
| 1392 |
end subroutine test_feature_complex_chain_compiler_os_compiler |
| 1393 |
|
| 1394 |
!> Test complex chaining: os.compiler.os (should fail) |
| 1395 |
subroutine test_feature_complex_chain_os_compiler_os(error) |
| 1396 |
!> Error handling |
| 1397 |
type(error_t), allocatable, intent(out) :: error |
| 1398 |
|
| 1399 |
type(package_config_t) :: package |
| 1400 |
character(:), allocatable :: temp_file |
| 1401 |
integer :: unit |
| 1402 |
|
| 1403 |
allocate(temp_file, source=get_temp_filename()) |
| 1404 |
|
| 1405 |
open(file=temp_file, newunit=unit) |
| 1406 |
write(unit, '(a)') & |
| 1407 |
& 'name = "complex-chain-test2"', & |
| 1408 |
& 'version = "0.1.0"', & |
| 1409 |
& '[features]', & |
| 1410 |
& 'myfeature.windows.ifx.macos.flags = "-invalid"' ! windows.ifx.macos chain |
| 1411 |
close(unit) |
| 1412 |
|
| 1413 |
call get_package_data(package, temp_file, error) |
| 1414 |
|
| 1415 |
! This should fail due to chained OS constraints: windows -> ifx (OK) -> macos (ERROR) |
| 1416 |
|
| 1417 |
end subroutine test_feature_complex_chain_os_compiler_os |
| 1418 |
|
| 1419 |
!> Test mixed valid chains (should pass) |
| 1420 |
subroutine test_feature_mixed_valid_chains(error) |
| 1421 |
!> Error handling |
| 1422 |
type(error_t), allocatable, intent(out) :: error |
| 1423 |
|
| 1424 |
type(package_config_t) :: package |
| 1425 |
character(:), allocatable :: temp_file |
| 1426 |
integer :: unit |
| 1427 |
integer :: i |
| 1428 |
|
| 1429 |
allocate(temp_file, source=get_temp_filename()) |
| 1430 |
|
| 1431 |
open(file=temp_file, newunit=unit) |
| 1432 |
write(unit, '(a)') & |
| 1433 |
& 'name = "valid-chains-test"', & |
| 1434 |
& 'version = "0.1.0"', & |
| 1435 |
& '[features]', & |
| 1436 |
& 'debug.flags = "-g"', & ! Base feature (all OS, all compilers) |
| 1437 |
& 'debug.gfortran.flags = "-Wall"', & ! Compiler-specific (gfortran, all OS) |
| 1438 |
& 'debug.windows.flags = "-DWINDOWS"', & ! OS-specific (all compilers, Windows) |
| 1439 |
& 'debug.gfortran.windows.flags = "-fbacktrace"', & ! Target-specific (gfortran + Windows) |
| 1440 |
& 'debug.linux.ifort.flags = "-check all"', & ! Target-specific (Linux + ifort) |
| 1441 |
& 'release.ifx.macos.flags = "-O3"' ! Another valid target-specific (ifx + macOS) |
| 1442 |
close(unit) |
| 1443 |
|
| 1444 |
call get_package_data(package, temp_file, error) |
| 1445 |
if (allocated(error)) return |
| 1446 |
|
| 1447 |
! Verify that valid chains are accepted and collections created |
| 1448 |
if (.not. allocated(package%features)) then |
| 1449 |
call test_failed(error, "No feature collections found for valid chains test") |
| 1450 |
return |
| 1451 |
end if |
| 1452 |
|
| 1453 |
! Should have debug and release features |
| 1454 |
if (size(package%features) < 2) then |
| 1455 |
call test_failed(error, "Expected at least 2 feature collections for valid chains") |
| 1456 |
return |
| 1457 |
end if |
| 1458 |
|
| 1459 |
! Check that debug feature has multiple variants |
| 1460 |
do i = 1, size(package%features) |
| 1461 |
if (package%features(i)%base%name == "debug") then |
| 1462 |
if (.not. allocated(package%features(i)%variants)) then |
| 1463 |
call test_failed(error, "Debug collection should have variants for valid chains") |
| 1464 |
return |
| 1465 |
end if |
| 1466 |
|
| 1467 |
! Should have multiple variants: gfortran, windows, gfortran.windows, linux.ifort |
| 1468 |
if (size(package%features(i)%variants) < 4) then |
| 1469 |
call test_failed(error, "Debug collection should have at least 4 variants for valid chains") |
| 1470 |
return |
| 1471 |
end if |
| 1472 |
exit |
| 1473 |
end if |
| 1474 |
end do |
| 1475 |
|
| 1476 |
end subroutine test_feature_mixed_valid_chains |
| 1477 |
|
| 1478 |
!> Test integration of feature compiler flags with new_compiler_flags |
| 1479 |
subroutine test_feature_compiler_flags_integration(error) |
| 1480 |
use fpm, only: new_compiler_flags |
| 1481 |
use fpm_model, only: fpm_model_t |
| 1482 |
use fpm_command_line, only: fpm_build_settings |
| 1483 |
use fpm_compiler, only: new_compiler, id_gcc |
| 1484 |
|
| 1485 |
!> Error handling |
| 1486 |
type(error_t), allocatable, intent(out) :: error |
| 1487 |
|
| 1488 |
type(package_config_t) :: package_config,package |
| 1489 |
type(fpm_model_t) :: model |
| 1490 |
type(fpm_build_settings) :: settings |
| 1491 |
type(platform_config_t) :: target_platform |
| 1492 |
character(:), allocatable :: temp_file |
| 1493 |
integer :: unit |
| 1494 |
|
| 1495 |
allocate(temp_file, source=get_temp_filename()) |
| 1496 |
|
| 1497 |
! Create a test package with feature-based compiler flags |
| 1498 |
open(newunit=unit, file=temp_file, status='unknown') |
| 1499 |
write(unit, '(a)') 'name = "test_flags"' |
| 1500 |
write(unit, '(a)') 'version = "0.1.0"' |
| 1501 |
write(unit, '(a)') '' |
| 1502 |
write(unit, '(a)') '[library]' |
| 1503 |
write(unit, '(a)') 'source-dir = "src"' |
| 1504 |
write(unit, '(a)') '' |
| 1505 |
write(unit, '(a)') '[features]' |
| 1506 |
write(unit, '(a)') 'debug.gfortran.flags = "-g -Wall -fcheck=bounds"' |
| 1507 |
write(unit, '(a)') 'debug.flags = "-g"' |
| 1508 |
write(unit, '(a)') 'release.gfortran.flags = "-O3 -mtune=generic -funroll-loops"' |
| 1509 |
write(unit, '(a)') 'release.flags = "-O2"' |
| 1510 |
write(unit, '(a)') '' |
| 1511 |
write(unit, '(a)') '[profiles]' |
| 1512 |
write(unit, '(a)') 'development = ["debug"]' |
| 1513 |
write(unit, '(a)') 'production = ["release"]' |
| 1514 |
close(unit) |
| 1515 |
|
| 1516 |
! Set up build settings without CLI flags |
| 1517 |
settings%flag = "" |
| 1518 |
settings%cflag = "" |
| 1519 |
settings%cxxflag = "" |
| 1520 |
settings%ldflag = "" |
| 1521 |
|
| 1522 |
! Load the package configuration |
| 1523 |
call get_package_data(package_config, temp_file, error, apply_defaults=.true.) |
| 1524 |
if (allocated(error)) return |
| 1525 |
|
| 1526 |
! 1) Choose first desired target platform: gfortran on Linux with development profile |
| 1527 |
target_platform = platform_config_t(id_gcc, OS_LINUX) |
| 1528 |
settings%profile = "development" ! This should activate debug features |
| 1529 |
|
| 1530 |
! Extract the current package configuration request |
| 1531 |
package = package_config%export_config(target_platform, profile=settings%profile, verbose=.false., error=error) |
| 1532 |
if (allocated(error)) return |
| 1533 |
|
| 1534 |
! Set up model with mock compiler |
| 1535 |
call new_compiler(model%compiler, "gfortran", "gcc", "g++", echo=.false., verbose=.false.) |
| 1536 |
|
| 1537 |
! Test that package flags are used when no CLI flags provided |
| 1538 |
call new_compiler_flags(model, settings, package) |
| 1539 |
|
| 1540 |
! 2) Ensure flags are picked from gfortran platform (should include both base debug and gfortran-specific) |
| 1541 |
if (.not. allocated(model%fortran_compile_flags)) then |
| 1542 |
call test_failed(error, "Expected fortran_compile_flags to be allocated for gfortran") |
| 1543 |
return |
| 1544 |
end if |
| 1545 |
|
| 1546 |
if (index(model%fortran_compile_flags, "-g") == 0) then |
| 1547 |
call test_failed(error, "Expected debug flags to contain '-g' for gfortran platform") |
| 1548 |
return |
| 1549 |
end if |
| 1550 |
|
| 1551 |
if (index(model%fortran_compile_flags, "-Wall") == 0) then |
| 1552 |
call test_failed(error, "Expected gfortran-specific flags to contain '-Wall'") |
| 1553 |
return |
| 1554 |
end if |
| 1555 |
|
| 1556 |
if (index(model%fortran_compile_flags, "-fcheck=bounds") == 0) then |
| 1557 |
call test_failed(error, "Expected gfortran-specific flags to contain '-fcheck=bounds'") |
| 1558 |
return |
| 1559 |
end if |
| 1560 |
|
| 1561 |
! 3) Choose another target platform: gfortran on Linux with production profile |
| 1562 |
settings%profile = "production" ! This should activate release features |
| 1563 |
|
| 1564 |
! Extract the new package configuration request |
| 1565 |
package = package_config%export_config(target_platform, profile=settings%profile, verbose=.false., error=error) |
| 1566 |
if (allocated(error)) return |
| 1567 |
|
| 1568 |
! Reset flags and test production profile |
| 1569 |
call new_compiler_flags(model, settings, package) |
| 1570 |
|
| 1571 |
! 4) Ensure flags are picked from the release platform (should include release flags) |
| 1572 |
if (.not. allocated(model%fortran_compile_flags)) then |
| 1573 |
call test_failed(error, "Expected fortran_compile_flags to be allocated for release") |
| 1574 |
return |
| 1575 |
end if |
| 1576 |
|
| 1577 |
if (index(model%fortran_compile_flags, "-O3") == 0) then |
| 1578 |
call test_failed(error, "Expected release gfortran flags to contain '-O3'") |
| 1579 |
return |
| 1580 |
end if |
| 1581 |
|
| 1582 |
if (index(model%fortran_compile_flags, "-mtune") == 0) then |
| 1583 |
call test_failed(error, "Expected release gfortran flags to contain '-mtune'") |
| 1584 |
return |
| 1585 |
end if |
| 1586 |
|
| 1587 |
if (index(model%fortran_compile_flags, "-funroll-loops") == 0) then |
| 1588 |
call test_failed(error, "Expected release gfortran flags to contain '-funroll-loops'") |
| 1589 |
return |
| 1590 |
end if |
| 1591 |
|
| 1592 |
if (index(model%fortran_compile_flags, "-O2") == 0) then |
| 1593 |
call test_failed(error, "Expected base release flags to contain '-O2'") |
| 1594 |
return |
| 1595 |
end if |
| 1596 |
|
| 1597 |
! Test CLI flags still override package flags |
| 1598 |
settings%flag = "-O1 -DCUSTOM" |
| 1599 |
call new_compiler_flags(model, settings, package) |
| 1600 |
|
| 1601 |
if (index(model%fortran_compile_flags, "-O1") == 0) then |
| 1602 |
call test_failed(error, "Expected CLI flags to be used when provided") |
| 1603 |
return |
| 1604 |
end if |
| 1605 |
|
| 1606 |
if (index(model%fortran_compile_flags, "-DCUSTOM") == 0) then |
| 1607 |
call test_failed(error, "Expected CLI flags to contain custom flags") |
| 1608 |
return |
| 1609 |
end if |
| 1610 |
|
| 1611 |
! Clean up - file was already closed after writing |
| 1612 |
|
| 1613 |
end subroutine test_feature_compiler_flags_integration |
| 1614 |
|
| 1615 |
!> Test that "default" profile features are applied alongside --profile debug |
| 1616 |
subroutine test_default_profile_with_debug(error) |
| 1617 |
type(error_t), allocatable, intent(out) :: error |
| 1618 |
|
| 1619 |
type(package_config_t) :: package_config, package |
| 1620 |
type(platform_config_t) :: target_platform |
| 1621 |
character(:), allocatable :: temp_file |
| 1622 |
integer :: unit |
| 1623 |
|
| 1624 |
allocate(temp_file, source=get_temp_filename()) |
| 1625 |
|
| 1626 |
open(newunit=unit, file=temp_file, status='unknown') |
| 1627 |
write(unit, '(a)') 'name = "test_default"' |
| 1628 |
write(unit, '(a)') 'version = "0.1.0"' |
| 1629 |
write(unit, '(a)') '[library]' |
| 1630 |
write(unit, '(a)') 'source-dir = "src"' |
| 1631 |
write(unit, '(a)') '' |
| 1632 |
write(unit, '(a)') '[features]' |
| 1633 |
write(unit, '(a)') 'baseline.flags = "-fPIC"' |
| 1634 |
write(unit, '(a)') 'debug.flags = "-g"' |
| 1635 |
write(unit, '(a)') '' |
| 1636 |
write(unit, '(a)') '[profiles]' |
| 1637 |
write(unit, '(a)') 'default = ["baseline"]' |
| 1638 |
write(unit, '(a)') 'debug = ["debug"]' |
| 1639 |
close(unit) |
| 1640 |
|
| 1641 |
call get_package_data(package_config, temp_file, error, apply_defaults=.true.) |
| 1642 |
if (allocated(error)) return |
| 1643 |
|
| 1644 |
target_platform = platform_config_t(id_gcc, OS_LINUX) |
| 1645 |
|
| 1646 |
! Export with --profile debug: should get both default (baseline) and debug features |
| 1647 |
package = package_config%export_config(target_platform, profile="debug", verbose=.false., error=error) |
| 1648 |
if (allocated(error)) return |
| 1649 |
|
| 1650 |
! Should have baseline flags from default profile |
| 1651 |
if (index(package%flags, "-fPIC") == 0) then |
| 1652 |
call test_failed(error, "Expected default profile flags '-fPIC' to be present with --profile debug") |
| 1653 |
return |
| 1654 |
end if |
| 1655 |
|
| 1656 |
! Should also have debug flags |
| 1657 |
if (index(package%flags, "-g") == 0) then |
| 1658 |
call test_failed(error, "Expected debug flags '-g' to be present with --profile debug") |
| 1659 |
return |
| 1660 |
end if |
| 1661 |
|
| 1662 |
end subroutine test_default_profile_with_debug |
| 1663 |
|
| 1664 |
!> Test that "default" profile features are applied alongside --profile release |
| 1665 |
subroutine test_default_profile_with_release(error) |
| 1666 |
type(error_t), allocatable, intent(out) :: error |
| 1667 |
|
| 1668 |
type(package_config_t) :: package_config, package |
| 1669 |
type(platform_config_t) :: target_platform |
| 1670 |
character(:), allocatable :: temp_file |
| 1671 |
integer :: unit |
| 1672 |
|
| 1673 |
allocate(temp_file, source=get_temp_filename()) |
| 1674 |
|
| 1675 |
open(newunit=unit, file=temp_file, status='unknown') |
| 1676 |
write(unit, '(a)') 'name = "test_default"' |
| 1677 |
write(unit, '(a)') 'version = "0.1.0"' |
| 1678 |
write(unit, '(a)') '[library]' |
| 1679 |
write(unit, '(a)') 'source-dir = "src"' |
| 1680 |
write(unit, '(a)') '' |
| 1681 |
write(unit, '(a)') '[features]' |
| 1682 |
write(unit, '(a)') 'baseline.flags = "-fPIC"' |
| 1683 |
write(unit, '(a)') 'release.flags = "-O3"' |
| 1684 |
write(unit, '(a)') '' |
| 1685 |
write(unit, '(a)') '[profiles]' |
| 1686 |
write(unit, '(a)') 'default = ["baseline"]' |
| 1687 |
write(unit, '(a)') 'release = ["release"]' |
| 1688 |
close(unit) |
| 1689 |
|
| 1690 |
call get_package_data(package_config, temp_file, error, apply_defaults=.true.) |
| 1691 |
if (allocated(error)) return |
| 1692 |
|
| 1693 |
target_platform = platform_config_t(id_gcc, OS_LINUX) |
| 1694 |
|
| 1695 |
! Export with --profile release: should get both default (baseline) and release features |
| 1696 |
package = package_config%export_config(target_platform, profile="release", verbose=.false., error=error) |
| 1697 |
if (allocated(error)) return |
| 1698 |
|
| 1699 |
! Should have baseline flags from default profile |
| 1700 |
if (index(package%flags, "-fPIC") == 0) then |
| 1701 |
call test_failed(error, "Expected default profile flags '-fPIC' to be present with --profile release") |
| 1702 |
return |
| 1703 |
end if |
| 1704 |
|
| 1705 |
! Should also have release flags |
| 1706 |
if (index(package%flags, "-O3") == 0) then |
| 1707 |
call test_failed(error, "Expected release flags '-O3' to be present with --profile release") |
| 1708 |
return |
| 1709 |
end if |
| 1710 |
|
| 1711 |
end subroutine test_default_profile_with_release |
| 1712 |
|
| 1713 |
!> Test that "default" profile features are applied when no profile is specified (implicit debug) |
| 1714 |
subroutine test_default_profile_implicit_debug(error) |
| 1715 |
type(error_t), allocatable, intent(out) :: error |
| 1716 |
|
| 1717 |
type(package_config_t) :: package_config, package |
| 1718 |
type(platform_config_t) :: target_platform |
| 1719 |
character(:), allocatable :: temp_file |
| 1720 |
integer :: unit |
| 1721 |
|
| 1722 |
allocate(temp_file, source=get_temp_filename()) |
| 1723 |
|
| 1724 |
open(newunit=unit, file=temp_file, status='unknown') |
| 1725 |
write(unit, '(a)') 'name = "test_default"' |
| 1726 |
write(unit, '(a)') 'version = "0.1.0"' |
| 1727 |
write(unit, '(a)') '[library]' |
| 1728 |
write(unit, '(a)') 'source-dir = "src"' |
| 1729 |
write(unit, '(a)') '' |
| 1730 |
write(unit, '(a)') '[features]' |
| 1731 |
write(unit, '(a)') 'baseline.flags = "-fPIC"' |
| 1732 |
write(unit, '(a)') '' |
| 1733 |
write(unit, '(a)') '[profiles]' |
| 1734 |
write(unit, '(a)') 'default = ["baseline"]' |
| 1735 |
close(unit) |
| 1736 |
|
| 1737 |
call get_package_data(package_config, temp_file, error, apply_defaults=.true.) |
| 1738 |
if (allocated(error)) return |
| 1739 |
|
| 1740 |
target_platform = platform_config_t(id_gcc, OS_LINUX) |
| 1741 |
|
| 1742 |
! Export with no profile/features: should still get default profile features |
| 1743 |
package = package_config%export_config(target_platform, verbose=.false., error=error) |
| 1744 |
if (allocated(error)) return |
| 1745 |
|
| 1746 |
! Should have baseline flags from default profile |
| 1747 |
if (index(package%flags, "-fPIC") == 0) then |
| 1748 |
call test_failed(error, "Expected default profile flags '-fPIC' to be present with no explicit profile") |
| 1749 |
return |
| 1750 |
end if |
| 1751 |
|
| 1752 |
end subroutine test_default_profile_implicit_debug |
| 1753 |
|
| 1754 |
!> Test that "default" profile features are NOT applied when a custom profile is requested |
| 1755 |
subroutine test_default_profile_skipped_custom(error) |
| 1756 |
type(error_t), allocatable, intent(out) :: error |
| 1757 |
|
| 1758 |
type(package_config_t) :: package_config, package |
| 1759 |
type(platform_config_t) :: target_platform |
| 1760 |
character(:), allocatable :: temp_file |
| 1761 |
integer :: unit |
| 1762 |
|
| 1763 |
allocate(temp_file, source=get_temp_filename()) |
| 1764 |
|
| 1765 |
open(newunit=unit, file=temp_file, status='unknown') |
| 1766 |
write(unit, '(a)') 'name = "test_default"' |
| 1767 |
write(unit, '(a)') 'version = "0.1.0"' |
| 1768 |
write(unit, '(a)') '[library]' |
| 1769 |
write(unit, '(a)') 'source-dir = "src"' |
| 1770 |
write(unit, '(a)') '' |
| 1771 |
write(unit, '(a)') '[features]' |
| 1772 |
write(unit, '(a)') 'baseline.flags = "-fPIC"' |
| 1773 |
write(unit, '(a)') 'custom_opt.flags = "-O1"' |
| 1774 |
write(unit, '(a)') '' |
| 1775 |
write(unit, '(a)') '[profiles]' |
| 1776 |
write(unit, '(a)') 'default = ["baseline"]' |
| 1777 |
write(unit, '(a)') 'myprofile = ["custom_opt"]' |
| 1778 |
close(unit) |
| 1779 |
|
| 1780 |
call get_package_data(package_config, temp_file, error, apply_defaults=.true.) |
| 1781 |
if (allocated(error)) return |
| 1782 |
|
| 1783 |
target_platform = platform_config_t(id_gcc, OS_LINUX) |
| 1784 |
|
| 1785 |
! Export with --profile myprofile: should NOT get default profile features |
| 1786 |
package = package_config%export_config(target_platform, profile="myprofile", verbose=.false., error=error) |
| 1787 |
if (allocated(error)) return |
| 1788 |
|
| 1789 |
! Should have custom profile flags |
| 1790 |
if (index(package%flags, "-O1") == 0) then |
| 1791 |
call test_failed(error, "Expected custom profile flags '-O1' to be present") |
| 1792 |
return |
| 1793 |
end if |
| 1794 |
|
| 1795 |
! Should NOT have baseline flags from default profile |
| 1796 |
if (index(package%flags, "-fPIC") /= 0) then |
| 1797 |
call test_failed(error, "Default profile flags '-fPIC' should NOT be present with custom profile") |
| 1798 |
return |
| 1799 |
end if |
| 1800 |
|
| 1801 |
end subroutine test_default_profile_skipped_custom |
| 1802 |
|
| 1803 |
end module test_features |