summaryrefslogtreecommitdiffstats
path: root/test/CXX/CXX.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/CXX/CXX.py')
-rw-r--r--test/CXX/CXX.py127
1 files changed, 47 insertions, 80 deletions
diff --git a/test/CXX/CXX.py b/test/CXX/CXX.py
index 4be4199..836324f 100644
--- a/test/CXX/CXX.py
+++ b/test/CXX/CXX.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
-# __COPYRIGHT__
+# MIT License
+#
+# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -20,9 +22,6 @@
# 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 sys
import TestSCons
@@ -32,33 +31,16 @@ _exe = TestSCons._exe
test = TestSCons.TestSCons()
+test.file_fixture('mylink.py')
-
+# Note: mycxx.py differs from the general fixture file mycompile.py
+# in arg handling: that one is intended for use as a *COM consvar,
+# where no compiler consvars will be passed on, this one is intended
+# for use as $CXX, where arguments like -o come into play.
if sys.platform == 'win32':
-
- test.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], 'r')
-outfile = open(out, 'w')
-for l in infile.readlines():
- if l[:8] != '/*link*/':
- outfile.write(l)
-sys.exit(0)
-""")
-
test.write('myc++.py', r"""
import sys
+
args = sys.argv[1:]
inf = None
while args:
@@ -73,79 +55,67 @@ while args:
inf = a
continue
if a[:3] == '/Fo': out = a[3:]
-infile = open(inf, 'r')
-outfile = open(out, 'w')
-for l in infile.readlines():
- if l[:7] != '/*c++*/':
- outfile.write(l)
-sys.exit(0)
-""")
-
-else:
- test.write('mylink.py', r"""
-import getopt
-import sys
-opts, args = getopt.getopt(sys.argv[1:], 'o:')
-for opt, arg in opts:
- if opt == '-o': out = arg
-infile = open(args[0], 'r')
-outfile = open(out, 'w')
-for l in infile.readlines():
- if l[:8] != '/*link*/':
- outfile.write(l)
+with open(inf, 'rb') as infile, open(out, 'wb') as outfile:
+ for line in infile:
+ if not line.startswith(b'/*c++*/'):
+ outfile.write(line)
sys.exit(0)
""")
+else:
test.write('myc++.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], 'r')
-outfile = open(out, 'w')
-for l in infile.readlines():
- if l[:7] != '/*c++*/':
- outfile.write(l)
+
+with open(args[0], 'rb') as infile, open(out, 'wb') as outfile:
+ for line in infile:
+ if not line.startswith(b'/*c++*/'):
+ outfile.write(line)
sys.exit(0)
""")
test.write('SConstruct', """
-env = Environment(LINK = r'%(_python_)s mylink.py',
- LINKFLAGS = [],
- CXX = r'%(_python_)s myc++.py',
- CXXFLAGS = [])
-env.Program(target = 'test1', source = 'test1.cc')
-env.Program(target = 'test2', source = 'test2.cpp')
-env.Program(target = 'test3', source = 'test3.cxx')
-env.Program(target = 'test4', source = 'test4.c++')
-env.Program(target = 'test5', source = 'test5.C++')
+env = Environment(
+ LINK=r'%(_python_)s mylink.py',
+ LINKFLAGS=[],
+ CXX=r'%(_python_)s myc++.py',
+ CXXFLAGS=[],
+)
+env.Program(target='test1', source='test1.cc')
+env.Program(target='test2', source='test2.cpp')
+env.Program(target='test3', source='test3.cxx')
+env.Program(target='test4', source='test4.c++')
+env.Program(target='test5', source='test5.C++')
""" % locals())
test.write('test1.cc', r"""This is a .cc file.
/*c++*/
-/*link*/
+#link
""")
test.write('test2.cpp', r"""This is a .cpp file.
/*c++*/
-/*link*/
+#link
""")
test.write('test3.cxx', r"""This is a .cxx file.
/*c++*/
-/*link*/
+#link
""")
test.write('test4.c++', r"""This is a .c++ file.
/*c++*/
-/*link*/
+#link
""")
test.write('test5.C++', r"""This is a .C++ file.
/*c++*/
-/*link*/
+#link
""")
test.run(arguments = '.', stderr = None)
@@ -161,35 +131,32 @@ test.must_match('test4' + _exe, "This is a .c++ file.\n", mode='r')
test.must_match('test5' + _exe, "This is a .C++ file.\n", mode='r')
if TestSCons.case_sensitive_suffixes('.c', '.C'):
-
test.write('SConstruct', """
-env = Environment(LINK = r'%(_python_)s mylink.py',
- LINKFLAGS = [],
- CXX = r'%(_python_)s myc++.py',
- CXXFLAGS = [])
-env.Program(target = 'test6', source = 'test6.C')
+env = Environment(
+ LINK=r'%(_python_)s mylink.py',
+ LINKFLAGS=[],
+ CXX=r'%(_python_)s myc++.py',
+ CXXFLAGS=[],
+)
+env.Program(target='test6', source='test6.C')
""" % locals())
test.write('test6.C', r"""This is a .C file.
/*c++*/
-/*link*/
+#link
""")
test.run(arguments = '.', stderr = None)
-
test.must_match('test6' + _exe, "This is a .C file.\n", mode='r')
-
-
-
test.file_fixture('wrapper.py')
test.write('SConstruct', """
foo = Environment()
cxx = foo.Dictionary('CXX')
-bar = Environment(CXX = r'%(_python_)s wrapper.py ' + cxx)
-foo.Program(target = 'foo', source = 'foo.cxx')
-bar.Program(target = 'bar', source = 'bar.cxx')
+bar = Environment(CXX=r'%(_python_)s wrapper.py ' + cxx)
+foo.Program(target='foo', source='foo.cxx')
+bar.Program(target='bar', source='bar.cxx')
""" % locals())
test.write('foo.cxx', r"""