Add a skip_test() method to the infrastructure and use it for test scripts that skip...
[scons.git] / test / Fortran / F95FLAGS.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 os
28 import string
29 import sys
30 import TestSCons
31
32 python = TestSCons.python
33
34 test = TestSCons.TestSCons()
35 _exe = TestSCons._exe
36
37 if sys.platform == 'win32':
38
39     test.write('mylink.py', r"""
40 import string
41 import sys
42 args = sys.argv[1:]
43 while args:
44     a = args[0]
45     if a[0] != '/':
46         break
47     args = args[1:]
48     if string.lower(a[:5]) == '/out:': out = a[5:]
49 infile = open(args[0], 'rb')
50 outfile = open(out, 'wb')
51 for l in infile.readlines():
52     if l[:5] != '#link':
53         outfile.write(l)
54 sys.exit(0)
55 """)
56
57 else:
58
59     test.write('mylink.py', r"""
60 import getopt
61 import sys
62 opts, args = getopt.getopt(sys.argv[1:], 'o:')
63 for opt, arg in opts:
64     if opt == '-o': out = arg
65 infile = open(args[0], 'rb')
66 outfile = open(out, 'wb')
67 for l in infile.readlines():
68     if l[:5] != '#link':
69         outfile.write(l)
70 sys.exit(0)
71 """)
72
73 test.write('myfortran.py', r"""
74 import getopt
75 import sys
76 comment = '#' + sys.argv[1]
77 opts, args = getopt.getopt(sys.argv[2:], 'co:xy')
78 optstring = ''
79 for opt, arg in opts:
80     if opt == '-o': out = arg
81     else: optstring = optstring + ' ' + opt
82 infile = open(args[0], 'rb')
83 outfile = open(out, 'wb')
84 outfile.write(optstring + "\n")
85 for l in infile.readlines():
86     if l[:len(comment)] != comment:
87         outfile.write(l)
88 sys.exit(0)
89 """)
90
91
92
93 test.write('SConstruct', """
94 env = Environment(LINK = r'%s mylink.py',
95                   LINKFLAGS = [],
96                   F95 = r'%s myfortran.py g95',
97                   F95FLAGS = '-x',
98                   FORTRAN = r'%s myfortran.py fortran',
99                   FORTRANFLAGS = '-y')
100 env.Program(target = 'test01', source = 'test01.f')
101 env.Program(target = 'test02', source = 'test02.F')
102 env.Program(target = 'test03', source = 'test03.for')
103 env.Program(target = 'test04', source = 'test04.FOR')
104 env.Program(target = 'test05', source = 'test05.ftn')
105 env.Program(target = 'test06', source = 'test06.FTN')
106 env.Program(target = 'test07', source = 'test07.fpp')
107 env.Program(target = 'test08', source = 'test08.FPP')
108 env.Program(target = 'test09', source = 'test09.f77')
109 env.Program(target = 'test10', source = 'test10.F77')
110 env.Program(target = 'test11', source = 'test11.f90')
111 env.Program(target = 'test12', source = 'test12.F90')
112 env.Program(target = 'test13', source = 'test13.f95')
113 env.Program(target = 'test14', source = 'test14.F95')
114 """ % (python, python, python))
115
116 test.write('test01.f',   "This is a .f file.\n#link\n#fortran\n")
117 test.write('test02.F',   "This is a .F file.\n#link\n#fortran\n")
118 test.write('test03.for', "This is a .for file.\n#link\n#fortran\n")
119 test.write('test04.FOR', "This is a .FOR file.\n#link\n#fortran\n")
120 test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortran\n")
121 test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortran\n")
122 test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortran\n")
123 test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortran\n")
124 test.write('test09.f77', "This is a .f77 file.\n#link\n#fortran\n")
125 test.write('test10.F77', "This is a .F77 file.\n#link\n#fortran\n")
126 test.write('test11.f90', "This is a .f90 file.\n#link\n#fortran\n")
127 test.write('test12.F90', "This is a .F90 file.\n#link\n#fortran\n")
128 test.write('test13.f95', "This is a .f95 file.\n#link\n#g95\n")
129 test.write('test14.F95', "This is a .F95 file.\n#link\n#g95\n")
130
131 test.run(arguments = '.', stderr = None)
132
133 test.must_match('test01' + _exe, " -y -c\nThis is a .f file.\n")
134 test.must_match('test02' + _exe, " -y -c\nThis is a .F file.\n")
135 test.must_match('test03' + _exe, " -y -c\nThis is a .for file.\n")
136 test.must_match('test04' + _exe, " -y -c\nThis is a .FOR file.\n")
137 test.must_match('test05' + _exe, " -y -c\nThis is a .ftn file.\n")
138 test.must_match('test06' + _exe, " -y -c\nThis is a .FTN file.\n")
139 test.must_match('test07' + _exe, " -y -c\nThis is a .fpp file.\n")
140 test.must_match('test08' + _exe, " -y -c\nThis is a .FPP file.\n")
141 test.must_match('test09' + _exe, " -y -c\nThis is a .f77 file.\n")
142 test.must_match('test10' + _exe, " -y -c\nThis is a .F77 file.\n")
143 test.must_match('test11' + _exe, " -y -c\nThis is a .f90 file.\n")
144 test.must_match('test12' + _exe, " -y -c\nThis is a .F90 file.\n")
145 test.must_match('test13' + _exe, " -x -c\nThis is a .f95 file.\n")
146 test.must_match('test14' + _exe, " -x -c\nThis is a .F95 file.\n")
147
148
149
150 g95 = test.detect('F95', 'g95')
151 FTN_LIB = TestSCons.fortran_lib
152
153 if g95:
154
155     test.write("wrapper.py",
156 """import os
157 import string
158 import sys
159 open('%s', 'wb').write("wrapper.py\\n")
160 os.system(string.join(sys.argv[1:], " "))
161 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
162
163     test.write('SConstruct', """
164 foo = Environment(LIBS = %s)
165 f95 = foo.Dictionary('F95')
166 bar = foo.Copy(F95 = r'%s wrapper.py ' + f95, F95FLAGS = '-Ix')
167 foo.Program(target = 'foo', source = 'foo.f')
168 bar.Program(target = 'bar', source = 'bar.f')
169 """ % (FTN_LIB, python))
170
171     test.write('foo.f', r"""
172       PROGRAM FOO
173       PRINT *,'foo.f'
174       STOP
175       END
176 """)
177
178     test.write('bar.f', r"""
179       PROGRAM BAR
180       PRINT *,'bar.f'
181       STOP
182       END
183 """)
184
185
186     test.run(arguments = 'foo' + _exe, stderr = None)
187
188     test.run(program = test.workpath('foo'), stdout =  " foo.f\n")
189
190     test.must_not_exist('wrapper.out')
191
192     test.run(arguments = 'bar' + _exe)
193
194     test.run(program = test.workpath('bar'), stdout =  " bar.f\n")
195
196     test.must_match('wrapper.out', "wrapper.py\n")
197
198 test.pass_test()