Remove unnecessary imports.
[scons.git] / test / Fortran / FORTRANFILESUFFIXES2.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import TestSCons
28
29 from common import write_fake_link
30
31 _python_ = TestSCons._python_
32 _exe   = TestSCons._exe
33
34 test = TestSCons.TestSCons()
35
36 write_fake_link(test)
37
38 test.write('myfortran.py', r"""
39 import getopt
40 import sys
41 comment = '#' + sys.argv[1]
42 opts, args = getopt.getopt(sys.argv[2:], 'co:')
43 for opt, arg in opts:
44     if opt == '-o': out = arg
45 infile = open(args[0], 'rb')
46 outfile = open(out, 'wb')
47 for l in infile.readlines():
48     if l[:len(comment)] != comment:
49         outfile.write(l)
50 sys.exit(0)
51 """)
52
53 # Test non default file suffix: .f, .f90 and .f95 for FORTRAN
54 test.write('SConstruct', """
55 env = Environment(LINK = r'%(_python_)s mylink.py',
56                   LINKFLAGS = [],
57                   F77 = r'%(_python_)s myfortran.py g77',
58                   FORTRAN = r'%(_python_)s myfortran.py fortran',
59                   FORTRANFILESUFFIXES = ['.f', '.f95', '.f90', '.ffake'],
60                   tools = ['default', 'fortran'])
61 #print env.Dump()
62 env.Program(target = 'test01', source = 'test01.f')
63 env.Program(target = 'test02', source = 'test02.f90')
64 env.Program(target = 'test03', source = 'test03.f95')
65 env.Program(target = 'test04', source = 'test04.ffake')
66 env.Program(target = 'test05', source = 'test05.f77')
67 """ % locals())
68
69 test.write('test01.f',   "This is a .f file.\n#link\n#fortran\n")
70 test.write('test02.f90',   "This is a .f90 file.\n#link\n#fortran\n")
71 test.write('test03.f95', "This is a .f95 file.\n#link\n#fortran\n")
72 test.write('test04.ffake', "This is a .ffake file.\n#link\n#fortran\n")
73 test.write('test05.f77', "This is a .f77 file.\n#link\n#g77\n")
74
75 test.run(arguments = '.', stderr = None)
76
77 test.must_match('test01' + _exe, "This is a .f file.\n")
78 test.must_match('test02' + _exe, "This is a .f90 file.\n")
79 test.must_match('test03' + _exe, "This is a .f95 file.\n")
80 test.must_match('test04' + _exe, "This is a .ffake file.\n")
81 test.must_match('test05' + _exe, "This is a .f77 file.\n")
82
83 test.pass_test()