Debian Codegraph @

test/fpm_test/test_toml.f90

raw
1 !> Define tests for the `fpm_toml` modules
2 module test_toml
3 use testsuite, only : new_unittest, unittest_t, error_t
4 use tomlf, only: toml_table, toml_load
5 use fpm_toml, only: read_package_file, toml_array, toml_key, toml_stat, &
6 get_value, set_value, get_list, new_table, add_table, add_array, len, &
7 toml_error, toml_serialize, check_keys, set_list, set_string, &
8 name_is_json
9 use tomlf_constants, only: tf_i8
10 use fpm_git, only: git_target_t, git_target_revision, git_target_branch, &
11 & git_target_tag
12 use fpm_dependency, only: dependency_node_t, destroy_dependency_node, dependency_tree_t, &
13 & new_dependency_node, new_dependency_tree, resize
14 use fpm_manifest_dependency, only: dependency_config_t, dependency_destroy
15 use fpm_manifest_install, only: install_config_t
16 use fpm_manifest_fortran, only: fortran_config_t
17 use fpm_manifest_library, only: library_config_t
18 use fpm_manifest_executable, only: executable_config_t
19 use fpm_manifest_preprocess, only: preprocess_config_t
20 use fpm_manifest_platform, only: platform_config_t
21 use fpm_manifest_metapackages, only: metapackage_config_t
22 use fpm_manifest_feature_collection, only: feature_collection_t
23 use fpm_manifest_profile, only: profile_config_t
24 use fpm_environment, only: OS_ALL, OS_LINUX, OS_MACOS
25 use fpm_versioning, only: new_version
26 use fpm_strings, only: string_t, operator(==), split
27 use fpm_model, only: fortran_config_t, package_t, FPM_SCOPE_LIB, FPM_UNIT_MODULE, fpm_model_t, &
28 & srcfile_t
29 use fpm_compiler, only: archiver_t, compiler_t, id_all, id_gcc
30 use fpm_error, only: fatal_error
31
32
33 implicit none
34 private
35
36 public :: collect_toml
37
38 character, parameter :: NL = new_line('a')
39
40 contains
41
42 !> Collect all exported unit tests
43 subroutine collect_toml(testsuite)
44
45 !> Collection of tests
46 type(unittest_t), allocatable, intent(out) :: testsuite(:)
47
48 testsuite = [ &
49 & new_unittest("valid-toml", test_valid_toml), &
50 & new_unittest("invalid-toml", test_invalid_toml, should_fail=.true.), &
51 & new_unittest("missing-file", test_missing_file, should_fail=.true.), &
52 & new_unittest("serialize-git-target", git_target_roundtrip), &
53 & new_unittest("serialize-git-invalid", git_target_invalid, should_fail=.true.), &
54 & new_unittest("serialize-dependency-config", dependency_config_roundtrip), &
55 & new_unittest("serialize-dependency-node", dependency_node_roundtrip), &
56 & new_unittest("serialize-dependency-invalid", dependency_node_invalid, should_fail=.true.), &
57 & new_unittest("serialize-dependency-invalid2", dependency_node_invalid_2, should_fail=.true.), &
58 & new_unittest("serialize-dependency-tree", dependency_tree_roundtrip), &
59 & new_unittest("serialize-dependency-tree-invalid", dependency_tree_invalid, should_fail=.true.), &
60 & new_unittest("serialize-dependency-tree-invalid2", dependency_tree_invalid2, should_fail=.true.), &
61 & new_unittest("serialize-install-config", install_config_roundtrip), &
62 & new_unittest("serialize-fortran-config", fortran_features_roundtrip), &
63 & new_unittest("serialize-library-config", library_config_roundtrip), &
64 & new_unittest("serialize-executable-config", executable_config_roundtrip), &
65 & new_unittest("serialize-preprocess-config", preprocess_config_roundtrip), &
66 & new_unittest("serialize-string-array", string_array_roundtrip), &
67 & new_unittest("serialize-fortran-features", fft_roundtrip), &
68 & new_unittest("serialize-fortran-invalid", fft_invalid, should_fail=.true.), &
69 & new_unittest("serialize-package", package_roundtrip), &
70 & new_unittest("serialize-package-invalid", package_invalid, should_fail=.true.), &
71 & new_unittest("serialize-srcfile-invalid", source_invalid, should_fail=.true.), &
72 & new_unittest("serialize-archiver", ar_roundtrip), &
73 & new_unittest("serialize-archiver-invalid", ar_invalid, should_fail=.true.), &
74 & new_unittest("serialize-compiler", compiler_roundtrip), &
75 & new_unittest("serialize-compiler-invalid", compiler_invalid, should_fail=.true.), &
76 & new_unittest("serialize-model", fpm_model_roundtrip), &
77 & new_unittest("serialize-model-invalid", fpm_model_invalid, should_fail=.true.), &
78 & new_unittest("serialize-metapackage-config", metapackage_config_roundtrip), &
79 & new_unittest("serialize-feature-collection", feature_collection_roundtrip), &
80 & new_unittest("serialize-profile-config", profile_config_roundtrip)]
81
82
83 end subroutine collect_toml
84
85
86 !> Try to read some unnecessary obscure and convoluted but not invalid package file
87 subroutine test_valid_toml(error)
88
89 !> Error handling
90 type(error_t), allocatable, intent(out) :: error
91
92 type(toml_table), allocatable :: table
93 character(len=*), parameter :: manifest = 'fpm-valid-toml.toml'
94 integer :: unit
95
96 open(file=manifest, newunit=unit)
97 write(unit, '(a)') &
98 & 'name = "example"', &
99 & '[dependencies.fpm]', &
100 & 'git = "https://github.com/fortran-lang/fpm"', &
101 & '[[executable]]', &
102 & 'name = "example-1" # comment', &
103 & 'source-dir = "prog"', &
104 & '[dependencies]', &
105 & 'toml-f.git = "[email protected]:toml-f/toml-f.git"', &
106 & '"toml..f" = { path = ".." }', &
107 & '[["executable"]]', &
108 & 'name = "example-2"', &
109 & 'source-dir = "prog"', &
110 & '[executable.dependencies]', &
111 & '[''library'']', &
112 & 'source-dir = """', &
113 & 'lib""" # comment'
114 close(unit)
115
116 call read_package_file(table, manifest, error)
117
118 open(file=manifest, newunit=unit)
119 close(unit, status='delete')
120
121 end subroutine test_valid_toml
122
123
124 !> Try to read an invalid TOML document
125 subroutine test_invalid_toml(error)
126
127 !> Error handling
128 type(error_t), allocatable, intent(out) :: error
129
130 type(toml_table), allocatable :: table
131 character(len=*), parameter :: manifest = 'fpm-invalid-toml.toml'
132 integer :: unit
133
134 open(file=manifest, newunit=unit)
135 write(unit, '(a)') &
136 & '# INVALID TOML DOC', &
137 & 'name = "example"', &
138 & 'dependencies.fpm.git = "https://github.com/fortran-lang/fpm"', &
139 & '[dependencies]', &
140 & 'toml-f.git = "[email protected]:toml-f/toml-f.git"', &
141 & '"toml..f" = { path = ".." }'
142 close(unit)
143
144 call read_package_file(table, manifest, error)
145
146 open(file=manifest, newunit=unit)
147 close(unit, status='delete')
148
149 end subroutine test_invalid_toml
150
151
152 !> Try to read configuration from a non-existing file
153 subroutine test_missing_file(error)
154
155 !> Error handling
156 type(error_t), allocatable, intent(out) :: error
157
158 type(toml_table), allocatable :: table
159
160 call read_package_file(table, 'low+chance+of+existing.toml', error)
161
162 end subroutine test_missing_file
163
164 !> Test git_target_t serialization
165 subroutine git_target_roundtrip(error)
166
167 !> Error handling
168 type(error_t), allocatable, intent(out) :: error
169
170 type(git_target_t) :: git
171
172 ! Revision type
173 git = git_target_revision(url="https://github.com/urbanjost/M_CLI2.git", &
174 sha1="7264878cdb1baff7323cc48596d829ccfe7751b8")
175 call git%test_serialization("revision git type",error)
176 if (allocated(error)) return
177
178 ! Branch type
179 git = git_target_branch(url="https://github.com/urbanjost/M_CLI2.git", &
180 branch="main")
181 call git%test_serialization("branch git type",error)
182 if (allocated(error)) return
183
184 ! Tag type
185 git = git_target_tag(url="https://github.com/urbanjost/M_CLI2.git", &
186 tag="1.0.0")
187 call git%test_serialization("target git type",error)
188 if (allocated(error)) return
189
190 ! Incomplete type
191 if (allocated(git%object)) deallocate(git%object)
192 call git%test_serialization("incomplete git type 1/2",error)
193 if (allocated(error)) return
194
195 ! Incomplete type
196 if (allocated(git%url)) deallocate(git%url)
197 call git%test_serialization("incomplete git type 2/2",error)
198 if (allocated(error)) return
199
200 end subroutine git_target_roundtrip
201
202
203 !> Test invalid git_target_t serialization
204 subroutine git_target_invalid(error)
205
206 !> Error handling
207 type(error_t), allocatable, intent(out) :: error
208
209 type(git_target_t) :: git
210 type(toml_table), allocatable :: table
211
212 character(*), parameter :: toml = 'descriptor = ""'//NL//& ! invalid descriptor ID
213 'url = "https://github.com/toml-f/toml-f"'//NL//&
214 'object = "54686e45993f3a9a1d05d5c7419f39e7d5a4eb3f"'
215
216
217 call string_to_toml(toml, table)
218
219 call git%load(table, error)
220
221 end subroutine git_target_invalid
222
223 !> Test git_target_t serialization
224 subroutine dependency_config_roundtrip(error)
225
226 !> Error handling
227 type(error_t), allocatable, intent(out) :: error
228
229 type(dependency_config_t) :: dep
230
231 call dependency_destroy(dep)
232
233 dep%name = "M_CLI2"
234 dep%path = "~/./some/dummy/path"
235 dep%namespace = "urbanjost"
236 allocate(dep%requested_version)
237 call new_version(dep%requested_version, "3.2.0",error); if (allocated(error)) return
238
239 allocate(dep%git)
240 dep%git = git_target_revision(url="https://github.com/urbanjost/M_CLI2.git", &
241 sha1="7264878cdb1baff7323cc48596d829ccfe7751b8")
242
243 ! Test full object
244 call dep%test_serialization("full object",error)
245 if (allocated(error)) return
246
247 ! Remove namespace
248 deallocate(dep%namespace)
249 call dep%test_serialization("no namespace",error)
250 if (allocated(error)) return
251
252 ! Remove git
253 deallocate(dep%git)
254 call dep%test_serialization("no git",error)
255 if (allocated(error)) return
256
257 ! Remove version
258 deallocate(dep%requested_version)
259 call dep%test_serialization("no requested_version",error)
260 if (allocated(error)) return
261
262 ! Remove name
263 deallocate(dep%name)
264 call dep%test_serialization("no name",error)
265 if (allocated(error)) return
266
267 ! Remove path
268 deallocate(dep%path)
269 call dep%test_serialization("no path",error)
270 if (allocated(error)) return
271
272 end subroutine dependency_config_roundtrip
273
274 !> Test dependency_node_t serialization
275 subroutine dependency_node_roundtrip(error)
276
277 !> Error handling
278 type(error_t), allocatable, intent(out) :: error
279
280 type(dependency_node_t) :: dep
281
282 call destroy_dependency_node(dep)
283
284 dep%name = "M_CLI2"
285 dep%path = "~/./some/dummy/path"
286 dep%proj_dir = "~/./"
287 dep%namespace = "urbanjost"
288 dep%revision = "7264878cdb1baff7323cc48596d829ccfe7751b8"
289 dep%cached = .true.
290 dep%done = .false.
291 dep%update = .true.
292 allocate(dep%requested_version)
293 call new_version(dep%requested_version, "3.2.0",error); if (allocated(error)) return
294 allocate(dep%version)
295 call new_version(dep%version, "4.53.2",error); if (allocated(error)) return
296
297 allocate(dep%git)
298 dep%git = git_target_revision(url="https://github.com/urbanjost/M_CLI2.git", &
299 sha1="7264878cdb1baff7323cc48596d829ccfe7751b8")
300
301 ! Test full object
302 call dep%test_serialization("full object",error)
303 if (allocated(error)) return
304
305 ! Remove namespace
306 deallocate(dep%namespace)
307 call dep%test_serialization("no namespace",error)
308 if (allocated(error)) return
309
310 ! Remove git
311 deallocate(dep%git)
312 call dep%test_serialization("no git",error)
313 if (allocated(error)) return
314
315 ! Remove version
316 deallocate(dep%requested_version)
317 call dep%test_serialization("no requested_version",error)
318 if (allocated(error)) return
319
320 ! Remove name
321 deallocate(dep%name)
322 call dep%test_serialization("no name",error)
323 if (allocated(error)) return
324
325 ! Remove path
326 deallocate(dep%path)
327 call dep%test_serialization("no path",error)
328 if (allocated(error)) return
329
330 ! Remove revision
331 deallocate(dep%revision)
332 call dep%test_serialization("no revision",error)
333 if (allocated(error)) return
334
335 ! Remove proj_dir
336 deallocate(dep%proj_dir)
337 call dep%test_serialization("no proj_dir",error)
338 if (allocated(error)) return
339
340 ! Remove version
341 deallocate(dep%version)
342 call dep%test_serialization("no version",error)
343 if (allocated(error)) return
344
345 end subroutine dependency_node_roundtrip
346
347 !> Test loading invalid dependency node
348 subroutine dependency_node_invalid(error)
349
350 !> Error handling
351 type(error_t), allocatable, intent(out) :: error
352
353 type(dependency_node_t) :: dep
354 type(toml_table), allocatable :: table
355
356 character(*), parameter :: toml = 'name = "jonquil" '//NL//&
357 & 'version = "h0.2.0"'//NL//& ! invalid version
358 & 'proj-dir = "build/dependencies/jonquil"'//NL//&
359 & 'revision = "05d30818bb12fb877226ce284b9a3a41b971a889"'//NL//&
360 & 'done = true'//NL//&
361 & 'update = false'//NL//&
362 & 'cached = true'
363
364 call string_to_toml(toml, table)
365
366 call dep%load(table, error)
367
368 end subroutine dependency_node_invalid
369
370 !> Test loading invalid dependency node
371 subroutine dependency_node_invalid_2(error)
372
373 !> Error handling
374 type(error_t), allocatable, intent(out) :: error
375
376 type(dependency_node_t) :: dep
377 type(toml_table), allocatable :: table
378
379 character(*), parameter :: toml = 'name = "jonquil" '//NL//&
380 & 'version = "0.2.0"'//NL//&
381 & 'proj-dir = "build/dependencies/jonquil"'//NL//&
382 & 'revision = "05d30818bb12fb877226ce284b9a3a41b971a889"'//NL//&
383 & 'done = 123'//NL//& ! not a boolean
384 & 'update = false'//NL//&
385 & 'cached = true'
386
387 call string_to_toml(toml, table)
388 call dep%load(table, error)
389
390 end subroutine dependency_node_invalid_2
391
392 !> Test dependency_tree_t serialization
393 subroutine dependency_tree_roundtrip(error)
394
395 !> Error handling
396 type(error_t), allocatable, intent(out) :: error
397
398 type(dependency_tree_t) :: deps
399 type(dependency_config_t) :: dep
400
401 integer, parameter :: ALLOCATED_DEPS = 5
402 character(36) :: msg
403 integer :: ii
404
405 ! Generate dummy tree with ndep=3 but 5 allocated dependencies
406 call new_dependency_tree(deps)
407 call resize(deps%dep, ALLOCATED_DEPS)
408 deps%ndep = 3
409 dep%name = "dep1"
410 dep%path = "fpm-tmp1-dir"
411 call new_dependency_node(deps%dep(1), dep, proj_dir=dep%path)
412 dep%name = "dep2"
413 dep%path = "fpm-tmp2-dir"
414 call new_dependency_node(deps%dep(2), dep, proj_dir=dep%path)
415 deps%dep(3)%name = "M_CLI2"
416 deps%dep(3)%path = "~/./some/dummy/path"
417 deps%dep(3)%proj_dir = "~/./"
418 deps%dep(3)%namespace = "urbanjost"
419 deps%dep(3)%revision = "7264878cdb1baff7323cc48596d829ccfe7751b8"
420 deps%dep(3)%cached = .true.
421 deps%dep(3)%done = .false.
422 deps%dep(3)%update = .true.
423 allocate(deps%dep(3)%requested_version)
424 call new_version(deps%dep(3)%requested_version, "3.2.0",error); if (allocated(error)) return
425 allocate(deps%dep(3)%version)
426 call new_version(deps%dep(3)%version, "4.53.2",error); if (allocated(error)) return
427 allocate(deps%dep(3)%git)
428 deps%dep(3)%git = git_target_revision(url="https://github.com/urbanjost/M_CLI2.git", &
429 sha1="7264878cdb1baff7323cc48596d829ccfe7751b8")
430
431 call deps%test_serialization("full dependency tree", error)
432 if (allocated(error)) return
433
434 ! Remove dependencies (including all them)
435 do ii = 1, ALLOCATED_DEPS
436 write(msg,1) ii
437 call resize(deps%dep, size(deps%dep) - 1)
438 call deps%test_serialization(trim(msg), error)
439 if (allocated(error)) return
440 end do
441
442 ! deallocate dependencies
443 deallocate(deps%dep)
444 call deps%test_serialization("unallocated deps(:)", error)
445 if (allocated(error)) return
446
447 ! Remove deps dir
448 deallocate(deps%dep_dir)
449 call deps%test_serialization("no deps dir", error)
450 if (allocated(error)) return
451
452 1 format('removed ',i0,' dependencies')
453
454 end subroutine dependency_tree_roundtrip
455
456 !> Test invalid dependency tree loading
457 subroutine dependency_tree_invalid(error)
458
459 !> Error handling
460 type(error_t), allocatable, intent(out) :: error
461
462 type(toml_table), allocatable :: table
463 type(dependency_tree_t) :: dep
464
465 character(len=*), parameter :: toml = &
466 & 'unit = 6 '//NL//&
467 & 'verbosity = true'//NL//& ! not a number
468 & 'dep-dir = "build/dependencies"'//NL//&
469 & 'ndep = 3'//NL//& ! consistency is not checked:
470 & '[dependencies]'//NL//&
471 & '[dependencies.dep1]'//NL//&
472 & 'name = "dep1"'//NL//&
473 & 'path = "fpm-tmp1-dir"'//NL//&
474 & 'proj-dir = "fpm-tmp1-dir"'//NL//&
475 & 'done = false'//NL//&
476 & 'update = false'//NL//&
477 & 'cached = false'
478
479 call string_to_toml(toml, table)
480 call dep%load(table, error)
481
482 end subroutine dependency_tree_invalid
483
484 !> Test invalid dependency tree loading
485 subroutine dependency_tree_invalid2(error)
486
487 !> Error handling
488 type(error_t), allocatable, intent(out) :: error
489
490 type(toml_table), allocatable :: table
491 type(dependency_tree_t) :: dep
492
493 character(len=*), parameter :: toml = &
494 & 'unit = "" '//NL//& ! not provided
495 & 'verbosity = 1'//NL//&
496 & 'dep-dir = "build/dependencies"'//NL//&
497 & 'ndep = 3'//NL//& ! consistency is not checked:
498 & '[dependencies.M_CLI2]'//NL//&
499 & 'name = "M_CLI2"'//NL//&
500 & 'path = "~/./some/dummy/path"'//NL//&
501 & 'namespace = "urbanjost"'//NL//&
502 & 'requested_version = "3.2.0"'//NL//&
503 & 'version = "4.53.2"'//NL//&
504 & 'proj-dir = "~/./"'//NL//&
505 & 'revision = "7264878cdb1baff7323cc48596d829ccfe7751b8"'//NL//&
506 & 'done = false'//NL//&
507 & 'update = true'//NL//&
508 & 'cached = true'//NL//&
509 & '[dependencies.M_CLI2.git]'//NL//&
510 & 'descriptor = "revision"'//NL//&
511 & 'url = "https://github.com/urbanjost/M_CLI2.git"'//NL//&
512 & 'object = "7264878cdb1baff7323cc48596d829ccfe7751b8"'
513
514 call string_to_toml(toml, table)
515 call dep%load(table, error)
516
517 end subroutine dependency_tree_invalid2
518
519 !> Test serialization/deserialization of a string array
520 subroutine string_array_roundtrip(error)
521
522 !> Error handling
523 type(error_t), allocatable, intent(out) :: error
524
525 character(len=*), parameter :: lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing " &
526 & //"elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad " &
527 & //"minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " &
528 & //"consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " &
529 & //"dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt " &
530 & //"in culpa qui officia deserunt mollit anim id est laborum"
531
532 integer :: ii, nword
533 character(len=:), allocatable :: tokens(:)
534 type(string_t), allocatable :: list(:),copy(:)
535 type(toml_table) :: table
536 character(len=16) :: key
537
538 call split(lorem, tokens)
539 nword = size(tokens)
540
541 !> Convert to string_t array
542 allocate(list(nword))
543 do ii = 1, nword
544 list(ii) = string_t(trim(tokens(ii)))
545 end do
546
547 ! Test list with any length
548 do ii = nword, 1, -1
549
550 ! Shorten list
551 list = list(1:ii)
552
553 ! Set list to table
554 table = toml_table()
555
556 call set_list(table, key="lorem-ipsum", list=list, error=error)
557 if (allocated(error)) return
558
559 ! Load list from table
560 call get_list(table, key="lorem-ipsum", list=copy, error=error)
561 if (allocated(error)) return
562
563 if (.not.(list==copy)) then
564 call fatal_error(error,'string_array is not equal after TOML roundtrip')
565 return
566 end if
567
568 end do
569
570 ! Test empty list
571 deallocate(list)
572 allocate(list(0))
573 ! Set list to table
574 table = toml_table()
575
576 call set_list(table, key="lorem-ipsum", list=list, error=error)
577 if (allocated(error)) return
578
579 ! Load list from table
580 call get_list(table, key="lorem-ipsum", list=copy, error=error)
581 if (allocated(error)) return
582
583 if (.not.(list==copy)) then
584 call fatal_error(error,'empty string_array is not equal after TOML roundtrip')
585 return
586 end if
587
588 ! Test unallocated list
589 deallocate(list)
590 table = toml_table()
591
592 call set_list(table, key="lorem-ipsum", list=list, error=error)
593 if (allocated(error)) return
594
595 ! Load list from table
596 call get_list(table, key="lorem-ipsum", list=copy, error=error)
597 if (allocated(error)) return
598
599 if (.not.(list==copy)) then
600 call fatal_error(error,'deallocated string_array is not equal after TOML roundtrip')
601 return
602 end if
603
604 1 format('word_',i0)
605
606 end subroutine string_array_roundtrip
607
608 !> Test serialization/deserialization of a fortran-features structure
609 subroutine fft_roundtrip(error)
610
611 !> Error handling
612 type(error_t), allocatable, intent(out) :: error
613
614 type(fortran_config_t) :: fortran
615
616 !> Default object
617 call fortran%test_serialization('fortran_config_t: default object',error)
618 if (allocated(error)) return
619
620 !> Set form
621 fortran%source_form = "free"
622 call fortran%test_serialization('fortran_config_t: with form',error)
623 if (allocated(error)) return
624
625 end subroutine fft_roundtrip
626
627 !> Test deserialization of an invalid fortran-features structure
628 subroutine fft_invalid(error)
629
630 !> Error handling
631 type(error_t), allocatable, intent(out) :: error
632
633 type(fortran_config_t) :: fortran
634 type(toml_table), allocatable :: table
635
636 character(len=*), parameter :: toml = 'implicit-typing = false '//NL//&
637 & 'implicit-external = 0 '//NL//& ! not a boolean
638 & 'source-form = "free" '
639
640 call string_to_toml(toml, table)
641
642 !> Default object
643 call fortran%load(table,error)
644
645 end subroutine fft_invalid
646
647 !> Test serialization/deserialization of a package_t structure
648 subroutine package_roundtrip(error)
649
650 !> Error handling
651 type(error_t), allocatable, intent(out) :: error
652
653 type(package_t) :: pkg
654 integer :: ierr
655
656 !> Default object
657 call pkg%test_serialization('package_t: default object',error)
658 if (allocated(error)) return
659
660 !> Create a dummy package
661 pkg%name = "orderpack"
662 if (.not.allocated(pkg%version)) allocate(pkg%version)
663 call new_version(pkg%version, "0.1.0", error)
664 if (allocated(error)) return
665 pkg%enforce_module_names = .false.
666 pkg%module_prefix = string_t("")
667 pkg%features%source_form = "free"
668
669 if (allocated(pkg%sources)) deallocate(pkg%sources)
670 allocate(pkg%sources(4))
671
672 pkg%sources(1)%file_name = "build/dependencies/orderpack/src/M_valnth.f90"
673 pkg%sources(1)%digest = 2662523002405134329_tf_i8
674 pkg%sources(1)%unit_scope = FPM_SCOPE_LIB
675 pkg%sources(1)%unit_type = FPM_UNIT_MODULE
676 pkg%sources(1)%modules_provided = [string_t("m_valnth")]
677 deallocate(pkg%sources(1)%parent_modules, stat=ierr)
678 deallocate(pkg%sources(1)%modules_used, stat=ierr)
679 deallocate(pkg%sources(1)%include_dependencies, stat=ierr)
680 deallocate(pkg%sources(1)%link_libraries, stat=ierr)
681
682 pkg%sources(2)%file_name = "build/dependencies/orderpack/src/M_mrgrnk.f90"
683 pkg%sources(2)%digest = 7985690966656622651_tf_i8
684 pkg%sources(2)%unit_scope = FPM_SCOPE_LIB
685 pkg%sources(2)%unit_type = FPM_UNIT_MODULE
686 pkg%sources(2)%modules_provided = [string_t("m_mrgrnk")]
687 pkg%sources(2)%link_libraries = [string_t("netcdf"),string_t("hdf-5")]
688 deallocate(pkg%sources(2)%parent_modules, stat=ierr)
689 deallocate(pkg%sources(2)%modules_used, stat=ierr)
690 deallocate(pkg%sources(2)%include_dependencies, stat=ierr)
691 deallocate(pkg%sources(2)%link_libraries, stat=ierr)
692
693 pkg%sources(3)%file_name = "build/dependencies/orderpack/src/M_median.f90"
694 pkg%sources(3)%digest = 7985690966656622651_tf_i8
695 pkg%sources(3)%unit_scope = FPM_SCOPE_LIB
696 pkg%sources(3)%unit_type = FPM_UNIT_MODULE
697 pkg%sources(3)%modules_provided = [string_t("m_median")]
698 deallocate(pkg%sources(3)%parent_modules, stat=ierr)
699 deallocate(pkg%sources(3)%modules_used, stat=ierr)
700 deallocate(pkg%sources(3)%include_dependencies, stat=ierr)
701 deallocate(pkg%sources(3)%link_libraries, stat=ierr)
702
703 pkg%sources(4)%file_name = "build/dependencies/orderpack/src/M_unista.f90"
704 pkg%sources(4)%digest = -7512253540457404792_tf_i8
705 pkg%sources(4)%unit_scope = FPM_SCOPE_LIB
706 pkg%sources(4)%unit_type = FPM_UNIT_MODULE
707 pkg%sources(4)%modules_provided = [string_t("m_unista")]
708 pkg%sources(4)%modules_used = [string_t("m_uniinv")]
709 deallocate(pkg%sources(4)%parent_modules, stat=ierr)
710 deallocate(pkg%sources(4)%include_dependencies, stat=ierr)
711 deallocate(pkg%sources(4)%link_libraries, stat=ierr)
712
713 !> Package mock
714 call pkg%test_serialization('package_t: orderpack',error)
715 if (allocated(error)) return
716
717 !> Remove some entries
718 pkg%sources(1)%file_name = ""
719 pkg%sources(3)%digest = 0
720 pkg%sources = pkg%sources(1:3)
721 call pkg%test_serialization('package_t: orderpack (reduced)',error)
722 if (allocated(error)) return
723
724 !> Remove all sources
725 deallocate(pkg%sources,stat=ierr)
726 call pkg%test_serialization('package_t: no sources',error)
727 if (allocated(error)) return
728
729 end subroutine package_roundtrip
730
731 !> Test deserialization of an invalid package TOML file
732 subroutine package_invalid(error)
733
734 !> Error handling
735 type(error_t), allocatable, intent(out) :: error
736
737 character(len=*), parameter :: toml = &
738 & 'name = "toml-f" '//NL//&
739 & 'version = "0.8.0" '//NL//&
740 & 'module-naming = "prefix" '//NL//& ! this should be boolean
741 & 'module-prefix = "" '
742
743 type(package_t) :: pkg
744 type(toml_table), allocatable :: table
745
746 call string_to_toml(toml, table)
747
748 !> Default object
749 call pkg%load(table,error)
750
751 end subroutine package_invalid
752
753 !> Test deserialization of an invalid source file
754 subroutine source_invalid(error)
755
756 !> Error handling
757 type(error_t), allocatable, intent(out) :: error
758
759 character(len=*), parameter :: toml = &
760 & 'file-name = "build/dependencies/toml-f/src/tomlf.f90" '//NL//&
761 & 'digest = "abcde" '//NL//& ! not a number
762 & 'unit-scope = "FPM_SCOPE_MODULE" '//NL//&
763 & 'unit-type = "FPM_UNIT_MODULE" '//NL//&
764 & 'modules-provided = "tomlf" '//NL//&
765 & 'parent-modules = [ ] '//NL//&
766 & 'modules-used = [ "tomlf_build", "tomlf_datetime" ] '//NL//&
767 & 'include-dependencies = [ ] '//NL//&
768 & 'link-libraries = [ ] '
769
770 type(srcfile_t) :: src
771 type(toml_table), allocatable :: table
772
773 call string_to_toml(toml, table)
774
775 !> Default object
776 call src%load(table,error)
777
778 end subroutine source_invalid
779
780 !> Test serialization/deserialization of an archiver_t structure
781 subroutine ar_roundtrip(error)
782
783 !> Error handling
784 type(error_t), allocatable, intent(out) :: error
785
786 type(archiver_t) :: ar
787 integer :: ierr
788
789 !> Default object
790 call ar%test_serialization('archiver_t: default object',error)
791 if (allocated(error)) return
792
793 !> change a few items
794 ar%ar = "ar"
795 ar%echo = .true.
796 ar%use_response_file = .false.
797
798 call ar%test_serialization('archiver_t: ar',error)
799
800 end subroutine ar_roundtrip
801
802 !> Test deserialization of an invalid archiver_t structure
803 subroutine ar_invalid(error)
804
805 !> Error handling
806 type(error_t), allocatable, intent(out) :: error
807
808 character(len=*), parameter :: toml = &
809 & 'ar = "ar -rs " '//NL//&
810 & 'use-response-file = false '//NL//&
811 & 'echo = 123 '//NL//& ! not a boolean
812 & 'verbose = false '
813
814 type(archiver_t) :: ar
815 type(toml_table), allocatable :: table
816
817 call string_to_toml(toml, table)
818
819 !> Default object
820 call ar%load(table,error)
821
822 end subroutine ar_invalid
823
824 !> Test serialization/deserialization of a compiler_t structure
825 subroutine compiler_roundtrip(error)
826
827 !> Error handling
828 type(error_t), allocatable, intent(out) :: error
829
830 type(compiler_t) :: compiler
831
832 !> Default object
833 call compiler%test_serialization('compiler_t: default object',error)
834 if (allocated(error)) return
835
836 !> change a few items
837 compiler%id = id_gcc
838 compiler%fc = "gfortran -ffree-line-length-none -fdefault-real-8 -O3"
839 compiler%cc = ""
840 compiler%cxx = "g++ -O3 -std=c++11"
841 compiler%echo = .false.
842
843 call compiler%test_serialization('compiler_t: gcc',error)
844
845 end subroutine compiler_roundtrip
846
847 !> Test deserialization of an invalid compiler_t TOML structure
848 subroutine compiler_invalid(error)
849
850 !> Error handling
851 type(error_t), allocatable, intent(out) :: error
852
853 character(len=*), parameter :: toml = &
854 & 'id = "gfortran" '//NL//& ! not an integer identifier
855 & 'fc = "gfortran" '//NL//&
856 & 'cc = "gcc" '//NL//&
857 & 'cxx = "g++" '//NL//&
858 & 'echo = false '//NL//&
859 & 'verbose = false '
860
861 type(compiler_t) :: cc
862 type(toml_table), allocatable :: table
863
864 call string_to_toml(toml, table)
865
866 !> Default object
867 call cc%load(table,error)
868
869 end subroutine compiler_invalid
870
871 !> Get a shortened TOML representation of the fpm v0.8.1 model
872 subroutine fpm_081_table(table)
873
874 !> TOML representation of the fpm v0.8.1 model
875 type(toml_table), allocatable, intent(out) :: table
876
877 !> simplified TOML representation of the fpm v0.8.1 model
878 character(len=:), allocatable :: fpm
879
880 integer :: iunit
881
882 allocate(character(len=0) :: fpm)
883 fpm = fpm//NL//'package-name = "fpm"'
884 fpm = fpm//NL//'fortran-flags = " -Wall -Wextra -Wno-external-argument-mismatch -fPIC -fmax-errors=1 -g "'
885 fpm = fpm//NL//'c-flags = ""'
886 fpm = fpm//NL//'cxx-flags = ""'
887 fpm = fpm//NL//'link-flags = ""'
888 fpm = fpm//NL//'build-prefix = "build/gfortran"'
889 fpm = fpm//NL//'include-dirs = [ ]'
890 fpm = fpm//NL//'link-libraries = [ ]'
891 fpm = fpm//NL//'external-modules = [ ]'
892 fpm = fpm//NL//'include-tests = false'
893 fpm = fpm//NL//'module-naming = false'
894 fpm = fpm//NL//'module-prefix = ""'
895 fpm = fpm//NL//'[compiler]'
896 fpm = fpm//NL//'id = 1'
897 fpm = fpm//NL//'fc = "gfortran"'
898 fpm = fpm//NL//'cc = "gcc"'
899 fpm = fpm//NL//'cxx = "g++"'
900 fpm = fpm//NL//'echo = false'
901 fpm = fpm//NL//'verbose = false'
902 fpm = fpm//NL//'[archiver]'
903 fpm = fpm//NL//'ar = "ar -rs "'
904 fpm = fpm//NL//'use-response-file = false'
905 fpm = fpm//NL//'echo = false'
906 fpm = fpm//NL//'verbose = false'
907 fpm = fpm//NL//'[deps]'
908 fpm = fpm//NL//'unit = 6'
909 fpm = fpm//NL//'verbosity = 1'
910 fpm = fpm//NL//'dep-dir = "build/dependencies"'
911 fpm = fpm//NL//'cache = "build/cache.toml"'
912 fpm = fpm//NL//'ndep = 4'
913 fpm = fpm//NL//'[deps.dependencies]'
914 fpm = fpm//NL//'[deps.dependencies.fpm]'
915 fpm = fpm//NL//'name = "fpm"'
916 fpm = fpm//NL//'path = "."'
917 fpm = fpm//NL//'version = "0.8.0"'
918 fpm = fpm//NL//'proj-dir = "./."'
919 fpm = fpm//NL//'done = true'
920 fpm = fpm//NL//'update = false'
921 fpm = fpm//NL//'cached = false'
922 fpm = fpm//NL//'[deps.dependencies.toml-f]'
923 fpm = fpm//NL//'name = "toml-f"'
924 fpm = fpm//NL//'version = "0.4.0"'
925 fpm = fpm//NL//'proj-dir = "build/dependencies/toml-f"'
926 fpm = fpm//NL//'revision = "54686e45993f3a9a1d05d5c7419f39e7d5a4eb3f"'
927 fpm = fpm//NL//'done = true'
928 fpm = fpm//NL//'update = false'
929 fpm = fpm//NL//'cached = true'
930 fpm = fpm//NL//'[deps.dependencies.toml-f.git]'
931 fpm = fpm//NL//'descriptor = "revision"'
932 fpm = fpm//NL//'url = "https://github.com/toml-f/toml-f"'
933 fpm = fpm//NL//'object = "54686e45993f3a9a1d05d5c7419f39e7d5a4eb3f"'
934 fpm = fpm//NL//'[deps.dependencies.UNNAMED_DEPENDENCY_5]'
935 fpm = fpm//NL//'done = false'
936 fpm = fpm//NL//'update = false'
937 fpm = fpm//NL//'cached = false'
938 fpm = fpm//NL//'[packages]'
939 fpm = fpm//NL//'[packages.fpm]'
940 fpm = fpm//NL//'name = "fpm"'
941 fpm = fpm//NL//'version = "0.8.0"'
942 fpm = fpm//NL//'module-naming = false'
943 fpm = fpm//NL//'module-prefix = ""'
944 fpm = fpm//NL//'[packages.fpm.fortran]'
945 fpm = fpm//NL//'implicit-typing = false'
946 fpm = fpm//NL//'implicit-external = false'
947 fpm = fpm//NL//'source-form = "free"'
948 fpm = fpm//NL//'[packages.fpm.sources]'
949 fpm = fpm//NL//'[packages.fpm.sources.src_1]'
950 fpm = fpm//NL//'file-name = "././src/fpm.f90"'
951 fpm = fpm//NL//'digest = 4322290725857190613'
952 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
953 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
954 fpm = fpm//NL//'modules-provided = "fpm"'
955 fpm = fpm//NL//'parent-modules = [ ]'
956 fpm = fpm//NL//'modules-used = [ "fpm_strings", "fpm_backend", "fpm_compiler", "fpm_error" ]'
957 fpm = fpm//NL//'include-dependencies = [ ]'
958 fpm = fpm//NL//'link-libraries = [ ]'
959 fpm = fpm//NL//'[packages.fpm.sources.src_2]'
960 fpm = fpm//NL//'file-name = "././src/fpm_backend.F90"'
961 fpm = fpm//NL//'digest = -3210121688944515946'
962 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
963 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
964 fpm = fpm//NL//'modules-provided = "fpm_backend"'
965 fpm = fpm//NL//'parent-modules = [ ]'
966 fpm = fpm//NL//'modules-used = [ "fpm_error", "fpm_filesystem", "fpm_backend_output" ]'
967 fpm = fpm//NL//'include-dependencies = [ ]'
968 fpm = fpm//NL//'link-libraries = [ ]'
969 fpm = fpm//NL//'[packages.fpm.sources.src_3]'
970 fpm = fpm//NL//'file-name = "././src/fpm_environment.f90"'
971 fpm = fpm//NL//'digest = 2235607720245152632'
972 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
973 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
974 fpm = fpm//NL//'modules-provided = "fpm_environment"'
975 fpm = fpm//NL//'parent-modules = [ ]'
976 fpm = fpm//NL//'modules-used = "fpm_error"'
977 fpm = fpm//NL//'include-dependencies = [ ]'
978 fpm = fpm//NL//'link-libraries = [ ]'
979 fpm = fpm//NL//'[packages.fpm.sources.src_4]'
980 fpm = fpm//NL//'file-name = "././src/fpm_model.f90"'
981 fpm = fpm//NL//'digest = -6774177234665080583'
982 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
983 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
984 fpm = fpm//NL//'modules-provided = "fpm_model"'
985 fpm = fpm//NL//'parent-modules = [ ]'
986 fpm = fpm//NL//'modules-used = [ "fpm_compiler", "fpm_dependency" ]'
987 fpm = fpm//NL//'include-dependencies = [ ]'
988 fpm = fpm//NL//'link-libraries = [ ]'
989 fpm = fpm//NL//'[packages.fpm.sources.src_5]'
990 fpm = fpm//NL//'file-name = "././src/filesystem_utilities.c"'
991 fpm = fpm//NL//'digest = 4957633104775755438'
992 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
993 fpm = fpm//NL//'unit-type = "FPM_UNIT_CSOURCE"'
994 fpm = fpm//NL//'modules-provided = [ ]'
995 fpm = fpm//NL//'parent-modules = [ ]'
996 fpm = fpm//NL//'modules-used = [ ]'
997 fpm = fpm//NL//'include-dependencies = [ ]'
998 fpm = fpm//NL//'link-libraries = [ ]'
999 fpm = fpm//NL//'[packages.fpm.sources.src_59]'
1000 fpm = fpm//NL//'file-name = "test/new_test/new_test.f90"'
1001 fpm = fpm//NL//'exe-name = "new-test"'
1002 fpm = fpm//NL//'digest = 4683353150944180202'
1003 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_TEST"'
1004 fpm = fpm//NL//'unit-type = "FPM_UNIT_PROGRAM"'
1005 fpm = fpm//NL//'modules-provided = [ ]'
1006 fpm = fpm//NL//'parent-modules = [ ]'
1007 fpm = fpm//NL//'modules-used = [ "fpm_filesystem", "fpm_strings", "fpm_environment" ]'
1008 fpm = fpm//NL//'include-dependencies = [ ]'
1009 fpm = fpm//NL//'link-libraries = [ ]'
1010 fpm = fpm//NL//'[packages.toml-f]'
1011 fpm = fpm//NL//'name = "toml-f"'
1012 fpm = fpm//NL//'version = "0.8.0"'
1013 fpm = fpm//NL//'module-naming = false'
1014 fpm = fpm//NL//'module-prefix = ""'
1015 fpm = fpm//NL//'[packages.toml-f.fortran]'
1016 fpm = fpm//NL//'implicit-typing = false'
1017 fpm = fpm//NL//'implicit-external = false'
1018 fpm = fpm//NL//'source-form = "free"'
1019 fpm = fpm//NL//'[packages.toml-f.sources]'
1020 fpm = fpm//NL//'[packages.toml-f.sources.src_1]'
1021 fpm = fpm//NL//'file-name = "build/dependencies/toml-f/src/tomlf.f90"'
1022 fpm = fpm//NL//'digest = -8299830903248890534'
1023 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
1024 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
1025 fpm = fpm//NL//'modules-provided = "tomlf"'
1026 fpm = fpm//NL//'parent-modules = [ ]'
1027 fpm = fpm//NL//'modules-used = [ "tomlf_build", "tomlf_datetime" ]'
1028 fpm = fpm//NL//'include-dependencies = [ ]'
1029 fpm = fpm//NL//'link-libraries = [ ]'
1030 fpm = fpm//NL//'[packages.toml-f.sources.src_2]'
1031 fpm = fpm//NL//'file-name = "build/dependencies/toml-f/src/tomlf/constants.f90"'
1032 fpm = fpm//NL//'digest = 7170350792708576173'
1033 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
1034 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
1035 fpm = fpm//NL//'modules-provided = "tomlf_constants"'
1036 fpm = fpm//NL//'parent-modules = [ ]'
1037 fpm = fpm//NL//'modules-used = [ ]'
1038 fpm = fpm//NL//'include-dependencies = [ ]'
1039 fpm = fpm//NL//'link-libraries = [ ]'
1040 fpm = fpm//NL//'[packages.M_CLI2]'
1041 fpm = fpm//NL//'name = "M_CLI2"'
1042 fpm = fpm//NL//'version = "0.8.0"'
1043 fpm = fpm//NL//'module-naming = false'
1044 fpm = fpm//NL//'module-prefix = ""'
1045 fpm = fpm//NL//'[packages.M_CLI2.fortran]'
1046 fpm = fpm//NL//'implicit-typing = false'
1047 fpm = fpm//NL//'implicit-external = false'
1048 fpm = fpm//NL//'source-form = "free"'
1049 fpm = fpm//NL//'[packages.M_CLI2.sources]'
1050 fpm = fpm//NL//'[packages.M_CLI2.sources.src_1]'
1051 fpm = fpm//NL//'file-name = "build/dependencies/M_CLI2/src/M_CLI2.F90"'
1052 fpm = fpm//NL//'digest = -6169834068995303802'
1053 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
1054 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
1055 fpm = fpm//NL//'modules-provided = "m_cli2"'
1056 fpm = fpm//NL//'parent-modules = [ ]'
1057 fpm = fpm//NL//'modules-used = [ ]'
1058 fpm = fpm//NL//'include-dependencies = [ ]'
1059 fpm = fpm//NL//'link-libraries = [ ]'
1060 fpm = fpm//NL//'[packages.jonquil]'
1061 fpm = fpm//NL//'name = "jonquil"'
1062 fpm = fpm//NL//'version = "0.8.0"'
1063 fpm = fpm//NL//'module-naming = false'
1064 fpm = fpm//NL//'module-prefix = ""'
1065 fpm = fpm//NL//'[packages.jonquil.fortran]'
1066 fpm = fpm//NL//'implicit-typing = false'
1067 fpm = fpm//NL//'implicit-external = false'
1068 fpm = fpm//NL//'source-form = "free"'
1069 fpm = fpm//NL//'[packages.jonquil.sources]'
1070 fpm = fpm//NL//'[packages.jonquil.sources.src_1]'
1071 fpm = fpm//NL//'file-name = "build/dependencies/jonquil/src/jonquil.f90"'
1072 fpm = fpm//NL//'digest = 5552073973512025871'
1073 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
1074 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
1075 fpm = fpm//NL//'modules-provided = "jonquil"'
1076 fpm = fpm//NL//'parent-modules = [ ]'
1077 fpm = fpm//NL//'modules-used = [ "tomlf", "tomlf_type", "jonquil_ser" ]'
1078 fpm = fpm//NL//'include-dependencies = [ ]'
1079 fpm = fpm//NL//'link-libraries = [ ]'
1080 fpm = fpm//NL//'[packages.jonquil.sources.src_2]'
1081 fpm = fpm//NL//'file-name = "build/dependencies/jonquil/src/jonquil/version.f90"'
1082 fpm = fpm//NL//'digest = -2934903401983932826'
1083 fpm = fpm//NL//'unit-scope = "FPM_SCOPE_LIB"'
1084 fpm = fpm//NL//'unit-type = "FPM_UNIT_MODULE"'
1085 fpm = fpm//NL//'modules-provided = "jonquil_version"'
1086 fpm = fpm//NL//'parent-modules = [ ]'
1087 fpm = fpm//NL//'modules-used = [ ]'
1088 fpm = fpm//NL//'include-dependencies = [ ]'
1089 fpm = fpm//NL//'link-libraries = [ ]'
1090
1091 call string_to_toml(fpm, table)
1092
1093 end subroutine fpm_081_table
1094
1095 !> Convert a character string to a TOML table
1096 subroutine string_to_toml(string, table)
1097
1098 !> The input TOML as a string
1099 character(*), intent(in) :: string
1100
1101 !> The TOML table
1102 type(toml_table), allocatable, intent(out) :: table
1103
1104 integer :: iunit
1105
1106 ! Write
1107 open(newunit=iunit,form='formatted',status='scratch',action='readwrite',recl=1073741824)
1108
1109 !> Dump to scratch file
1110 write(iunit,*) string
1111
1112 !> Load from scratch file
1113 rewind(iunit)
1114 call toml_load(table, iunit)
1115
1116 close(iunit)
1117
1118 end subroutine string_to_toml
1119
1120 subroutine fpm_model_roundtrip(error)
1121
1122 !> Error handling
1123 type(error_t), allocatable, intent(out) :: error
1124 type(fpm_model_t) :: model
1125 type(toml_table), allocatable :: table
1126
1127 call model%test_serialization('fpm_model_t: default object', error)
1128 if (allocated(error)) return
1129
1130 !> Now init form fpm 0.8.1 table
1131 call fpm_081_table(table)
1132
1133 call model%load(table, error)
1134 if (allocated(error)) then
1135 call fatal_error(error, 'fpm_model_t: cannot load model from fpm v0.8.1 TOML')
1136 return
1137 end if
1138
1139 call model%test_serialization('fpm_model_t: fpm v0.8.1 model test', error)
1140
1141 end subroutine fpm_model_roundtrip
1142
1143
1144 subroutine fpm_model_invalid(error)
1145
1146 !> Error handling
1147 type(error_t), allocatable, intent(out) :: error
1148
1149 type(fpm_model_t) :: model
1150 type(toml_table), allocatable :: table
1151 character(len=:), allocatable :: fpm
1152
1153 allocate(character(len=0) :: fpm)
1154 fpm = fpm//NL//'package-name = "fpm"'
1155 fpm = fpm//NL//'fortran-flags = " -Wall -Wextra -Wno-external-argument-mismatch -fPIC -fmax-errors=1 -g "'
1156 fpm = fpm//NL//'c-flags = ""'
1157 fpm = fpm//NL//'cxx-flags = ""'
1158 fpm = fpm//NL//'link-flags = ""'
1159 fpm = fpm//NL//'build-prefix = "build/gfortran"'
1160 fpm = fpm//NL//'include-dirs = [ ]'
1161 fpm = fpm//NL//'link-libraries = [ ]'
1162 fpm = fpm//NL//'external-modules = "" '
1163 fpm = fpm//NL//'include-tests = "my_test"' ! not a boolean
1164 fpm = fpm//NL//'module-naming = false'
1165 fpm = fpm//NL//'module-prefix = ""'
1166
1167 call string_to_toml(fpm, table)
1168 call model%load(table,error)
1169
1170 end subroutine fpm_model_invalid
1171
1172 subroutine install_config_roundtrip(error)
1173
1174 !> Error handling
1175 type(error_t), allocatable, intent(out) :: error
1176
1177 type(install_config_t) :: install
1178
1179 integer :: loop
1180
1181 do loop=1,2
1182
1183 install % library = mod(loop,2)==0
1184
1185 ! Test full object
1186 call install%test_serialization('install_config_roundtrip',error)
1187 if (allocated(error)) return
1188
1189 end do
1190
1191 end subroutine install_config_roundtrip
1192
1193 subroutine fortran_features_roundtrip(error)
1194
1195 !> Error handling
1196 type(error_t), allocatable, intent(out) :: error
1197
1198 type(fortran_config_t) :: fortran
1199
1200 fortran%implicit_external = .true.
1201 fortran%implicit_typing = .false.
1202 fortran%source_form = 'free'
1203
1204 call fortran%test_serialization('fortran_features_roundtrip',error)
1205 if (allocated(error)) return
1206
1207 deallocate(fortran%source_form)
1208 call fortran%test_serialization('fortran_features_roundtrip 2',error)
1209
1210 end subroutine fortran_features_roundtrip
1211
1212 subroutine library_config_roundtrip(error)
1213
1214 !> Error handling
1215 type(error_t), allocatable, intent(out) :: error
1216
1217 type(library_config_t) :: lib
1218
1219 lib%source_dir = 'lib'
1220 lib%include_dir = [string_t('a'),string_t('b')]
1221
1222 call lib%test_serialization('library_config: 1',error)
1223 if (allocated(error)) return
1224
1225 lib%build_script = 'install.sh'
1226
1227 call lib%test_serialization('library_config: 2',error)
1228 if (allocated(error)) return
1229
1230 deallocate(lib%include_dir)
1231 call lib%test_serialization('library_config: 3',error)
1232
1233 end subroutine library_config_roundtrip
1234
1235
1236 subroutine executable_config_roundtrip(error)
1237
1238 !> Error handling
1239 type(error_t), allocatable, intent(out) :: error
1240
1241 type(executable_config_t) :: exe
1242 type(dependency_config_t) :: dep
1243
1244 exe%name = "my_executable"
1245 exe%source_dir = 'app'
1246
1247 call exe%test_serialization('executable_config: 1',error)
1248 if (allocated(error)) return
1249
1250 exe%main = 'main_program.F90'
1251
1252 call exe%test_serialization('executable_config: 2',error)
1253 if (allocated(error)) return
1254
1255 exe%link = [string_t('netcdf'),string_t('hdf5')]
1256 call exe%test_serialization('executable_config: 3',error)
1257
1258 call dependency_destroy(dep)
1259
1260 dep%name = "M_CLI2"
1261 dep%path = "~/./some/dummy/path"
1262 dep%namespace = "urbanjost"
1263 allocate(dep%requested_version)
1264 call new_version(dep%requested_version, "3.2.0",error); if (allocated(error)) return
1265
1266 allocate(dep%git)
1267 dep%git = git_target_revision(url="https://github.com/urbanjost/M_CLI2.git", &
1268 sha1="7264878cdb1baff7323cc48596d829ccfe7751b8")
1269
1270 allocate(exe%dependency(1),source=dep)
1271 call exe%test_serialization('executable_config: 4',error)
1272
1273 end subroutine executable_config_roundtrip
1274
1275
1276 subroutine preprocess_config_roundtrip(error)
1277
1278 !> Error handling
1279 type(error_t), allocatable, intent(out) :: error
1280
1281 type(preprocess_config_t) :: prep
1282
1283 prep%name = "preprocessor config"
1284 prep%macros = [string_t('Whatever'),string_t('FPM_BOOTSTRAP')]
1285
1286 call prep%test_serialization('preprocess_config', error)
1287
1288 end subroutine preprocess_config_roundtrip
1289
1290 !> Test a metapackage configuration
1291 subroutine metapackage_config_roundtrip(error)
1292
1293 !> Error handling
1294 type(error_t), allocatable, intent(out) :: error
1295
1296 type(metapackage_config_t) :: meta
1297
1298 meta%mpi%on = .true.
1299 meta%mpi%version = "MPICH"
1300 meta%minpack%on = .true.
1301 meta%blas%on = .false.
1302
1303 call meta%test_serialization('metapackage_config_t', error)
1304
1305 end subroutine metapackage_config_roundtrip
1306
1307 subroutine feature_collection_roundtrip(error)
1308 type(error_t), allocatable, intent(out) :: error
1309 type(feature_collection_t) :: fc
1310
1311 ! Base feature (applies everywhere)
1312 fc%base%name = "my_blas"
1313 fc%base%flags = "-O2"
1314 fc%base%link_time_flags = "-lblas -llapack"
1315
1316 ! Two platform/compiler-specific variants
1317 if (allocated(fc%variants)) deallocate(fc%variants)
1318 allocate(fc%variants(2))
1319
1320 ! Variant 1: GCC on Linux → OpenBLAS
1321 fc%variants(1)%name = "my_blas"
1322 fc%variants(1)%platform = platform_config_t("gfortran",OS_LINUX)
1323 fc%variants(1)%link_time_flags = "-lopenblas"
1324
1325 ! Variant 2: any compiler on macOS → Accelerate framework
1326 fc%variants(2)%name = "my_blas"
1327 fc%variants(2)%platform = platform_config_t("all",OS_MACOS)
1328 fc%variants(2)%link_time_flags = "-framework Accelerate"
1329
1330 ! Round-trip via the generic serialization tester
1331 call fc%test_serialization('feature_collection: base + 2 variants', error)
1332
1333 end subroutine feature_collection_roundtrip
1334
1335 subroutine profile_config_roundtrip(error)
1336 type(error_t), allocatable, intent(out) :: error
1337 type(profile_config_t) :: profile
1338
1339 ! Set up a profile with features
1340 profile%name = "development"
1341
1342 ! Allocate and populate features array
1343 allocate(profile%features(3))
1344 profile%features(1)%s = "debug"
1345 profile%features(2)%s = "testing"
1346 profile%features(3)%s = "verbose"
1347
1348 ! Round-trip via the generic serialization tester
1349 call profile%test_serialization('profile_config_t: development profile', error)
1350
1351 end subroutine profile_config_roundtrip
1352
1353
1354 end module test_toml