Skip to content

Commit de769ad

Browse files
committed
compile_commands registration tests
1 parent 18d0ce3 commit de769ad

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

test/fpm_test/test_backend.f90

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ subroutine collect_backend(testsuite)
2929
& new_unittest("target-sort-rebuild-all", test_target_sort_rebuild_all), &
3030
& new_unittest("schedule-targets", test_schedule_targets), &
3131
& new_unittest("schedule-targets-empty", test_schedule_empty), &
32-
& new_unittest("serialize-compile-commands", compile_commands_roundtrip) &
32+
& new_unittest("serialize-compile-commands", compile_commands_roundtrip), &
33+
& new_unittest("compile-commands-write", compile_commands_register_from_cmd), &
34+
& new_unittest("compile-commands-register-string", compile_commands_register_from_string) &
3335
]
3436

3537
end subroutine collect_backend
@@ -391,4 +393,81 @@ subroutine compile_commands_roundtrip(error)
391393

392394
end subroutine compile_commands_roundtrip
393395

396+
subroutine compile_commands_register_from_cmd(error)
397+
type(error_t), allocatable, intent(out) :: error
398+
399+
type(compile_command_table_t) :: table
400+
type(compile_command_t) :: cmd
401+
integer :: i
402+
403+
cmd = compile_command_t(directory = string_t("/src"), &
404+
arguments = [string_t("gfortran"), &
405+
string_t("-c"), string_t("example.f90"), &
406+
string_t("-o"), string_t("example.o")], &
407+
file = string_t("example.f90"))
408+
409+
call table%register(cmd, error)
410+
if (allocated(error)) return
411+
412+
if (.not.allocated(table%command)) then
413+
call test_failed(error, "Command table not allocated after registration")
414+
return
415+
endif
416+
417+
if (size(table%command) /= 1) then
418+
call test_failed(error, "Expected one registered command")
419+
return
420+
endif
421+
422+
if (table%command(1)%file%s /= "example.f90") then
423+
call test_failed(error, "Registered file mismatch")
424+
return
425+
endif
426+
427+
end subroutine compile_commands_register_from_cmd
428+
429+
subroutine compile_commands_register_from_string(error)
430+
type(error_t), allocatable, intent(out) :: error
431+
432+
type(compile_command_table_t) :: table
433+
character(len=*), parameter :: cmd_line = "gfortran -c example.f90 -o example.o"
434+
435+
! Register a raw command line string
436+
call table%register(cmd_line, error)
437+
if (allocated(error)) return
438+
439+
if (.not.allocated(table%command)) then
440+
call test_failed(error, "Command table not allocated after string registration")
441+
return
442+
end if
443+
444+
if (size(table%command) /= 1) then
445+
call test_failed(error, "Expected one registered command after string registration")
446+
return
447+
end if
448+
449+
if (.not.allocated(table%command(1)%arguments)) then
450+
call test_failed(error, "Command arguments not allocated")
451+
return
452+
end if
453+
454+
if (size(table%command(1)%arguments) /= 5) then
455+
call test_failed(error, "Wrong number of parsed arguments, should be 5")
456+
return
457+
end if
458+
459+
if (table%command(1)%arguments(1)%s /= "gfortran") then
460+
call test_failed(error, "Expected 'gfortran' as first argument")
461+
return
462+
end if
463+
464+
if (table%command(1)%arguments(3)%s /= "example.f90") then
465+
call test_failed(error, "Expected 'example.f90' as third argument")
466+
return
467+
end if
468+
469+
end subroutine compile_commands_register_from_string
470+
471+
472+
394473
end module test_backend

0 commit comments

Comments
 (0)