diff options
Diffstat (limited to 'test/Fortran')
66 files changed, 8107 insertions, 0 deletions
diff --git a/test/Fortran/.exclude_tests b/test/Fortran/.exclude_tests new file mode 100644 index 0000000..671ec92 --- /dev/null +++ b/test/Fortran/.exclude_tests @@ -0,0 +1 @@ +common.py diff --git a/test/Fortran/F03.py b/test/Fortran/F03.py new file mode 100644 index 0000000..ea706a9 --- /dev/null +++ b/test/Fortran/F03.py @@ -0,0 +1,153 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F03 = r'%(_python_)s myfortran.py f03', + FORTRAN = r'%(_python_)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 = 'test13', source = 'test13.f03') +env.Program(target = 'test14', source = 'test14.F03') +""" % locals()) + +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('test13.f03', "This is a .f03 file.\n#link\n#f03\n") +test.write('test14.F03', "This is a .F03 file.\n#link\n#f03\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('test13' + _exe, "This is a .f03 file.\n") +test.must_match('test14' + _exe, "This is a .F03 file.\n") + + +fc = 'f03' +g03 = test.detect_tool(fc) + +if g03: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F03 = '%(fc)s') +f03 = foo.Dictionary('F03') +bar = foo.Clone(F03 = r'%(_python_)s wrapper.py ' + f03) +foo.Program(target = 'foo', source = 'foo.f03') +bar.Program(target = 'bar', source = 'bar.f03') +""" % locals()) + + test.write('foo.f03', r""" + PROGRAM FOO + PRINT *,'foo.f03' + STOP + END +""") + + test.write('bar.f03', r""" + PROGRAM BAR + PRINT *,'bar.f03' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f03\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f03\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F03COM.py b/test/Fortran/F03COM.py new file mode 100644 index 0000000..b0d1f79 --- /dev/null +++ b/test/Fortran/F03COM.py @@ -0,0 +1,110 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F03COM = r'%(_python_)s myfortran.py f03 $TARGET $SOURCES', + F03PPCOM = r'%(_python_)s myfortran.py f03pp $TARGET $SOURCES', + FORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + FORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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 = 'test13', source = 'test13.f03') +env.Program(target = 'test14', source = 'test14.F03') +env2 = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F03COM = r'%(_python_)s myfortran.py f03 $TARGET $SOURCES', + F03PPCOM = r'%(_python_)s myfortran.py f03pp $TARGET $SOURCES') +env2.Program(target = 'test21', source = 'test21.f03') +env2.Program(target = 'test22', source = 'test22.F03') +""" % locals()) + +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#fortranpp\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#fortranpp\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#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortranpp\n") +test.write('test13.f03', "This is a .f03 file.\n#link\n#f03\n") +test.write('test14.F03', "This is a .F03 file.\n#link\n#f03pp\n") + +test.write('test21.f03', "This is a .f03 file.\n#link\n#f03\n") +test.write('test22.F03', "This is a .F03 file.\n#link\n#f03pp\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('test13' + _exe, "This is a .f03 file.\n") +test.must_match('test14' + _exe, "This is a .F03 file.\n") + +test.must_match('test21' + _exe, "This is a .f03 file.\n") +test.must_match('test22' + _exe, "This is a .F03 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F03COMSTR.py b/test/Fortran/F03COMSTR.py new file mode 100644 index 0000000..327c1cd --- /dev/null +++ b/test/Fortran/F03COMSTR.py @@ -0,0 +1,78 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f03pp = 'f03' +else: + f03pp = 'f03pp' + + +test.write('SConstruct', """ +env = Environment(F03COM = r'%(_python_)s myfc.py f03 $TARGET $SOURCES', + F03COMSTR = 'Building f03 $TARGET from $SOURCES', + F03PPCOM = r'%(_python_)s myfc.py f03pp $TARGET $SOURCES', + F03PPCOMSTR = 'Building f03pp $TARGET from $SOURCES', + OBJSUFFIX='.obj') +env.Object(source = 'test01.f03') +env.Object(source = 'test02.F03') +""" % locals()) + +test.write('test01.f03', "A .f03 file.\n#f03\n") +test.write('test02.F03', "A .F03 file.\n#%s\n" % f03pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f03 test01.obj from test01.f03 +Building %(f03pp)s test02.obj from test02.F03 +""" % locals())) + +test.must_match('test01.obj', "A .f03 file.\n") +test.must_match('test02.obj', "A .F03 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F03FILESUFFIXES.py b/test/Fortran/F03FILESUFFIXES.py new file mode 100644 index 0000000..ffc2169 --- /dev/null +++ b/test/Fortran/F03FILESUFFIXES.py @@ -0,0 +1,101 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 default file suffix: .f90/.F90 for F90 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F03 = r'%(_python_)s myfortran.py f03', + FORTRAN = r'%(_python_)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.f03') +env.Program(target = 'test10', source = 'test10.F03') +""" % locals()) + +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.f03', "This is a .f03 file.\n#link\n#f03\n") +test.write('test10.F03', "This is a .F03 file.\n#link\n#f03\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 .f03 file.\n") +test.must_match('test10' + _exe, "This is a .F03 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F03FILESUFFIXES2.py b/test/Fortran/F03FILESUFFIXES2.py new file mode 100644 index 0000000..77a601f --- /dev/null +++ b/test/Fortran/F03FILESUFFIXES2.py @@ -0,0 +1,91 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 non-default file suffix: .f/.F for F03 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py f77', + F03 = r'%(_python_)s myfortran.py f03', + F03FILESUFFIXES = ['.f', '.F', '.f03', '.F03'], + tools = ['default', 'f03']) +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.f03') +env.Program(target = 'test04', source = 'test04.F03') +env.Program(target = 'test05', source = 'test05.f77') +env.Program(target = 'test06', source = 'test06.F77') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#link\n#f03\n") +test.write('test02.F', "This is a .F file.\n#link\n#f03\n") +test.write('test03.f03', "This is a .f03 file.\n#link\n#f03\n") +test.write('test04.F03', "This is a .F03 file.\n#link\n#f03\n") +test.write('test05.f77', "This is a .f77 file.\n#link\n#f77\n") +test.write('test06.F77', "This is a .F77 file.\n#link\n#f77\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 .f03 file.\n") +test.must_match('test04' + _exe, "This is a .F03 file.\n") +test.must_match('test05' + _exe, "This is a .f77 file.\n") +test.must_match('test06' + _exe, "This is a .F77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F03FLAGS.py b/test/Fortran/F03FLAGS.py new file mode 100644 index 0000000..0c5bf93 --- /dev/null +++ b/test/Fortran/F03FLAGS.py @@ -0,0 +1,160 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F03 = r'%(_python_)s myfortran.py g03', + F03FLAGS = '-x', + FORTRAN = r'%(_python_)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 = 'test13', source = 'test13.f03') +env.Program(target = 'test14', source = 'test14.F03') +""" % locals()) + +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('test13.f03', "This is a .f03 file.\n#link\n#g03\n") +test.write('test14.F03', "This is a .F03 file.\n#link\n#g03\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -c -y\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -c -y\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -c -y\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -c -y\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -c -y\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -c -y\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -c -y\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -c -y\nThis is a .FPP file.\n") +test.must_match('test13' + _exe, " -c -x\nThis is a .f03 file.\n") +test.must_match('test14' + _exe, " -c -x\nThis is a .F03 file.\n") + + +fc = 'f03' +g03 = test.detect_tool(fc) + + +if g03: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F03 = '%(fc)s') +f03 = foo.Dictionary('F03') +bar = foo.Clone(F03 = r'%(_python_)s wrapper.py ' + f03, F03FLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f03') +bar.Program(target = 'bar', source = 'bar.f03') +""" % locals()) + + test.write('foo.f03', r""" + PROGRAM FOO + PRINT *,'foo.f03' + STOP + END +""") + + test.write('bar.f03', r""" + PROGRAM BAR + PRINT *,'bar.f03' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f03\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f03\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F08.py b/test/Fortran/F08.py new file mode 100644 index 0000000..35df37c --- /dev/null +++ b/test/Fortran/F08.py @@ -0,0 +1,151 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F08 = r'%(_python_)s myfortran.py f08', + FORTRAN = r'%(_python_)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.f08') +env.Program(target = 'test10', source = 'test10.F08') +""" % locals()) + +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.f08', "This is a .f08 file.\n#link\n#f08\n") +test.write('test10.F08', "This is a .F08 file.\n#link\n#f08\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 .f08 file.\n") +test.must_match('test10' + _exe, "This is a .F08 file.\n") + + +fc = 'f08' +g08 = test.detect_tool(fc) + +if g08: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F08 = '%(fc)s') +f08 = foo.Dictionary('F08') +bar = foo.Clone(F08 = r'%(_python_)s wrapper.py ' + f08) +foo.Program(target = 'foo', source = 'foo.f08') +bar.Program(target = 'bar', source = 'bar.f08') +""" % locals()) + + test.write('foo.f08', r""" + PROGRAM FOO + PRINT *,'foo.f08' + ENDPROGRAM FOO +""") + + test.write('bar.f08', r""" + PROGRAM BAR + PRINT *,'bar.f08' + ENDPROGRAM BAR +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f08\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f08\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F08COM.py b/test/Fortran/F08COM.py new file mode 100644 index 0000000..783a163 --- /dev/null +++ b/test/Fortran/F08COM.py @@ -0,0 +1,98 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F08COM = r'%(_python_)s myfortran.py f08 $TARGET $SOURCES', + F08PPCOM = r'%(_python_)s myfortran.py f08pp $TARGET $SOURCES', + FORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + FORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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.f08') +env.Program(target = 'test10', source = 'test10.F08') +""" % locals()) + +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#fortranpp\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#fortranpp\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#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortranpp\n") +test.write('test09.f08', "This is a .f08 file.\n#link\n#f08\n") +test.write('test10.F08', "This is a .F08 file.\n#link\n#f08pp\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 .f08 file.\n") +test.must_match('test10' + _exe, "This is a .F08 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F08COMSTR.py b/test/Fortran/F08COMSTR.py new file mode 100644 index 0000000..65bf32c --- /dev/null +++ b/test/Fortran/F08COMSTR.py @@ -0,0 +1,78 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f08pp = 'f08' +else: + f08pp = 'f08pp' + + +test.write('SConstruct', """ +env = Environment(F08COM = r'%(_python_)s myfc.py f08 $TARGET $SOURCES', + F08COMSTR = 'Building f08 $TARGET from $SOURCES', + F08PPCOM = r'%(_python_)s myfc.py f08pp $TARGET $SOURCES', + F08PPCOMSTR = 'Building f08pp $TARGET from $SOURCES', + OBJSUFFIX='.obj') +env.Object(source = 'test01.f08') +env.Object(source = 'test02.F08') +""" % locals()) + +test.write('test01.f08', "A .f08 file.\n#f08\n") +test.write('test02.F08', "A .F08 file.\n#%s\n" % f08pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f08 test01.obj from test01.f08 +Building %(f08pp)s test02.obj from test02.F08 +""" % locals())) + +test.must_match('test01.obj', "A .f08 file.\n") +test.must_match('test02.obj', "A .F08 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F08FILESUFFIXES.py b/test/Fortran/F08FILESUFFIXES.py new file mode 100644 index 0000000..8463403 --- /dev/null +++ b/test/Fortran/F08FILESUFFIXES.py @@ -0,0 +1,101 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 default file suffix: .f90/.F90 for F90 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F08 = r'%(_python_)s myfortran.py f08', + FORTRAN = r'%(_python_)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.f08') +env.Program(target = 'test10', source = 'test10.F08') +""" % locals()) + +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#fortranpp\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#fortranpp\n") +test.write('test05.ftn', "This is a .ftn file.\n#link\n#fortranpp\n") +test.write('test06.FTN', "This is a .FTN file.\n#link\n#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortranpp\n") +test.write('test09.f08', "This is a .f08 file.\n#link\n#f08\n") +test.write('test10.F08', "This is a .F08 file.\n#link\n#f08pp\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 .f08 file.\n") +test.must_match('test10' + _exe, "This is a .F08 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F08FILESUFFIXES2.py b/test/Fortran/F08FILESUFFIXES2.py new file mode 100644 index 0000000..39bba44 --- /dev/null +++ b/test/Fortran/F08FILESUFFIXES2.py @@ -0,0 +1,91 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 non-default file suffix: .f/.F for F08 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py f77', + F08 = r'%(_python_)s myfortran.py f08', + F08FILESUFFIXES = ['.f', '.F', '.f08', '.F08'], + tools = ['default', 'f08']) +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.f08') +env.Program(target = 'test04', source = 'test04.F08') +env.Program(target = 'test05', source = 'test05.f77') +env.Program(target = 'test06', source = 'test06.F77') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#link\n#f08\n") +test.write('test02.F', "This is a .F file.\n#link\n#f08\n") +test.write('test03.f08', "This is a .f08 file.\n#link\n#f08\n") +test.write('test04.F08', "This is a .F08 file.\n#link\n#f08\n") +test.write('test05.f77', "This is a .f77 file.\n#link\n#f77\n") +test.write('test06.F77', "This is a .F77 file.\n#link\n#f77\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 .f08 file.\n") +test.must_match('test04' + _exe, "This is a .F08 file.\n") +test.must_match('test05' + _exe, "This is a .f77 file.\n") +test.must_match('test06' + _exe, "This is a .F77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F08FLAGS.py b/test/Fortran/F08FLAGS.py new file mode 100644 index 0000000..866ea2c --- /dev/null +++ b/test/Fortran/F08FLAGS.py @@ -0,0 +1,158 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F08 = r'%(_python_)s myfortran.py g08', + F08FLAGS = '-x', + FORTRAN = r'%(_python_)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.f08') +env.Program(target = 'test10', source = 'test10.F08') +""" % locals()) + +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.f08', "This is a .f08 file.\n#link\n#g08\n") +test.write('test10.F08', "This is a .F08 file.\n#link\n#g08\n") + +test.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -c -y\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -c -y\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -c -y\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -c -y\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -c -y\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -c -y\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -c -y\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -c -y\nThis is a .FPP file.\n") +test.must_match('test09' + _exe, " -c -x\nThis is a .f08 file.\n") +test.must_match('test10' + _exe, " -c -x\nThis is a .F08 file.\n") + + +fc = 'f08' +g08 = test.detect_tool(fc) + + +if g08: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F08 = '%(fc)s') +f08 = foo.Dictionary('F08') +bar = foo.Clone(F08 = r'%(_python_)s wrapper.py ' + f08, F08FLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f08') +bar.Program(target = 'bar', source = 'bar.f08') +""" % locals()) + + test.write('foo.f08', r""" + PROGRAM FOO + PRINT *,'foo.f08' + ENDPROGRAM FOO +""") + + test.write('bar.f08', r""" + PROGRAM BAR + PRINT *,'bar.f08' + ENDPROGRAM FOO +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f08\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f08\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F77.py b/test/Fortran/F77.py new file mode 100644 index 0000000..0ebd7ee --- /dev/null +++ b/test/Fortran/F77.py @@ -0,0 +1,151 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py g77', + FORTRAN = r'%(_python_)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') +""" % locals()) + +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.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") + +fc = 'f77' +f77 = test.detect_tool(fc) + +if f77: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F77 = '%(fc)s', tools = ['default', 'f77'], F77FILESUFFIXES = ['.f']) +f77 = foo.Dictionary('F77') +bar = foo.Clone(F77 = r'%(_python_)s wrapper.py ' + f77) +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + 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() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F77COM.py b/test/Fortran/F77COM.py new file mode 100644 index 0000000..1efbe05 --- /dev/null +++ b/test/Fortran/F77COM.py @@ -0,0 +1,98 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77COM = r'%(_python_)s myfortran.py f77 $TARGET $SOURCES', + F77PPCOM = r'%(_python_)s myfortran.py f77pp $TARGET $SOURCES', + FORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + FORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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') +""" % locals()) + +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#fortranpp\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#fortranpp\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#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortranpp\n") +test.write('test09.f77', "This is a .f77 file.\n#link\n#f77\n") +test.write('test10.F77', "This is a .F77 file.\n#link\n#f77pp\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.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F77COMSTR.py b/test/Fortran/F77COMSTR.py new file mode 100644 index 0000000..6c89833 --- /dev/null +++ b/test/Fortran/F77COMSTR.py @@ -0,0 +1,78 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f77pp = 'f77' +else: + f77pp = 'f77pp' + + +test.write('SConstruct', """ +env = Environment(F77COM = r'%(_python_)s myfc.py f77 $TARGET $SOURCES', + F77COMSTR = 'Building f77 $TARGET from $SOURCES', + F77PPCOM = r'%(_python_)s myfc.py f77pp $TARGET $SOURCES', + F77PPCOMSTR = 'Building f77pp $TARGET from $SOURCES', + OBJSUFFIX='.obj') +env.Object(source = 'test09.f77') +env.Object(source = 'test10.F77') +""" % locals()) + +test.write('test09.f77', "A .f77 file.\n#f77\n") +test.write('test10.F77', "A .F77 file.\n#%s\n" % f77pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f77 test09.obj from test09.f77 +Building %(f77pp)s test10.obj from test10.F77 +""" % locals())) + +test.must_match('test09.obj', "A .f77 file.\n") +test.must_match('test10.obj', "A .F77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F77FILESUFFIXES.py b/test/Fortran/F77FILESUFFIXES.py new file mode 100644 index 0000000..2070ff2 --- /dev/null +++ b/test/Fortran/F77FILESUFFIXES.py @@ -0,0 +1,101 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 default file suffix: .f77/.F77 for F77 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py g77', + FORTRAN = r'%(_python_)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') +""" % locals()) + +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.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.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F77FILESUFFIXES2.py b/test/Fortran/F77FILESUFFIXES2.py new file mode 100644 index 0000000..52e4d68 --- /dev/null +++ b/test/Fortran/F77FILESUFFIXES2.py @@ -0,0 +1,85 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 non-default file suffix: .f/.F for F77 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py g77', + F95 = r'%(_python_)s myfortran.py f95', + F77FILESUFFIXES = ['.f', '.F'], + tools = ['default', 'f77']) +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test05', source = 'test05.f95') +env.Program(target = 'test06', source = 'test06.F95') +""" % locals()) + +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('test05.f95', "This is a .f95 file.\n#link\n#f95\n") +test.write('test06.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('test05' + _exe, "This is a .f95 file.\n") +test.must_match('test06' + _exe, "This is a .F95 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F77FLAGS.py b/test/Fortran/F77FLAGS.py new file mode 100644 index 0000000..b708f9e --- /dev/null +++ b/test/Fortran/F77FLAGS.py @@ -0,0 +1,132 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myg77.py', + F77FLAGS = '-x') +env.Program(target = 'test09', source = 'test09.f77') +env.Program(target = 'test10', source = 'test10.F77') +""" % locals()) + +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('test09' + _exe, " -c -x\nThis is a .f77 file.\n") +test.must_match('test10' + _exe, " -c -x\nThis is a .F77 file.\n") + + +fc = 'f77' +g77 = test.detect_tool(fc) + +if g77: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F77 = '%(fc)s', tools = ['default', 'f77'], F77FILESUFFIXES = [".f"]) +f77 = foo.Dictionary('F77') +bar = foo.Clone(F77 = r'%(_python_)s wrapper.py ' + f77, F77FLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + 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() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F77PATH.py b/test/Fortran/F77PATH.py new file mode 100644 index 0000000..260782c --- /dev/null +++ b/test/Fortran/F77PATH.py @@ -0,0 +1,317 @@ +#!/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 TestSCons + +_exe = TestSCons._exe +prog = 'prog' + _exe +subdir_prog = os.path.join('subdir', 'prog' + _exe) +variant_prog = os.path.join('variant', 'prog' + _exe) + +args = prog + ' ' + variant_prog + ' ' + subdir_prog + +test = TestSCons.TestSCons() + +fc = 'f77' +if not test.detect_tool(fc): + test.skip_test('Could not find a f77 tool; skipping test.\n') + +test.subdir('include', + 'subdir', + ['subdir', 'include'], + 'foobar', + 'inc2') + + + +test.write('SConstruct', """ +env = Environment(F77 = '%s', + F77PATH = ['$FOO', '${TARGET.dir}', '${SOURCE.dir}'], + FOO='include', + F77FLAGS = '-x f77') +obj = env.Object(target='foobar/prog', source='subdir/prog.f77') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +VariantDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F77 = '%s', + F77PATH=[include, '#foobar', '#subdir'], + F77FLAGS = '-x f77') +SConscript('variant/SConscript', "env") +""" % (fc, fc)) + +test.write(['subdir', 'SConscript'], +""" +Import("env") +env.Program(target='prog', source='prog.f77') +""") + +test.write(['include', 'foo.f77'], +r""" + PRINT *, 'include/foo.f77 1' + INCLUDE 'bar.f77' +""") + +test.write(['include', 'bar.f77'], +r""" + PRINT *, 'include/bar.f77 1' +""") + +test.write(['subdir', 'prog.f77'], +r""" + PROGRAM PROG + PRINT *, 'subdir/prog.f77' + include 'foo.f77' + include 'sss.f77' + include 'ttt.f77' + STOP + END +""") + +test.write(['subdir', 'include', 'foo.f77'], +r""" + PRINT *, 'subdir/include/foo.f77 1' + INCLUDE 'bar.f77' +""") + +test.write(['subdir', 'include', 'bar.f77'], +r""" + PRINT *, 'subdir/include/bar.f77 1' +""") + +test.write(['subdir', 'sss.f77'], +r""" + PRINT *, 'subdir/sss.f77' +""") + +test.write(['subdir', 'ttt.f77'], +r""" + PRINT *, 'subdir/ttt.f77' +""") + + + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f77 + include/foo.f77 1 + include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f77 + subdir/include/foo.f77 1 + subdir/include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f77 + include/foo.f77 1 + include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f77')) + +test.up_to_date(arguments = args) + + + +test.write(['include', 'foo.f77'], +r""" + PRINT *, 'include/foo.f77 2' + INCLUDE 'bar.f77' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f77 + include/foo.f77 2 + include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f77 + subdir/include/foo.f77 1 + subdir/include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f77 + include/foo.f77 2 + include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f77')) + +test.up_to_date(arguments = args) + + + +# +test.write(['include', 'bar.f77'], +r""" + PRINT *, 'include/bar.f77 2' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f77 + include/foo.f77 2 + include/bar.f77 2 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f77 + subdir/include/foo.f77 1 + subdir/include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f77 + include/foo.f77 2 + include/bar.f77 2 + subdir/sss.f77 + subdir/ttt.f77 +""") + +# Make sure we didn't duplicate the source file in the variant subdirectory. +test.must_not_exist(test.workpath('variant', 'prog.f77')) + +test.up_to_date(arguments = args) + + + +# Change F77PATH and make sure we don't rebuild because of it. +test.write('SConstruct', """ +env = Environment(F77 = '%s', + F77PATH = Split('inc2 include ${TARGET.dir} ${SOURCE.dir}'), + F77FLAGS = '-x f77') +obj = env.Object(target='foobar/prog', source='subdir/prog.f77') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +VariantDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F77 = '%s', + F77PATH=['inc2', include, '#foobar', '#subdir'], + F77FLAGS = '-x f77') +SConscript('variant/SConscript', "env") +""" % (fc, fc)) + +test.up_to_date(arguments = args) + +# +test.write(['inc2', 'foo.f77'], +r""" + PRINT *, 'inc2/foo.f77 1' + INCLUDE 'bar.f77' +""") + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f77 + inc2/foo.f77 1 + include/bar.f77 2 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f77 + subdir/include/foo.f77 1 + subdir/include/bar.f77 1 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f77 + include/foo.f77 2 + include/bar.f77 2 + subdir/sss.f77 + subdir/ttt.f77 +""") + +test.up_to_date(arguments = args) + + + +# Check that a null-string F77PATH doesn't blow up. +test.write('SConstruct', """ +env = Environment(tools = ['f77'], F77PATH = '', F77FLAGS = '-x f77') +env.Object('foo', source = 'empty.f77') +""") + +test.write('empty.f77', '') + +test.run(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F90.py b/test/Fortran/F90.py new file mode 100644 index 0000000..d7c73c6 --- /dev/null +++ b/test/Fortran/F90.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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F90 = r'%(_python_)s myfortran.py f90', + FORTRAN = r'%(_python_)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 = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +""" % locals()) + +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('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.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('test11' + _exe, "This is a .f90 file.\n") +test.must_match('test12' + _exe, "This is a .F90 file.\n") + + +fc = 'f90' +g90 = test.detect_tool(fc) + +if g90: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F90 = '%(fc)s') +f90 = foo.Dictionary('F90') +bar = foo.Clone(F90 = r'%(_python_)s wrapper.py ' + f90) +foo.Program(target = 'foo', source = 'foo.f90') +bar.Program(target = 'bar', source = 'bar.f90') +""" % locals()) + + test.write('foo.f90', r""" + PROGRAM FOO + PRINT *,'foo.f90' + END +""") + + test.write('bar.f90', r""" + PROGRAM BAR + PRINT *,'bar.f90' + END +""") + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f90\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f90\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F90COM.py b/test/Fortran/F90COM.py new file mode 100644 index 0000000..8981bb3 --- /dev/null +++ b/test/Fortran/F90COM.py @@ -0,0 +1,110 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F90COM = r'%(_python_)s myfortran.py f90 $TARGET $SOURCES', + F90PPCOM = r'%(_python_)s myfortran.py f90pp $TARGET $SOURCES', + FORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + FORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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 = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +env2 = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F90COM = r'%(_python_)s myfortran.py f90 $TARGET $SOURCES', + F90PPCOM = r'%(_python_)s myfortran.py f90pp $TARGET $SOURCES') +env2.Program(target = 'test21', source = 'test21.f90') +env2.Program(target = 'test22', source = 'test22.F90') +""" % locals()) + +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#fortranpp\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#fortranpp\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#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortranpp\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#f90pp\n") + +test.write('test21.f90', "This is a .f90 file.\n#link\n#f90\n") +test.write('test22.F90', "This is a .F90 file.\n#link\n#f90pp\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('test11' + _exe, "This is a .f90 file.\n") +test.must_match('test12' + _exe, "This is a .F90 file.\n") + +test.must_match('test21' + _exe, "This is a .f90 file.\n") +test.must_match('test22' + _exe, "This is a .F90 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F90COMSTR.py b/test/Fortran/F90COMSTR.py new file mode 100644 index 0000000..117a5a9 --- /dev/null +++ b/test/Fortran/F90COMSTR.py @@ -0,0 +1,77 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f90pp = 'f90' +else: + f90pp = 'f90pp' + +test.write('SConstruct', """ +env = Environment(F90COM = r'%(_python_)s myfc.py f90 $TARGET $SOURCES', + F90COMSTR = 'Building f90 $TARGET from $SOURCES', + F90PPCOM = r'%(_python_)s myfc.py f90pp $TARGET $SOURCES', + F90PPCOMSTR = 'Building f90pp $TARGET from $SOURCES', + OBJSUFFIX='.obj') +env.Object(source = 'test01.f90') +env.Object(source = 'test02.F90') +""" % locals()) + +test.write('test01.f90', "A .f90 file.\n#f90\n") +test.write('test02.F90', "A .F90 file.\n#%s\n" % f90pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f90 test01.obj from test01.f90 +Building %(f90pp)s test02.obj from test02.F90 +""" % locals())) + +test.must_match('test01.obj', "A .f90 file.\n") +test.must_match('test02.obj', "A .F90 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F90FILESUFFIXES.py b/test/Fortran/F90FILESUFFIXES.py new file mode 100644 index 0000000..ae61a84 --- /dev/null +++ b/test/Fortran/F90FILESUFFIXES.py @@ -0,0 +1,101 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 default file suffix: .f90/.F90 for F90 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F90 = r'%(_python_)s myfortran.py f90', + FORTRAN = r'%(_python_)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.f90') +env.Program(target = 'test10', source = 'test10.F90') +""" % locals()) + +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.f90', "This is a .f90 file.\n#link\n#f90\n") +test.write('test10.F90', "This is a .F90 file.\n#link\n#f90\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 .f90 file.\n") +test.must_match('test10' + _exe, "This is a .F90 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F90FILESUFFIXES2.py b/test/Fortran/F90FILESUFFIXES2.py new file mode 100644 index 0000000..ab62ca7 --- /dev/null +++ b/test/Fortran/F90FILESUFFIXES2.py @@ -0,0 +1,91 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 non-default file suffix: .f/.F for F90 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py f77', + F90 = r'%(_python_)s myfortran.py f90', + F90FILESUFFIXES = ['.f', '.F', '.f90', '.F90'], + tools = ['default', 'f90']) +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.f90') +env.Program(target = 'test04', source = 'test04.F90') +env.Program(target = 'test05', source = 'test05.f77') +env.Program(target = 'test06', source = 'test06.F77') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#link\n#f90\n") +test.write('test02.F', "This is a .F file.\n#link\n#f90\n") +test.write('test03.f90', "This is a .f90 file.\n#link\n#f90\n") +test.write('test04.F90', "This is a .F90 file.\n#link\n#f90\n") +test.write('test05.f77', "This is a .f77 file.\n#link\n#f77\n") +test.write('test06.F77', "This is a .F77 file.\n#link\n#f77\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 .f90 file.\n") +test.must_match('test04' + _exe, "This is a .F90 file.\n") +test.must_match('test05' + _exe, "This is a .f77 file.\n") +test.must_match('test06' + _exe, "This is a .F77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F90FLAGS.py b/test/Fortran/F90FLAGS.py new file mode 100644 index 0000000..f0b3003 --- /dev/null +++ b/test/Fortran/F90FLAGS.py @@ -0,0 +1,157 @@ + +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F90 = r'%(_python_)s myfortran.py g90', + F90FLAGS = '-x', + FORTRAN = r'%(_python_)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 = 'test11', source = 'test11.f90') +env.Program(target = 'test12', source = 'test12.F90') +""" % locals()) + +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('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.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -c -y\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -c -y\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -c -y\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -c -y\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -c -y\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -c -y\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -c -y\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -c -y\nThis is a .FPP file.\n") +test.must_match('test11' + _exe, " -c -x\nThis is a .f90 file.\n") +test.must_match('test12' + _exe, " -c -x\nThis is a .F90 file.\n") + + + +fc = 'f90' +g90 = test.detect_tool(fc) + +if g90: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F90 = '%(fc)s') +f90 = foo.Dictionary('F90') +bar = foo.Clone(F90 = r'%(_python_)s wrapper.py ' + f90) +foo.Program(target = 'foo', source = 'foo.f90') +bar.Program(target = 'bar', source = 'bar.f90') +""" % locals()) + + test.write('foo.f90', r""" + PROGRAM FOO + PRINT *,'foo.f90' + END +""") + + test.write('bar.f90', r""" + PROGRAM BAR + PRINT *,'bar.f90' + END +""") + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f90\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f90\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F90PATH.py b/test/Fortran/F90PATH.py new file mode 100644 index 0000000..341b241 --- /dev/null +++ b/test/Fortran/F90PATH.py @@ -0,0 +1,307 @@ +#!/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 TestSCons + +_exe = TestSCons._exe +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() + +fc = 'f90' +if not test.detect_tool(fc): + test.skip_test('Could not find a f90 tool; skipping test.\n') + +test.subdir('include', + 'subdir', + ['subdir', 'include'], + 'foobar', + 'inc2') + + + +test.write('SConstruct', """ +env = Environment(F90 = r'%s', + F90PATH = ['$FOO', '${TARGET.dir}', '${SOURCE.dir}'], + LINK = '$F90', + FOO='include') +obj = env.Object(target='foobar/prog', source='subdir/prog.f90') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +VariantDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F90 = r'%s', + F90PATH=[include, '#foobar', '#subdir'], + LINK = '$F90') +SConscript('variant/SConscript', "env") +""" % (fc, fc, )) + +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' + include 'sss.f90' + include 'ttt.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.write(['subdir', 'sss.f90'], +r""" + PRINT *, 'subdir/sss.f90' +""") + +test.write(['subdir', 'ttt.f90'], +r""" + PRINT *, 'subdir/ttt.f90' +""") + + + +test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f90 + include/foo.f90 1 + include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f90 + subdir/include/foo.f90 1 + subdir/include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f90 + include/foo.f90 1 + include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +# 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 + include/foo.f90 2 + include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f90 + subdir/include/foo.f90 1 + subdir/include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f90 + include/foo.f90 2 + include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +# 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 + include/foo.f90 2 + include/bar.f90 2 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f90 + subdir/include/foo.f90 1 + subdir/include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f90 + include/foo.f90 2 + include/bar.f90 2 + subdir/sss.f90 + subdir/ttt.f90 +""") + +# 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 ${TARGET.dir} ${SOURCE.dir}'), + LINK = '$F90') +obj = env.Object(target='foobar/prog', source='subdir/prog.f90') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +VariantDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(F90 = r'%s', + F90PATH=['inc2', include, '#foobar', '#subdir'], + LINK = '$F90') +SConscript('variant/SConscript', "env") +""" % (fc, fc)) + +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 + inc2/foo.f90 1 + include/bar.f90 2 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f90 + subdir/include/foo.f90 1 + subdir/include/bar.f90 1 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f90 + include/foo.f90 2 + include/bar.f90 2 + subdir/sss.f90 + subdir/ttt.f90 +""") + +test.up_to_date(arguments = args) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F95.py b/test/Fortran/F95.py new file mode 100644 index 0000000..e7745b1 --- /dev/null +++ b/test/Fortran/F95.py @@ -0,0 +1,153 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F95 = r'%(_python_)s myfortran.py f95', + FORTRAN = r'%(_python_)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 = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % locals()) + +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('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('test13' + _exe, "This is a .f95 file.\n") +test.must_match('test14' + _exe, "This is a .F95 file.\n") + + +fc = 'f95' +g95 = test.detect_tool(fc) + +if g95: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F95 = '%(fc)s') +f95 = foo.Dictionary('F95') +bar = foo.Clone(F95 = r'%(_python_)s wrapper.py ' + f95) +foo.Program(target = 'foo', source = 'foo.f95') +bar.Program(target = 'bar', source = 'bar.f95') +""" % locals()) + + test.write('foo.f95', r""" + PROGRAM FOO + PRINT *,'foo.f95' + STOP + END +""") + + test.write('bar.f95', r""" + PROGRAM BAR + PRINT *,'bar.f95' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f95\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f95\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F95COM.py b/test/Fortran/F95COM.py new file mode 100644 index 0000000..6ef6eb0 --- /dev/null +++ b/test/Fortran/F95COM.py @@ -0,0 +1,110 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F95COM = r'%(_python_)s myfortran.py f95 $TARGET $SOURCES', + F95PPCOM = r'%(_python_)s myfortran.py f95pp $TARGET $SOURCES', + FORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + FORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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 = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +env2 = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F95COM = r'%(_python_)s myfortran.py f95 $TARGET $SOURCES', + F95PPCOM = r'%(_python_)s myfortran.py f95pp $TARGET $SOURCES') +env2.Program(target = 'test21', source = 'test21.f95') +env2.Program(target = 'test22', source = 'test22.F95') +""" % locals()) + +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#fortranpp\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#fortranpp\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#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortranpp\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#f95pp\n") + +test.write('test21.f95', "This is a .f95 file.\n#link\n#f95\n") +test.write('test22.F95', "This is a .F95 file.\n#link\n#f95pp\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('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 .f95 file.\n") +test.must_match('test22' + _exe, "This is a .F95 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F95COMSTR.py b/test/Fortran/F95COMSTR.py new file mode 100644 index 0000000..5d162f9 --- /dev/null +++ b/test/Fortran/F95COMSTR.py @@ -0,0 +1,78 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f95pp = 'f95' +else: + f95pp = 'f95pp' + + +test.write('SConstruct', """ +env = Environment(F95COM = r'%(_python_)s myfc.py f95 $TARGET $SOURCES', + F95COMSTR = 'Building f95 $TARGET from $SOURCES', + F95PPCOM = r'%(_python_)s myfc.py f95pp $TARGET $SOURCES', + F95PPCOMSTR = 'Building f95pp $TARGET from $SOURCES', + OBJSUFFIX='.obj') +env.Object(source = 'test01.f95') +env.Object(source = 'test02.F95') +""" % locals()) + +test.write('test01.f95', "A .f95 file.\n#f95\n") +test.write('test02.F95', "A .F95 file.\n#%s\n" % f95pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f95 test01.obj from test01.f95 +Building %(f95pp)s test02.obj from test02.F95 +""" % locals())) + +test.must_match('test01.obj', "A .f95 file.\n") +test.must_match('test02.obj', "A .F95 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F95FILESUFFIXES.py b/test/Fortran/F95FILESUFFIXES.py new file mode 100644 index 0000000..119629d --- /dev/null +++ b/test/Fortran/F95FILESUFFIXES.py @@ -0,0 +1,101 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 default file suffix: .f90/.F90 for F90 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F95 = r'%(_python_)s myfortran.py f95', + FORTRAN = r'%(_python_)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.f95') +env.Program(target = 'test10', source = 'test10.F95') +""" % locals()) + +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.f95', "This is a .f95 file.\n#link\n#f95\n") +test.write('test10.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 .f95 file.\n") +test.must_match('test10' + _exe, "This is a .F95 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F95FILESUFFIXES2.py b/test/Fortran/F95FILESUFFIXES2.py new file mode 100644 index 0000000..d89839b --- /dev/null +++ b/test/Fortran/F95FILESUFFIXES2.py @@ -0,0 +1,91 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 non-default file suffix: .f/.F for F95 +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py f77', + F95 = r'%(_python_)s myfortran.py f95', + F95FILESUFFIXES = ['.f', '.F', '.f95', '.F95'], + tools = ['default', 'f95']) +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.F') +env.Program(target = 'test03', source = 'test03.f95') +env.Program(target = 'test04', source = 'test04.F95') +env.Program(target = 'test05', source = 'test05.f77') +env.Program(target = 'test06', source = 'test06.F77') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#link\n#f95\n") +test.write('test02.F', "This is a .F file.\n#link\n#f95\n") +test.write('test03.f95', "This is a .f95 file.\n#link\n#f95\n") +test.write('test04.F95', "This is a .F95 file.\n#link\n#f95\n") +test.write('test05.f77', "This is a .f77 file.\n#link\n#f77\n") +test.write('test06.F77', "This is a .F77 file.\n#link\n#f77\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 .f95 file.\n") +test.must_match('test04' + _exe, "This is a .F95 file.\n") +test.must_match('test05' + _exe, "This is a .f77 file.\n") +test.must_match('test06' + _exe, "This is a .F77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/F95FLAGS.py b/test/Fortran/F95FLAGS.py new file mode 100644 index 0000000..8c3ce09 --- /dev/null +++ b/test/Fortran/F95FLAGS.py @@ -0,0 +1,166 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + F95 = r'%(_python_)s myfortran.py g95', + F95FLAGS = '-x', + FORTRAN = r'%(_python_)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 = 'test13', source = 'test13.f95') +env.Program(target = 'test14', source = 'test14.F95') +""" % locals()) + +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('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, " -c -y\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -c -y\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -c -y\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -c -y\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -c -y\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -c -y\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -c -y\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -c -y\nThis is a .FPP file.\n") +test.must_match('test13' + _exe, " -c -x\nThis is a .f95 file.\n") +test.must_match('test14' + _exe, " -c -x\nThis is a .F95 file.\n") + + +fc = 'f95' +g95 = test.detect_tool(fc) + + +if g95: + test.subdir('x') + + test.write(['x','dummy.i'], +""" +# Exists only such that -Ix finds the directory... +""") + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(F95 = '%(fc)s') +f95 = foo.Dictionary('F95') +bar = foo.Clone(F95 = r'%(_python_)s wrapper.py ' + f95, F95FLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f95') +bar.Program(target = 'bar', source = 'bar.f95') +""" % locals()) + + test.write('foo.f95', r""" + PROGRAM FOO + PRINT *,'foo.f95' + STOP + END +""") + + test.write('bar.f95', r""" + PROGRAM BAR + PRINT *,'bar.f95' + STOP + END +""") + + + test.run(arguments = 'foo' + _exe, stderr = None) + + test.run(program = test.workpath('foo'), stdout = " foo.f95\n") + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + test.run(arguments = 'bar' + _exe) + + test.run(program = test.workpath('bar'), stdout = " bar.f95\n") + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRAN.py b/test/Fortran/FORTRAN.py new file mode 100644 index 0000000..4a2529c --- /dev/null +++ b/test/Fortran/FORTRAN.py @@ -0,0 +1,146 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + FORTRAN = r'%(_python_)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') +""" % locals()) + +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.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") + + + +fc = 'f77' +f77 = test.detect_tool(fc) +FTN_LIB = test.gccFortranLibs() + +if f77: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(FORTRAN = '%(fc)s') +f77 = foo.Dictionary('FORTRAN') +bar = foo.Clone(FORTRAN = r'%(_python_)s wrapper.py ' + f77) +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + 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() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANCOM.py b/test/Fortran/FORTRANCOM.py new file mode 100644 index 0000000..6948b96 --- /dev/null +++ b/test/Fortran/FORTRANCOM.py @@ -0,0 +1,90 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + FORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + FORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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') +""" % locals()) + +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#fortranpp\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#fortranpp\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#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#link\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#link\n#fortranpp\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.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANCOMSTR.py b/test/Fortran/FORTRANCOMSTR.py new file mode 100644 index 0000000..5efa820 --- /dev/null +++ b/test/Fortran/FORTRANCOMSTR.py @@ -0,0 +1,102 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + fortranpp = 'fortran' +else: + fortranpp = 'fortranpp' + + +test.write('SConstruct', """ +env = Environment(FORTRANCOM = r'%(_python_)s myfc.py fortran $TARGET $SOURCES', + FORTRANCOMSTR = 'Building fortran $TARGET from $SOURCES', + FORTRANPPCOM = r'%(_python_)s myfc.py fortranpp $TARGET $SOURCES', + FORTRANPPCOMSTR = 'Building fortranpp $TARGET from $SOURCES', + OBJSUFFIX='.obj') +env.Object(source = 'test01.f') +env.Object(source = 'test02.F') +env.Object(source = 'test03.for') +env.Object(source = 'test04.FOR') +env.Object(source = 'test05.ftn') +env.Object(source = 'test06.FTN') +env.Object(source = 'test07.fpp') +env.Object(source = 'test08.FPP') +""" % locals()) + +test.write('test01.f', "A .f file.\n#fortran\n") +test.write('test02.F', "A .F file.\n#%s\n" % fortranpp) +test.write('test03.for', "A .for file.\n#fortran\n") +test.write('test04.FOR', "A .FOR file.\n#%s\n" % fortranpp) +test.write('test05.ftn', "A .ftn file.\n#fortran\n") +test.write('test06.FTN', "A .FTN file.\n#%s\n" % fortranpp) +test.write('test07.fpp', "A .fpp file.\n#fortranpp\n") +test.write('test08.FPP', "A .FPP file.\n#fortranpp\n") + +test.run(stdout = test.wrap_stdout("""\ +Building fortran test01.obj from test01.f +Building %(fortranpp)s test02.obj from test02.F +Building fortran test03.obj from test03.for +Building %(fortranpp)s test04.obj from test04.FOR +Building fortran test05.obj from test05.ftn +Building %(fortranpp)s test06.obj from test06.FTN +Building fortranpp test07.obj from test07.fpp +Building fortranpp test08.obj from test08.FPP +""" % locals())) + +test.must_match('test01.obj', "A .f file.\n") +test.must_match('test02.obj', "A .F file.\n") +test.must_match('test03.obj', "A .for file.\n") +test.must_match('test04.obj', "A .FOR file.\n") +test.must_match('test05.obj', "A .ftn file.\n") +test.must_match('test06.obj', "A .FTN file.\n") +test.must_match('test07.obj', "A .fpp file.\n") +test.must_match('test08.obj', "A .FPP file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANFILESUFFIXES.py b/test/Fortran/FORTRANFILESUFFIXES.py new file mode 100644 index 0000000..92e30ea --- /dev/null +++ b/test/Fortran/FORTRANFILESUFFIXES.py @@ -0,0 +1,94 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 default file suffix: .f/.F for FORTRAN +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + FORTRAN = r'%(_python_)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') +""" % locals()) + +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.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.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANFILESUFFIXES2.py b/test/Fortran/FORTRANFILESUFFIXES2.py new file mode 100644 index 0000000..8ba0962 --- /dev/null +++ b/test/Fortran/FORTRANFILESUFFIXES2.py @@ -0,0 +1,89 @@ +#!/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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +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 non default file suffix: .f, .f90 and .f95 for FORTRAN +test.write('SConstruct', """ +env = Environment(LINK = r'%(_python_)s mylink.py', + LINKFLAGS = [], + F77 = r'%(_python_)s myfortran.py g77', + FORTRAN = r'%(_python_)s myfortran.py fortran', + FORTRANFILESUFFIXES = ['.f', '.f95', '.f90', '.ffake'], + tools = ['default', 'fortran']) +#print env.Dump() +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.f90') +env.Program(target = 'test03', source = 'test03.f95') +env.Program(target = 'test04', source = 'test04.ffake') +env.Program(target = 'test05', source = 'test05.f77') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.f90', "This is a .f90 file.\n#link\n#fortran\n") +test.write('test03.f95', "This is a .f95 file.\n#link\n#fortran\n") +test.write('test04.ffake', "This is a .ffake file.\n#link\n#fortran\n") +test.write('test05.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 .f90 file.\n") +test.must_match('test03' + _exe, "This is a .f95 file.\n") +test.must_match('test04' + _exe, "This is a .ffake file.\n") +test.must_match('test05' + _exe, "This is a .f77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANFLAGS.py b/test/Fortran/FORTRANFLAGS.py new file mode 100644 index 0000000..8c5e781 --- /dev/null +++ b/test/Fortran/FORTRANFLAGS.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 TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +_exe = TestSCons._exe + +write_fake_link(test) + +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'%(_python_)s mylink.py', + LINKFLAGS = [], + FORTRAN = r'%(_python_)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') +""" % locals()) + +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.run(arguments = '.', stderr = None) + +test.must_match('test01' + _exe, " -c -x\nThis is a .f file.\n") +test.must_match('test02' + _exe, " -c -x\nThis is a .F file.\n") +test.must_match('test03' + _exe, " -c -x\nThis is a .for file.\n") +test.must_match('test04' + _exe, " -c -x\nThis is a .FOR file.\n") +test.must_match('test05' + _exe, " -c -x\nThis is a .ftn file.\n") +test.must_match('test06' + _exe, " -c -x\nThis is a .FTN file.\n") +test.must_match('test07' + _exe, " -c -x\nThis is a .fpp file.\n") +test.must_match('test08' + _exe, " -c -x\nThis is a .FPP file.\n") + + +fc = 'f77' +g77 = test.detect_tool(fc) + +if g77: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(FORTRAN = '%(fc)s') +f77 = foo.Dictionary('FORTRAN') +bar = foo.Clone(FORTRAN = r'%(_python_)s wrapper.py ' + f77, FORTRANFLAGS = '-Ix') +foo.Program(target = 'foo', source = 'foo.f') +bar.Program(target = 'bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar' + _exe, stderr = None) + else: + 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() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANMODDIR.py b/test/Fortran/FORTRANMODDIR.py new file mode 100644 index 0000000..3c14632 --- /dev/null +++ b/test/Fortran/FORTRANMODDIR.py @@ -0,0 +1,106 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import os.path +import re +import sys +mod_regex = "(?im)^\\s*MODULE\\s+(?!PROCEDURE)(\\w+)" +contents = open(sys.argv[2]).read() +modules = re.findall(mod_regex, contents) +modules = [os.path.join(sys.argv[1], m.lower()+'.mod') for m in modules] +for t in sys.argv[3:] + modules: + open(t, 'wb').write('myfortran.py wrote %s\n' % os.path.split(t)[1]) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(FORTRANCOM = r'%(_python_)s myfortran.py $FORTRANMODDIR $SOURCE $TARGET', + FORTRANMODDIR = 'modules') +env.Object(target = 'test1.obj', source = 'test1.f') +env.Object(target = 'sub2/test2.obj', source = 'test1.f', + FORTRANMODDIR='${TARGET.dir}') +env.Object(target = 'sub3/test3.obj', source = 'test1.f', + FORTRANCOM = r'%(_python_)s myfortran.py $_FORTRANMODFLAG $SOURCE $TARGET', + FORTRANMODDIR='${TARGET.dir}') +""" % locals()) + +test.write('test1.f', """\ + PROGRAM TEST + USE MOD_FOO + USE MOD_BAR + PRINT *,'TEST.f' + CALL P + STOP + END + MODULE MOD_FOO + IMPLICIT NONE + CONTAINS + SUBROUTINE P + PRINT *,'mod_foo' + END SUBROUTINE P + END MODULE MOD_FOO + MODULE PROCEDURE MOD_BAR + IMPLICIT NONE + CONTAINS + SUBROUTINE P + PRINT *,'mod_bar' + END SUBROUTINE P + END MODULE MOD_BAR +""") + +test.run(arguments = '.', stderr = None) + +test.must_match('test1.obj', "myfortran.py wrote test1.obj\n") +test.must_match(['modules', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n") +test.must_not_exist(['modules', 'mod_bar.mod']) + +test.must_match(['sub2', 'test2.obj'], "myfortran.py wrote test2.obj\n") +test.must_match(['sub2', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n") + +test.must_match(['sub3', 'test3.obj'], "myfortran.py wrote test3.obj\n") +test.must_match(['sub3', 'mod_foo.mod'], "myfortran.py wrote mod_foo.mod\n") + +test.up_to_date(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANPATH.py b/test/Fortran/FORTRANPATH.py new file mode 100644 index 0000000..ee01aee --- /dev/null +++ b/test/Fortran/FORTRANPATH.py @@ -0,0 +1,335 @@ +#!/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 TestSCons + +_exe = TestSCons._exe +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() + +fc = 'f77' +if not test.detect_tool(fc): + test.skip_test('Could not find a f77 tool; skipping test.\n') + +test.subdir('include', + 'subdir', + ['subdir', 'include'], + 'foobar', + 'inc2') + + + +test.write('SConstruct', """ +env = Environment(FORTRAN = '%s', + FORTRANPATH = ['$FOO', '${TARGET.dir}', '${SOURCE.dir}'], + FOO='include') +obj = env.Object(target='foobar/prog', source='subdir/prog.f') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +VariantDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(FORTRAN = '%s', + FORTRANPATH=[include, '#foobar', '#subdir']) +SConscript('variant/SConscript', "env") +""" % (fc, fc)) + +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' + include 'sss.f' + include 'ttt.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.write(['subdir', 'sss.f'], +r""" + PRINT *, 'subdir/sss.f' +""") + +test.write(['subdir', 'ttt.f'], +r""" + PRINT *, 'subdir/ttt.f' +""") + + +import sys +if sys.platform[:5] == 'sunos': + # Sun f77 always put some junk in stderr + test.run(arguments = args, stderr = None) +else: + test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f + include/foo.f 1 + include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f + subdir/include/foo.f 1 + subdir/include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f + include/foo.f 1 + include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +# 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' +""") + +if sys.platform[:5] == 'sunos': + # Sun f77 always put some junk in stderr + test.run(arguments = args, stderr = None) +else: + test.run(arguments = args) + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f + include/foo.f 2 + include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f + subdir/include/foo.f 1 + subdir/include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f + include/foo.f 2 + include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +# 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' +""") + +if sys.platform[:5] == 'sunos': + # Sun f77 always put some junk in stderr + test.run(arguments = args, stderr = None) +else: + test.run(arguments = args) + + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f + include/foo.f 2 + include/bar.f 2 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f + subdir/include/foo.f 1 + subdir/include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f + include/foo.f 2 + include/bar.f 2 + subdir/sss.f + subdir/ttt.f +""") + +# 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(FORTRAN = '%s', + FORTRANPATH = Split('inc2 include ${TARGET.dir} ${SOURCE.dir}')) +obj = env.Object(target='foobar/prog', source='subdir/prog.f') +env.Program(target='prog', source=obj) +SConscript('subdir/SConscript', "env") + +VariantDir('variant', 'subdir', 0) +include = Dir('include') +env = Environment(FORTRAN = '%s', + FORTRANPATH=['inc2', include, '#foobar', '#subdir']) +SConscript('variant/SConscript', "env") +""" % (fc, fc)) + +test.up_to_date(arguments = args) + + + +# +test.write(['inc2', 'foo.f'], +r""" + PRINT *, 'inc2/foo.f 1' + INCLUDE 'bar.f' +""") + +if sys.platform[:5] == 'sunos': + # Sun f77 always put some junk in stderr + test.run(arguments = args, stderr = None) +else: + test.run(arguments = args) + + +test.run(program = test.workpath(prog), + stdout = """\ + subdir/prog.f + inc2/foo.f 1 + include/bar.f 2 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(subdir_prog), + stdout = """\ + subdir/prog.f + subdir/include/foo.f 1 + subdir/include/bar.f 1 + subdir/sss.f + subdir/ttt.f +""") + +test.run(program = test.workpath(variant_prog), + stdout = """\ + subdir/prog.f + include/foo.f 2 + include/bar.f 2 + subdir/sss.f + subdir/ttt.f +""") + +test.up_to_date(arguments = args) + + + +# Check that a null-string FORTRANPATH doesn't blow up. +test.write('SConstruct', """ +env = Environment(FORTRANPATH = '') +env.Object('foo', source = 'empty.f') +""") + +test.write('empty.f', '') + +if sys.platform[:5] == 'sunos': + # Sun f77 always put some junk in stderr + test.run(arguments = '.', stderr = None) +else: + test.run(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/FORTRANPPFILESUFFIXES.py b/test/Fortran/FORTRANPPFILESUFFIXES.py new file mode 100644 index 0000000..e0c6974 --- /dev/null +++ b/test/Fortran/FORTRANPPFILESUFFIXES.py @@ -0,0 +1,89 @@ +#!/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. +# +""" Test manipulating FORTRANPPFILESUFFIXES. """ + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +from common import write_fake_link + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +write_fake_link(test) + +test.write('myfortran.py', r""" +import getopt +import sys + +comment = '#' + sys.argv[1] +args = sys.argv[2:] +# First parse defines, since getopt won't have it +defines = [] +for a in args[:]: + if a.startswith("-D") or a.startswith("/D"): + defines.append(a[2:]) + args.remove(a) + +opts, args = getopt.getopt(args, 'co:') +for opt, arg in opts: + if opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for d in defines: + outfile.write("#define %s\n" % (d,)) +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + +# Test non default file suffix: .f, .f90 and .f95 for FORTRAN +test.write('SConstruct', """ +env = Environment(LINK=r'%(_python_)s mylink.py', + LINKFLAGS=[], + CPPDEFINES=["mosdef"], + F77=r'%(_python_)s myfortran.py g77', + FORTRAN=r'%(_python_)s myfortran.py fortran', + FORTRANPPFILESUFFIXES=['.f', '.fpp'], + tools=['default', 'fortran']) +env.Program(target = 'test01', source = 'test01.f') +env.Program(target = 'test02', source = 'test02.fpp') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#link\n#fortran\n") +test.write('test02.fpp', "This is a .fpp file.\n#link\n#fortran\n") + +test.run(arguments='.', stderr=None) + +test.must_match('test01' + _exe, "#define mosdef\nThis is a .f file.\n") +test.must_match('test02' + _exe, "#define mosdef\nThis is a .fpp file.\n") + +test.pass_test() diff --git a/test/Fortran/FORTRANSUFFIXES.py b/test/Fortran/FORTRANSUFFIXES.py new file mode 100644 index 0000000..583b71b --- /dev/null +++ b/test/Fortran/FORTRANSUFFIXES.py @@ -0,0 +1,172 @@ +#!/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 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'%(_python_)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') +""" % locals()) + +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 +""") + +expect = test.wrap_stdout("""\ +%(_python_)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" +""" % locals()) + +test.run(arguments='.', stdout=expect) + +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 +""") + +expect = test.wrap_stdout("""\ +%(_python_)s myfc.py test1.o test1.f +""" % locals()) + +test.run(arguments='.', stdout=expect) + +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' +""") + +expect = test.wrap_stdout("""\ +%(_python_)s myfc.py test1.o test1.f +Install file: "test1.x" as "test1_x" +""" % locals()) + +test.run(arguments='.', stdout=expect) + +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' +""") + +expect = test.wrap_stdout("""\ +%(_python_)s myfc.py test1.o test1.f +Install file: "test1.h" as "test1_h" +""" % locals()) + +test.run(arguments='.', stdout=expect) + +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() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF03.py b/test/Fortran/SHF03.py new file mode 100644 index 0000000..6502f49 --- /dev/null +++ b/test/Fortran/SHF03.py @@ -0,0 +1,146 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +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:K:') +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(SHF03 = r'%(_python_)s myfortran.py g03', + SHFORTRAN = r'%(_python_)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 = 'test13', source = 'test13.f03') +env.SharedObject(target = 'test14', source = 'test14.F03') +""" % locals()) + +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('test13.f03', "This is a .f03 file.\n#g03\n") +test.write('test14.F03', "This is a .F03 file.\n#g03\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test13' + _obj, "This is a .f03 file.\n") +test.must_match(obj_ + 'test14' + _obj, "This is a .F03 file.\n") + +fc = 'f03' +g03 = test.detect_tool(fc) + +if g03: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF03 = '%(fc)s') +shf03 = foo.Dictionary('SHF03') +bar = foo.Clone(SHF03 = r'%(_python_)s wrapper.py ' + shf03) +foo.SharedObject(target = 'foo/foo', source = 'foo.f03') +bar.SharedObject(target = 'bar/bar', source = 'bar.f03') +""" % locals()) + + test.write('foo.f03', r""" + PROGRAM FOO + PRINT *,'foo.f03' + STOP + END +""") + + test.write('bar.f03', r""" + PROGRAM BAR + PRINT *,'bar.f03' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF08.py b/test/Fortran/SHF08.py new file mode 100644 index 0000000..85f2bcd --- /dev/null +++ b/test/Fortran/SHF08.py @@ -0,0 +1,144 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +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:K:') +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(SHF08 = r'%(_python_)s myfortran.py g08', + SHFORTRAN = r'%(_python_)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.f08') +env.SharedObject(target = 'test10', source = 'test10.F08') +""" % locals()) + +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.f08', "This is a .f08 file.\n#g08\n") +test.write('test10.F08', "This is a .F08 file.\n#g08\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test09' + _obj, "This is a .f08 file.\n") +test.must_match(obj_ + 'test10' + _obj, "This is a .F08 file.\n") + +fc = 'f08' +g08 = test.detect_tool(fc) + +if g08: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF08 = '%(fc)s') +shf08 = foo.Dictionary('SHF08') +bar = foo.Clone(SHF08 = r'%(_python_)s wrapper.py ' + shf08) +foo.SharedObject(target = 'foo/foo', source = 'foo.f08') +bar.SharedObject(target = 'bar/bar', source = 'bar.f08') +""" % locals()) + + test.write('foo.f08', r""" + PROGRAM FOO + PRINT *,'foo.f08' + ENDPROGRAM FOO +""") + + test.write('bar.f08', r""" + PROGRAM BAR + PRINT *,'bar.f08' + ENDPROGRAM BAR +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF77.py b/test/Fortran/SHF77.py new file mode 100644 index 0000000..ff2a0ca --- /dev/null +++ b/test/Fortran/SHF77.py @@ -0,0 +1,145 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +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:K:') +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'%(_python_)s myfortran.py g77', + SHFORTRAN = r'%(_python_)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') +""" % locals()) + +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.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test09' + _obj, "This is a .f77 file.\n") + +fc = 'f77' +f77 = test.detect_tool(fc) + +if f77: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF77 = '%(fc)s') +shf77 = foo.Dictionary('SHF77') +bar = foo.Clone(SHF77 = r'%(_python_)s wrapper.py ' + shf77, tools = ['default', 'f77'], F77FILESUFFIXES = ['.f']) +foo.SharedObject(target = 'foo/foo', source = 'foo.f') +bar.SharedObject(target = 'bar/bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF77COM.py b/test/Fortran/SHF77COM.py new file mode 100644 index 0000000..c99207f --- /dev/null +++ b/test/Fortran/SHF77COM.py @@ -0,0 +1,97 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +obj_ = TestSCons.shobj_ + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF77COM = r'%(_python_)s myfortran.py f77 $TARGET $SOURCES', + SHF77PPCOM = r'%(_python_)s myfortran.py f77pp $TARGET $SOURCES', + SHFORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + SHFORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortranpp\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortranpp\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortranpp\n") +test.write('test09.f77', "This is a .f77 file.\n#f77\n") +test.write('test10.F77', "This is a .F77 file.\n#f77pp\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test09' + _obj, "This is a .f77 file.\n") +test.must_match(obj_ + 'test10' + _obj, "This is a .F77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF77COMSTR.py b/test/Fortran/SHF77COMSTR.py new file mode 100644 index 0000000..7a43a4a --- /dev/null +++ b/test/Fortran/SHF77COMSTR.py @@ -0,0 +1,86 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f77pp = 'f77' +else: + f77pp = 'f77pp' + + +test.write('SConstruct', """ +env = Environment(SHF77COM = r'%(_python_)s myfc.py f77 $TARGET $SOURCES', + SHF77COMSTR = 'Building f77 $TARGET from $SOURCES', + SHF77PPCOM = r'%(_python_)s myfc.py f77pp $TARGET $SOURCES', + SHF77PPCOMSTR = 'Building f77pp $TARGET from $SOURCES', + SHOBJPREFIX='', SHOBJSUFFIX='.shobj') +env.SharedObject(source = 'test09.f77') +env.SharedObject(source = 'test10.F77') +""" % locals()) + +test.write('test01.f', "A .f file.\n#f77\n") +test.write('test02.F', "A .F file.\n#%s\n" % f77pp) +test.write('test03.for', "A .for file.\n#f77\n") +test.write('test04.FOR', "A .FOR file.\n#%s\n" % f77pp) +test.write('test05.ftn', "A .ftn file.\n#f77\n") +test.write('test06.FTN', "A .FTN file.\n#%s\n" % f77pp) +test.write('test07.fpp', "A .fpp file.\n#f77pp\n") +test.write('test08.FPP', "A .FPP file.\n#f77pp\n") +test.write('test09.f77', "A .f77 file.\n#f77\n") +test.write('test10.F77', "A .F77 file.\n#%s\n" % f77pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f77 test09.shobj from test09.f77 +Building %(f77pp)s test10.shobj from test10.F77 +""" % locals())) + +test.must_match('test09.shobj', "A .f77 file.\n") +test.must_match('test10.shobj', "A .F77 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF77FLAGS.py b/test/Fortran/SHF77FLAGS.py new file mode 100644 index 0000000..644b827 --- /dev/null +++ b/test/Fortran/SHF77FLAGS.py @@ -0,0 +1,128 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +_obj = TestSCons._shobj +obj_ = TestSCons.shobj_ + +test = TestSCons.TestSCons() + + + +test.write('myg77.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'cf:K:o:x') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + elif opt not in ('-f', '-K'): 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'%(_python_)s myg77.py') +env.Append(SHF77FLAGS = '-x') +env.SharedObject(target = 'test09', source = 'test09.f77') +env.SharedObject(target = 'test10', source = 'test10.F77') +""" % locals()) + +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(obj_ + 'test09' + _obj, " -c -x\nThis is a .f77 file.\n") +test.must_match(obj_ + 'test10' + _obj, " -c -x\nThis is a .F77 file.\n") + + +fc = 'f77' +g77 = test.detect_tool(fc) + +if g77: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF77 = '%(fc)s') +shf77 = foo.Dictionary('SHF77') +bar = foo.Clone(SHF77 = r'%(_python_)s wrapper.py ' + shf77, + tools = ["default", 'f77'], F77FILESUFFIXES = [".f"]) +bar.Append(SHF77FLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF90.py b/test/Fortran/SHF90.py new file mode 100644 index 0000000..486b57b --- /dev/null +++ b/test/Fortran/SHF90.py @@ -0,0 +1,147 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +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:K:') +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'%(_python_)s myfortran.py g90', + SHFORTRAN = r'%(_python_)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 = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +""" % locals()) + +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('test11.f90', "This is a .f90 file.\n#g90\n") +test.write('test12.F90', "This is a .F90 file.\n#g90\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test11' + _obj, "This is a .f90 file.\n") +test.must_match(obj_ + 'test12' + _obj, "This is a .F90 file.\n") + + +fc = 'f90' +g90 = test.detect_tool(fc) + +if g90: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF90 = '%(fc)s') +shf90 = foo.Dictionary('SHF90') +bar = foo.Clone(SHF90 = r'%(_python_)s wrapper.py ' + shf90) +foo.SharedObject(target = 'foo/foo', source = 'foo.f90') +bar.SharedObject(target = 'bar/bar', source = 'bar.f90') +""" % locals()) + + test.write('foo.f90', r""" + PROGRAM FOO + PRINT *,'foo.f90' + STOP + END +""") + + test.write('bar.f90', r""" + PROGRAM BAR + PRINT *,'bar.f90' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF90COM.py b/test/Fortran/SHF90COM.py new file mode 100644 index 0000000..415cb9b --- /dev/null +++ b/test/Fortran/SHF90COM.py @@ -0,0 +1,107 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +obj_ = TestSCons.shobj_ + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF90COM = r'%(_python_)s myfortran.py f90 $TARGET $SOURCES', + SHF90PPCOM = r'%(_python_)s myfortran.py f90pp $TARGET $SOURCES', + SHFORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + SHFORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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 = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +env2 = Environment(SHF90COM = r'%(_python_)s myfortran.py f90 $TARGET $SOURCES', + SHF90PPCOM = r'%(_python_)s myfortran.py f90pp $TARGET $SOURCES') +env2.SharedObject(target = 'test21', source = 'test21.f90') +env2.SharedObject(target = 'test22', source = 'test22.F90') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortranpp\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortranpp\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortranpp\n") +test.write('test11.f90', "This is a .f90 file.\n#f90\n") +test.write('test12.F90', "This is a .F90 file.\n#f90pp\n") + +test.write('test21.f90', "This is a .f90 file.\n#f90\n") +test.write('test22.F90', "This is a .F90 file.\n#f90pp\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test11' + _obj, "This is a .f90 file.\n") +test.must_match(obj_ + 'test12' + _obj, "This is a .F90 file.\n") + +test.must_match(obj_ + 'test21' + _obj, "This is a .f90 file.\n") +test.must_match(obj_ + 'test22' + _obj, "This is a .F90 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF90COMSTR.py b/test/Fortran/SHF90COMSTR.py new file mode 100644 index 0000000..a3353fa --- /dev/null +++ b/test/Fortran/SHF90COMSTR.py @@ -0,0 +1,78 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f90pp = 'f90' +else: + f90pp = 'f90pp' + + +test.write('SConstruct', """ +env = Environment(SHF90COM = r'%(_python_)s myfc.py f90 $TARGET $SOURCES', + SHF90COMSTR = 'Building f90 $TARGET from $SOURCES', + SHF90PPCOM = r'%(_python_)s myfc.py f90pp $TARGET $SOURCES', + SHF90PPCOMSTR = 'Building f90pp $TARGET from $SOURCES', + SHOBJPREFIX='', SHOBJSUFFIX='.shobj') +env.SharedObject(source = 'test01.f90') +env.SharedObject(source = 'test02.F90') +""" % locals()) + +test.write('test01.f90', "A .f90 file.\n#f90\n") +test.write('test02.F90', "A .F90 file.\n#%s\n" % f90pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f90 test01.shobj from test01.f90 +Building %(f90pp)s test02.shobj from test02.F90 +""" % locals())) + +test.must_match('test01.shobj', "A .f90 file.\n") +test.must_match('test02.shobj', "A .F90 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF90FLAGS.py b/test/Fortran/SHF90FLAGS.py new file mode 100644 index 0000000..d5066c6 --- /dev/null +++ b/test/Fortran/SHF90FLAGS.py @@ -0,0 +1,153 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +_obj = TestSCons._shobj +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:K:o:xy') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + elif opt not in ('-f', '-K'): 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'%(_python_)s myfortran.py g90', + SHFORTRAN = r'%(_python_)s myfortran.py fortran') +env.Append(SHF90FLAGS = '-x', + 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 = 'test11', source = 'test11.f90') +env.SharedObject(target = 'test12', source = 'test12.F90') +""" % locals()) + +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('test11.f90', "This is a .f90 file.\n#g90\n") +test.write('test12.F90', "This is a .F90 file.\n#g90\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, " -c -y\nThis is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, " -c -y\nThis is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, " -c -y\nThis is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, " -c -y\nThis is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, " -c -y\nThis is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, " -c -y\nThis is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, " -c -y\nThis is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, " -c -y\nThis is a .FPP file.\n") +test.must_match(obj_ + 'test11' + _obj, " -c -x\nThis is a .f90 file.\n") +test.must_match(obj_ + 'test12' + _obj, " -c -x\nThis is a .F90 file.\n") + +fc = 'f90' +g90 = test.detect_tool(fc) + +if g90: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF90 = '%(fc)s') +shf90 = foo.Dictionary('SHF90') +bar = foo.Clone(SHF90 = r'%(_python_)s wrapper.py ' + shf90) +bar.Append(SHF90FLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f90') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f90') +""" % locals()) + + test.write('foo.f90', r""" + PROGRAM FOO + PRINT *,'foo.f90' + STOP + END +""") + + test.write('bar.f90', r""" + PROGRAM BAR + PRINT *,'bar.f90' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF95.py b/test/Fortran/SHF95.py new file mode 100644 index 0000000..0b64923 --- /dev/null +++ b/test/Fortran/SHF95.py @@ -0,0 +1,146 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +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:K:') +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'%(_python_)s myfortran.py g95', + SHFORTRAN = r'%(_python_)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 = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % locals()) + +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('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(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test13' + _obj, "This is a .f95 file.\n") +test.must_match(obj_ + 'test14' + _obj, "This is a .F95 file.\n") + +fc = 'f95' +g95 = test.detect_tool(fc) + +if g95: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF95 = '%(fc)s') +shf95 = foo.Dictionary('SHF95') +bar = foo.Clone(SHF95 = r'%(_python_)s wrapper.py ' + shf95) +foo.SharedObject(target = 'foo/foo', source = 'foo.f95') +bar.SharedObject(target = 'bar/bar', source = 'bar.f95') +""" % locals()) + + test.write('foo.f95', r""" + PROGRAM FOO + PRINT *,'foo.f95' + STOP + END +""") + + test.write('bar.f95', r""" + PROGRAM BAR + PRINT *,'bar.f95' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF95COM.py b/test/Fortran/SHF95COM.py new file mode 100644 index 0000000..0984b20 --- /dev/null +++ b/test/Fortran/SHF95COM.py @@ -0,0 +1,107 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +obj_ = TestSCons.shobj_ + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHF95COM = r'%(_python_)s myfortran.py f95 $TARGET $SOURCES', + SHF95PPCOM = r'%(_python_)s myfortran.py f95pp $TARGET $SOURCES', + SHFORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + SHFORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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 = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +env2 = Environment(SHF95COM = r'%(_python_)s myfortran.py f95 $TARGET $SOURCES', + SHF95PPCOM = r'%(_python_)s myfortran.py f95pp $TARGET $SOURCES') +env2.SharedObject(target = 'test21', source = 'test21.f95') +env2.SharedObject(target = 'test22', source = 'test22.F95') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortranpp\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortranpp\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortranpp\n") +test.write('test13.f95', "This is a .f95 file.\n#f95\n") +test.write('test14.F95', "This is a .F95 file.\n#f95pp\n") + +test.write('test21.f95', "This is a .f95 file.\n#f95\n") +test.write('test22.F95', "This is a .F95 file.\n#f95pp\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") +test.must_match(obj_ + 'test13' + _obj, "This is a .f95 file.\n") +test.must_match(obj_ + 'test14' + _obj, "This is a .F95 file.\n") + +test.must_match(obj_ + 'test21' + _obj, "This is a .f95 file.\n") +test.must_match(obj_ + 'test22' + _obj, "This is a .F95 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF95COMSTR.py b/test/Fortran/SHF95COMSTR.py new file mode 100644 index 0000000..5aec6b0 --- /dev/null +++ b/test/Fortran/SHF95COMSTR.py @@ -0,0 +1,78 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + f95pp = 'f95' +else: + f95pp = 'f95pp' + + +test.write('SConstruct', """ +env = Environment(SHF95COM = r'%(_python_)s myfc.py f95 $TARGET $SOURCES', + SHF95COMSTR = 'Building f95 $TARGET from $SOURCES', + SHF95PPCOM = r'%(_python_)s myfc.py f95pp $TARGET $SOURCES', + SHF95PPCOMSTR = 'Building f95pp $TARGET from $SOURCES', + SHOBJPREFIX='', SHOBJSUFFIX='.shobj') +env.SharedObject(source = 'test01.f95') +env.SharedObject(source = 'test02.F95') +""" % locals()) + +test.write('test01.f95', "A .f95 file.\n#f95\n") +test.write('test02.F95', "A .F95 file.\n#%s\n" % f95pp) + +test.run(stdout = test.wrap_stdout("""\ +Building f95 test01.shobj from test01.f95 +Building %(f95pp)s test02.shobj from test02.F95 +""" % locals())) + +test.must_match('test01.shobj', "A .f95 file.\n") +test.must_match('test02.shobj', "A .F95 file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHF95FLAGS.py b/test/Fortran/SHF95FLAGS.py new file mode 100644 index 0000000..8e75878 --- /dev/null +++ b/test/Fortran/SHF95FLAGS.py @@ -0,0 +1,162 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +_obj = TestSCons._shobj +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:K:o:xy') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + elif opt not in ('-f', '-K'): 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'%(_python_)s myfortran.py g95', + SHFORTRAN = r'%(_python_)s myfortran.py fortran') +env.Append(SHF95FLAGS = '-x', + 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 = 'test13', source = 'test13.f95') +env.SharedObject(target = 'test14', source = 'test14.F95') +""" % locals()) + +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('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(obj_ + 'test01' + _obj, " -c -y\nThis is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, " -c -y\nThis is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, " -c -y\nThis is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, " -c -y\nThis is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, " -c -y\nThis is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, " -c -y\nThis is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, " -c -y\nThis is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, " -c -y\nThis is a .FPP file.\n") +test.must_match(obj_ + 'test13' + _obj, " -c -x\nThis is a .f95 file.\n") +test.must_match(obj_ + 'test14' + _obj, " -c -x\nThis is a .F95 file.\n") + + + +fc = 'f95' +g95 = test.detect_tool(fc) + +if g95: + + test.subdir('x') + + test.write(['x','dummy.i'], +""" +# Exists only such that -Ix finds the directory... +""") + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHF95 = '%(fc)s') +shf95 = foo.Dictionary('SHF95') +bar = foo.Clone(SHF95 = r'%(_python_)s wrapper.py ' + shf95) +bar.Append(SHF95FLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f95') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f95') +""" % locals()) + + test.write('foo.f95', r""" + PROGRAM FOO + PRINT *,'foo.f95' + STOP + END +""") + + test.write('bar.f95', r""" + PROGRAM BAR + PRINT *,'bar.f95' + STOP + END +""") + + + test.run(arguments = 'foo', stderr = None) + + test.must_not_exist('wrapper.out') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHFORTRAN.py b/test/Fortran/SHFORTRAN.py new file mode 100644 index 0000000..d9ae55d --- /dev/null +++ b/test/Fortran/SHFORTRAN.py @@ -0,0 +1,140 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +obj_ = TestSCons.shobj_ + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'cf:o:K:') +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'%(_python_)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') +""" % locals()) + +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.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") + + + +fc = 'f77' +fortran = test.detect_tool(fc) + +if fortran: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHFORTRAN = '%(fc)s') +shfortran = foo.Dictionary('SHFORTRAN') +bar = foo.Clone(SHFORTRAN = r'%(_python_)s wrapper.py ' + shfortran) +foo.SharedObject(target = 'foo/foo', source = 'foo.f') +bar.SharedObject(target = 'bar/bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHFORTRANCOM.py b/test/Fortran/SHFORTRANCOM.py new file mode 100644 index 0000000..f89358d --- /dev/null +++ b/test/Fortran/SHFORTRANCOM.py @@ -0,0 +1,89 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +obj_ = TestSCons.shobj_ + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import sys +comment = '#' + sys.argv[1] +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in infile.readlines(): + if l[:len(comment)] != comment: + outfile.write(l) +sys.exit(0) +""") + + + +test.write('SConstruct', """ +env = Environment(SHFORTRANCOM = r'%(_python_)s myfortran.py fortran $TARGET $SOURCES', + SHFORTRANPPCOM = r'%(_python_)s myfortran.py fortranpp $TARGET $SOURCES') +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') +""" % locals()) + +test.write('test01.f', "This is a .f file.\n#fortran\n") +test.write('test02.F', "This is a .F file.\n#fortranpp\n") +test.write('test03.for', "This is a .for file.\n#fortran\n") +test.write('test04.FOR', "This is a .FOR file.\n#fortranpp\n") +test.write('test05.ftn', "This is a .ftn file.\n#fortran\n") +test.write('test06.FTN', "This is a .FTN file.\n#fortranpp\n") +test.write('test07.fpp', "This is a .fpp file.\n#fortranpp\n") +test.write('test08.FPP', "This is a .FPP file.\n#fortranpp\n") + +test.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, "This is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, "This is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, "This is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, "This is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, "This is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, "This is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, "This is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, "This is a .FPP file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHFORTRANCOMSTR.py b/test/Fortran/SHFORTRANCOMSTR.py new file mode 100644 index 0000000..3b801db --- /dev/null +++ b/test/Fortran/SHFORTRANCOMSTR.py @@ -0,0 +1,102 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myfc.py', r""" +import sys +fline = '#'+sys.argv[1]+'\n' +outfile = open(sys.argv[2], 'wb') +infile = open(sys.argv[3], 'rb') +for l in [l for l in infile.readlines() if l != fline]: + outfile.write(l) +sys.exit(0) +""") + +if not TestSCons.case_sensitive_suffixes('.f','.F'): + fortranpp = 'fortran' +else: + fortranpp = 'fortranpp' + + +test.write('SConstruct', """ +env = Environment(SHFORTRANCOM = r'%(_python_)s myfc.py fortran $TARGET $SOURCES', + SHFORTRANCOMSTR = 'Building fortran $TARGET from $SOURCES', + SHFORTRANPPCOM = r'%(_python_)s myfc.py fortranpp $TARGET $SOURCES', + SHFORTRANPPCOMSTR = 'Building fortranpp $TARGET from $SOURCES', + SHOBJPREFIX='', SHOBJSUFFIX='.shobj') +env.SharedObject(source = 'test01.f') +env.SharedObject(source = 'test02.F') +env.SharedObject(source = 'test03.for') +env.SharedObject(source = 'test04.FOR') +env.SharedObject(source = 'test05.ftn') +env.SharedObject(source = 'test06.FTN') +env.SharedObject(source = 'test07.fpp') +env.SharedObject(source = 'test08.FPP') +""" % locals()) + +test.write('test01.f', "A .f file.\n#fortran\n") +test.write('test02.F', "A .F file.\n#%s\n" % fortranpp) +test.write('test03.for', "A .for file.\n#fortran\n") +test.write('test04.FOR', "A .FOR file.\n#%s\n" % fortranpp) +test.write('test05.ftn', "A .ftn file.\n#fortran\n") +test.write('test06.FTN', "A .FTN file.\n#%s\n" % fortranpp) +test.write('test07.fpp', "A .fpp file.\n#fortranpp\n") +test.write('test08.FPP', "A .FPP file.\n#fortranpp\n") + +test.run(stdout = test.wrap_stdout("""\ +Building fortran test01.shobj from test01.f +Building %(fortranpp)s test02.shobj from test02.F +Building fortran test03.shobj from test03.for +Building %(fortranpp)s test04.shobj from test04.FOR +Building fortran test05.shobj from test05.ftn +Building %(fortranpp)s test06.shobj from test06.FTN +Building fortranpp test07.shobj from test07.fpp +Building fortranpp test08.shobj from test08.FPP +""" % locals())) + +test.must_match('test01.shobj', "A .f file.\n") +test.must_match('test02.shobj', "A .F file.\n") +test.must_match('test03.shobj', "A .for file.\n") +test.must_match('test04.shobj', "A .FOR file.\n") +test.must_match('test05.shobj', "A .ftn file.\n") +test.must_match('test06.shobj', "A .FTN file.\n") +test.must_match('test07.shobj', "A .fpp file.\n") +test.must_match('test08.shobj', "A .FPP file.\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/SHFORTRANFLAGS.py b/test/Fortran/SHFORTRANFLAGS.py new file mode 100644 index 0000000..11116f4 --- /dev/null +++ b/test/Fortran/SHFORTRANFLAGS.py @@ -0,0 +1,143 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_obj = TestSCons._shobj +obj_ = TestSCons.shobj_ + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'cf:K:o:x') +optstring = '' +for opt, arg in opts: + if opt == '-o': out = arg + elif opt not in ('-f', '-K'): 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'%(_python_)s myfortran.py') +env.Append(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') +""" % locals()) + +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.run(arguments = '.', stderr = None) + +test.must_match(obj_ + 'test01' + _obj, " -c -x\nThis is a .f file.\n") +test.must_match(obj_ + 'test02' + _obj, " -c -x\nThis is a .F file.\n") +test.must_match(obj_ + 'test03' + _obj, " -c -x\nThis is a .for file.\n") +test.must_match(obj_ + 'test04' + _obj, " -c -x\nThis is a .FOR file.\n") +test.must_match(obj_ + 'test05' + _obj, " -c -x\nThis is a .ftn file.\n") +test.must_match(obj_ + 'test06' + _obj, " -c -x\nThis is a .FTN file.\n") +test.must_match(obj_ + 'test07' + _obj, " -c -x\nThis is a .fpp file.\n") +test.must_match(obj_ + 'test08' + _obj, " -c -x\nThis is a .FPP file.\n") + +fc = 'f77' +fortran = test.detect_tool(fc) + +if fortran: + + test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(SHFORTRAN = '%(fc)s') +shfortran = foo.Dictionary('SHFORTRAN') +bar = foo.Clone(SHFORTRAN = r'%(_python_)s wrapper.py ' + shfortran) +bar.Append(SHFORTRANFLAGS = '-Ix') +foo.SharedLibrary(target = 'foo/foo', source = 'foo.f') +bar.SharedLibrary(target = 'bar/bar', source = 'bar.f') +""" % locals()) + + 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') + + import sys + if sys.platform[:5] == 'sunos': + test.run(arguments = 'bar', stderr = None) + else: + test.run(arguments = 'bar') + + test.must_match('wrapper.out', "wrapper.py\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/USE-MODULE-CASEINSENS.py b/test/Fortran/USE-MODULE-CASEINSENS.py new file mode 100644 index 0000000..44c03fe --- /dev/null +++ b/test/Fortran/USE-MODULE-CASEINSENS.py @@ -0,0 +1,67 @@ +#!/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__" + +# This test tests whether a file that defines a module "a" and +# then uses it with a different case ("A") works. Pre-2.0, this +# gave a spurious dependency cycle error. +# See http://scons.tigris.org/issues/show_bug.cgi?id=2574 + +import TestSCons + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +test.write('myfortran.py', r""" +# dummy fortran +import sys +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(FORTRANCOM = r'%(_python_)s myfortran.py $SOURCE $TARGET') +env.Object("mod1", "mod1.f") +""" % locals()) + +test.write('mod1.f', """\ +module a +end module a + +module b + use A +end module b +""") + +test.run(arguments = '.', stderr = None) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/USE-MODULE.py b/test/Fortran/USE-MODULE.py new file mode 100644 index 0000000..8f537dd --- /dev/null +++ b/test/Fortran/USE-MODULE.py @@ -0,0 +1,94 @@ +#!/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 TestSCons + +_python_ = TestSCons._python_ +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + + + +test.write('myfortran.py', r""" +import os.path +import re +import sys +mod_regex = "(?im)^\\s*MODULE\\s+(?!PROCEDURE)(\\w+)" +contents = open(sys.argv[1]).read() +modules = re.findall(mod_regex, contents) +modules = [m.lower()+'.mod' for m in modules] +for t in sys.argv[2:] + modules: + open(t, 'wb').write('myfortran.py wrote %s\n' % os.path.split(t)[1]) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(FORTRANCOM = r'%(_python_)s myfortran.py $SOURCE $TARGET') +env.Object(target = 'test1.obj', source = 'test1.f') +""" % locals()) + +test.write('test1.f', """\ + PROGRAM TEST + USE MOD_FOO + USE MOD_BAR + PRINT *,'TEST.f' + CALL P + STOP + END + MODULE MOD_FOO + IMPLICIT NONE + CONTAINS + SUBROUTINE P + PRINT *,'mod_foo' + END SUBROUTINE P + END MODULE MOD_FOO + MODULE PROCEDURE MOD_BAR + IMPLICIT NONE + CONTAINS + SUBROUTINE P + PRINT *,'mod_bar' + END SUBROUTINE P + END MODULE MOD_BAR +""") + +test.run(arguments = '.', stderr = None) + +test.must_match('test1.obj', "myfortran.py wrote test1.obj\n") +test.must_match('mod_foo.mod', "myfortran.py wrote mod_foo.mod\n") +test.must_not_exist('mod_bar.mod') + +test.up_to_date(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/common.py b/test/Fortran/common.py new file mode 100644 index 0000000..6763ef4 --- /dev/null +++ b/test/Fortran/common.py @@ -0,0 +1,75 @@ +#!/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__" + + +"""This module implements common code to all fortran tests.""" + +import sys + +def write_fake_link(t): + """Writes a mylink.py script to remove the link step for 'fake' (e.g. + non-compiled) tests.""" + if sys.platform == 'win32': + t.write('mylink.py', r""" +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == '-o': + out = args[1] + args = args[2:] + continue + if not a[0] in '/-': + break + args = args[1:] + if a[:5].lower() == '/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: + t.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) + """) + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/link-with-cxx.py b/test/Fortran/link-with-cxx.py new file mode 100644 index 0000000..a29558e --- /dev/null +++ b/test/Fortran/link-with-cxx.py @@ -0,0 +1,155 @@ +#!/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__" + +""" +Verify the smart_link() warning messages used when attempting to link +C++ and Fortran object files, and the ability to suppress them with the +right --warn= options. +""" + +import re + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons(match = TestSCons.match_re) + + +test.write('test_linker.py', r""" +import sys +if sys.argv[1] == '-o': + outfile = open(sys.argv[2], 'wb') + infiles = sys.argv[3:] +elif sys.argv[1][:5] == '/OUT:': + outfile = open(sys.argv[1][5:], 'wb') + infiles = sys.argv[2:] +for infile in infiles: + outfile.write(open(infile, 'rb').read()) +outfile.close() +sys.exit(0) +""") + + +test.write('test_fortran.py', r""" +import sys +outfile = open(sys.argv[2], 'wb') +for infile in sys.argv[4:]: + outfile.write(open(infile, 'rb').read()) +outfile.close() +sys.exit(0) +""") + + +test.write('SConstruct', """ +import SCons.Tool.link +def copier(target, source, env): + s = str(source[0]) + t = str(target[0]) + open(t, 'wb').write(open(s, 'rb').read()) +env = Environment(CXX = r'%(_python_)s test_linker.py', + CXXCOM = Action(copier), + SMARTLINK = SCons.Tool.link.smart_link, + LINK = r'$SMARTLINK', + LINKFLAGS = '', + # We want to re-define this as follows (so as to + # not rely on a real Fortran compiler) but can't + # because $FORTRANCOM is defined with an extra space + # so it ends up as a CommandAction, not a LazyAction. + # Must look into changing that after 1.0 is out. + #FORTRANCOM = Action(copier)) + FORTRAN = r'%(_python_)s test_fortran.py') +env.Program('prog1.exe', ['f1.cpp', 'f2.f']) +env.Program('prog2.exe', ['f1.cpp', 'f2.f']) +if ARGUMENTS.get('NO_LINK'): + # Can remove no-deprecated when we drop Python1.5 + SetOption('warn', ['no-link', 'no-deprecated']) +if ARGUMENTS.get('NO_MIX'): + # Can remove no-deprecated when we drop Python1.5 + SetOption('warn', ['no-fortran-cxx-mix', 'no-deprecated']) +""" % locals()) + +test.write('f1.cpp', "f1.cpp\n") +test.write('f2.f', "f2.f\n") + +expect = (""" +scons: warning: Using \\$CXX to link Fortran and C\\+\\+ code together. +\tThis may generate a buggy executable if the '%s test_linker.py' +\tcompiler does not know how to deal with Fortran runtimes. +""" % re.escape(_python_)) + TestSCons.file_expr + +test.run(arguments = '.', stderr=expect) + +test.must_match('prog1.exe', "f1.cpp\nf2.f\n") +test.must_match('prog2.exe', "f1.cpp\nf2.f\n") + +test.run(arguments = '-c .', stderr=expect) + +test.must_not_exist('prog1.exe') +test.must_not_exist('prog2.exe') + +test.run(arguments = '--warning=no-link .') + +test.must_match('prog1.exe', "f1.cpp\nf2.f\n") +test.must_match('prog2.exe', "f1.cpp\nf2.f\n") + +test.run(arguments = '-c .', stderr=expect) + +test.must_not_exist('prog1.exe') +test.must_not_exist('prog2.exe') + +test.run(arguments = '--warning=no-fortran-cxx-mix .') + +test.must_match('prog1.exe', "f1.cpp\nf2.f\n") +test.must_match('prog2.exe', "f1.cpp\nf2.f\n") + +test.run(arguments = '-c .', stderr=expect) + +test.must_not_exist('prog1.exe') +test.must_not_exist('prog2.exe') + +test.run(arguments = 'NO_LINK=1 .') + +test.must_match('prog1.exe', "f1.cpp\nf2.f\n") +test.must_match('prog2.exe', "f1.cpp\nf2.f\n") + +test.run(arguments = '-c .', stderr=expect) + +test.must_not_exist('prog1.exe') +test.must_not_exist('prog2.exe') + +test.run(arguments = 'NO_MIX=1 .') + +test.must_match('prog1.exe', "f1.cpp\nf2.f\n") +test.must_match('prog2.exe', "f1.cpp\nf2.f\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Fortran/module-subdir.py b/test/Fortran/module-subdir.py new file mode 100644 index 0000000..def1e5c --- /dev/null +++ b/test/Fortran/module-subdir.py @@ -0,0 +1,120 @@ +#!/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__" + +""" +Validate that $FORTRANMODDIR values get expanded correctly on Fortran +command lines relative to the appropriate subdirectory. +""" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.subdir('subdir', + ['subdir', 'src'], + ['subdir', 'build']) + +test.write('myfortran.py', r""" +import getopt +import os +import sys +comment = '#' + sys.argv[1] +length = len(comment) +opts, args = getopt.getopt(sys.argv[2:], 'cM:o:') +for opt, arg in opts: + if opt == '-o': out = arg + elif opt == '-M': modsubdir = arg +import os +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:7] == 'module ': + module = modsubdir + os.sep + l[7:-1] + '.mod' + open(module, 'wb').write('myfortran.py wrote %s\n' % module) + if l[:length] != comment: + outfile.write(l) +sys.exit(0) +""") + +test.write('myar.py', """\ +import sys +t = open(sys.argv[1], 'wb') +for s in sys.argv[2:]: + t.write(open(s, 'rb').read()) +t.close +sys.exit(0) +""") + +test.write('SConstruct', """\ +env = Environment(FORTRANMODDIRPREFIX = '-M', + FORTRANMODDIR = 'modules', + FORTRAN = r'%(_python_)s myfortran.py fortran', + AR = 'myar.py', + ARCOM = r'%(_python_)s $AR $TARGET $SOURCES', + RANLIBCOM = '') +Export('env') +objs = SConscript('subdir/SConscript') +env.Library('bidule', objs) +""" % locals()) + +test.write(['subdir', 'SConscript'], """\ +Import('env') + +env['FORTRANMODDIR'] = 'build' +sources = ['src/modfile.f'] +objs = env.Object(sources) +Return("objs") +""") + +test.write(['subdir', 'src', 'modfile.f'], """\ +#fortran comment +module somemodule + +integer :: nothing + +end module +""") + + +test.run(arguments = '.') + +somemodule = os.path.join('subdir', 'build', 'somemodule.mod') + +expect = "myfortran.py wrote %s\n" % somemodule + +test.must_match(['subdir', 'build', 'somemodule.mod'], expect) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: |
