summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2022-01-19 17:35:38 (GMT)
committerMats Wichmann <mats@linux.com>2022-01-19 17:35:38 (GMT)
commita94950db308154798e65e07704e65a85c0aef6f6 (patch)
tree0c3e08a4c51d1540030441517353209b1604df41
parentb54e9d95e0ee70460cdb86773f31660f2c16d650 (diff)
downloadSCons-a94950db308154798e65e07704e65a85c0aef6f6.zip
SCons-a94950db308154798e65e07704e65a85c0aef6f6.tar.gz
SCons-a94950db308154798e65e07704e65a85c0aef6f6.tar.bz2
A bit more test fixture work
mylex.py is now a general fixture Some of the existing fixtures had a bit more cleanup. the unneeded mylink_win32.py is dropped (only referenced by a test which already skips on win32, and the general mylink.py covers the win32 case anyway). Signed-off-by: Mats Wichmann <mats@linux.com>
-rw-r--r--test/CC/CC-fixture/mycc.py12
-rw-r--r--test/CFILESUFFIX.py32
-rw-r--r--test/CPPFLAGS.py63
-rw-r--r--test/CXX/CXX-fixture/myc++.py12
-rw-r--r--test/CXX/CXXFILESUFFIX.py33
-rw-r--r--test/LEX/LEX.py55
-rw-r--r--test/LEX/LEXFLAGS.py27
-rw-r--r--test/fixture/mygcc.py18
-rw-r--r--test/fixture/mylex.py37
-rw-r--r--test/fixture/mylink.py10
-rw-r--r--test/fixture/mylink_win32.py16
-rw-r--r--test/fixture/wrapper.py9
-rw-r--r--test/fixture/wrapper_with_args.py9
13 files changed, 154 insertions, 179 deletions
diff --git a/test/CC/CC-fixture/mycc.py b/test/CC/CC-fixture/mycc.py
index 78017f4..eb11c87 100644
--- a/test/CC/CC-fixture/mycc.py
+++ b/test/CC/CC-fixture/mycc.py
@@ -17,18 +17,18 @@ def fake_win32_cc():
args = sys.argv[1:]
inf = None
while args:
- a = args[0]
- if a == '-o':
+ arg = args[0]
+ if arg == '-o':
out = args[1]
args = args[2:]
continue
args = args[1:]
- if a[0] not in '/-':
+ if arg[0] not in '/-':
if not inf:
- inf = a
+ inf = arg
continue
- if a[:3] == '/Fo':
- out = a[3:]
+ if arg.startswith('/Fo'):
+ out = arg[3:]
with open(inf, 'rb') as infile, open(out, 'wb') as outfile:
for line in infile:
diff --git a/test/CFILESUFFIX.py b/test/CFILESUFFIX.py
index 0a62307..2d24e25 100644
--- a/test/CFILESUFFIX.py
+++ b/test/CFILESUFFIX.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__"
"""
Verify that we can set CFILESUFFIX to arbitrary values.
@@ -35,32 +34,19 @@ _python_ = TestSCons._python_
test = TestSCons.TestSCons()
-test.write('mylex.py', """
-import getopt
-import sys
-if sys.platform == 'win32':
- longopts = ['nounistd']
-else:
- longopts = []
-cmd_opts, args = getopt.getopt(sys.argv[1:], 't', longopts)
-for a in args:
- with open(a, 'rb') as f:
- contents = f.read()
- sys.stdout.write((contents.replace(b'LEX', b'mylex.py')).decode())
-sys.exit(0)
-""")
+test.file_fixture('mylex.py')
test.write('SConstruct', """
-env = Environment(LEX = r'%(_python_)s mylex.py', tools = ['lex'])
-env.CFile(target = 'foo', source = 'foo.l')
-env.Clone(CFILESUFFIX = '.xyz').CFile(target = 'bar', source = 'bar.l')
+env = Environment(LEX=r'%(_python_)s mylex.py', tools=['lex'])
+env.CFile(target='foo', source='foo.l')
+env.Clone(CFILESUFFIX='.xyz').CFile(target='bar', source='bar.l')
# Make sure that calling a Tool on a construction environment *after*
# we've set CFILESUFFIX doesn't overwrite the value.
-env2 = Environment(tools = [], CFILESUFFIX = '.env2')
+env2 = Environment(tools=[], CFILESUFFIX='.env2')
env2.Tool('lex')
env2['LEX'] = r'%(_python_)s mylex.py'
-env2.CFile(target = 'f3', source = 'f3.l')
+env2.CFile(target='f3', source='f3.l')
""" % locals())
input = r"""
diff --git a/test/CPPFLAGS.py b/test/CPPFLAGS.py
index 2808a53..ebae2df 100644
--- a/test/CPPFLAGS.py
+++ b/test/CPPFLAGS.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
@@ -38,25 +37,22 @@ test = TestSCons.TestSCons()
if sys.platform == 'win32':
test.skip_test('Skipping on win32.\n')
-if sys.platform == 'win32':
- test.file_fixture('mylink_win32.py', 'mylink.py')
-else:
- test.file_fixture('mylink.py')
-
+test.file_fixture('mylink.py')
test.file_fixture('mygcc.py')
-
test.write('SConstruct', """
-env = Environment(CPPFLAGS = '-x',
- LINK = r'%(_python_)s mylink.py',
- LINKFLAGS = [],
- CC = r'%(_python_)s mygcc.py cc',
- CXX = r'%(_python_)s mygcc.py c++',
- CXXFLAGS = [],
- FORTRAN = r'%(_python_)s mygcc.py g77',
- OBJSUFFIX = '.obj',
- PROGSUFFIX = '.exe')
-env.Program(target = 'foo', source = Split('test1.c test2.cpp test3.F'))
+env = Environment(
+ CPPFLAGS='-x',
+ LINK=r'%(_python_)s mylink.py',
+ LINKFLAGS=[],
+ CC=r'%(_python_)s mygcc.py cc',
+ CXX=r'%(_python_)s mygcc.py c++',
+ CXXFLAGS=[],
+ FORTRAN=r'%(_python_)s mygcc.py g77',
+ OBJSUFFIX='.obj',
+ PROGSUFFIX='.exe',
+)
+env.Program(target='foo', source=Split('test1.c test2.cpp test3.F'))
""" % locals())
test.write('test1.c', r"""test1.c
@@ -86,19 +82,20 @@ else:
test.must_match('mygcc.out', "cc\nc++\n")
test.write('SConstruct', """
-env = Environment(CPPFLAGS = '-x',
- SHLINK = r'%(_python_)s mylink.py',
- SHLINKFLAGS = [],
- CC = r'%(_python_)s mygcc.py cc',
- CXX = r'%(_python_)s mygcc.py c++',
- CXXFLAGS = [],
- FORTRAN = r'%(_python_)s mygcc.py g77',
- OBJSUFFIX = '.obj',
- SHOBJPREFIX = '',
- SHOBJSUFFIX = '.shobj',
- PROGSUFFIX = '.exe')
-env.SharedLibrary(target = File('foo.bar'),
- source = Split('test1.c test2.cpp test3.F'))
+env = Environment(
+ CPPFLAGS='-x',
+ SHLINK=r'%(_python_)s mylink.py',
+ SHLINKFLAGS=[],
+ CC=r'%(_python_)s mygcc.py cc',
+ CXX=r'%(_python_)s mygcc.py c++',
+ CXXFLAGS=[],
+ FORTRAN=r'%(_python_)s mygcc.py g77',
+ OBJSUFFIX='.obj',
+ SHOBJPREFIX='',
+ SHOBJSUFFIX='.shobj',
+ PROGSUFFIX='.exe',
+)
+env.SharedLibrary(target=File('foo.bar'), source=Split('test1.c test2.cpp test3.F'))
""" % locals())
test.write('test1.c', r"""test1.c
diff --git a/test/CXX/CXX-fixture/myc++.py b/test/CXX/CXX-fixture/myc++.py
index 06565c7..d369f61 100644
--- a/test/CXX/CXX-fixture/myc++.py
+++ b/test/CXX/CXX-fixture/myc++.py
@@ -17,18 +17,18 @@ def fake_win32_cxx():
args = sys.argv[1:]
inf = None
while args:
- a = args[0]
- if a == '-o':
+ arg = args[0]
+ if arg == '-o':
out = args[1]
args = args[2:]
continue
args = args[1:]
- if a[0] not in '/-':
+ if arg[0] not in '/-':
if not inf:
- inf = a
+ inf = arg
continue
- if a[:3] == '/Fo':
- out = a[3:]
+ if arg.startswith('/Fo'):
+ out = arg[3:]
with open(inf, 'rb') as infile, open(out, 'wb') as outfile:
for line in infile:
diff --git a/test/CXX/CXXFILESUFFIX.py b/test/CXX/CXXFILESUFFIX.py
index 0ae5827..1c55106 100644
--- a/test/CXX/CXXFILESUFFIX.py
+++ b/test/CXX/CXXFILESUFFIX.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,10 +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 TestSCons
@@ -31,32 +29,19 @@ _python_ = TestSCons._python_
test = TestSCons.TestSCons()
-test.write('mylex.py', """
-import getopt
-import sys
-if sys.platform == 'win32':
- longopts = ['nounistd']
-else:
- longopts = []
-cmd_opts, args = getopt.getopt(sys.argv[1:], 't', longopts)
-for a in args:
- with open(a, 'r') as f:
- contents = f.read()
- sys.stdout.write(contents.replace('LEX', 'mylex.py'))
-sys.exit(0)
-""")
+test.file_fixture('mylex.py')
test.write('SConstruct', """
-env = Environment(LEX = r'%(_python_)s mylex.py', tools = ['lex'])
-env.CXXFile(target = 'foo', source = 'foo.ll')
-env.Clone(CXXFILESUFFIX = '.xyz').CXXFile(target = 'bar', source = 'bar.ll')
+env = Environment(LEX=r'%(_python_)s mylex.py', tools=['lex'])
+env.CXXFile(target='foo', source='foo.ll')
+env.Clone(CXXFILESUFFIX='.xyz').CXXFile(target='bar', source='bar.ll')
# Make sure that calling a Tool on a construction environment *after*
# we've set CXXFILESUFFIX doesn't overwrite the value.
-env2 = Environment(tools = [], CXXFILESUFFIX = '.env2')
+env2 = Environment(tools=[], CXXFILESUFFIX='.env2')
env2.Tool('lex')
env2['LEX'] = r'%(_python_)s mylex.py'
-env2.CXXFile(target = 'f3', source = 'f3.ll')
+env2.CXXFile(target='f3', source='f3.ll')
""" % locals())
input = r"""
diff --git a/test/LEX/LEX.py b/test/LEX/LEX.py
index 79d8359..7dc8436 100644
--- a/test/LEX/LEX.py
+++ b/test/LEX/LEX.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,10 +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 TestSCons
@@ -32,46 +30,29 @@ _exe = TestSCons._exe
test = TestSCons.TestSCons()
-
-
-test.write('mylex.py', """
-import getopt
-import sys
-if sys.platform == 'win32':
- longopts = ['nounistd']
-else:
- longopts = []
-cmd_opts, args = getopt.getopt(sys.argv[1:], 't', longopts)
-for a in args:
- with open(a, 'rb') as f:
- contents = f.read()
- sys.stdout.write(contents.replace(b'LEX', b'mylex.py').decode())
-sys.exit(0)
-""")
+test.file_fixture('mylex.py')
test.write('SConstruct', """
-env = Environment(LEX = r'%(_python_)s mylex.py', tools=['default', 'lex'])
-env.CFile(target = 'aaa', source = 'aaa.l')
-env.CFile(target = 'bbb', source = 'bbb.lex')
-env.CXXFile(target = 'ccc', source = 'ccc.ll')
-env.CXXFile(target = 'ddd', source = 'ddd.lm')
+env = Environment(LEX=r'%(_python_)s mylex.py', tools=['default', 'lex'])
+env.CFile(target='aaa', source='aaa.l')
+env.CFile(target='bbb', source='bbb.lex')
+env.CXXFile(target='ccc', source='ccc.ll')
+env.CXXFile(target='ddd', source='ddd.lm')
""" % locals())
-test.write('aaa.l', "aaa.l\nLEX\n")
-test.write('bbb.lex', "bbb.lex\nLEX\n")
-test.write('ccc.ll', "ccc.ll\nLEX\n")
-test.write('ddd.lm', "ddd.lm\nLEX\n")
+test.write('aaa.l', "aaa.l\nLEX\n")
+test.write('bbb.lex', "bbb.lex\nLEX\n")
+test.write('ccc.ll', "ccc.ll\nLEX\n")
+test.write('ddd.lm', "ddd.lm\nLEX\n")
-test.run(arguments = '.', stderr = None)
+test.run(arguments='.', stderr=None)
# Read in with mode='r' because mylex.py implicitley wrote to stdout
# with mode='w'.
-test.must_match('aaa.c', "aaa.l\nmylex.py\n", mode='r')
-test.must_match('bbb.c', "bbb.lex\nmylex.py\n", mode='r')
-test.must_match('ccc.cc', "ccc.ll\nmylex.py\n", mode='r')
-test.must_match('ddd.m', "ddd.lm\nmylex.py\n", mode='r')
-
-
+test.must_match('aaa.c', "aaa.l\nmylex.py\n", mode='r')
+test.must_match('bbb.c', "bbb.lex\nmylex.py\n", mode='r')
+test.must_match('ccc.cc', "ccc.ll\nmylex.py\n", mode='r')
+test.must_match('ddd.m', "ddd.lm\nmylex.py\n", mode='r')
test.pass_test()
diff --git a/test/LEX/LEXFLAGS.py b/test/LEX/LEXFLAGS.py
index efcf9c4..f7d16c1 100644
--- a/test/LEX/LEXFLAGS.py
+++ b/test/LEX/LEXFLAGS.py
@@ -35,28 +35,7 @@ test = TestSCons.TestSCons()
test.subdir('in')
-test.write('mylex.py', """
-import getopt
-import sys
-import os
-if sys.platform == 'win32':
- longopts = ['nounistd']
-else:
- longopts = []
-cmd_opts, args = getopt.getopt(sys.argv[1:], 'I:tx', longopts)
-opt_string = ''
-i_arguments = ''
-for opt, arg in cmd_opts:
- if opt == '-I': i_arguments = i_arguments + ' ' + arg
- else: opt_string = opt_string + ' ' + opt
-for a in args:
- with open(a, 'r') as f:
- contents = f.read()
- contents = contents.replace('LEXFLAGS', opt_string)
- contents = contents.replace('I_ARGS', i_arguments)
- sys.stdout.write(contents)
-sys.exit(0)
-""")
+test.file_fixture('mylex.py')
test.write('SConstruct', """
env = Environment(
@@ -76,9 +55,7 @@ if sys.platform == 'win32' and not sysconfig.get_platform() in ("mingw",):
lexflags = ' --nounistd' + lexflags
# Read in with mode='r' because mylex.py implicitley wrote to stdout
# with mode='w'.
-test.must_match(['out', 'aaa.c'], "aaa.l\n%s\n out in\n" % lexflags, mode='r')
-
-
+test.must_match(['out', 'aaa.c'], "aaa.l\n%s\n out in\n" % lexflags, mode='r')
test.pass_test()
diff --git a/test/fixture/mygcc.py b/test/fixture/mygcc.py
index 5f524c2..91ca386 100644
--- a/test/fixture/mygcc.py
+++ b/test/fixture/mygcc.py
@@ -1,3 +1,17 @@
+"""
+Phony compiler for testing SCons.
+
+Copies its source file to the target file, dropping lines that match
+a pattern, so we can recognize the tool has made a modification.
+
+The first argument is the language (cc, c__, g77, etc.).
+
+Recognizes a -x option to append the language to 'mygcc.out'
+for tracing purposes.
+
+Intended for use as $CC, $CXX, etc.
+"""
+
import getopt
import sys
@@ -8,8 +22,8 @@ def fake_gcc():
if opt == '-o':
out = arg
elif opt == '-x':
- with open('mygcc.out', 'ab') as f:
- f.write(compiler + b"\n")
+ with open('mygcc.out', 'ab') as logfile:
+ logfile.write(compiler + b"\n")
with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp:
for line in ifp:
diff --git a/test/fixture/mylex.py b/test/fixture/mylex.py
new file mode 100644
index 0000000..accc96a
--- /dev/null
+++ b/test/fixture/mylex.py
@@ -0,0 +1,37 @@
+"""
+Phony lex for testing SCons.
+
+Writes the contents of input file to stdout,
+after "substituting" $LEXFLAGS and $I_ARGS
+
+Intended for use as $LEX
+"""
+
+import getopt
+import sys
+import os
+
+def fake_lex():
+ if sys.platform == 'win32':
+ longopts = ['nounistd']
+ else:
+ longopts = []
+ cmd_opts, args = getopt.getopt(sys.argv[1:], 'I:tx', longopts)
+ opt_string = ''
+ i_arguments = ''
+ for opt, arg in cmd_opts:
+ if opt == '-I':
+ i_arguments = f'{i_arguments} {arg}'
+ else:
+ opt_string = f'{opt_string} {opt}'
+ for arg in args:
+ with open(arg, 'rb') as ifp:
+ contents = ifp.read().decode(encoding='utf-8')
+ contents = contents.replace('LEXFLAGS', opt_string)
+ contents = contents.replace('LEX', 'mylex.py')
+ contents = contents.replace('I_ARGS', i_arguments)
+ sys.stdout.write(contents)
+
+if __name__ == '__main__':
+ fake_lex()
+ sys.exit(0)
diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py
index a0b4e27..f462655 100644
--- a/test/fixture/mylink.py
+++ b/test/fixture/mylink.py
@@ -23,16 +23,16 @@ def fake_link():
def fake_win32_link():
args = sys.argv[1:]
while args:
- a = args[0]
- if a == '-o':
+ arg = args[0]
+ if arg == '-o':
out = args[1]
args = args[2:]
continue
- if a[0] not in '/-':
+ if arg[0] not in '/-':
break
args = args[1:]
- if a.lower().startswith('/out:'):
- out = a[5:]
+ if arg.lower().startswith('/out:'):
+ out = arg[5:]
with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
for line in ifp:
if not line.startswith(b'#link'):
diff --git a/test/fixture/mylink_win32.py b/test/fixture/mylink_win32.py
deleted file mode 100644
index 8edbe70..0000000
--- a/test/fixture/mylink_win32.py
+++ /dev/null
@@ -1,16 +0,0 @@
-import sys
-
-args = sys.argv[1:]
-while args:
- a = args[0]
- if a[0] != '/':
- break
- args.pop(0)
- if a[:5] == '/OUT:':
- out = a[5:]
-
-with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp:
- for line in ifp:
- if not line.startswith(b'#link'):
- ofp.write(line)
-sys.exit(0)
diff --git a/test/fixture/wrapper.py b/test/fixture/wrapper.py
index 112186e..c266cfa 100644
--- a/test/fixture/wrapper.py
+++ b/test/fixture/wrapper.py
@@ -1,3 +1,10 @@
+"""
+Command wrapper, for testing SCons.
+
+Writes the command name to file "wrapper.out",
+then passes the command line on to subprocess.
+No checking is done.
+"""
import os
import sys
import subprocess
@@ -7,4 +14,4 @@ if __name__ == '__main__':
if '--version' not in sys.argv and '-dumpversion' not in sys.argv:
with open(path, 'wb') as f:
f.write(b"wrapper.py\n")
- subprocess.run(sys.argv[1:])
+ subprocess.run(sys.argv[1:], check=False)
diff --git a/test/fixture/wrapper_with_args.py b/test/fixture/wrapper_with_args.py
index b8d6ae5..769aea4 100644
--- a/test/fixture/wrapper_with_args.py
+++ b/test/fixture/wrapper_with_args.py
@@ -1,3 +1,10 @@
+"""
+Command wrapper taking arguments, for testing SCons.
+
+Writes the command name and argument list to file "wrapper.out",
+then passes the command line on to subprocess.
+No checking is done.
+"""
import os
import sys
import subprocess
@@ -6,4 +13,4 @@ if __name__ == '__main__':
path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out')
with open(path, 'a') as f:
f.write("wrapper_with_args.py %s\n" % " ".join(sys.argv[1:]))
- subprocess.run(sys.argv[1:])
+ subprocess.run(sys.argv[1:], check=False)