diff --git a/src/fpm/manifest/dependency.f90 b/src/fpm/manifest/dependency.f90 index b1edf983bd..00f136472f 100644 --- a/src/fpm/manifest/dependency.f90 +++ b/src/fpm/manifest/dependency.f90 @@ -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 @@ -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 diff --git a/test/fpm_test/test_manifest.f90 b/test/fpm_test/test_manifest.f90 index 6687cbdf08..e608e79fcf 100644 --- a/test/fpm_test/test_manifest.f90 +++ b/test/fpm_test/test_manifest.f90 @@ -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.), & @@ -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