From b2d5bd79c01af8f51ab41a3d7b7a4b996d1944f8 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sun, 16 Jan 2022 14:15:03 -0700 Subject: Massage test fixtures a bit To avoid double loops, a couple now use fileinput module. CC and CXX tests switch to using general mylink.py fixture instead of locally defined linker script. This did mean that the marker for the mock linker that the script removes had to be harmonized as #link - some were using /*link*/. Could not switch CC/CXX to use the general mycompile.py mock compiler due to difference in intent: mycompile.py is intended to plug in as a *COM variable, which means the whole cmdline is in the caller's control. mycc.py is intended to plug in as CC and mycxx.py as CXX, which means standard os-dependent construction vars will be passed via the default CCCOM and CXXCOM and have to be handled. Signed-off-by: Mats Wichmann --- test/AS/fixture/myas.py | 37 +++++++++---- test/AS/fixture/myas_args.py | 40 +++++++++----- test/CC/CC-fixture/test1.c | 2 +- test/CC/CC-fixture/test2.C | 2 +- test/CC/CC.py | 111 +++++++++++++++---------------------- test/CXX/CXX.py | 127 ++++++++++++++++--------------------------- test/fixture/mycompile.py | 36 ++++++++---- test/fixture/mygcc.py | 31 ++++++----- test/fixture/mylink.py | 27 +++++---- test/fixture/mylink_win32.py | 6 +- test/fixture/myrewrite.py | 13 +++-- 11 files changed, 211 insertions(+), 221 deletions(-) diff --git a/test/AS/fixture/myas.py b/test/AS/fixture/myas.py index 3d05c79..a348ace 100644 --- a/test/AS/fixture/myas.py +++ b/test/AS/fixture/myas.py @@ -1,6 +1,7 @@ import sys -if sys.platform == 'win32': + +def my_win32_as(): args = sys.argv[1:] inf = None while args: @@ -10,29 +11,41 @@ if sys.platform == 'win32': args = args[2:] continue args = args[1:] - if not a[0] in "/-": + if not a[0] in '/-': if not inf: inf = a continue - if a[:3] == '/Fo': out = a[3:] + if a[:3] == '/Fo': + out = a[3:] + with open(inf, 'rb') as ifp, open(out, 'wb') as ofp: - for l in ifp.readlines(): - if l[:3] != b'#as': - ofp.write(l) - sys.exit(0) + for line in ifp: + if not line.startswith(b'#as'): + ofp.write(line) + -else: +def my_as(): import getopt + try: opts, args = getopt.getopt(sys.argv[1:], 'co:') except getopt.GetoptError: # we may be called with --version, just quit if so sys.exit(0) for opt, arg in opts: - if opt == '-o': out = arg + if opt == '-o': + out = arg + if args: with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: - for l in ifp.readlines(): - if l[:3] != b'#as': - ofp.write(l) + for line in ifp: + if not line.startswith(b'#as'): + ofp.write(line) + + +if __name__ == "__main__": + if sys.platform == 'win32': + my_win32_as() + else: + my_as() sys.exit(0) diff --git a/test/AS/fixture/myas_args.py b/test/AS/fixture/myas_args.py index 24d68dc..7a5e6fa 100644 --- a/test/AS/fixture/myas_args.py +++ b/test/AS/fixture/myas_args.py @@ -1,6 +1,7 @@ import sys -if sys.platform == 'win32': + +def my_win32_as(): args = sys.argv[1:] inf = None optstring = '' @@ -21,25 +22,38 @@ if sys.platform == 'win32': out = a[3:] continue optstring = optstring + ' ' + a + with open(inf, 'rb') as ifp, open(out, 'wb') as ofp: - ofp.write(bytearray(optstring + "\n",'utf-8')) - for l in ifp.readlines(): - if l[:3] != b'#as': - ofp.write(l) - sys.exit(0) -else: + optstring = optstring + "\n" + ofp.write(optstring.encode('utf-8')) + for line in ifp: + if not line.startswith(b'#as'): + ofp.write(line) + + +def my_as(): import getopt + opts, args = getopt.getopt(sys.argv[1:], 'co:x') optstring = '' for opt, arg in opts: - if opt == '-o': out = arg - else: optstring = optstring + ' ' + opt + if opt == '-o': + out = arg + else: + optstring = optstring + ' ' + opt with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: - ofp.write(bytearray(optstring + "\n",'utf-8')) - for l in ifp.readlines(): - if l[:3] != b'#as': - ofp.write(l) + optstring = optstring + "\n" + ofp.write(optstring.encode('utf-8')) + for line in ifp: + if not line.startswith(b'#as'): + ofp.write(line) + +if __name__ == "__main__": + if sys.platform == 'win32': + my_win32_as() + else: + my_as() sys.exit(0) diff --git a/test/CC/CC-fixture/test1.c b/test/CC/CC-fixture/test1.c index 7535b0a..6748e2c 100644 --- a/test/CC/CC-fixture/test1.c +++ b/test/CC/CC-fixture/test1.c @@ -1,3 +1,3 @@ This is a .c file. /*cc*/ -/*link*/ +#link diff --git a/test/CC/CC-fixture/test2.C b/test/CC/CC-fixture/test2.C index a1ee9e3..388133b 100644 --- a/test/CC/CC-fixture/test2.C +++ b/test/CC/CC-fixture/test2.C @@ -1,3 +1,3 @@ This is a .C file. /*cc*/ -/*link*/ +#link diff --git a/test/CC/CC.py b/test/CC/CC.py index 6363273..c2562d5 100644 --- a/test/CC/CC.py +++ b/test/CC/CC.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,46 +22,27 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# - -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import sys import TestSCons _python_ = TestSCons._python_ -_exe = TestSCons._exe +_exe = TestSCons._exe test = TestSCons.TestSCons() test.dir_fixture('CC-fixture') +test.file_fixture('mylink.py') +# Note: mycc.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 $CC, 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], 'rb') -outfile = open(out, 'wb') -for l in infile.readlines(): - if l[:8] != b'/*link*/': - outfile.write(l) -sys.exit(0) -""") - test.write('mycc.py', r""" import sys + args = sys.argv[1:] inf = None while args: @@ -69,57 +52,47 @@ while args: args = args[2:] continue args = args[1:] - if not a[0] in '-/': + if a[0] not in '-/': if not inf: inf = a continue - if a[:3] == '/Fo': out = a[3:] -infile = open(inf, 'rb') -outfile = open(out, 'wb') -for l in infile.readlines(): - if l[:6] != b'/*cc*/': - outfile.write(l) -sys.exit(0) -""") - -else: + if a.startswith('/Fo'): + out = a[3:] - test.write('mylink.py', r""" -import getopt -import sys -opts, args = getopt.getopt(sys.argv[1:], 'o:') -for opt, arg in opts: - if opt == '-o': out = arg -infile = open(args[0], 'rb') -outfile = open(out, 'wb') -for l in infile.readlines(): - if l[:8] != b'/*link*/': - outfile.write(l) +with open(inf, 'rb') as infile, open(out, 'wb') as outfile: + for line in infile: + if not line.startswith(b'/*cc*/'): + outfile.write(line) sys.exit(0) """) +else: test.write('mycc.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[:6] != b'/*cc*/': - outfile.write(l) + if opt == '-o': + out = arg + +with open(args[0], 'rb') as infile, open(out, 'wb') as outfile: + for line in infile: + if not line.startswith(b'/*cc*/'): + outfile.write(line) sys.exit(0) """) test.write('SConstruct', """ cc = Environment().Dictionary('CC') -env = Environment(LINK = r'%(_python_)s mylink.py', - LINKFLAGS = [], - CC = r'%(_python_)s mycc.py', - CXX = cc, - CXXFLAGS = []) -env.Program(target = 'test1', source = 'test1.c') +env = Environment( + LINK=r'%(_python_)s mylink.py', + LINKFLAGS=[], + CC=r'%(_python_)s mycc.py', + CXX=cc, + CXXFLAGS=[], +) +env.Program(target='test1', source='test1.c') """ % locals()) test.run(arguments = '.', stderr = None) @@ -130,10 +103,12 @@ if os.path.normcase('.c') == os.path.normcase('.C'): test.write('SConstruct', """ cc = Environment().Dictionary('CC') -env = Environment(LINK = r'%(_python_)s mylink.py', - CC = r'%(_python_)s mycc.py', - CXX = cc) -env.Program(target = 'test2', source = 'test2.C') +env = Environment( + LINK=r'%(_python_)s mylink.py', + CC=r'%(_python_)s mycc.py', + CXX=cc, +) +env.Program(target='test2', source='test2.C') """ % locals()) test.run(arguments = '.', stderr = None) @@ -144,9 +119,9 @@ test.file_fixture('wrapper.py') test.write('SConstruct', """ foo = Environment() cc = foo.Dictionary('CC') -bar = Environment(CC = r'%(_python_)s wrapper.py ' + cc) -foo.Program(target = 'foo', source = 'foo.c') -bar.Program(target = 'bar', source = 'bar.c') +bar = Environment(CC=r'%(_python_)s wrapper.py ' + cc) +foo.Program(target='foo', source='foo.c') +bar.Program(target='bar', source='bar.c') """ % locals()) test.run(arguments = 'foo' + _exe) 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""" diff --git a/test/fixture/mycompile.py b/test/fixture/mycompile.py index 0f37d19..a60a35f 100644 --- a/test/fixture/mycompile.py +++ b/test/fixture/mycompile.py @@ -1,19 +1,31 @@ -r""" -Phony "compiler" for testing SCons. +""" +Phony compiler for testing SCons. + +Copies its source files to the target file, dropping lines that match +a pattern, so we can recognize the tool has made a modification. +Intended for use as a *COM construction variable. + +Calling convention is: + argv[1] the function of the script (cc, c++, as, link etc.) + argv[2] the output file to write + argv[3:] one or more input files to "compile" -Copies its source files to the target file, dropping lines -that match a pattern, so we can recognize the tool -has made a modification. +Invocation often looks like: + Environment(CCCOM = r'%(_python_)s mycompile.py cc $TARGET $SOURCE', ... """ +import fileinput +import getopt import sys +def fake_compile(): + skipline = f"/*{sys.argv[1]}*/\n".encode("utf-8") + with open(sys.argv[2], 'wb') as ofp, fileinput.input(files=sys.argv[3:], mode='rb') as ifp: + for line in ifp: + if line != skipline: + ofp.write(line) + + if __name__ == '__main__': - line = ('/*' + sys.argv[1] + '*/\n').encode() - with open(sys.argv[2], 'wb') as ofp: - for f in sys.argv[3:]: - with open(f, 'rb') as ifp: - lines = [ln for ln in ifp if ln != line] - for ln in lines: - ofp.write(ln) + fake_compile() sys.exit(0) diff --git a/test/fixture/mygcc.py b/test/fixture/mygcc.py index ceb10e5..5f524c2 100644 --- a/test/fixture/mygcc.py +++ b/test/fixture/mygcc.py @@ -1,18 +1,21 @@ import getopt import sys -compiler = sys.argv[1] -clen = len(compiler) + 1 -opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:') -for opt, arg in opts: - if opt == '-o': - out = arg - elif opt == '-x': - with open('mygcc.out', 'a') as f: - f.write(compiler + "\n") +def fake_gcc(): + compiler = sys.argv[1].encode('utf-8') + opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:') + for opt, arg in opts: + if opt == '-o': + out = arg + elif opt == '-x': + with open('mygcc.out', 'ab') as f: + f.write(compiler + b"\n") -with open(out, 'w') as ofp, open(args[0], 'r') as ifp: - for line in ifp.readlines(): - if line[:clen] != '#' + compiler: - ofp.write(line) -sys.exit(0) + with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp: + for line in ifp: + if not line.startswith(b'#' + compiler): + ofp.write(line) + +if __name__ == '__main__': + fake_gcc() + sys.exit(0) diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index 19969f0..a0b4e27 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -1,6 +1,11 @@ """ -Dummy linker for use by tests" +Phony linker for testing SCons. + +Copies its source files to the target file, dropping lines that match +a pattern, so we can recognize the tool has made a modification. +Intended for use as the $LINK construction variable. """ +import fileinput import getopt import sys @@ -10,13 +15,10 @@ def fake_link(): if opt == '-o': out = arg - with open(out, 'w') as ofp: - for f in args: - with open(f, 'r') as ifp: - for line in ifp.readlines(): - if line[:5] != '#link': - ofp.write(line) - sys.exit(0) + with open(out, 'wb') as ofp, fileinput.input(files=args, mode='rb') as ifp: + for line in ifp: + if not line.startswith(b'#link'): + ofp.write(line) def fake_win32_link(): args = sys.argv[1:] @@ -26,18 +28,19 @@ def fake_win32_link(): out = args[1] args = args[2:] continue - if not a[0] in '/-': + if a[0] not in '/-': break args = args[1:] - if a[:5].lower() == '/out:': out = a[5:] + if a.lower().startswith('/out:'): + out = a[5:] with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: - for line in ifp.readlines(): + for line in ifp: if not line.startswith(b'#link'): ofp.write(line) - sys.exit(0) if __name__ == '__main__': if sys.platform == 'win32': fake_win32_link() else: fake_link() + sys.exit(0) diff --git a/test/fixture/mylink_win32.py b/test/fixture/mylink_win32.py index 477fc95..8edbe70 100644 --- a/test/fixture/mylink_win32.py +++ b/test/fixture/mylink_win32.py @@ -9,8 +9,8 @@ while args: if a[:5] == '/OUT:': out = a[5:] -with open(out, 'w') as ofp, open(args[0], 'r') as ifp: - for line in ifp.readlines(): - if line[:5] != '#link': +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/myrewrite.py b/test/fixture/myrewrite.py index 6914611..eb83cac 100644 --- a/test/fixture/myrewrite.py +++ b/test/fixture/myrewrite.py @@ -2,16 +2,19 @@ r""" Phony tool to modify a file in place for testing SCons. Drops lines that match a pattern. Currently used to test -ranlib-related behavior without invoking ranlib. +ranlib and ar behavior without actually invoking those tools. """ import sys -if __name__ == '__main__': - line = ('/*' + sys.argv[1] + '*/\n').encode() +def rewrite(): + line = ('/*' + sys.argv[1] + '*/\n').encode('utf-8') with open(sys.argv[2], 'rb') as ifp: lines = [ln for ln in ifp if ln != line] with open(sys.argv[2], 'wb') as ofp: - for ln in lines: - ofp.write(ln) + ofp.writelines(lines) + + +if __name__ == '__main__': + rewrite() sys.exit(0) -- cgit v0.12 From 8c9ff2495360cdf0928ba13dfa8149f86abe1bc6 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Mon, 17 Jan 2022 13:00:17 -0700 Subject: Drop an unused import - sider complaint Signed-off-by: Mats Wichmann --- test/fixture/mycompile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fixture/mycompile.py b/test/fixture/mycompile.py index a60a35f..15a1c6f 100644 --- a/test/fixture/mycompile.py +++ b/test/fixture/mycompile.py @@ -15,7 +15,6 @@ Invocation often looks like: """ import fileinput -import getopt import sys def fake_compile(): -- cgit v0.12 From b54e9d95e0ee70460cdb86773f31660f2c16d650 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Tue, 18 Jan 2022 16:15:50 -0700 Subject: Also move CC and CXX mock compiler to fixture CC/CC.py uses a local mycc.py and CXX/CXX.py uses a local myc++.py. These could not be replaced by mycompile.py because theu usage model is different, but these two are moved to a local (to the test) fixture directory instead of being inline. Signed-off-by: Mats Wichmann --- test/CC/CC-fixture/.exclude_tests | 1 + test/CC/CC-fixture/mycc.py | 55 +++++++++++++++++++++++++++++++++++++ test/CC/CC.py | 48 -------------------------------- test/CXX/CXX-fixture/.exclude_tests | 1 + test/CXX/CXX-fixture/myc++.py | 55 +++++++++++++++++++++++++++++++++++++ test/CXX/CXX.py | 47 +------------------------------ 6 files changed, 113 insertions(+), 94 deletions(-) create mode 100644 test/CC/CC-fixture/.exclude_tests create mode 100644 test/CC/CC-fixture/mycc.py create mode 100644 test/CXX/CXX-fixture/.exclude_tests create mode 100644 test/CXX/CXX-fixture/myc++.py diff --git a/test/CC/CC-fixture/.exclude_tests b/test/CC/CC-fixture/.exclude_tests new file mode 100644 index 0000000..3f2bc0f --- /dev/null +++ b/test/CC/CC-fixture/.exclude_tests @@ -0,0 +1 @@ +mycc.py diff --git a/test/CC/CC-fixture/mycc.py b/test/CC/CC-fixture/mycc.py new file mode 100644 index 0000000..78017f4 --- /dev/null +++ b/test/CC/CC-fixture/mycc.py @@ -0,0 +1,55 @@ +""" +Phony cc command 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. +Intended for use as the $CXX construction variable. + +Note: mycc.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 $CC, where arguments like -o come into play. +""" +import getopt +import sys + +def fake_win32_cc(): + args = sys.argv[1:] + inf = None + while args: + a = args[0] + if a == '-o': + out = args[1] + args = args[2:] + continue + args = args[1:] + if a[0] not in '/-': + if not inf: + inf = a + continue + if a[:3] == '/Fo': + out = a[3:] + + with open(inf, 'rb') as infile, open(out, 'wb') as outfile: + for line in infile: + if not line.startswith(b'/*cc*/'): + outfile.write(line) + +def fake_cc(): + opts, args = getopt.getopt(sys.argv[1:], 'co:') + for opt, arg in opts: + if opt == '-o': + out = arg + + with open(args[0], 'rb') as infile, open(out, 'wb') as outfile: + for line in infile: + if not line.startswith(b'/*cc*/'): + outfile.write(line) + +if __name__ == '__main__': + print(f"DEBUG: {sys.argv[0]}: {sys.argv[1:]}") + if sys.platform == 'win32': + fake_win32_cc() + else: + fake_cc() + sys.exit(0) diff --git a/test/CC/CC.py b/test/CC/CC.py index c2562d5..a548421 100644 --- a/test/CC/CC.py +++ b/test/CC/CC.py @@ -35,54 +35,6 @@ test = TestSCons.TestSCons() test.dir_fixture('CC-fixture') test.file_fixture('mylink.py') -# Note: mycc.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 $CC, where arguments like -o come into play. -if sys.platform == 'win32': - test.write('mycc.py', r""" -import sys - -args = sys.argv[1:] -inf = None -while args: - a = args[0] - if a == '-o': - out = args[1] - args = args[2:] - continue - args = args[1:] - if a[0] not in '-/': - if not inf: - inf = a - continue - if a.startswith('/Fo'): - out = a[3:] - -with open(inf, 'rb') as infile, open(out, 'wb') as outfile: - for line in infile: - if not line.startswith(b'/*cc*/'): - outfile.write(line) -sys.exit(0) -""") - -else: - test.write('mycc.py', r""" -import getopt -import sys - -opts, args = getopt.getopt(sys.argv[1:], 'co:') -for opt, arg in opts: - if opt == '-o': - out = arg - -with open(args[0], 'rb') as infile, open(out, 'wb') as outfile: - for line in infile: - if not line.startswith(b'/*cc*/'): - outfile.write(line) -sys.exit(0) -""") - test.write('SConstruct', """ cc = Environment().Dictionary('CC') env = Environment( diff --git a/test/CXX/CXX-fixture/.exclude_tests b/test/CXX/CXX-fixture/.exclude_tests new file mode 100644 index 0000000..9e0e6ff --- /dev/null +++ b/test/CXX/CXX-fixture/.exclude_tests @@ -0,0 +1 @@ +myc++.py diff --git a/test/CXX/CXX-fixture/myc++.py b/test/CXX/CXX-fixture/myc++.py new file mode 100644 index 0000000..06565c7 --- /dev/null +++ b/test/CXX/CXX-fixture/myc++.py @@ -0,0 +1,55 @@ +""" +Phony c++ command 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. +Intended for use as the $CXX construction variable. + +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. +""" +import getopt +import sys + +def fake_win32_cxx(): + args = sys.argv[1:] + inf = None + while args: + a = args[0] + if a == '-o': + out = args[1] + args = args[2:] + continue + args = args[1:] + if a[0] not in '/-': + if not inf: + inf = a + continue + if a[:3] == '/Fo': + out = a[3:] + + with open(inf, 'rb') as infile, open(out, 'wb') as outfile: + for line in infile: + if not line.startswith(b'/*c++*/'): + outfile.write(line) + +def fake_cxx(): + opts, args = getopt.getopt(sys.argv[1:], 'co:') + for opt, arg in opts: + if opt == '-o': + out = arg + + 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) + +if __name__ == '__main__': + print(f"DEBUG: {sys.argv[0]}: {sys.argv[1:]}") + if sys.platform == 'win32': + fake_win32_cxx() + else: + fake_cxx() + sys.exit(0) diff --git a/test/CXX/CXX.py b/test/CXX/CXX.py index 836324f..ad00b55 100644 --- a/test/CXX/CXX.py +++ b/test/CXX/CXX.py @@ -32,52 +32,7 @@ _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('myc++.py', r""" -import sys - -args = sys.argv[1:] -inf = None -while args: - a = args[0] - if a == '-o': - out = args[1] - args = args[2:] - continue - args = args[1:] - if not a[0] in '/-': - if not inf: - inf = a - continue - if a[:3] == '/Fo': out = a[3:] - -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 - -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.dir_fixture('CXX-fixture') test.write('SConstruct', """ env = Environment( -- cgit v0.12 From a94950db308154798e65e07704e65a85c0aef6f6 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Wed, 19 Jan 2022 10:35:38 -0700 Subject: 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 --- test/CC/CC-fixture/mycc.py | 12 ++++---- test/CFILESUFFIX.py | 32 ++++++-------------- test/CPPFLAGS.py | 63 +++++++++++++++++++-------------------- test/CXX/CXX-fixture/myc++.py | 12 ++++---- test/CXX/CXXFILESUFFIX.py | 33 ++++++-------------- test/LEX/LEX.py | 55 +++++++++++----------------------- test/LEX/LEXFLAGS.py | 27 ++--------------- test/fixture/mygcc.py | 18 +++++++++-- test/fixture/mylex.py | 37 +++++++++++++++++++++++ test/fixture/mylink.py | 10 +++---- test/fixture/mylink_win32.py | 16 ---------- test/fixture/wrapper.py | 9 +++++- test/fixture/wrapper_with_args.py | 9 +++++- 13 files changed, 154 insertions(+), 179 deletions(-) create mode 100644 test/fixture/mylex.py delete mode 100644 test/fixture/mylink_win32.py 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) -- cgit v0.12 From d10e283fb19caff12319c698bddb4f6ffda571f7 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Wed, 19 Jan 2022 10:47:57 -0700 Subject: flake8: remove unused import in test fixture Signed-off-by: Mats Wichmann --- test/fixture/mylex.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fixture/mylex.py b/test/fixture/mylex.py index accc96a..8f47049 100644 --- a/test/fixture/mylex.py +++ b/test/fixture/mylex.py @@ -9,7 +9,6 @@ Intended for use as $LEX import getopt import sys -import os def fake_lex(): if sys.platform == 'win32': -- cgit v0.12