5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__
= "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Verify the following things:
29 * _FORTRANMODFLAG is correctly constructed from FORTRANMODDIRPREFIX and
31 * The dependency scanner does not expect a module file to be created
32 from a "module procedure" statement.
33 * The dependency scanner expects the module files to be created in the correct
34 module directory (this is verified by the test.up_to_date()).
39 _python_
= TestSCons
._python
_
42 test
= TestSCons
.TestSCons()
44 test
.write('myfortran.py', r
"""
48 # case insensitive matching, because Fortran is case insensitive
49 mod_regex = "(?im)^\\s*MODULE\\s+(?!PROCEDURE)(\\w+)"
50 with open(sys.argv[2]) as f:
52 modules = re.findall(mod_regex, contents)
53 (prefix, moddir) = sys.argv[1].split('=')
54 if prefix != 'moduledir':
56 modules = [os.path.join(moddir, m.lower()+'.mod') for m in modules]
57 for t in sys.argv[3:] + modules:
58 with open(t, 'wb') as f:
59 f.write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode())
62 test
.write('SConstruct', """
63 env = Environment(F90COM = r'%(_python_)s myfortran.py $_FORTRANMODFLAG $SOURCE $TARGET',
64 FORTRANMODDIRPREFIX='moduledir=', FORTRANMODDIR='modules')
65 env.Object(target = 'test1.obj', source = 'test1.f90')
66 env.Object(target = 'sub2/test2.obj', source = 'test1.f90',
67 FORTRANMODDIR='${TARGET.dir}')
68 env.Object(target = 'sub3/test3.obj', source = 'test1.f90',
69 F90COM = r'%(_python_)s myfortran.py moduledir=$FORTRANMODDIR $SOURCE $TARGET',
70 FORTRANMODDIR='${TARGET.dir}')
73 test
.write('test1.f90', """\
94 test
.run(arguments
= '.', stderr
= None)
96 test
.must_match('test1.obj', "myfortran.py wrote test1.obj\n")
97 test
.must_match(['modules', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n")
98 test
.must_not_exist(['modules', 'p.mod'])
100 test
.must_match(['sub2', 'test2.obj'], "myfortran.py wrote test2.obj\n")
101 test
.must_match(['sub2', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n")
103 test
.must_match(['sub3', 'test3.obj'], "myfortran.py wrote test3.obj\n")
104 test
.must_match(['sub3', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n")
106 test
.up_to_date(arguments
= '.')
112 # indent-tabs-mode:nil
114 # vim: set expandtab tabstop=4 shiftwidth=4: