Tests: Add Fortran submodule tests
Co-Author: Damian Rouson <damian@sourceryinstitute.org> Issue: #16234
This commit is contained in:
parent
6757e66089
commit
b66bc6606e
|
@ -3109,6 +3109,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
|
||||||
--build-project FortranModules
|
--build-project FortranModules
|
||||||
--build-options ${build_options}
|
--build-options ${build_options}
|
||||||
-DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
|
-DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
|
||||||
|
-DCMake_TEST_Fortran_SUBMODULES:BOOL=${CMake_TEST_Fortran_SUBMODULES}
|
||||||
)
|
)
|
||||||
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranModules")
|
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranModules")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -5,6 +5,33 @@ if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "V
|
||||||
set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
|
set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if("x${CMake_TEST_Fortran_SUBMODULES}" STREQUAL "x"
|
||||||
|
AND NOT CMAKE_VERSION VERSION_LESS 3.6.20160923 # for CheckFortranSourceCompiles SRC_EXT
|
||||||
|
)
|
||||||
|
include(CheckFortranSourceCompiles)
|
||||||
|
CHECK_Fortran_SOURCE_COMPILES([[
|
||||||
|
module parent
|
||||||
|
interface
|
||||||
|
module function id(x)
|
||||||
|
real, intent(in) :: x
|
||||||
|
real :: id
|
||||||
|
end function id
|
||||||
|
end interface
|
||||||
|
end module parent
|
||||||
|
submodule ( parent ) child
|
||||||
|
contains
|
||||||
|
module procedure id
|
||||||
|
f = x
|
||||||
|
end procedure id
|
||||||
|
end submodule child
|
||||||
|
program main
|
||||||
|
end program
|
||||||
|
]] HAVE_SUBMODULES SRC_EXT F90)
|
||||||
|
set(CMake_TEST_Fortran_SUBMODULES ${HAVE_SUBMODULES})
|
||||||
|
elseif(CMake_TEST_Fortran_SUBMODULES)
|
||||||
|
message(STATUS "Enabling Fortran submodule tests by explicit request.")
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(test_module
|
add_executable(test_module
|
||||||
test_module_main.f90
|
test_module_main.f90
|
||||||
test_module_implementation.f90
|
test_module_implementation.f90
|
||||||
|
@ -76,3 +103,7 @@ endif()
|
||||||
add_subdirectory(Library)
|
add_subdirectory(Library)
|
||||||
add_subdirectory(Subdir)
|
add_subdirectory(Subdir)
|
||||||
add_subdirectory(Executable)
|
add_subdirectory(Executable)
|
||||||
|
|
||||||
|
if(CMake_TEST_Fortran_SUBMODULES)
|
||||||
|
add_subdirectory(Submodules)
|
||||||
|
endif()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
add_executable(submod main.f90 provide.f90)
|
|
@ -0,0 +1,5 @@
|
||||||
|
program main
|
||||||
|
use parent, only : child_function,grandchild_subroutine
|
||||||
|
implicit none
|
||||||
|
if (child_function()) call grandchild_subroutine
|
||||||
|
end program
|
|
@ -0,0 +1,57 @@
|
||||||
|
! The program units in this file consist of a
|
||||||
|
! module/submodule tree represented by the following
|
||||||
|
! graph:
|
||||||
|
!
|
||||||
|
! parent
|
||||||
|
! |
|
||||||
|
! / \
|
||||||
|
! / \
|
||||||
|
! child sibling
|
||||||
|
! |
|
||||||
|
! grandchild
|
||||||
|
!
|
||||||
|
! where the parent node is a module and all other
|
||||||
|
! nodes are submodules.
|
||||||
|
|
||||||
|
module parent
|
||||||
|
implicit none
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
! Test Fortran 2008 "module function" syntax
|
||||||
|
module function child_function() result(child_stuff)
|
||||||
|
logical :: child_stuff
|
||||||
|
end function
|
||||||
|
|
||||||
|
! Test Fortran 2008 "module subroutine" syntax
|
||||||
|
module subroutine grandchild_subroutine()
|
||||||
|
end subroutine
|
||||||
|
|
||||||
|
end interface
|
||||||
|
|
||||||
|
end module parent
|
||||||
|
|
||||||
|
! Test the notation for a 1st-generation direct
|
||||||
|
! descendant of a parent module
|
||||||
|
submodule ( parent ) child
|
||||||
|
implicit none
|
||||||
|
contains
|
||||||
|
module function child_function() result(child_stuff)
|
||||||
|
logical :: child_stuff
|
||||||
|
child_stuff=.true.
|
||||||
|
end function
|
||||||
|
end submodule child
|
||||||
|
|
||||||
|
! Empty submodule for checking disambiguation of
|
||||||
|
! nodes at the same vertical level in the tree
|
||||||
|
submodule ( parent ) sibling
|
||||||
|
end submodule sibling
|
||||||
|
|
||||||
|
! Test the notation for an Nth-generation descendant
|
||||||
|
! for N>1, which necessitates the colon.
|
||||||
|
submodule ( parent : child ) grandchild
|
||||||
|
contains
|
||||||
|
module subroutine grandchild_subroutine()
|
||||||
|
print *,"Test passed."
|
||||||
|
end subroutine
|
||||||
|
end submodule grandchild
|
Loading…
Reference in New Issue