aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Ehlert <28669218+awvwgk@users.noreply.github.com>2020-12-10 17:32:01 +0100
committerGitHub <noreply@github.com>2020-12-10 17:32:01 +0100
commit3e2e6caff72cd07987efcfcf863188e0f56d09f5 (patch)
treec7db3facd2f2327da98b8d6975dfc4c4f74cd5c3
parent575d1e4a5813d1c08fde4f44a95c1acf7655f1cd (diff)
downloadfpm-3e2e6caff72cd07987efcfcf863188e0f56d09f5.tar.gz
fpm-3e2e6caff72cd07987efcfcf863188e0f56d09f5.zip
Implement check for duplicated program names (#286)
- check within an executable/test array for duplicate programs - also check that the program name is not empty or contains ascii control chars
-rw-r--r--fpm/src/fpm/manifest/package.f9047
-rw-r--r--fpm/test/fpm_test/test_manifest.f9028
2 files changed, 75 insertions, 0 deletions
diff --git a/fpm/src/fpm/manifest/package.f90 b/fpm/src/fpm/manifest/package.f90
index 64b0f82..987f2d1 100644
--- a/fpm/src/fpm/manifest/package.f90
+++ b/fpm/src/fpm/manifest/package.f90
@@ -93,6 +93,10 @@ contains
!> Error handling
type(error_t), allocatable, intent(out) :: error
+ ! Backspace (8), tabulator (9), newline (10), formfeed (12) and carriage
+ ! return (13) are invalid in package names
+ character(len=*), parameter :: invalid_chars = &
+ achar(8) // achar(9) // achar(10) // achar(12) // achar(13)
type(toml_table), pointer :: child, node
type(toml_array), pointer :: children
character(len=:), allocatable :: version
@@ -107,6 +111,17 @@ contains
return
end if
+ if (len(self%name) <= 0) then
+ call syntax_error(error, "Package name must be a non-empty string")
+ return
+ end if
+
+ ii = scan(self%name, invalid_chars)
+ if (ii > 0) then
+ call syntax_error(error, "Package name contains invalid characters")
+ return
+ end if
+
call get_value(table, "build", child, requested=.true., stat=stat)
if (stat /= toml_stat%success) then
call fatal_error(error, "Type mismatch for build entry, must be a table")
@@ -154,6 +169,9 @@ contains
if (allocated(error)) exit
end do
if (allocated(error)) return
+
+ call unique_programs(self%executable, error)
+ if (allocated(error)) return
end if
call get_value(table, "test", children, requested=.false.)
@@ -170,6 +188,9 @@ contains
if (allocated(error)) exit
end do
if (allocated(error)) return
+
+ call unique_programs(self%test, error)
+ if (allocated(error)) return
end if
end subroutine new_package
@@ -298,4 +319,30 @@ contains
end subroutine info
+ !> Check whether or not the names in a set of executables are unique
+ subroutine unique_programs(executable, error)
+
+ !> Array of executables
+ class(executable_config_t), intent(in) :: executable(:)
+
+ !> Error handling
+ type(error_t), allocatable, intent(out) :: error
+
+ integer :: i, j
+
+ do i = 1, size(executable)
+ do j = 1, i - 1
+ if (executable(i)%name == executable(j)%name) then
+ call fatal_error(error, "The program named '"//&
+ executable(j)%name//"' is duplicated. "//&
+ "Unique program names are required.")
+ exit
+ end if
+ end do
+ end do
+ if (allocated(error)) return
+
+ end subroutine unique_programs
+
+
end module fpm_manifest_package
diff --git a/fpm/test/fpm_test/test_manifest.f90 b/fpm/test/fpm_test/test_manifest.f90
index a81504d..1c2cfb7 100644
--- a/fpm/test/fpm_test/test_manifest.f90
+++ b/fpm/test/fpm_test/test_manifest.f90
@@ -47,6 +47,7 @@ contains
& new_unittest("package-noname", test_package_noname, should_fail=.true.), &
& new_unittest("package-wrongexe", test_package_wrongexe, should_fail=.true.), &
& new_unittest("package-wrongtest", test_package_wrongtest, should_fail=.true.), &
+ & new_unittest("package-duplicate", test_package_duplicate, should_fail=.true.), &
& new_unittest("test-simple", test_test_simple), &
& new_unittest("test-empty", test_test_empty, should_fail=.true.), &
& new_unittest("test-typeerror", test_test_typeerror, should_fail=.true.), &
@@ -744,6 +745,33 @@ contains
end subroutine test_package_wrongtest
+ !> Try to read tests from a mixed type array
+ subroutine test_package_duplicate(error)
+ use fpm_manifest_package
+ use fpm_toml, only : set_value, add_table, add_array, toml_table, toml_array
+
+ !> Error handling
+ type(error_t), allocatable, intent(out) :: error
+
+ type(toml_table) :: table
+ type(toml_table), pointer :: child
+ type(toml_array), pointer :: children
+ integer :: stat
+ type(package_config_t) :: package
+
+ table = toml_table()
+ call set_value(table, 'name', '"example"', stat)
+ call add_array(table, 'test', children, stat)
+ call add_table(children, child, stat)
+ call set_value(child, 'name', '"prog"', stat)
+ call add_table(children, child, stat)
+ call set_value(child, 'name', '"prog"', stat)
+
+ call new_package(package, table, error)
+
+ end subroutine test_package_duplicate
+
+
!> Tests cannot be created from empty tables
subroutine test_test_simple(error)
use fpm_manifest_test