8000 Improve error handling for invalid `git` dependencies by minhqdao · Pull Request #797 · fortran-lang/fpm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve error handling for invalid git dependencies #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/fpm/manifest/dependency.f90
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ subroutine check(table, error)
!> Error handling
type(error_t), allocatable, intent(out) :: error

character(len=:), allocatable :: name
character(len=:), allocatable :: name, url
type(toml_key), allocatable :: list(:)
logical :: url_present, git_target_present, has_path
integer :: ikey
Expand All @@ -148,13 +148,25 @@ subroutine check(table, error)
call syntax_error(error, "Key "//list(ikey)%key//" is not allowed in dependency "//name)
exit

case("git", "path")
case("git")
if (url_present) then
call syntax_error(error, "Dependency "//name//" cannot have both git and path entries")
exit
end if
call get_value(table, "git", url)
if (.not.allocated(url)) then
call syntax_error(error, "Dependency "//name//" has invalid git source")
exit
end if
url_present = .true.

case("path")
if (url_present) then
call syntax_error(error, "Dependency "//name//" cannot have both git and path entries")
exit
end if
url_present = .true.
has_path = list(ikey)%key == 'path'
has_path = .true.

case("branch", "rev", "tag")
if (git_target_present) then
Expand Down
24 changes: 24 additions & 0 deletions test/fpm_test/test_manifest.f90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ subroutine collect_manifest(testsuite)
& new_unittest("dependency-gitpath", test_dependency_gitpath, should_fail=.true.), &
& new_unittest("dependency-nourl", test_dependency_nourl, should_fail=.true.), &
& new_unittest("dependency-gitconflict", test_dependency_gitconflict, should_fail=.true.), &
& new_unittest("dependency-invalid-git", test_dependency_invalid_git, should_fail=.true.), &
& new_unittest("dependency-wrongkey", test_dependency_wrongkey, should_fail=.true.), &
& new_unittest("dependencies-empty", test_dependencies_empty), &
& new_unittest("dependencies-typeerror", test_dependencies_typeerror, should_fail=.true.), &
Expand Down Expand Up @@ -350,6 +351,29 @@ subroutine test_dependency_gitconflict(error)
end subroutine test_dependency_gitconflict


!> Try to create a git dependency with invalid source format
subroutine test_dependency_invalid_git(error)
use fpm_manifest_dependency
use fpm_toml, only : new_table, add_table, toml_table, set_value

!> Error handling
type(error_t), allocatable, intent(out) :: error

type(toml_table) :: table
type(toml_table), pointer :: child
integer :: stat
type(dependency_config_t) :: dependency

call new_table(table)
table%key = 'example'
call add_table(table, 'git', child)
call set_value(child, 'path', '../../package')

call new_dependency(dependency, table, error=error)

end subroutine test_dependency_invalid_git


!> Try to create a dependency with conflicting entries
subroutine test_dependency_wrongkey(error)
use fpm_manifest_dependency
Expand Down
0