Skip to content

Commit a6c4483

Browse files
committed
test: compile_commands serialization
1 parent 05eb31b commit a6c4483

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

test/fpm_test/test_backend.f90

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module test_backend
77
FPM_TARGET_OBJECT, FPM_TARGET_ARCHIVE, &
88
add_target, add_dependency
99
use fpm_backend, only: sort_target, schedule_targets
10+
use fpm_compile_commands, only: compile_command_t, compile_command_table_t
1011
implicit none
1112
private
1213

@@ -26,7 +27,8 @@ subroutine collect_backend(testsuite)
2627
& new_unittest("target-sort-skip-all", test_target_sort_skip_all), &
2728
& new_unittest("target-sort-rebuild-all", test_target_sort_rebuild_all), &
2829
& new_unittest("schedule-targets", test_schedule_targets), &
29-
& new_unittest("schedule-targets-empty", test_schedule_empty) &
30+
& new_unittest("schedule-targets-empty", test_schedule_empty), &
31+
& new_unittest("serialize-compile-commands", compile_commands_roundtrip) &
3032
]
3133

3234
end subroutine collect_backend
@@ -354,5 +356,38 @@ function new_test_package() result(targets)
354356

355357
end function new_test_package
356358

359+
subroutine compile_commands_roundtrip(error)
360+
361+
!> Error handling
362+
type(error_t), allocatable, intent(out) :: error
363+
364+
type(compile_command_t) :: cmd
365+
type(compile_command_table_t) :: cc
366+
integer :: i
367+
368+
call cmd%test_serialization('compile_command: empty', error)
369+
if (allocated(error)) return
370+
371+
cmd = compile_command_t(directory = string_t("/test/dir"), &
372+
arguments = [string_t("gfortran"), &
373+
string_t("-c"), string_t("main.f90"), &
374+
string_t("-o"), string_t("main.o")], &
375+
file = string_t("main.f90"))
376+
377+
call cmd%test_serialization('compile_command: non-empty', error)
378+
if (allocated(error)) return
379+
380+
call cc%test_serialization('compile_command_table: empty', error)
381+
if (allocated(error)) return
382+
383+
do i=1,10
384+
call cc%register(cmd,error)
385+
if (allocated(error)) return
386+
end do
387+
388+
call cc%test_serialization('compile_command_table: non-empty', error)
389+
if (allocated(error)) return
390+
391+
end subroutine compile_commands_roundtrip
357392

358393
end module test_backend

0 commit comments

Comments
 (0)