added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Fortran / FORTRANMODDIR.py
bloba0e03af79d26e4fd7ac008f6d1d4aadabe467f87
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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__"
27 """
28 Verify the following things:
29 * _FORTRANMODFLAG is correctly constructed from FORTRANMODDIRPREFIX and
30 FORTRANMODDIR.
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()).
35 """
37 import TestSCons
39 _python_ = TestSCons._python_
40 _exe = TestSCons._exe
42 test = TestSCons.TestSCons()
44 test.write('myfortran.py', r"""
45 import os.path
46 import re
47 import sys
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:
51 contents = f.read()
52 modules = re.findall(mod_regex, contents)
53 (prefix, moddir) = sys.argv[1].split('=')
54 if prefix != 'moduledir':
55 sys.exit(1)
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())
60 """)
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}')
71 """ % locals())
73 test.write('test1.f90', """\
74 module mod_foo
75 implicit none
76 interface q
77 module procedure p
78 end interface q
79 contains
80 subroutine p
81 implicit none
82 print *, 'mod_foo::p'
83 end subroutine p
84 end module mod_foo
85 program test
86 use mod_foo
87 implicit none
88 print *, 'test1.f90'
89 call p
90 call q
91 end
92 """)
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 = '.')
108 test.pass_test()
110 # Local Variables:
111 # tab-width:4
112 # indent-tabs-mode:nil
113 # End:
114 # vim: set expandtab tabstop=4 shiftwidth=4: