From f0caa736e0fee49ee8680899ba4d17a6e33d6b10 Mon Sep 17 00:00:00 2001 From: LKedward Date: Fri, 18 Sep 2020 10:15:13 +0100 Subject: Add: example package with c code compilation --- ci/run_tests.bat | 10 ++++++++++ ci/run_tests.sh | 6 +++++- test/example_packages/with_c/app/main.f90 | 10 ++++++++++ test/example_packages/with_c/fpm.toml | 1 + test/example_packages/with_c/src/c_code.c | 10 ++++++++++ test/example_packages/with_c/src/with_c.f90 | 26 ++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/example_packages/with_c/app/main.f90 create mode 100644 test/example_packages/with_c/fpm.toml create mode 100644 test/example_packages/with_c/src/c_code.c create mode 100644 test/example_packages/with_c/src/with_c.f90 diff --git a/ci/run_tests.bat b/ci/run_tests.bat index 9435e0d..2aa27e7 100755 --- a/ci/run_tests.bat +++ b/ci/run_tests.bat @@ -41,4 +41,14 @@ if errorlevel 1 exit 1 if errorlevel 1 exit 1 .\build\gfortran_debug\test\farewell_test +if errorlevel 1 exit 1 + + +cd ..\with_c +if errorlevel 1 exit 1 + +..\..\..\fpm\build\gfortran_debug\app\fpm build +if errorlevel 1 exit 1 + +.\build\gfortran_debug\app\with_c if errorlevel 1 exit 1 \ No newline at end of file diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 3033c2a..ea29da8 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -17,4 +17,8 @@ cd ../hello_complex ./build/gfortran_debug/app/say_Hello ./build/gfortran_debug/app/say_goodbye ./build/gfortran_debug/test/greet_test -./build/gfortran_debug/test/farewell_test \ No newline at end of file +./build/gfortran_debug/test/farewell_test + +cd ../with_c +../../../fpm/build/gfortran_debug/app/fpm build +./build/gfortran_debug/app/with_c \ No newline at end of file diff --git a/test/example_packages/with_c/app/main.f90 b/test/example_packages/with_c/app/main.f90 new file mode 100644 index 0000000..4d3174b --- /dev/null +++ b/test/example_packages/with_c/app/main.f90 @@ -0,0 +1,10 @@ +program with_c_app +use with_c +implicit none + +write(*,*) "isdir('app') = ", system_isdir('app') +write(*,*) "isdir('src') = ", system_isdir('src') +write(*,*) "isdir('test') = ", system_isdir('test') +write(*,*) "isdir('bench') = ", system_isdir('bench') + +end program with_c_app \ No newline at end of file diff --git a/test/example_packages/with_c/fpm.toml b/test/example_packages/with_c/fpm.toml new file mode 100644 index 0000000..97e3110 --- /dev/null +++ b/test/example_packages/with_c/fpm.toml @@ -0,0 +1 @@ +name = "with_c" diff --git a/test/example_packages/with_c/src/c_code.c b/test/example_packages/with_c/src/c_code.c new file mode 100644 index 0000000..44604f0 --- /dev/null +++ b/test/example_packages/with_c/src/c_code.c @@ -0,0 +1,10 @@ +#include +/* + * Decides whether a given file name is a directory. + * return 1 if file exists and is a directory + * Source (Public domain): https://github.com/urbanjost/M_system + */ +int my_isdir (const char *path) { + struct stat sb; + return stat(path, &sb) == 0 && S_ISDIR (sb.st_mode); +} \ No newline at end of file diff --git a/test/example_packages/with_c/src/with_c.f90 b/test/example_packages/with_c/src/with_c.f90 new file mode 100644 index 0000000..edd839e --- /dev/null +++ b/test/example_packages/with_c/src/with_c.f90 @@ -0,0 +1,26 @@ +module with_c + use iso_c_binding, only: c_char, c_int, c_null_char + implicit none + +contains + + function system_isdir(dirname) + ! Source (Public domain): https://github.com/urbanjost/M_system + ! + implicit none + character(len=*),intent(in) :: dirname + logical :: system_isdir + + interface + function c_isdir(dirname) bind (C,name="my_isdir") result (c_ierr) + import c_char,c_int + character(kind=c_char,len=1),intent(in) :: dirname(*) + integer(kind=c_int) :: c_ierr + end function c_isdir + end interface + + system_isdir= c_isdir(trim(dirname)//c_null_char) == 1 + + end function system_isdir + +end module with_c \ No newline at end of file -- cgit v1.2.3 From 800289818fe97d5855ca8400f52080751b0f199f Mon Sep 17 00:00:00 2001 From: LKedward Date: Fri, 18 Sep 2020 10:49:25 +0100 Subject: Fix: remove leading spaces in string split routine --- fpm/src/fpm_sources.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fpm/src/fpm_sources.f90 b/fpm/src/fpm_sources.f90 index 787efff..dc50fd1 100644 --- a/fpm/src/fpm_sources.f90 +++ b/fpm/src/fpm_sources.f90 @@ -526,7 +526,7 @@ function split_n(string,delims,n,stat) result(substring) return end if - substring = trim(string_parts(i)) + substring = trim(adjustl(string_parts(i))) stat = 0 end function split_n @@ -553,6 +553,7 @@ subroutine resolve_module_dependencies(sources) if (.not.associated(sources(i)%file_dependencies(j)%ptr)) then write(*,*) '(!) Unable to find source for module dependency: ',sources(i)%modules_used(j)%s + write(*,*) ' for file ',sources(i)%file_name ! stop end if -- cgit v1.2.3 From 507b315570d1d6521e2e15ad9579df205c53bc39 Mon Sep 17 00:00:00 2001 From: LKedward Date: Fri, 18 Sep 2020 10:51:36 +0100 Subject: Fix: add submodule name to modules_provided --- fpm/src/fpm_sources.f90 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/fpm/src/fpm_sources.f90 b/fpm/src/fpm_sources.f90 index dc50fd1..b104fa6 100644 --- a/fpm/src/fpm_sources.f90 +++ b/fpm/src/fpm_sources.f90 @@ -310,7 +310,7 @@ function parse_f_source(f_filename,error) result(f_source) if (.not.validate_name(mod_name)) then call file_parse_error(error,f_filename, & 'empty or invalid name for module',i, & - file_lines(i)%s) + file_lines(i)%s, index(file_lines(i)%s,mod_name)) return end if @@ -327,6 +327,22 @@ function parse_f_source(f_filename,error) result(f_source) ! Extract name of submodule if is submodule if (index(adjustl(lower(file_lines(i)%s)),'submodule') == 1) then + mod_name = split_n(file_lines(i)%s,n=3,delims='()',stat=stat) + if (stat /= 0) then + call file_parse_error(error,f_filename, & + 'unable to get submodule name',i, & + file_lines(i)%s) + return + end if + if (.not.validate_name(mod_name)) then + call file_parse_error(error,f_filename, & + 'empty or invalid name for submodule',i, & + file_lines(i)%s, index(file_lines(i)%s,mod_name)) + return + end if + + n_mod = n_mod + 1 + temp_string = split_n(file_lines(i)%s,n=2,delims='()',stat=stat) if (stat /= 0) then call file_parse_error(error,f_filename, & @@ -347,8 +363,6 @@ function parse_f_source(f_filename,error) result(f_source) end if - f_source%modules_used(n_use)%s = lower(temp_string) - if (.not.validate_name(temp_string)) then call file_parse_error(error,f_filename, & 'empty or invalid name for submodule parent',i, & @@ -356,6 +370,10 @@ function parse_f_source(f_filename,error) result(f_source) return end if + f_source%modules_used(n_use)%s = lower(temp_string) + + f_source%modules_provided(n_mod)%s = lower(mod_name) + end if end if -- cgit v1.2.3 From 27b2ead1813368abe297db1913871f69836f48c0 Mon Sep 17 00:00:00 2001 From: LKedward Date: Fri, 18 Sep 2020 11:14:43 +0100 Subject: Update: source parsing tests for dd5bf1 --- fpm/test/test_source_parsing.f90 | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/fpm/test/test_source_parsing.f90 b/fpm/test/test_source_parsing.f90 index c55a206..eec92d7 100644 --- a/fpm/test/test_source_parsing.f90 +++ b/fpm/test/test_source_parsing.f90 @@ -308,7 +308,7 @@ contains open(file=temp_file, newunit=unit) write(unit, '(a)') & - & 'submodule (parent) :: child', & + & 'submodule (parent) child', & & 'use module_one', & & 'end submodule test' close(unit) @@ -323,8 +323,8 @@ contains return end if - if (size(f_source%modules_provided) /= 0) then - call test_failed(error,'Unexpected modules_provided - expecting zero') + if (size(f_source%modules_provided) /= 1) then + call test_failed(error,'Unexpected modules_provided - expecting one') return end if @@ -333,6 +333,11 @@ contains return end if + if (.not.('child' .in. f_source%modules_provided)) then + call test_failed(error,'Missing module in modules_provided') + return + end if + if (.not.('module_one' .in. f_source%modules_used)) then call test_failed(error,'Missing module in modules_used') return @@ -360,7 +365,7 @@ contains open(file=temp_file, newunit=unit) write(unit, '(a)') & - & 'submodule (ancestor:parent) :: child', & + & 'submodule (ancestor:parent) child', & & 'use module_one', & & 'end submodule test' close(unit) @@ -375,8 +380,8 @@ contains return end if - if (size(f_source%modules_provided) /= 0) then - call test_failed(error,'Unexpected modules_provided - expecting zero') + if (size(f_source%modules_provided) /= 1) then + call test_failed(error,'Unexpected modules_provided - expecting one') return end if @@ -385,6 +390,11 @@ contains return end if + if (.not.('child' .in. f_source%modules_provided)) then + call test_failed(error,'Missing module in modules_provided') + return + end if + if (.not.('module_one' .in. f_source%modules_used)) then call test_failed(error,'Missing module in modules_used') return -- cgit v1.2.3 From 35f4779647ddab4ef7edef26b4e0027004d6c756 Mon Sep 17 00:00:00 2001 From: LKedward Date: Fri, 18 Sep 2020 11:38:13 +0100 Subject: Add: example package with submodules --- ci/run_tests.bat | 7 +++++++ ci/run_tests.sh | 5 ++++- test/example_packages/submodules/fpm.toml | 1 + test/example_packages/submodules/src/child1.f90 | 16 ++++++++++++++++ test/example_packages/submodules/src/child2.f90 | 10 ++++++++++ test/example_packages/submodules/src/grandchild.f90 | 10 ++++++++++ test/example_packages/submodules/src/parent.f90 | 15 +++++++++++++++ 7 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test/example_packages/submodules/fpm.toml create mode 100644 test/example_packages/submodules/src/child1.f90 create mode 100644 test/example_packages/submodules/src/child2.f90 create mode 100644 test/example_packages/submodules/src/grandchild.f90 create mode 100644 test/example_packages/submodules/src/parent.f90 diff --git a/ci/run_tests.bat b/ci/run_tests.bat index 2aa27e7..5a4d624 100755 --- a/ci/run_tests.bat +++ b/ci/run_tests.bat @@ -51,4 +51,11 @@ if errorlevel 1 exit 1 if errorlevel 1 exit 1 .\build\gfortran_debug\app\with_c +if errorlevel 1 exit 1 + + +cd ..\submodules +if errorlevel 1 exit 1 + +..\..\..\fpm\build\gfortran_debug\app\fpm build if errorlevel 1 exit 1 \ No newline at end of file diff --git a/ci/run_tests.sh b/ci/run_tests.sh index ea29da8..1f6d867 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -21,4 +21,7 @@ cd ../hello_complex cd ../with_c ../../../fpm/build/gfortran_debug/app/fpm build -./build/gfortran_debug/app/with_c \ No newline at end of file +./build/gfortran_debug/app/with_c + +cd ../submodules +../../../fpm/build/gfortran_debug/app/fpm build \ No newline at end of file diff --git a/test/example_packages/submodules/fpm.toml b/test/example_packages/submodules/fpm.toml new file mode 100644 index 0000000..cfc3d61 --- /dev/null +++ b/test/example_packages/submodules/fpm.toml @@ -0,0 +1 @@ +name = "submodules" diff --git a/test/example_packages/submodules/src/child1.f90 b/test/example_packages/submodules/src/child1.f90 new file mode 100644 index 0000000..dbd0fa5 --- /dev/null +++ b/test/example_packages/submodules/src/child1.f90 @@ -0,0 +1,16 @@ +submodule(parent) child1 +implicit none + +interface + module function my_fun() result (b) + integer :: b + end function my_fun +end interface + +contains + +module procedure my_sub1 + a = 1 +end procedure my_sub1 + +end submodule child1 \ No newline at end of file diff --git a/test/example_packages/submodules/src/child2.f90 b/test/example_packages/submodules/src/child2.f90 new file mode 100644 index 0000000..179cc32 --- /dev/null +++ b/test/example_packages/submodules/src/child2.f90 @@ -0,0 +1,10 @@ +submodule(parent) child2 +implicit none + +contains + +module procedure my_sub2 + a = 2 +end procedure my_sub2 + +end submodule child2 \ No newline at end of file diff --git a/test/example_packages/submodules/src/grandchild.f90 b/test/example_packages/submodules/src/grandchild.f90 new file mode 100644 index 0000000..8c5aa17 --- /dev/null +++ b/test/example_packages/submodules/src/grandchild.f90 @@ -0,0 +1,10 @@ +submodule(parent:child1) grandchild +implicit none + +contains + +module procedure my_fun + b = 2 +end procedure my_fun + +end submodule grandchild \ No newline at end of file diff --git a/test/example_packages/submodules/src/parent.f90 b/test/example_packages/submodules/src/parent.f90 new file mode 100644 index 0000000..570827c --- /dev/null +++ b/test/example_packages/submodules/src/parent.f90 @@ -0,0 +1,15 @@ +module parent +implicit none + +interface + + module subroutine my_sub1(a) + integer, intent(out) :: a + end subroutine my_sub1 + + module subroutine my_sub2(a) + integer, intent(out) :: a + end subroutine my_sub2 +end interface + +end module parent \ No newline at end of file -- cgit v1.2.3 From 02ffa065b8a84828645ef13fd3447d346f23e257 Mon Sep 17 00:00:00 2001 From: LKedward Date: Fri, 18 Sep 2020 11:39:33 +0100 Subject: Add: README for example packages --- test/example_packages/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/example_packages/README.md diff --git a/test/example_packages/README.md b/test/example_packages/README.md new file mode 100644 index 0000000..086b967 --- /dev/null +++ b/test/example_packages/README.md @@ -0,0 +1,17 @@ +# Example packages + +See the table below for a list of the example packages provided in this directory including +the features demonstrated in each package and which versions of fpm are supported. + + +| Name | Features | Bootstrap (Haskell) fpm | fpm | +|------------------|---------------------------------------------------------------|:-----------------------:|:---:| +| circular_example | Local path dependency; circular dependency | Y | N | +| circular_test | Local path dependency; circular dependency | Y | N | +| hello_complex | Non-standard directory layout; multiple tests and executables | Y | Y | +| hello_fpm | App-only; local path dependency | Y | N | +| hello_world | App-only | Y | Y | +| makefile_complex | External build command (makefile); local path dependency | Y | N | +| submodules | Lib-only; submodules (3 levels) | N | Y | +| with_c | Compile with `c` source files | N | Y | +| with_makefile | External build command (makefile) | Y | N | \ No newline at end of file -- cgit v1.2.3 From 0f0a191051f9721d656301e92ab7024229d60c41 Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 19 Sep 2020 11:13:24 +0100 Subject: Update: parsing to allow program after module If a program is found at the end of a source file, it will override any previous definition of unit_type to FPM_UNIT_PROGRAM. --- fpm/src/fpm_sources.f90 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fpm/src/fpm_sources.f90 b/fpm/src/fpm_sources.f90 index b104fa6..2c15b8c 100644 --- a/fpm/src/fpm_sources.f90 +++ b/fpm/src/fpm_sources.f90 @@ -378,9 +378,9 @@ function parse_f_source(f_filename,error) result(f_source) end if - ! Detect if is program - if (f_source%unit_type == FPM_UNIT_UNKNOWN .and. & - index(adjustl(lower(file_lines(i)%s)),'program') == 1) then + ! Detect if contains a program + ! (no modules allowed after program def) + if (index(adjustl(lower(file_lines(i)%s)),'program') == 1) then f_source%unit_type = FPM_UNIT_PROGRAM -- cgit v1.2.3 From 5f7e4e5ec4fe10b7cca8aeaadb98ab376cdedfaf Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 19 Sep 2020 11:23:10 +0100 Subject: Update: module resolution to ignore same file dependency If a module dependency is satisfied in the same file, it is not added to file_dependencies. Use two-pass procedure to count the number of actual file_dependencies required for module resolution. --- fpm/src/fpm_sources.f90 | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/fpm/src/fpm_sources.f90 b/fpm/src/fpm_sources.f90 index 2c15b8c..89e0849 100644 --- a/fpm/src/fpm_sources.f90 +++ b/fpm/src/fpm_sources.f90 @@ -556,23 +556,42 @@ subroutine resolve_module_dependencies(sources) ! type(srcfile_t), intent(inout), target :: sources(:) - integer :: n_depend, i, j + type(srcfile_ptr) :: dep + + integer :: n_depend, i, pass, j do i=1,size(sources) - n_depend = size(sources(i)%modules_used) + do pass=1,2 + + n_depend = 0 + + do j=1,size(sources(i)%modules_used) + + if (sources(i)%modules_used(j)%s .in. sources(i)%modules_provided) then + ! Dependency satisfied in same file, skip + cycle + end if - allocate(sources(i)%file_dependencies(n_depend)) + dep%ptr => find_module_dependency(sources,sources(i)%modules_used(j)%s) - do j=1,n_depend + if (.not.associated(dep%ptr)) then + write(*,*) '(!) Unable to find source for module dependency: ', & + sources(i)%modules_used(j)%s + write(*,*) ' for file ',sources(i)%file_name + ! stop + end if + + n_depend = n_depend + 1 + + if (pass == 2) then + sources(i)%file_dependencies(n_depend) = dep + end if - sources(i)%file_dependencies(j)%ptr => & - find_module_dependency(sources,sources(i)%modules_used(j)%s) + end do - if (.not.associated(sources(i)%file_dependencies(j)%ptr)) then - write(*,*) '(!) Unable to find source for module dependency: ',sources(i)%modules_used(j)%s - write(*,*) ' for file ',sources(i)%file_name - ! stop + if (pass == 1) then + allocate(sources(i)%file_dependencies(n_depend)) end if end do -- cgit v1.2.3 From f2a51196aa33fca3ae19a02a601dfa190fe14d80 Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 19 Sep 2020 11:28:45 +0100 Subject: Add: example package with single source program and module --- ci/run_tests.bat | 10 ++++++++++ ci/run_tests.sh | 6 +++++- test/example_packages/README.md | 23 +++++++++++----------- .../program_with_module/app/main.f90 | 10 ++++++++++ test/example_packages/program_with_module/fpm.toml | 1 + 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 test/example_packages/program_with_module/app/main.f90 create mode 100644 test/example_packages/program_with_module/fpm.toml diff --git a/ci/run_tests.bat b/ci/run_tests.bat index 5a4d624..92b3cd6 100755 --- a/ci/run_tests.bat +++ b/ci/run_tests.bat @@ -58,4 +58,14 @@ cd ..\submodules if errorlevel 1 exit 1 ..\..\..\fpm\build\gfortran_debug\app\fpm build +if errorlevel 1 exit 1 + + +cd ..\program_with_module +if errorlevel 1 exit 1 + +..\..\..\fpm\build\gfortran_debug\app\fpm build +if errorlevel 1 exit 1 + +.\build\gfortran_debug\app\Program_with_module if errorlevel 1 exit 1 \ No newline at end of file diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 1f6d867..418fcf2 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -24,4 +24,8 @@ cd ../with_c ./build/gfortran_debug/app/with_c cd ../submodules -../../../fpm/build/gfortran_debug/app/fpm build \ No newline at end of file +../../../fpm/build/gfortran_debug/app/fpm build + +cd ../program_with_module +../../../fpm/build/gfortran_debug/app/fpm build +./build/gfortran_debug/app/Program_with_module \ No newline at end of file diff --git a/test/example_packages/README.md b/test/example_packages/README.md index 086b967..06de927 100644 --- a/test/example_packages/README.md +++ b/test/example_packages/README.md @@ -4,14 +4,15 @@ See the table below for a list of the example packages provided in this director the features demonstrated in each package and which versions of fpm are supported. -| Name | Features | Bootstrap (Haskell) fpm | fpm | -|------------------|---------------------------------------------------------------|:-----------------------:|:---:| -| circular_example | Local path dependency; circular dependency | Y | N | -| circular_test | Local path dependency; circular dependency | Y | N | -| hello_complex | Non-standard directory layout; multiple tests and executables | Y | Y | -| hello_fpm | App-only; local path dependency | Y | N | -| hello_world | App-only | Y | Y | -| makefile_complex | External build command (makefile); local path dependency | Y | N | -| submodules | Lib-only; submodules (3 levels) | N | Y | -| with_c | Compile with `c` source files | N | Y | -| with_makefile | External build command (makefile) | Y | N | \ No newline at end of file +| Name | Features | Bootstrap (Haskell) fpm | fpm | +|---------------------|---------------------------------------------------------------|:-----------------------:|:---:| +| circular_example | Local path dependency; circular dependency | Y | N | +| circular_test | Local path dependency; circular dependency | Y | N | +| hello_complex | Non-standard directory layout; multiple tests and executables | Y | Y | +| hello_fpm | App-only; local path dependency | Y | N | +| hello_world | App-only | Y | Y | +| makefile_complex | External build command (makefile); local path dependency | Y | N | +| program_with_module | App-only; module+program in single source file | Y | Y | +| submodules | Lib-only; submodules (3 levels) | N | Y | +| with_c | Compile with `c` source files | N | Y | +| with_makefile | External build command (makefile) | Y | N | \ No newline at end of file diff --git a/test/example_packages/program_with_module/app/main.f90 b/test/example_packages/program_with_module/app/main.f90 new file mode 100644 index 0000000..59441f0 --- /dev/null +++ b/test/example_packages/program_with_module/app/main.f90 @@ -0,0 +1,10 @@ +module greet_m + implicit none + character(*), parameter :: greeting = 'Hello, fpm!' +end module greet_m + +program program_with_module + use greet_m, only: greeting + implicit none + print *, greeting +end program program_with_module diff --git a/test/example_packages/program_with_module/fpm.toml b/test/example_packages/program_with_module/fpm.toml new file mode 100644 index 0000000..bce6aa2 --- /dev/null +++ b/test/example_packages/program_with_module/fpm.toml @@ -0,0 +1 @@ +name = "Program_with_module" -- cgit v1.2.3 From db67194d936181916bcef873e9317b3cf5048c3d Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 19 Sep 2020 11:45:39 +0100 Subject: Add: parsing unit test for program with module case --- fpm/test/test_source_parsing.f90 | 68 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/fpm/test/test_source_parsing.f90 b/fpm/test/test_source_parsing.f90 index eec92d7..0b92bef 100644 --- a/fpm/test/test_source_parsing.f90 +++ b/fpm/test/test_source_parsing.f90 @@ -25,6 +25,7 @@ contains & new_unittest("intrinsic-modules-used", test_intrinsic_modules_used), & & new_unittest("include-stmt", test_include_stmt), & & new_unittest("module", test_module), & + & new_unittest("program-with-module", test_program_with_module), & & new_unittest("submodule", test_submodule), & & new_unittest("submodule-ancestor", test_submodule_ancestor), & & new_unittest("subprogram", test_subprogram), & @@ -258,7 +259,7 @@ contains & 'contains', & & 'module procedure f()', & & 'end procedure f', & - & 'end submodule test' + & 'end module test' close(unit) f_source = parse_f_source(temp_file,error) @@ -287,13 +288,76 @@ contains end if if (.not.('module_one' .in. f_source%modules_used)) then - call test_failed(error,'Missing parent module in modules_used') + call test_failed(error,'Missing module in modules_used') return end if end subroutine test_module + !> Try to parse combined fortran module and program + !> Check that parsed unit type is FPM_UNIT_PROGRAM + subroutine test_program_with_module(error) + + !> Error handling + type(error_t), allocatable, intent(out) :: error + + integer :: unit + character(:), allocatable :: temp_file + type(srcfile_t), allocatable :: f_source + + allocate(temp_file, source=get_temp_filename()) + + open(file=temp_file, newunit=unit) + write(unit, '(a)') & + & 'module my_mod', & + & 'use module_one', & + & 'interface', & + & ' module subroutine f()', & + & 'end interface', & + & 'contains', & + & 'module procedure f()', & + & 'end procedure f', & + & 'end module test', & + & 'program my_program', & + & 'use my_mod', & + & 'implicit none', & + & 'end my_program' + close(unit) + + f_source = parse_f_source(temp_file,error) + if (allocated(error)) then + return + end if + + if (f_source%unit_type /= FPM_UNIT_PROGRAM) then + call test_failed(error,'Wrong unit type detected - expecting FPM_UNIT_PROGRAM') + return + end if + + if (size(f_source%modules_provided) /= 1) then + call test_failed(error,'Unexpected modules_provided - expecting one') + return + end if + + if (.not.('my_mod' .in. f_source%modules_provided)) then + call test_failed(error,'Missing module in modules_provided') + return + end if + + if (.not.('module_one' .in. f_source%modules_used)) then + call test_failed(error,'Missing module in modules_used') + return + end if + + if (.not.('my_mod' .in. f_source%modules_used)) then + call test_failed(error,'Missing module in modules_used') + return + end if + + end subroutine test_program_with_module + + !> Try to parse fortran submodule for ancestry subroutine test_submodule(error) -- cgit v1.2.3