diff options
author | Steven Knight <knight@baldmt.com> | 2004-07-29 13:28:56 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2004-07-29 13:28:56 (GMT) |
commit | 89330e2ad1be10e91444afc5b3979a23d1b853fe (patch) | |
tree | 0c94a5cf416437e4ed3a006df56865f9b2c5e8c7 /test/Fortran | |
parent | 39c71db4a22f03bf17a39fa84ff6abe84e4f0d51 (diff) | |
download | SCons-89330e2ad1be10e91444afc5b3979a23d1b853fe.zip SCons-89330e2ad1be10e91444afc5b3979a23d1b853fe.tar.gz SCons-89330e2ad1be10e91444afc5b3979a23d1b853fe.tar.bz2 |
Add Fortran 90/95 support. (Chris Murray)
Diffstat (limited to 'test/Fortran')
-rw-r--r-- | test/Fortran/F77.py | 228 | ||||
-rw-r--r-- | test/Fortran/F77FLAGS.py | 183 | ||||
-rw-r--r-- | test/Fortran/F77PATH.py | 202 | ||||
-rw-r--r-- | test/Fortran/F90.py | 194 | ||||
-rw-r--r-- | test/Fortran/F90FLAGS.py | 198 | ||||
-rw-r--r-- | test/Fortran/F90PATH.py | 219 | ||||
-rw-r--r-- | test/Fortran/F95.py | 194 | ||||
-rw-r--r-- | test/Fortran/F95FLAGS.py | 198 | ||||
-rw-r--r-- | test/Fortran/FORTRAN.py | 191 | ||||
-rw-r--r-- | test/Fortran/FORTRANFLAGS.py | 195 | ||||
-rw-r--r-- | test/Fortran/FORTRANPATH.py | 202 | ||||
-rw-r--r-- | test/Fortran/FORTRANSUFFIXES.py | 159 | ||||
-rw-r--r-- | test/Fortran/SHF77.py | 179 | ||||
-rw-r--r-- | test/Fortran/SHF77FLAGS.py | 150 | ||||
-rw-r--r-- | test/Fortran/SHF90.py | 152 | ||||
-rw-r--r-- | test/Fortran/SHF90FLAGS.py | 165 | ||||
-rw-r--r-- | test/Fortran/SHF95.py | 152 | ||||
-rw-r--r-- | test/Fortran/SHF95FLAGS.py | 165 | ||||
-rw-r--r-- | test/Fortran/SHFORTRAN.py | 150 | ||||
-rw-r--r-- | test/Fortran/SHFORTRANFLAGS.py | 163 |
20 files changed, 3639 insertions, 0 deletions
diff --git a/test/Fortran/F77.py b/test/Fortran/F77.py new file mode 100644 index 0000000..403f6b1 --- /dev/null +++ b/test/Fortran/F77.py @@ -0,0 +1,228 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + + + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'co:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + F77 = r'%s myfortran.py g77', + FORTRAN = r'%s myfortran.py fortran') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +env.Program(target = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env.Program(target = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +env2 = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + F77 = r'%s myfortran.py g77') +env2.Program(target = 'test21', source = 'test21.f') +env2.Program(target = 'test22', source = 'test22.F') +env2.Program(target = 'test23', source = 'test23.for') +env2.Program(target = 'test24', source = 'test24.FOR') +env2.Program(target = 'test25', source = 'test25.ftn') +env2.Program(target = 'test26', source = 'test26.FTN') +env2.Program(target = 'test27', source = 'test27.fpp') +env2.Program(target = 'test28', source = 'test28.FPP') +env2.Program(target = 'test29', source = 'test29.f77') +env2.Program(target = 'test30', source = 'test30.F77') +""" % (python, python, python, python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#link\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#link\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#g77\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#g77\n") +test.write('test11.f90', "This is a .f90 file.\n#link\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#link\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#link\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#link\n#fortran\n") + +test.write('test21.f', "This is a .f file.\n#link\n#g77\n") +test.write('test22.F', "This is a .F file.\n#link\n#g77\n") +test.write('test23.for', "This is a .for file.\n#link\n#g77\n") +test.write('test24.FOR', "This is a .FOR file.\n#link\n#g77\n") +test.write('test25.ftn', "This is a .ftn file.\n#link\n#g77\n") +test.write('test26.FTN', "This is a .FTN file.\n#link\n#g77\n") +test.write('test27.fpp', "This is a .fpp file.\n#link\n#g77\n") +test.write('test28.FPP', "This is a .FPP file.\n#link\n#g77\n") +test.write('test29.f77', "This is a .f77 file.\n#link\n#g77\n") +test.write('test30.F77', "This is a .F77 file.\n#link\n#g77\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, "This is a .f file.\n") +test.must_match('test02' + _exe, "This is a .F file.\n") +test.must_match('test03' + _exe, "This is a .for file.\n") +test.must_match('test04' + _exe, "This is a .FOR file.\n") +test.must_match('test05' + _exe, "This is a .ftn file.\n") +test.must_match('test06' + _exe, "This is a .FTN file.\n") +test.must_match('test07' + _exe, "This is a .fpp file.\n") +test.must_match('test08' + _exe, "This is a .FPP file.\n") +test.must_match('test09' + _exe, "This is a .f77 file.\n") +test.must_match('test10' + _exe, "This is a .F77 file.\n") +test.must_match('test11' + _exe, "This is a .f90 file.\n") +test.must_match('test12' + _exe, "This is a .F90 file.\n") +test.must_match('test13' + _exe, "This is a .f95 file.\n") +test.must_match('test14' + _exe, "This is a .F95 file.\n") + +test.must_match('test21' + _exe, "This is a .f file.\n") +test.must_match('test22' + _exe, "This is a .F file.\n") +test.must_match('test23' + _exe, "This is a .for file.\n") +test.must_match('test24' + _exe, "This is a .FOR file.\n") +test.must_match('test25' + _exe, "This is a .ftn file.\n") +test.must_match('test26' + _exe, "This is a .FTN file.\n") +test.must_match('test27' + _exe, "This is a .fpp file.\n") +test.must_match('test28' + _exe, "This is a .FPP file.\n") +test.must_match('test29' + _exe, "This is a .f77 file.\n") +test.must_match('test30' + _exe, "This is a .F77 file.\n") + + + +g77 = test.detect('F77', 'g77') +FTN_LIB = TestSCons.fortran_lib + +if g77: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f77 = foo.Dictionary('F77') +bar = foo.Copy(F77 = r'%s wrapper.py ' + f77) +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/F77FLAGS.py b/test/Fortran/F77FLAGS.py new file mode 100644 index 0000000..b1de112 --- /dev/null +++ b/test/Fortran/F77FLAGS.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myg77.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'co:x') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:4] != '#g77': + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + F77 = r'%s myg77.py', + F77FLAGS = '-x') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +""" % (python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#g77\n") +test.write('test02.F', "This is a .F file.\n#link\n#g77\n") +test.write('test03.for', "This is a .for file.\n#link\n#g77\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#g77\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#g77\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#g77\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#g77\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#g77\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#g77\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#g77\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -x -c\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -x -c\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -x -c\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -x -c\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -x -c\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -x -c\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -x -c\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -x -c\nThis is a .FPP file.\n") +test.must_match('test09' + _exe, " -x -c\nThis is a .f77 file.\n") +test.must_match('test10' + _exe, " -x -c\nThis is a .F77 file.\n") + + + +g77 = test.detect('F77', 'g77') +FTN_LIB = TestSCons.fortran_lib + +if g77: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f77 = foo.Dictionary('F77') +bar = foo.Copy(F77 = r'%s wrapper.py ' + f77, F77FLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/F77PATH.py b/test/Fortran/F77PATH.py new file mode 100644 index 0000000..e88cdc7 --- /dev/null +++ b/test/Fortran/F77PATH.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import sys +import TestSCons + +_exe = TestSCons._exe +FTN_LIB = TestSCons.fortran_lib +prog = 'prog' + _exe +subdir_prog = os.path.join('subdir', 'prog' + _exe) +variant_prog = os.path.join('variant', 'prog' + _exe) + +args = prog + ' ' + subdir_prog + ' ' + variant_prog + +test = TestSCons.TestSCons() + +if not test.detect('F77', 'g77'): + test.pass_test() + +test.subdir('include', 'subdir', ['subdir', 'include'], 'inc2') + +test.write('SConstruct', """ +env = Environment(F77PATH = ['$FOO'], LIBS = %s, FOO='include') +obj = env.Object(target='foobar/prog', source='subdir/prog.f') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +BuildDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F77PATH=[include], LIBS = %s) +SConscript('variant/SConscript', "env") +""" % (FTN_LIB, FTN_LIB)) + +test.write(['subdir', 'SConscript'], +""" +Import("env") +env.Program(target='prog', source='prog.f') +""") + +test.write(['include', 'foo.f'], +r""" + PRINT *, 'include/foo.f 1' + INCLUDE 'bar.f' +""") + +test.write(['include', 'bar.f'], +r""" + PRINT *, 'include/bar.f 1' +""") + +test.write(['subdir', 'prog.f'], +r""" + PROGRAM PROG + PRINT *, 'subdir/prog.f' + include 'foo.f' + STOP + END +""") + +test.write(['subdir', 'include', 'foo.f'], +r""" + PRINT *, 'subdir/include/foo.f 1' + INCLUDE 'bar.f' +""") + +test.write(['subdir', 'include', 'bar.f'], +r""" + PRINT *, 'subdir/include/bar.f 1' +""") + + + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n include/foo.f 1\n include/bar.f 1\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 1\n include/bar.f 1\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f')) + +test.up_to_date(arguments = args) + +test.write(['include', 'foo.f'], +r""" + PRINT *, 'include/foo.f 2' + INCLUDE 'bar.f' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 1\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 1\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f')) + +test.up_to_date(arguments = args) + +# +test.write(['include', 'bar.f'], +r""" + PRINT *, 'include/bar.f 2' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 2\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 2\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f')) + +test.up_to_date(arguments = args) + +# Change F77PATH and make sure we don't rebuild because of it. +test.write('SConstruct', """ +env = Environment(F77PATH = Split('inc2 include'), LIBS = %s) +obj = env.Object(target='foobar/prog', source='subdir/prog.f') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +BuildDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F77PATH=['inc2', include], LIBS = %s) +SConscript('variant/SConscript', "env") +""" % (FTN_LIB, FTN_LIB)) + +test.up_to_date(arguments = args) + +# +test.write(['inc2', 'foo.f'], +r""" + PRINT *, 'inc2/foo.f 1' + INCLUDE 'bar.f' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n inc2/foo.f 1\n include/bar.f 2\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 2\n") + +test.up_to_date(arguments = args) + +# Check that a null-string F77PATH doesn't blow up. +test.write('SConstruct', """ +env = Environment(F77PATH = '', LIBS = %s) +env.Library('foo', source = 'empty.f') +""" % FTN_LIB) + +test.write('empty.f', '') + +test.run(arguments = '.') + +test.pass_test() diff --git a/test/Fortran/F90.py b/test/Fortran/F90.py new file mode 100644 index 0000000..4167410 --- /dev/null +++ b/test/Fortran/F90.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + + + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +length = len(comment) +opts, args = getopt.getopt(sys.argv[2:], 'co:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:length] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + F90 = r'%s myfortran.py f90', + FORTRAN = r'%s myfortran.py fortran') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +env.Program(target = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env.Program(target = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % (python, python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#link\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#link\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#link\n#f90\n") +test.write('test12.F90', "This is a .F90 file.\n#link\n#f90\n") +test.write('test13.f95', "This is a .f95 file.\n#link\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#link\n#fortran\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, "This is a .f file.\n") +test.must_match('test02' + _exe, "This is a .F file.\n") +test.must_match('test03' + _exe, "This is a .for file.\n") +test.must_match('test04' + _exe, "This is a .FOR file.\n") +test.must_match('test05' + _exe, "This is a .ftn file.\n") +test.must_match('test06' + _exe, "This is a .FTN file.\n") +test.must_match('test07' + _exe, "This is a .fpp file.\n") +test.must_match('test08' + _exe, "This is a .FPP file.\n") +test.must_match('test09' + _exe, "This is a .f77 file.\n") +test.must_match('test10' + _exe, "This is a .F77 file.\n") +test.must_match('test11' + _exe, "This is a .f90 file.\n") +test.must_match('test12' + _exe, "This is a .F90 file.\n") +test.must_match('test13' + _exe, "This is a .f95 file.\n") +test.must_match('test14' + _exe, "This is a .F95 file.\n") + + + +g90 = test.detect('F90', 'g90') +FTN_LIB = TestSCons.fortran_lib + +if g90: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f90 = foo.Dictionary('F90') +bar = foo.Copy(F90 = r'%s wrapper.py ' + f90) +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/F90FLAGS.py b/test/Fortran/F90FLAGS.py new file mode 100644 index 0000000..f598986 --- /dev/null +++ b/test/Fortran/F90FLAGS.py @@ -0,0 +1,198 @@ + +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'co:xy') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + F90 = r'%s myfortran.py g90', + F90FLAGS = '-x', + FORTRAN = r'%s myfortran.py fortran', + FORTRANFLAGS = '-y') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +env.Program(target = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env.Program(target = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % (python, python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#link\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#link\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#link\n#g90\n") +test.write('test12.F90', "This is a .F90 file.\n#link\n#g90\n") +test.write('test13.f95', "This is a .f95 file.\n#link\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#link\n#fortran\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -y -c\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -y -c\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -y -c\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -y -c\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -y -c\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -y -c\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -y -c\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -y -c\nThis is a .FPP file.\n") +test.must_match('test09' + _exe, " -y -c\nThis is a .f77 file.\n") +test.must_match('test10' + _exe, " -y -c\nThis is a .F77 file.\n") +test.must_match('test11' + _exe, " -x -c\nThis is a .f90 file.\n") +test.must_match('test12' + _exe, " -x -c\nThis is a .F90 file.\n") +test.must_match('test13' + _exe, " -y -c\nThis is a .f95 file.\n") +test.must_match('test14' + _exe, " -y -c\nThis is a .F95 file.\n") + + + +g90 = test.detect('F90', 'g90') +FTN_LIB = TestSCons.fortran_lib + +if g90: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f90 = foo.Dictionary('F90') +bar = foo.Copy(F90 = r'%s wrapper.py ' + f90, F90FLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/F90PATH.py b/test/Fortran/F90PATH.py new file mode 100644 index 0000000..7dbbf2b --- /dev/null +++ b/test/Fortran/F90PATH.py @@ -0,0 +1,219 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import os.path +import sys +import TestSCons + +_exe = TestSCons._exe +FTN_LIB = TestSCons.fortran_lib +prog = 'prog' + _exe +subdir_prog = os.path.join('subdir', 'prog' + _exe) +variant_prog = os.path.join('variant', 'prog' + _exe) + +args = prog + ' ' + subdir_prog + ' ' + variant_prog + +test = TestSCons.TestSCons() + +#if not test.detect('F90', 'g90'): +# test.pass_test() +base = '/opt/intel_fc_80' +F90 = os.path.join(base, 'bin', 'ifort') +LIBPATH = os.path.join(base, 'lib') +LIBS = ['irc'] +if not os.path.exists(F90): + sys.stderr.write('No (hard-coded) F90 compiler %s\n' % F90) + test.no_result(1) + +os.environ['LD_LIBRARY_PATH'] = LIBPATH + +test.subdir('include', 'subdir', ['subdir', 'include'], 'inc2') + +test.write('SConstruct', """ +env = Environment(F90 = r'%s', + F90PATH = ['$FOO'], + LINK = '$F90', + LIBPATH = %s, + LIBS = %s, + FOO='include') +obj = env.Object(target='foobar/prog', source='subdir/prog.f90') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +BuildDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F90 = r'%s', + F90PATH=[include], + LINK = '$F90', + LIBPATH = %s, + LIBS = %s) +SConscript('variant/SConscript', "env") +""" % (F90, repr(LIBPATH), LIBS, F90, repr(LIBPATH), LIBS)) + +test.write(['subdir', 'SConscript'], +""" +Import("env") +env.Program(target='prog', source='prog.f90') +""") + +test.write(['include', 'foo.f90'], +r""" + PRINT *, 'include/foo.f90 1' + INCLUDE 'bar.f90' +""") + +test.write(['include', 'bar.f90'], +r""" + PRINT *, 'include/bar.f90 1' +""") + +test.write(['subdir', 'prog.f90'], +r""" + PROGRAM PROG + PRINT *, 'subdir/prog.f90' + include 'foo.f90' + STOP + END +""") + +test.write(['subdir', 'include', 'foo.f90'], +r""" + PRINT *, 'subdir/include/foo.f90 1' + INCLUDE 'bar.f90' +""") + +test.write(['subdir', 'include', 'bar.f90'], +r""" + PRINT *, 'subdir/include/bar.f90 1' +""") + + + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f90\n include/foo.f90 1\n include/bar.f90 1\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f90\n subdir/include/foo.f90 1\n subdir/include/bar.f90 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f90\n include/foo.f90 1\n include/bar.f90 1\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f90')) + +test.up_to_date(arguments = args) + +test.write(['include', 'foo.f90'], +r""" + PRINT *, 'include/foo.f90 2' + INCLUDE 'bar.f90' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f90\n include/foo.f90 2\n include/bar.f90 1\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f90\n subdir/include/foo.f90 1\n subdir/include/bar.f90 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f90\n include/foo.f90 2\n include/bar.f90 1\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f90')) + +test.up_to_date(arguments = args) + +# +test.write(['include', 'bar.f90'], +r""" + PRINT *, 'include/bar.f90 2' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f90\n include/foo.f90 2\n include/bar.f90 2\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f90\n subdir/include/foo.f90 1\n subdir/include/bar.f90 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f90\n include/foo.f90 2\n include/bar.f90 2\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f90')) + +test.up_to_date(arguments = args) + +# Change F90PATH and make sure we don't rebuild because of it. +test.write('SConstruct', """ +env = Environment(F90 = r'%s', + F90PATH = Split('inc2 include'), + LINK = '$F90', + LIBPATH = %s, + LIBS = %s) +obj = env.Object(target='foobar/prog', source='subdir/prog.f90') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +BuildDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F90 = r'%s', + F90PATH=['inc2', include], + LINK = '$F90', + LIBPATH = %s, + LIBS = %s) +SConscript('variant/SConscript', "env") +""" % (F90, repr(LIBPATH), LIBS, F90, repr(LIBPATH), LIBS)) + +test.up_to_date(arguments = args) + +# +test.write(['inc2', 'foo.f90'], +r""" + PRINT *, 'inc2/foo.f90 1' + INCLUDE 'bar.f90' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f90\n inc2/foo.f90 1\n include/bar.f90 2\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f90\n subdir/include/foo.f90 1\n subdir/include/bar.f90 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f90\n include/foo.f90 2\n include/bar.f90 2\n") + +test.up_to_date(arguments = args) + +test.pass_test() diff --git a/test/Fortran/F95.py b/test/Fortran/F95.py new file mode 100644 index 0000000..23ed547 --- /dev/null +++ b/test/Fortran/F95.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + + + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +length = len(comment) +opts, args = getopt.getopt(sys.argv[2:], 'co:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:length] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + F95 = r'%s myfortran.py f95', + FORTRAN = r'%s myfortran.py fortran') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +env.Program(target = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env.Program(target = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % (python, python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#link\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#link\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#link\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#link\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#link\n#f95\n") +test.write('test14.F95', "This is a .F95 file.\n#link\n#f95\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, "This is a .f file.\n") +test.must_match('test02' + _exe, "This is a .F file.\n") +test.must_match('test03' + _exe, "This is a .for file.\n") +test.must_match('test04' + _exe, "This is a .FOR file.\n") +test.must_match('test05' + _exe, "This is a .ftn file.\n") +test.must_match('test06' + _exe, "This is a .FTN file.\n") +test.must_match('test07' + _exe, "This is a .fpp file.\n") +test.must_match('test08' + _exe, "This is a .FPP file.\n") +test.must_match('test09' + _exe, "This is a .f77 file.\n") +test.must_match('test10' + _exe, "This is a .F77 file.\n") +test.must_match('test11' + _exe, "This is a .f90 file.\n") +test.must_match('test12' + _exe, "This is a .F90 file.\n") +test.must_match('test13' + _exe, "This is a .f95 file.\n") +test.must_match('test14' + _exe, "This is a .F95 file.\n") + + + +g95 = test.detect('F95', 'g95') +FTN_LIB = TestSCons.fortran_lib + +if g95: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f95 = foo.Dictionary('F95') +bar = foo.Copy(F95 = r'%s wrapper.py ' + f95) +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/F95FLAGS.py b/test/Fortran/F95FLAGS.py new file mode 100644 index 0000000..1528a32 --- /dev/null +++ b/test/Fortran/F95FLAGS.py @@ -0,0 +1,198 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'co:xy') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + F95 = r'%s myfortran.py g95', + F95FLAGS = '-x', + FORTRAN = r'%s myfortran.py fortran', + FORTRANFLAGS = '-y') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +env.Program(target = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env.Program(target = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % (python, python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#link\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#link\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#link\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#link\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#link\n#g95\n") +test.write('test14.F95', "This is a .F95 file.\n#link\n#g95\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -y -c\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -y -c\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -y -c\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -y -c\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -y -c\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -y -c\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -y -c\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -y -c\nThis is a .FPP file.\n") +test.must_match('test09' + _exe, " -y -c\nThis is a .f77 file.\n") +test.must_match('test10' + _exe, " -y -c\nThis is a .F77 file.\n") +test.must_match('test11' + _exe, " -y -c\nThis is a .f90 file.\n") +test.must_match('test12' + _exe, " -y -c\nThis is a .F90 file.\n") +test.must_match('test13' + _exe, " -x -c\nThis is a .f95 file.\n") +test.must_match('test14' + _exe, " -x -c\nThis is a .F95 file.\n") + + + +g95 = test.detect('F95', 'g95') +FTN_LIB = TestSCons.fortran_lib + +if g95: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f95 = foo.Dictionary('F95') +bar = foo.Copy(F95 = r'%s wrapper.py ' + f95, F95FLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/FORTRAN.py b/test/Fortran/FORTRAN.py new file mode 100644 index 0000000..0195558 --- /dev/null +++ b/test/Fortran/FORTRAN.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + + + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myg77.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'co:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:4] != '#g77': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + FORTRAN = r'%s myg77.py') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +env.Program(target = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env.Program(target = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % (python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#g77\n") +test.write('test02.F', "This is a .F file.\n#link\n#g77\n") +test.write('test03.for', "This is a .for file.\n#link\n#g77\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#g77\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#g77\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#g77\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#g77\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#g77\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#g77\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#g77\n") +test.write('test11.f90', "This is a .f90 file.\n#link\n#g77\n") +test.write('test12.F90', "This is a .F90 file.\n#link\n#g77\n") +test.write('test13.f95', "This is a .f95 file.\n#link\n#g77\n") +test.write('test14.F95', "This is a .F95 file.\n#link\n#g77\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, "This is a .f file.\n") +test.must_match('test02' + _exe, "This is a .F file.\n") +test.must_match('test03' + _exe, "This is a .for file.\n") +test.must_match('test04' + _exe, "This is a .FOR file.\n") +test.must_match('test05' + _exe, "This is a .ftn file.\n") +test.must_match('test06' + _exe, "This is a .FTN file.\n") +test.must_match('test07' + _exe, "This is a .fpp file.\n") +test.must_match('test08' + _exe, "This is a .FPP file.\n") +test.must_match('test09' + _exe, "This is a .f77 file.\n") +test.must_match('test10' + _exe, "This is a .F77 file.\n") +test.must_match('test11' + _exe, "This is a .f90 file.\n") +test.must_match('test12' + _exe, "This is a .F90 file.\n") +test.must_match('test13' + _exe, "This is a .f95 file.\n") +test.must_match('test14' + _exe, "This is a .F95 file.\n") + + + +g77 = test.detect('FORTRAN', 'g77') +FTN_LIB = TestSCons.fortran_lib + +if g77: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f77 = foo.Dictionary('FORTRAN') +bar = foo.Copy(FORTRAN = r'%s wrapper.py ' + f77) +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/FORTRANFLAGS.py b/test/Fortran/FORTRANFLAGS.py new file mode 100644 index 0000000..1bed2d0 --- /dev/null +++ b/test/Fortran/FORTRANFLAGS.py @@ -0,0 +1,195 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +if sys.platform == 'win32': + + test.write('mylink.py', r""" +import string +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args = args[1:] + if string.lower(a[:5]) == '/out:': out = a[5:] +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +else: + + test.write('mylink.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:5] != '#link': + outfile.write(l) +sys.exit(0) +""") + +test.write('myfortran.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'co:x') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:8] != '#fortran': + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(LINK = r'%s mylink.py', + LINKFLAGS = [], + FORTRAN = r'%s myfortran.py', + FORTRANFLAGS = '-x') +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.for') +env.Program(target = 'test04', source = 'test04.FOR') +env.Program(target = 'test05', source = 'test05.ftn') +env.Program(target = 'test06', source = 'test06.FTN') +env.Program(target = 'test07', source = 'test07.fpp') +env.Program(target = 'test08', source = 'test08.FPP') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +env.Program(target = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env.Program(target = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % (python, python)) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#link\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#link\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#link\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#link\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#link\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#link\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#link\n#fortran\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -x -c\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -x -c\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -x -c\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -x -c\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -x -c\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -x -c\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -x -c\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -x -c\nThis is a .FPP file.\n") +test.must_match('test09' + _exe, " -x -c\nThis is a .f77 file.\n") +test.must_match('test10' + _exe, " -x -c\nThis is a .F77 file.\n") +test.must_match('test11' + _exe, " -x -c\nThis is a .f90 file.\n") +test.must_match('test12' + _exe, " -x -c\nThis is a .F90 file.\n") +test.must_match('test13' + _exe, " -x -c\nThis is a .f95 file.\n") +test.must_match('test14' + _exe, " -x -c\nThis is a .F95 file.\n") + + + +g77 = test.detect('FORTRAN', 'g77') +FTN_LIB = TestSCons.fortran_lib + +if g77: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +f77 = foo.Dictionary('FORTRAN') +bar = foo.Copy(FORTRAN = r'%s wrapper.py ' + f77, FORTRANFLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f\n") + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/FORTRANPATH.py b/test/Fortran/FORTRANPATH.py new file mode 100644 index 0000000..ec1b13e --- /dev/null +++ b/test/Fortran/FORTRANPATH.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import sys +import TestSCons + +_exe = TestSCons._exe +FTN_LIB = TestSCons.fortran_lib +prog = 'prog' + _exe +subdir_prog = os.path.join('subdir', 'prog' + _exe) +variant_prog = os.path.join('variant', 'prog' + _exe) + +args = prog + ' ' + subdir_prog + ' ' + variant_prog + +test = TestSCons.TestSCons() + +if not test.detect('F77', 'g77'): + test.pass_test() + +test.subdir('include', 'subdir', ['subdir', 'include'], 'inc2') + +test.write('SConstruct', """ +env = Environment(FORTRANPATH = ['$FOO'], LIBS = %s, FOO='include') +obj = env.Object(target='foobar/prog', source='subdir/prog.f') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +BuildDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(FORTRANPATH=[include], LIBS = %s) +SConscript('variant/SConscript', "env") +""" % (FTN_LIB, FTN_LIB)) + +test.write(['subdir', 'SConscript'], +""" +Import("env") +env.Program(target='prog', source='prog.f') +""") + +test.write(['include', 'foo.f'], +r""" + PRINT *, 'include/foo.f 1' + INCLUDE 'bar.f' +""") + +test.write(['include', 'bar.f'], +r""" + PRINT *, 'include/bar.f 1' +""") + +test.write(['subdir', 'prog.f'], +r""" + PROGRAM PROG + PRINT *, 'subdir/prog.f' + include 'foo.f' + STOP + END +""") + +test.write(['subdir', 'include', 'foo.f'], +r""" + PRINT *, 'subdir/include/foo.f 1' + INCLUDE 'bar.f' +""") + +test.write(['subdir', 'include', 'bar.f'], +r""" + PRINT *, 'subdir/include/bar.f 1' +""") + + + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n include/foo.f 1\n include/bar.f 1\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 1\n include/bar.f 1\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f')) + +test.up_to_date(arguments = args) + +test.write(['include', 'foo.f'], +r""" + PRINT *, 'include/foo.f 2' + INCLUDE 'bar.f' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 1\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 1\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f')) + +test.up_to_date(arguments = args) + +# +test.write(['include', 'bar.f'], +r""" + PRINT *, 'include/bar.f 2' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 2\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 2\n") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f')) + +test.up_to_date(arguments = args) + +# Change FORTRANPATH and make sure we don't rebuild because of it. +test.write('SConstruct', """ +env = Environment(FORTRANPATH = Split('inc2 include'), LIBS = %s) +obj = env.Object(target='foobar/prog', source='subdir/prog.f') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +BuildDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(FORTRANPATH=['inc2', include], LIBS = %s) +SConscript('variant/SConscript', "env") +""" % (FTN_LIB, FTN_LIB)) + +test.up_to_date(arguments = args) + +# +test.write(['inc2', 'foo.f'], +r""" + PRINT *, 'inc2/foo.f 1' + INCLUDE 'bar.f' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = " subdir/prog.f\n inc2/foo.f 1\n include/bar.f 2\n") + +test.run(program = test.workpath(subdir_prog), + stdout = " subdir/prog.f\n subdir/include/foo.f 1\n subdir/include/bar.f 1\n") + +test.run(program = test.workpath(variant_prog), + stdout = " subdir/prog.f\n include/foo.f 2\n include/bar.f 2\n") + +test.up_to_date(arguments = args) + +# Check that a null-string FORTRANPATH doesn't blow up. +test.write('SConstruct', """ +env = Environment(FORTRANPATH = '', LIBS = %s) +env.Library('foo', source = 'empty.f') +""" % FTN_LIB) + +test.write('empty.f', '') + +test.run(arguments = '.') + +test.pass_test() diff --git a/test/Fortran/FORTRANSUFFIXES.py b/test/Fortran/FORTRANSUFFIXES.py new file mode 100644 index 0000000..c172f7a --- /dev/null +++ b/test/Fortran/FORTRANSUFFIXES.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the ability to scan additional filesuffixes added to $FORTRANSUFFIXES. +""" + +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() + +test.write('myfc.py', r""" +import string +import sys +def do_file(outf, inf): + for line in open(inf, 'rb').readlines(): + if line[:15] == " INCLUDE '": + do_file(outf, line[15:-2]) + else: + outf.write(line) +outf = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + do_file(outf, f) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(FORTRANPATH = ['.'], + FORTRAN = r'%s myfc.py', + FORTRANCOM = '$FORTRAN $TARGET $SOURCES', + OBJSUFFIX = '.o') +env.Append(FORTRANSUFFIXES = ['.x']) +env.Object(target = 'test1', source = 'test1.f') +env.InstallAs('test1_f', 'test1.f') +env.InstallAs('test1_h', 'test1.h') +env.InstallAs('test1_x', 'test1.x') +""" % (python,)) + +test.write('test1.f', """\ + test1.f 1 + INCLUDE 'test1.h' + INCLUDE 'test1.x' +""") + +test.write('test1.h', """\ + test1.h 1 + INCLUDE 'foo.h' +""") + +test.write('test1.x', """\ + test1.x 1 + INCLUDE 'foo.h' +""") + +test.write('foo.h', """\ + foo.h 1 +""") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s myfc.py test1.o test1.f +Install file: "test1.f" as "test1_f" +Install file: "test1.h" as "test1_h" +Install file: "test1.x" as "test1_x" +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 1 + foo.h 1 + test1.x 1 + foo.h 1 +""") + +test.up_to_date(arguments='.') + +test.write('foo.h', """\ + foo.h 2 +""") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s myfc.py test1.o test1.f +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 1 + foo.h 2 + test1.x 1 + foo.h 2 +""") + +test.up_to_date(arguments='.') + +test.write('test1.x', """\ + test1.x 2 + INCLUDE 'foo.h' +""") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s myfc.py test1.o test1.f +Install file: "test1.x" as "test1_x" +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 1 + foo.h 2 + test1.x 2 + foo.h 2 +""") + +test.up_to_date(arguments='.') + +test.write('test1.h', """\ + test1.h 2 + INCLUDE 'foo.h' +""") + +test.run(arguments='.', stdout=test.wrap_stdout("""\ +%s myfc.py test1.o test1.f +Install file: "test1.h" as "test1_h" +""" % (python,))) + +test.must_match('test1.o', """\ + test1.f 1 + test1.h 2 + foo.h 2 + test1.x 2 + foo.h 2 +""") + +test.up_to_date(arguments='.') + +test.pass_test() diff --git a/test/Fortran/SHF77.py b/test/Fortran/SHF77.py new file mode 100644 index 0000000..2f259cd --- /dev/null +++ b/test/Fortran/SHF77.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_obj = TestSCons._shobj + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'cf:o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF77 = r'%s myfortran.py g77', + SHFORTRAN = r'%s myfortran.py fortran') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +env.SharedObject(target = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env.SharedObject(target = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +env2 = Environment(SHF77 = r'%s myfortran.py g77') +env2.SharedObject(target = 'test21', source = 'test21.f') +env2.SharedObject(target = 'test22', source = 'test22.F') +env2.SharedObject(target = 'test23', source = 'test23.for') +env2.SharedObject(target = 'test24', source = 'test24.FOR') +env2.SharedObject(target = 'test25', source = 'test25.ftn') +env2.SharedObject(target = 'test26', source = 'test26.FTN') +env2.SharedObject(target = 'test27', source = 'test27.fpp') +env2.SharedObject(target = 'test28', source = 'test28.FPP') +""" % (python, python, python)) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#g77\n") +test.write('test10.F77', "This is a .F77 file.\n#g77\n") +test.write('test11.f90', "This is a .f90 file.\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#fortran\n") + +test.write('test21.f', "This is a .f file.\n#g77\n") +test.write('test22.F', "This is a .F file.\n#g77\n") +test.write('test23.for', "This is a .for file.\n#g77\n") +test.write('test24.FOR', "This is a .FOR file.\n#g77\n") +test.write('test25.ftn', "This is a .ftn file.\n#g77\n") +test.write('test26.FTN', "This is a .FTN file.\n#g77\n") +test.write('test27.fpp', "This is a .fpp file.\n#g77\n") +test.write('test28.FPP', "This is a .FPP file.\n#g77\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, "This is a .f file.\n") +test.must_match('test02' + _obj, "This is a .F file.\n") +test.must_match('test03' + _obj, "This is a .for file.\n") +test.must_match('test04' + _obj, "This is a .FOR file.\n") +test.must_match('test05' + _obj, "This is a .ftn file.\n") +test.must_match('test06' + _obj, "This is a .FTN file.\n") +test.must_match('test07' + _obj, "This is a .fpp file.\n") +test.must_match('test08' + _obj, "This is a .FPP file.\n") +test.must_match('test09' + _obj, "This is a .f77 file.\n") +test.must_match('test10' + _obj, "This is a .F77 file.\n") +test.must_match('test11' + _obj, "This is a .f90 file.\n") +test.must_match('test12' + _obj, "This is a .F90 file.\n") +test.must_match('test13' + _obj, "This is a .f95 file.\n") +test.must_match('test14' + _obj, "This is a .F95 file.\n") + +test.must_match('test21' + _obj, "This is a .f file.\n") +test.must_match('test22' + _obj, "This is a .F file.\n") +test.must_match('test23' + _obj, "This is a .for file.\n") +test.must_match('test24' + _obj, "This is a .FOR file.\n") +test.must_match('test25' + _obj, "This is a .ftn file.\n") +test.must_match('test26' + _obj, "This is a .FTN file.\n") +test.must_match('test27' + _obj, "This is a .fpp file.\n") +test.must_match('test28' + _obj, "This is a .FPP file.\n") + + + +g77 = test.detect('F77', 'g77') + +if g77: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = 'g2c') +shf77 = foo.Dictionary('SHF77') +bar = foo.Copy(SHF77 = r'%s wrapper.py ' + shf77) +foo.SharedObject(target = 'foo/foo', source = 'foo.f') +bar.SharedObject(target = 'bar/bar', source = 'bar.f') +""" % python) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/SHF77FLAGS.py b/test/Fortran/SHF77FLAGS.py new file mode 100644 index 0000000..1595aee --- /dev/null +++ b/test/Fortran/SHF77FLAGS.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +if sys.platform == 'win32': + _obj = '.obj' +else: + if string.find(sys.platform, 'irix') > -1: + _obj = '.o' + else: + _obj = '.os' + +test = TestSCons.TestSCons() + + + +test.write('myg77.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'co:x') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:4] != '#g77': + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF77 = r'%s myg77.py', + SHF77FLAGS = '-x') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +""" % (python,)) + +test.write('test01.f', "This is a .f file.\n#g77\n") +test.write('test02.F', "This is a .F file.\n#g77\n") +test.write('test03.for', "This is a .for file.\n#g77\n") +test.write('test04.FOR', "This is a .FOR file.\n#g77\n") +test.write('test05.ftn', "This is a .ftn file.\n#g77\n") +test.write('test06.FTN', "This is a .FTN file.\n#g77\n") +test.write('test07.fpp', "This is a .fpp file.\n#g77\n") +test.write('test08.FPP', "This is a .FPP file.\n#g77\n") +test.write('test09.f77', "This is a .f77 file.\n#g77\n") +test.write('test10.F77', "This is a .F77 file.\n#g77\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, " -x -c\nThis is a .f file.\n") +test.must_match('test02' + _obj, " -x -c\nThis is a .F file.\n") +test.must_match('test03' + _obj, " -x -c\nThis is a .for file.\n") +test.must_match('test04' + _obj, " -x -c\nThis is a .FOR file.\n") +test.must_match('test05' + _obj, " -x -c\nThis is a .ftn file.\n") +test.must_match('test06' + _obj, " -x -c\nThis is a .FTN file.\n") +test.must_match('test07' + _obj, " -x -c\nThis is a .fpp file.\n") +test.must_match('test08' + _obj, " -x -c\nThis is a .FPP file.\n") +test.must_match('test09' + _obj, " -x -c\nThis is a .f77 file.\n") +test.must_match('test10' + _obj, " -x -c\nThis is a .F77 file.\n") + + + +g77 = test.detect('F77', 'g77') +FTN_LIB = TestSCons.fortran_lib + +if g77: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +shf77 = foo.Dictionary('SHF77') +bar = foo.Copy(SHF77 = r'%s wrapper.py ' + shf77, SHF77FLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/SHF90.py b/test/Fortran/SHF90.py new file mode 100644 index 0000000..b14c81d --- /dev/null +++ b/test/Fortran/SHF90.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_obj = TestSCons._shobj + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'cf:o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF90 = r'%s myfortran.py g90', + SHFORTRAN = r'%s myfortran.py fortran') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +env.SharedObject(target = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env.SharedObject(target = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % (python, python)) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#g90\n") +test.write('test12.F90', "This is a .F90 file.\n#g90\n") +test.write('test13.f95', "This is a .f95 file.\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#fortran\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, "This is a .f file.\n") +test.must_match('test02' + _obj, "This is a .F file.\n") +test.must_match('test03' + _obj, "This is a .for file.\n") +test.must_match('test04' + _obj, "This is a .FOR file.\n") +test.must_match('test05' + _obj, "This is a .ftn file.\n") +test.must_match('test06' + _obj, "This is a .FTN file.\n") +test.must_match('test07' + _obj, "This is a .fpp file.\n") +test.must_match('test08' + _obj, "This is a .FPP file.\n") +test.must_match('test09' + _obj, "This is a .f77 file.\n") +test.must_match('test10' + _obj, "This is a .F77 file.\n") +test.must_match('test11' + _obj, "This is a .f90 file.\n") +test.must_match('test12' + _obj, "This is a .F90 file.\n") +test.must_match('test13' + _obj, "This is a .f95 file.\n") +test.must_match('test14' + _obj, "This is a .F95 file.\n") + + + +g90 = test.detect('F90', 'g90') + +if g90: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = 'g2c') +shf90 = foo.Dictionary('SHF90') +bar = foo.Copy(SHF90 = r'%s wrapper.py ' + shf90) +foo.SharedObject(target = 'foo/foo', source = 'foo.f') +bar.SharedObject(target = 'bar/bar', source = 'bar.f') +""" % python) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/SHF90FLAGS.py b/test/Fortran/SHF90FLAGS.py new file mode 100644 index 0000000..5bb3f69 --- /dev/null +++ b/test/Fortran/SHF90FLAGS.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +if sys.platform == 'win32': + _obj = '.obj' +else: + if string.find(sys.platform, 'irix') > -1: + _obj = '.o' + else: + _obj = '.os' + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'co:xy') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF90 = r'%s myfortran.py g90', + SHF90FLAGS = '-x', + SHFORTRAN = r'%s myfortran.py fortran', + SHFORTRANFLAGS = '-y') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +env.SharedObject(target = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env.SharedObject(target = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % (python, python)) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#g90\n") +test.write('test12.F90', "This is a .F90 file.\n#g90\n") +test.write('test13.f95', "This is a .f95 file.\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#fortran\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, " -y -c\nThis is a .f file.\n") +test.must_match('test02' + _obj, " -y -c\nThis is a .F file.\n") +test.must_match('test03' + _obj, " -y -c\nThis is a .for file.\n") +test.must_match('test04' + _obj, " -y -c\nThis is a .FOR file.\n") +test.must_match('test05' + _obj, " -y -c\nThis is a .ftn file.\n") +test.must_match('test06' + _obj, " -y -c\nThis is a .FTN file.\n") +test.must_match('test07' + _obj, " -y -c\nThis is a .fpp file.\n") +test.must_match('test08' + _obj, " -y -c\nThis is a .FPP file.\n") +test.must_match('test09' + _obj, " -y -c\nThis is a .f77 file.\n") +test.must_match('test10' + _obj, " -y -c\nThis is a .F77 file.\n") +test.must_match('test11' + _obj, " -x -c\nThis is a .f90 file.\n") +test.must_match('test12' + _obj, " -x -c\nThis is a .F90 file.\n") +test.must_match('test13' + _obj, " -y -c\nThis is a .f95 file.\n") +test.must_match('test14' + _obj, " -y -c\nThis is a .F95 file.\n") + + + +g90 = test.detect('F90', 'g90') +FTN_LIB = TestSCons.fortran_lib + +if g90: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +shf90 = foo.Dictionary('SHF90') +bar = foo.Copy(SHF90 = r'%s wrapper.py ' + shf90, SHF90FLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/SHF95.py b/test/Fortran/SHF95.py new file mode 100644 index 0000000..c95b366 --- /dev/null +++ b/test/Fortran/SHF95.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_obj = TestSCons._shobj + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'cf:o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF95 = r'%s myfortran.py g95', + SHFORTRAN = r'%s myfortran.py fortran') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +env.SharedObject(target = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env.SharedObject(target = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % (python, python)) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#g95\n") +test.write('test14.F95', "This is a .F95 file.\n#g95\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, "This is a .f file.\n") +test.must_match('test02' + _obj, "This is a .F file.\n") +test.must_match('test03' + _obj, "This is a .for file.\n") +test.must_match('test04' + _obj, "This is a .FOR file.\n") +test.must_match('test05' + _obj, "This is a .ftn file.\n") +test.must_match('test06' + _obj, "This is a .FTN file.\n") +test.must_match('test07' + _obj, "This is a .fpp file.\n") +test.must_match('test08' + _obj, "This is a .FPP file.\n") +test.must_match('test09' + _obj, "This is a .f77 file.\n") +test.must_match('test10' + _obj, "This is a .F77 file.\n") +test.must_match('test11' + _obj, "This is a .f90 file.\n") +test.must_match('test12' + _obj, "This is a .F90 file.\n") +test.must_match('test13' + _obj, "This is a .f95 file.\n") +test.must_match('test14' + _obj, "This is a .F95 file.\n") + + + +g95 = test.detect('F95', 'g95') + +if g95: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = 'g2c') +shf95 = foo.Dictionary('SHF95') +bar = foo.Copy(SHF95 = r'%s wrapper.py ' + shf95) +foo.SharedObject(target = 'foo/foo', source = 'foo.f') +bar.SharedObject(target = 'bar/bar', source = 'bar.f') +""" % python) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/SHF95FLAGS.py b/test/Fortran/SHF95FLAGS.py new file mode 100644 index 0000000..f98871c --- /dev/null +++ b/test/Fortran/SHF95FLAGS.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +if sys.platform == 'win32': + _obj = '.obj' +else: + if string.find(sys.platform, 'irix') > -1: + _obj = '.o' + else: + _obj = '.os' + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +comment = '#' + sys.argv[1] +opts, args = getopt.getopt(sys.argv[2:], 'co:xy') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF95 = r'%s myfortran.py g95', + SHF95FLAGS = '-x', + SHFORTRAN = r'%s myfortran.py fortran', + SHFORTRANFLAGS = '-y') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +env.SharedObject(target = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env.SharedObject(target = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % (python, python)) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#g95\n") +test.write('test14.F95', "This is a .F95 file.\n#g95\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, " -y -c\nThis is a .f file.\n") +test.must_match('test02' + _obj, " -y -c\nThis is a .F file.\n") +test.must_match('test03' + _obj, " -y -c\nThis is a .for file.\n") +test.must_match('test04' + _obj, " -y -c\nThis is a .FOR file.\n") +test.must_match('test05' + _obj, " -y -c\nThis is a .ftn file.\n") +test.must_match('test06' + _obj, " -y -c\nThis is a .FTN file.\n") +test.must_match('test07' + _obj, " -y -c\nThis is a .fpp file.\n") +test.must_match('test08' + _obj, " -y -c\nThis is a .FPP file.\n") +test.must_match('test09' + _obj, " -y -c\nThis is a .f77 file.\n") +test.must_match('test10' + _obj, " -y -c\nThis is a .F77 file.\n") +test.must_match('test11' + _obj, " -y -c\nThis is a .f90 file.\n") +test.must_match('test12' + _obj, " -y -c\nThis is a .F90 file.\n") +test.must_match('test13' + _obj, " -x -c\nThis is a .f95 file.\n") +test.must_match('test14' + _obj, " -x -c\nThis is a .F95 file.\n") + + + +g95 = test.detect('F95', 'g95') +FTN_LIB = TestSCons.fortran_lib + +if g95: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +shf95 = foo.Dictionary('SHF95') +bar = foo.Copy(SHF95 = r'%s wrapper.py ' + shf95, SHF95FLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/SHFORTRAN.py b/test/Fortran/SHFORTRAN.py new file mode 100644 index 0000000..205a761 --- /dev/null +++ b/test/Fortran/SHFORTRAN.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python +_obj = TestSCons._shobj + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'cf:o:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:8] != '#fortran': + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHFORTRAN = r'%s myfortran.py') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +env.SharedObject(target = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env.SharedObject(target = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % python) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#fortran\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, "This is a .f file.\n") +test.must_match('test02' + _obj, "This is a .F file.\n") +test.must_match('test03' + _obj, "This is a .for file.\n") +test.must_match('test04' + _obj, "This is a .FOR file.\n") +test.must_match('test05' + _obj, "This is a .ftn file.\n") +test.must_match('test06' + _obj, "This is a .FTN file.\n") +test.must_match('test07' + _obj, "This is a .fpp file.\n") +test.must_match('test08' + _obj, "This is a .FPP file.\n") +test.must_match('test09' + _obj, "This is a .f77 file.\n") +test.must_match('test10' + _obj, "This is a .F77 file.\n") +test.must_match('test11' + _obj, "This is a .f90 file.\n") +test.must_match('test12' + _obj, "This is a .F90 file.\n") +test.must_match('test13' + _obj, "This is a .f95 file.\n") +test.must_match('test14' + _obj, "This is a .F95 file.\n") + + + +fortran = test.detect('FORTRAN', 'g77') + +if fortran: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = 'g2c') +shfortran = foo.Dictionary('SHFORTRAN') +bar = foo.Copy(SHFORTRAN = r'%s wrapper.py ' + shfortran) +foo.SharedObject(target = 'foo/foo', source = 'foo.f') +bar.SharedObject(target = 'bar/bar', source = 'bar.f') +""" % python) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() diff --git a/test/Fortran/SHFORTRANFLAGS.py b/test/Fortran/SHFORTRANFLAGS.py new file mode 100644 index 0000000..2d8c97c --- /dev/null +++ b/test/Fortran/SHFORTRANFLAGS.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +if sys.platform == 'win32': + _obj = '.obj' +else: + if string.find(sys.platform, 'irix') > -1: + _obj = '.o' + else: + _obj = '.os' + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'co:x') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + else: optstring = optstring + ' ' + opt +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +outfile.write(optstring + "\n") +for l in infile.readlines(): + if l[:8] != '#fortran': + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHFORTRAN = r'%s myfortran.py', + SHFORTRANFLAGS = '-x') +env.SharedObject(target = 'test01', source = 'test01.f') +env.SharedObject(target = 'test02', source = 'test02.F') +env.SharedObject(target = 'test03', source = 'test03.for') +env.SharedObject(target = 'test04', source = 'test04.FOR') +env.SharedObject(target = 'test05', source = 'test05.ftn') +env.SharedObject(target = 'test06', source = 'test06.FTN') +env.SharedObject(target = 'test07', source = 'test07.fpp') +env.SharedObject(target = 'test08', source = 'test08.FPP') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +env.SharedObject(target = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env.SharedObject(target = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % (python,)) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortran\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortran\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortran\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortran\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortran\n") +test.write('test09.f77', "This is a .f77 file.\n#fortran\n") +test.write('test10.F77', "This is a .F77 file.\n#fortran\n") +test.write('test11.f90', "This is a .f90 file.\n#fortran\n") +test.write('test12.F90', "This is a .F90 file.\n#fortran\n") +test.write('test13.f95', "This is a .f95 file.\n#fortran\n") +test.write('test14.F95', "This is a .F95 file.\n#fortran\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _obj, " -x -c\nThis is a .f file.\n") +test.must_match('test02' + _obj, " -x -c\nThis is a .F file.\n") +test.must_match('test03' + _obj, " -x -c\nThis is a .for file.\n") +test.must_match('test04' + _obj, " -x -c\nThis is a .FOR file.\n") +test.must_match('test05' + _obj, " -x -c\nThis is a .ftn file.\n") +test.must_match('test06' + _obj, " -x -c\nThis is a .FTN file.\n") +test.must_match('test07' + _obj, " -x -c\nThis is a .fpp file.\n") +test.must_match('test08' + _obj, " -x -c\nThis is a .FPP file.\n") +test.must_match('test09' + _obj, " -x -c\nThis is a .f77 file.\n") +test.must_match('test10' + _obj, " -x -c\nThis is a .F77 file.\n") +test.must_match('test11' + _obj, " -x -c\nThis is a .f90 file.\n") +test.must_match('test12' + _obj, " -x -c\nThis is a .F90 file.\n") +test.must_match('test13' + _obj, " -x -c\nThis is a .f95 file.\n") +test.must_match('test14' + _obj, " -x -c\nThis is a .F95 file.\n") + + + +fortran = test.detect('FORTRAN', 'g77') +FTN_LIB = TestSCons.fortran_lib + +if fortran: + + test.write("wrapper.py", +"""import os +import string +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(LIBS = %s) +shfortran = foo.Dictionary('SHFORTRAN') +bar = foo.Copy(SHFORTRAN = r'%s wrapper.py ' + shfortran, + SHFORTRANFLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f') +""" % (FTN_LIB, python)) + + test.write('foo.f', r""" + PROGRAM FOO + PRINT *,'foo.f' + STOP + END +""") + + test.write('bar.f', r""" + PROGRAM BAR + PRINT *,'bar.f' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() |