Skip to content

Commit

Permalink
Add the testcase for PR #4452
Browse files Browse the repository at this point in the history
Tests that module inclusion generates the proper dependencies,
so that if the alphabetically-first file uses other modules,
thse module files are built first.

Signed-off-by: Mats Wichmann <[email protected]>
  • Loading branch information
mwichmann committed Jan 1, 2024
1 parent f36ff25 commit 825b879
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/Fortran/USE-MODULE-live.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python
#
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""
Test Fortran module use, organized in such a way that
module files will be "not found" unless dependencies have been forced.
See PR #4452.
This is a "live" test - uses an actual Fortran compiler, as the
mock compiler would need to have a sophisticated regex to catch
the situation. Possibly we could convert later if the mock fortran.py
gets smarter.
"""

import TestSCons

_python_ = TestSCons._python_
_exe = TestSCons._exe

test = TestSCons.TestSCons()

test.file_fixture(['fixture-mod', 'SConstruct'])
test.file_fixture(['fixture-mod', 'main.f90'], dstfile=['src', 'main.f90'])
test.file_fixture(
['fixture-mod', 'module0.f90'],
dstfile=['src', 'module0.f90'],
)
test.file_fixture(
['fixture-mod', 'module1.f90'],
dstfile=['src', 'module1.f90'],
)
test.file_fixture(
['fixture-mod', 'module2.f90'],
dstfile=['src', 'module2.f90'],
)
test.file_fixture(
['fixture-mod', 'util_module.f90'],
dstfile=['src', 'utils', 'util_module.f90'],
)
test.run(arguments='.', stderr=None)
test.must_exist(["fortran_mods", "module0.mod"])
test.must_exist(["fortran_mods", "module1.mod"])
test.must_exist(["fortran_mods", "module2.mod"])
test.must_exist(["fortran_mods", "util_module.mod"])

test.pass_test()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
9 changes: 9 additions & 0 deletions test/Fortran/fixture-mod/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
env = Environment(
tools=['default', 'gfortran'],
F90='gfortran',
LINK='gfortran',
LINKFLAGS='',
FORTRANMODDIR='fortran_mods',
)
sources = env.Glob('src/*.f90') + env.Glob('src/utils/*.f90')
env.Program('main', sources)
13 changes: 13 additions & 0 deletions test/Fortran/fixture-mod/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

program main
use module0
use module1
use module2
use util_module
implicit none
write(*,*) 'Main program using modules!'
call module0_subroutine()
call module1_subroutine()
call module2_subroutine()
call util_subroutine()
end program main
10 changes: 10 additions & 0 deletions test/Fortran/fixture-mod/module0.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

module module0
use module1
use module2
implicit none
contains
subroutine module0_subroutine()
write(*,*) 'This is module0 subroutine.'
end subroutine module0_subroutine
end module module0
8 changes: 8 additions & 0 deletions test/Fortran/fixture-mod/module1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

module module1
implicit none
contains
subroutine module1_subroutine()
write(*,*) 'This is module1 subroutine.'
end subroutine module1_subroutine
end module module1
8 changes: 8 additions & 0 deletions test/Fortran/fixture-mod/module2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

module module2
implicit none
contains
subroutine module2_subroutine()
write(*,*) 'This is module2 subroutine.'
end subroutine module2_subroutine
end module module2
Empty file.
7 changes: 7 additions & 0 deletions test/Fortran/fixture-mod/util_module.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module util_module
implicit none
contains
subroutine util_subroutine()
write(*,*) 'This is a utility subroutine.'
end subroutine util_subroutine
end module util_module

0 comments on commit 825b879

Please sign in to comment.