1
1
! > Define tests for the `fpm_manifest` modules
2
2
module test_manifest
3
+ use fpm_filesystem, only: get_temp_filename
3
4
use testsuite, only : new_unittest, unittest_t, error_t, test_failed, &
4
5
& check_string
5
6
use fpm_manifest
@@ -17,10 +18,11 @@ subroutine collect_manifest(testsuite)
17
18
18
19
! > Collection of tests
19
20
type (unittest_t), allocatable , intent (out ) :: testsuite(:)
20
-
21
+
21
22
testsuite = [ &
22
23
& new_unittest(" valid-manifest" , test_valid_manifest), &
23
24
& new_unittest(" invalid-manifest" , test_invalid_manifest, should_fail= .true. ), &
25
+ & new_unittest(" default-build-configuration" , test_default_build_config), &
24
26
& new_unittest(" default-library" , test_default_library), &
25
27
& new_unittest(" default-executable" , test_default_executable), &
26
28
& new_unittest(" dependency-empty" , test_dependency_empty, should_fail= .true. ), &
@@ -35,6 +37,9 @@ subroutine collect_manifest(testsuite)
35
37
& new_unittest(" executable-typeerror" , test_executable_typeerror, should_fail= .true. ), &
36
38
& new_unittest(" executable-noname" , test_executable_noname, should_fail= .true. ), &
37
39
& new_unittest(" executable-wrongkey" , test_executable_wrongkey, should_fail= .true. ), &
40
+ & new_unittest(" build-config-valid" , test_build_config_valid), &
41
+ & new_unittest(" build-config-empty" , test_build_config_empty), &
42
+ & new_unittest(" build-config-invalid-values" , test_build_config_invalid_values, should_fail= .true. ), &
38
43
& new_unittest(" library-empty" , test_library_empty), &
39
44
& new_unittest(" library-wrongkey" , test_library_wrongkey, should_fail= .true. ), &
40
45
& new_unittest(" package-simple" , test_package_simple), &
@@ -65,6 +70,9 @@ subroutine test_valid_manifest(error)
65
70
open (file= manifest, newunit= unit)
66
71
write (unit, ' (a)' ) &
67
72
& ' name = "example"' , &
73
+ & ' [build]' , &
74
+ & ' auto-executables = false' , &
75
+ & ' auto-tests = false' , &
68
76
& ' [dependencies.fpm]' , &
69
77
& ' git = "https://github.com/fortran-lang/fpm"' , &
70
78
& ' [[executable]]' , &
@@ -94,6 +102,11 @@ subroutine test_valid_manifest(error)
94
102
return
95
103
end if
96
104
105
+ if (.not. allocated (package% build_config)) then
106
+ call test_failed(error, " build is not present in package data" )
107
+ return
108
+ end if
109
+
97
110
if (.not. allocated (package% library)) then
98
111
call test_failed(error, " library is not present in package data" )
99
112
return
@@ -152,6 +165,31 @@ subroutine test_invalid_manifest(error)
152
165
end subroutine test_invalid_manifest
153
166
154
167
168
+ ! > Create a default build configuration
169
+ subroutine test_default_build_config (error )
170
+
171
+ ! > Error handling
172
+ type (error_t), allocatable , intent (out ) :: error
173
+
174
+ type (package_t) :: package
175
+
176
+ allocate (package% build_config)
177
+ call default_build_config(package% build_config)
178
+
179
+ if (.not. package% build_config% auto_executables) then
180
+ call test_failed(error,' Incorrect value for auto_executables in default build configuration, expecting .true.' )
181
+ return
182
+ end if
183
+
184
+ if (.not. package% build_config% auto_tests) then
185
+ call test_failed(error,' Incorrect value for auto_tests in default build configuration, expecting .true.' )
186
+ return
187
+ end if
188
+
189
+
190
+ end subroutine test_default_build_config
191
+
192
+
155
193
! > Create a default library
156
194
subroutine test_default_library (error )
157
195
@@ -446,6 +484,113 @@ subroutine test_executable_wrongkey(error)
446
484
end subroutine test_executable_wrongkey
447
485
448
486
487
+ ! > Try to read values from the [build] table
488
+ subroutine test_build_config_valid (error )
489
+
490
+ ! > Error handling
491
+ type (error_t), allocatable , intent (out ) :: error
492
+
493
+ type (package_t) :: package
494
+ character (:), allocatable :: temp_file
495
+ integer :: unit
496
+
497
+ allocate (temp_file, source= get_temp_filename())
498
+
499
+ open (file= temp_file, newunit= unit)
500
+ write (unit, ' (a)' ) &
501
+ & ' name = "example"' , &
502
+ & ' [build]' , &
503
+ & ' auto-executables = false' , &
504
+ & ' auto-tests = false'
505
+ close (unit)
506
+
507
+ call get_package_data(package, temp_file, error)
508
+
509
+ if (allocated (error)) return
510
+
511
+ if (.not. allocated (package% build_config)) then
512
+ call test_failed(error, " build is not present in package data" )
513
+ return
514
+ end if
515
+
516
+ if (package% build_config% auto_executables) then
517
+ call test_failed(error, " Wong value of 'auto-executables' read, expecting .false." )
518
+ return
519
+ end if
520
+
521
+ if (package% build_config% auto_tests) then
522
+ call test_failed(error, " Wong value of 'auto-tests' read, expecting .false." )
523
+ return
524
+ end if
525
+
526
+ end subroutine test_build_config_valid
527
+
528
+
529
+ ! > Try to read values from an empty [build] table
530
+ subroutine test_build_config_empty (error )
531
+
532
+ ! > Error handling
533
+ type (error_t), allocatable , intent (out ) :: error
534
+
535
+ type (package_t) :: package
536
+ character (:), allocatable :: temp_file
537
+ integer :: unit
538
+
539
+ allocate (temp_file, source= get_temp_filename())
540
+
541
+ open (file= temp_file, newunit= unit)
542
+ write (unit, ' (a)' ) &
543
+ & ' name = "example"' , &
544
+ & ' [build]' , &
545
+ & ' [library]'
546
+ close (unit)
547
+
548
+ call get_package_data(package, temp_file, error)
549
+
550
+ if (allocated (error)) return
551
+
552
+ if (.not. allocated (package% build_config)) then
553
+ call test_failed(error, " build is not present in package data" )
554
+ return
555
+ end if
556
+
557
+ if (.not. package% build_config% auto_executables) then
558
+ call test_failed(error, " Wong default value of 'auto-executables' read, expecting .true." )
559
+ return
560
+ end if
561
+
562
+ if (.not. package% build_config% auto_tests) then
563
+ call test_failed(error, " Wong default value of 'auto-tests' read, expecting .true." )
564
+ return
565
+ end if
566
+
567
+ end subroutine test_build_config_empty
568
+
569
+
570
+ ! > Try to read values from a [build] table with invalid values
571
+ subroutine test_build_config_invalid_values (error )
572
+
573
+ ! > Error handling
574
+ type (error_t), allocatable , intent (out ) :: error
575
+
576
+ type (package_t) :: package
577
+ character (:), allocatable :: temp_file
578
+ integer :: unit
579
+
580
+ allocate (temp_file, source= get_temp_filename())
581
+
582
+ open (file= temp_file, newunit= unit)
583
+ write (unit, ' (a)' ) &
584
+ & ' name = "example"' , &
585
+ & ' [build]' , &
586
+ & ' auto-executables = "false"'
587
+ close (unit)
588
+
589
+ call get_package_data(package, temp_file, error)
590
+
591
+ end subroutine test_build_config_invalid_values
592
+
593
+
449
594
! > Libraries can be created from empty tables
450
595
subroutine test_library_empty (error )
451
596
use fpm_manifest_library
0 commit comments