86f1087444fb0e67afdfcaf4620d2c60b6c59d11
[scons.git] / test / SHF77.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2001, 2002 Steven Knight
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 = sys.executable
33
34 if sys.platform == 'win32':
35     _obj = '.obj'
36 else:
37     _obj = '.o'
38
39 test = TestSCons.TestSCons()
40
41
42
43 if sys.platform == 'win32':
44
45     test.write('myg77.py', r"""
46 import sys
47 args = sys.argv[1:]
48 inf = None
49 while args:
50     a = args[0]
51     args = args[1:]
52     if a[0] != '/':
53         if not inf:
54             inf = a
55         continue
56     if a[:3] == '/Fo': out = a[3:]
57 infile = open(inf, 'rb')
58 outfile = open(out, 'wb')
59 for l in infile.readlines():
60     if l[:4] != '#g77':
61         outfile.write(l)
62 sys.exit(0)
63 """)
64
65 else:
66
67     test.write('myg77.py', r"""
68 import getopt
69 import sys
70 opts, args = getopt.getopt(sys.argv[1:], 'cf:o:')
71 for opt, arg in opts:
72     if opt == '-o': out = arg
73 infile = open(args[0], 'rb')
74 outfile = open(out, 'wb')
75 for l in infile.readlines():
76     if l[:4] != '#g77':
77         outfile.write(l)
78 sys.exit(0)
79 """)
80
81
82
83 test.write('SConstruct', """
84 env = Environment(SHF77 = r'%s myg77.py')
85 env.SharedObject(target = 'test1', source = 'test1.f')
86 env.SharedObject(target = 'test2', source = 'test2.for')
87 env.SharedObject(target = 'test3', source = 'test3.FOR')
88 env.SharedObject(target = 'test4', source = 'test4.F')
89 env.SharedObject(target = 'test5', source = 'test5.fpp')
90 env.SharedObject(target = 'test6', source = 'test6.FPP')
91 """ % python)
92
93 test.write('test1.f', r"""This is a .f file.
94 #g77
95 """)
96
97 test.write('test2.for', r"""This is a .for file.
98 #g77
99 """)
100
101 test.write('test3.FOR', r"""This is a .FOR file.
102 #g77
103 """)
104
105 test.write('test4.F', r"""This is a .F file.
106 #g77
107 """)
108
109 test.write('test5.fpp', r"""This is a .fpp file.
110 #g77
111 """)
112
113 test.write('test6.FPP', r"""This is a .FPP file.
114 #g77
115 """)
116
117 test.run(arguments = '.', stderr = None)
118
119 test.fail_test(test.read('test1' + _obj) != "This is a .f file.\n")
120
121 test.fail_test(test.read('test2' + _obj) != "This is a .for file.\n")
122
123 test.fail_test(test.read('test3' + _obj) != "This is a .FOR file.\n")
124
125 test.fail_test(test.read('test4' + _obj) != "This is a .F file.\n")
126
127 test.fail_test(test.read('test5' + _obj) != "This is a .fpp file.\n")
128
129 test.fail_test(test.read('test6' + _obj) != "This is a .FPP file.\n")
130
131
132
133 g77 = test.where_is('g77')
134
135 if g77:
136
137     test.write("wrapper.py",
138 """import os
139 import string
140 import sys
141 open('%s', 'wb').write("wrapper.py\\n")
142 os.system(string.join(sys.argv[1:], " "))
143 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
144
145     test.write('SConstruct', """
146 foo = Environment(LIBS = 'g2c')
147 shf77 = foo.Dictionary('SHF77')
148 bar = foo.Copy(SHF77 = r'%s wrapper.py ' + shf77)
149 foo.SharedObject(target = 'foo/foo', source = 'foo.f')
150 bar.SharedObject(target = 'bar/bar', source = 'bar.f')
151 """ % python)
152
153     test.write('foo.f', r"""
154       PROGRAM FOO
155       PRINT *,'foo.f'
156       STOP
157       END
158 """)
159
160     test.write('bar.f', r"""
161       PROGRAM BAR
162       PRINT *,'bar.f'
163       STOP
164       END
165 """)
166
167
168     test.run(arguments = 'foo', stderr = None)
169
170     test.fail_test(os.path.exists(test.workpath('wrapper.out')))
171
172     test.run(arguments = 'bar')
173
174     test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
175
176 test.pass_test()