From 3f2c0a0cb3e65e01263f315cc5d1a017537de1c9 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Sun, 10 Mar 2002 19:39:12 +0000 Subject: Make the C*FILESUFFIX.py, LEX*.py and YACC*.py tests not dependent on the system's lex or yacc. --- test/CFILESUFFIX.py | 52 ++++++++++++++++---------------------- test/CXXFILESUFFIX.py | 52 ++++++++++++++++---------------------- test/LEX.py | 64 ++++++++++++++++++++++++++++++++++++----------- test/LEXFLAGS.py | 64 +++++++++++++++++++++++++++++++++++++---------- test/YACC.py | 69 ++++++++++++++++++++++++++++++++++++++++----------- test/YACCFLAGS.py | 67 +++++++++++++++++++++++++++++++++++++++---------- 6 files changed, 253 insertions(+), 115 deletions(-) diff --git a/test/CFILESUFFIX.py b/test/CFILESUFFIX.py index 002a756..5c04686 100644 --- a/test/CFILESUFFIX.py +++ b/test/CFILESUFFIX.py @@ -32,47 +32,39 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - -lex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'lex' + _exe) - if os.path.exists(l): - lex = l - break - test = TestSCons.TestSCons() -test.no_result(not lex) +test.write('mylex.py', """ +import getopt +import string +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 't', []) +for a in args: + contents = open(a, 'rb').read() + sys.stdout.write(string.replace(contents, 'LEX', 'mylex.py')) +sys.exit(0) +""") test.write('SConstruct', """ -Environment().CFile(target = 'foo', source = 'foo.l') -Environment(CFILESUFFIX = '.xyz').CFile(target = 'bar', source = 'bar.l') -""") +env = Environment(LEX = r'%s mylex.py') +env.CFile(target = 'foo', source = 'foo.l') +env.Copy(CFILESUFFIX = '.xyz').CFile(target = 'bar', source = 'bar.l') +""" % python) -lex = r""" -%%%% -a printf("A%sA"); -b printf("B%sB"); -%%%% +input = r""" int -yywrap() -{ - return 1; -} - -main() +main(int argc, char *argv[]) { - yylex(); + argv[argc++] = "--"; + printf("LEX\n"); + printf("%s\n"); + exit (0); } """ -test.write('foo.l', lex % ('foo.l', 'foo.l')) +test.write('foo.l', input % 'foo.l') -test.write('bar.l', lex % ('bar.l', 'bar.l')) +test.write('bar.l', input % 'bar.l') test.run(arguments = '.') diff --git a/test/CXXFILESUFFIX.py b/test/CXXFILESUFFIX.py index 3dde9af..48c62a9 100644 --- a/test/CXXFILESUFFIX.py +++ b/test/CXXFILESUFFIX.py @@ -32,47 +32,39 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - -lex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'lex' + _exe) - if os.path.exists(l): - lex = l - break - test = TestSCons.TestSCons() -test.no_result(not lex) +test.write('mylex.py', """ +import getopt +import string +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 't', []) +for a in args: + contents = open(a, 'rb').read() + sys.stdout.write(string.replace(contents, 'LEX', 'mylex.py')) +sys.exit(0) +""") test.write('SConstruct', """ -Environment().CXXFile(target = 'foo', source = 'foo.ll') -Environment(CXXFILESUFFIX = '.xyz').CXXFile(target = 'bar', source = 'bar.ll') -""") +env = Environment(LEX = r'%s mylex.py') +env.CXXFile(target = 'foo', source = 'foo.ll') +env.Copy(CXXFILESUFFIX = '.xyz').CXXFile(target = 'bar', source = 'bar.ll') +""" % python) -lex = r""" -%%%% -a printf("A%sA"); -b printf("B%sB"); -%%%% +input = r""" int -yywrap() -{ - return 1; -} - -main() +main(int argc, char *argv[]) { - yylex(); + argv[argc++] = "--"; + printf("LEX\n"); + printf("%s\n"); + exit (0); } """ -test.write('foo.ll', lex % ('foo.ll', 'foo.ll')) +test.write('foo.ll', input % 'foo.ll') -test.write('bar.ll', lex % ('bar.ll', 'bar.ll')) +test.write('bar.ll', input % 'bar.ll') test.run(arguments = '.') diff --git a/test/LEX.py b/test/LEX.py index ec03ba2..59a887d 100644 --- a/test/LEX.py +++ b/test/LEX.py @@ -37,6 +37,43 @@ if sys.platform == 'win32': else: _exe = '' +test = TestSCons.TestSCons() + + + +test.write('mylex.py', """ +import getopt +import string +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 't', []) +for a in args: + contents = open(a, 'rb').read() + sys.stdout.write(string.replace(contents, 'LEX', 'mylex.py')) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LEX = r'%s mylex.py') +env.Program(target = 'aaa', source = 'aaa.l') +""" % python) + +test.write('aaa.l', r""" +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + printf("LEX\n"); + printf("aaa.l\n"); + exit (0); +} +""") + +test.run(arguments = 'aaa' + _exe, stderr = None) + +test.run(program = test.workpath('aaa' + _exe), stdout = "mylex.py\naaa.l\n") + + + lex = None for dir in string.split(os.environ['PATH'], os.pathsep): l = os.path.join(dir, 'lex' + _exe) @@ -44,19 +81,16 @@ for dir in string.split(os.environ['PATH'], os.pathsep): lex = l break -test = TestSCons.TestSCons() +if lex: -test.no_result(not lex) - -test.write("wrapper.py", -"""import os + test.write("wrapper.py", """import os import string import sys open('%s', 'wb').write("wrapper.py\\n") os.system(string.join(sys.argv[1:], " ")) """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) -test.write('SConstruct', """ + test.write('SConstruct', """ foo = Environment() lex = foo.Dictionary('LEX') bar = Environment(LEX = r'%s wrapper.py ' + lex) @@ -64,7 +98,7 @@ foo.Program(target = 'foo', source = 'foo.l') bar.Program(target = 'bar', source = 'bar.l') """ % python) -lex = r""" + lex = r""" %%%% a printf("A%sA"); b printf("B%sB"); @@ -81,20 +115,20 @@ main() } """ -test.write('foo.l', lex % ('foo.l', 'foo.l')) + test.write('foo.l', lex % ('foo.l', 'foo.l')) -test.write('bar.l', lex % ('bar.l', 'bar.l')) + test.write('bar.l', lex % ('bar.l', 'bar.l')) -test.run(arguments = 'foo' + _exe, stderr = None) + test.run(arguments = 'foo' + _exe, stderr = None) -test.fail_test(os.path.exists(test.workpath('wrapper.out'))) + test.fail_test(os.path.exists(test.workpath('wrapper.out'))) -test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n") + test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n") -test.run(arguments = 'bar' + _exe) + test.run(arguments = 'bar' + _exe) -test.fail_test(test.read('wrapper.out') != "wrapper.py\n") + test.fail_test(test.read('wrapper.out') != "wrapper.py\n") -test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n") + test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n") test.pass_test() diff --git a/test/LEXFLAGS.py b/test/LEXFLAGS.py index 4a2940e..b415495 100644 --- a/test/LEXFLAGS.py +++ b/test/LEXFLAGS.py @@ -37,6 +37,46 @@ if sys.platform == 'win32': else: _exe = '' +test = TestSCons.TestSCons() + + + +test.write('mylex.py', """ +import getopt +import string +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 'tx', []) +opt_string = '' +for opt, arg in cmd_opts: + opt_string = opt_string + ' ' + opt +for a in args: + contents = open(a, 'rb').read() + sys.stdout.write(string.replace(contents, 'LEXFLAGS', opt_string)) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(LEX = r'%s mylex.py', LEXFLAGS = '-x') +env.Program(target = 'aaa', source = 'aaa.l') +""" % python) + +test.write('aaa.l', r""" +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + printf("LEXFLAGS\n"); + printf("aaa.l\n"); + exit (0); +} +""") + +test.run(arguments = 'aaa' + _exe, stderr = None) + +test.run(program = test.workpath('aaa' + _exe), stdout = " -x -t\naaa.l\n") + + + lex = None for dir in string.split(os.environ['PATH'], os.pathsep): l = os.path.join(dir, 'lex' + _exe) @@ -44,18 +84,16 @@ for dir in string.split(os.environ['PATH'], os.pathsep): lex = l break -test = TestSCons.TestSCons() +if lex: -test.no_result(not lex) - -test.write('SConstruct', """ + test.write('SConstruct', """ foo = Environment() bar = Environment(LEXFLAGS = '-b') foo.Program(target = 'foo', source = 'foo.l') bar.Program(target = 'bar', source = 'bar.l') """) -lex = r""" + lex = r""" %%%% a printf("A%sA"); b printf("B%sB"); @@ -72,20 +110,20 @@ main() } """ -test.write('foo.l', lex % ('foo.l', 'foo.l')) + test.write('foo.l', lex % ('foo.l', 'foo.l')) -test.write('bar.l', lex % ('bar.l', 'bar.l')) + test.write('bar.l', lex % ('bar.l', 'bar.l')) -test.run(arguments = 'foo' + _exe, stderr = None) + test.run(arguments = 'foo' + _exe, stderr = None) -test.fail_test(os.path.exists(test.workpath('lex.backup'))) + test.fail_test(os.path.exists(test.workpath('lex.backup'))) -test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n") + test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "Afoo.lA\n") -test.run(arguments = 'bar' + _exe) + test.run(arguments = 'bar' + _exe) -test.fail_test(not os.path.exists(test.workpath('lex.backup'))) + test.fail_test(not os.path.exists(test.workpath('lex.backup'))) -test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n") + test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "Bbar.lB\n") test.pass_test() diff --git a/test/YACC.py b/test/YACC.py index f7f8aae..3e8ea35 100644 --- a/test/YACC.py +++ b/test/YACC.py @@ -37,6 +37,49 @@ if sys.platform == 'win32': else: _exe = '' +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """ +import getopt +import string +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:', []) +output = None +opt_string = '' +for opt, arg in cmd_opts: + if opt == '-o': output = open(arg, 'wb') + else: opt_string = opt_string + ' ' + opt +for a in args: + contents = open(a, 'rb').read() + output.write(string.replace(contents, 'YACC', 'myyacc.py')) +output.close() +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(YACC = r'%s myyacc.py') +env.Program(target = 'aaa', source = 'aaa.y') +""" % python) + +test.write('aaa.y', r""" +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + printf("YACC\n"); + printf("aaa.y\n"); + exit (0); +} +""") + +test.run(arguments = 'aaa' + _exe, stderr = None) + +test.run(program = test.workpath('aaa' + _exe), stdout = "myyacc.py\naaa.y\n") + + + yacc = None for dir in string.split(os.environ['PATH'], os.pathsep): y = os.path.join(dir, 'yacc' + _exe) @@ -44,11 +87,9 @@ for dir in string.split(os.environ['PATH'], os.pathsep): yacc = y break -test = TestSCons.TestSCons() +if yacc: -test.no_result(not yacc) - -test.write("wrapper.py", + test.write("wrapper.py", """import os import string import sys @@ -56,7 +97,7 @@ open('%s', 'wb').write("wrapper.py\\n") os.system(string.join(sys.argv[1:], " ")) """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) -test.write('SConstruct', """ + test.write('SConstruct', """ foo = Environment() yacc = foo.Dictionary('YACC') bar = Environment(YACC = r'%s wrapper.py ' + yacc) @@ -64,7 +105,7 @@ foo.Program(target = 'foo', source = 'foo.y') bar.Program(target = 'bar', source = 'bar.y') """ % python) -yacc = r""" + yacc = r""" %%{ #include @@ -93,20 +134,20 @@ letter: 'a' | 'b'; newline: '\n'; """ -test.write('foo.y', yacc % 'foo.y') + test.write('foo.y', yacc % 'foo.y') -test.write('bar.y', yacc % 'bar.y') + test.write('bar.y', yacc % 'bar.y') -test.run(arguments = 'foo' + _exe, stderr = None) + test.run(arguments = 'foo' + _exe, stderr = None) -test.fail_test(os.path.exists(test.workpath('wrapper.out'))) + test.fail_test(os.path.exists(test.workpath('wrapper.out'))) -test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n") + test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n") -test.run(arguments = 'bar' + _exe) + test.run(arguments = 'bar' + _exe) -test.fail_test(test.read('wrapper.out') != "wrapper.py\n") + test.fail_test(test.read('wrapper.out') != "wrapper.py\n") -test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n") + test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n") test.pass_test() diff --git a/test/YACCFLAGS.py b/test/YACCFLAGS.py index 54d5391..10c29ca 100644 --- a/test/YACCFLAGS.py +++ b/test/YACCFLAGS.py @@ -37,6 +37,49 @@ if sys.platform == 'win32': else: _exe = '' +test = TestSCons.TestSCons() + + + +test.write('myyacc.py', """ +import getopt +import string +import sys +cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:x', []) +output = None +opt_string = '' +for opt, arg in cmd_opts: + if opt == '-o': output = open(arg, 'wb') + else: opt_string = opt_string + ' ' + opt +for a in args: + contents = open(a, 'rb').read() + output.write(string.replace(contents, 'YACCFLAGS', opt_string)) +output.close() +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(YACC = r'%s myyacc.py', YACCFLAGS = '-x') +env.Program(target = 'aaa', source = 'aaa.y') +""" % python) + +test.write('aaa.y', r""" +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + printf("YACCFLAGS\n"); + printf("aaa.y\n"); + exit (0); +} +""") + +test.run(arguments = 'aaa' + _exe, stderr = None) + +test.run(program = test.workpath('aaa' + _exe), stdout = " -x\naaa.y\n") + + + yacc = None for dir in string.split(os.environ['PATH'], os.pathsep): y = os.path.join(dir, 'yacc' + _exe) @@ -44,18 +87,16 @@ for dir in string.split(os.environ['PATH'], os.pathsep): yacc = y break -test = TestSCons.TestSCons() +if yacc: -test.no_result(not yacc) - -test.write('SConstruct', """ + test.write('SConstruct', """ foo = Environment() bar = Environment(YACCFLAGS = '-v') foo.Program(target = 'foo', source = 'foo.y') bar.Program(target = 'bar', source = 'bar.y') """) -yacc = r""" + yacc = r""" %%{ #include @@ -84,22 +125,22 @@ letter: 'a' | 'b'; newline: '\n'; """ -test.write('foo.y', yacc % 'foo.y') + test.write('foo.y', yacc % 'foo.y') -test.write('bar.y', yacc % 'bar.y') + test.write('bar.y', yacc % 'bar.y') -test.run(arguments = 'foo' + _exe, stderr = None) + test.run(arguments = 'foo' + _exe, stderr = None) -test.fail_test(os.path.exists(test.workpath('foo.output')) + test.fail_test(os.path.exists(test.workpath('foo.output')) or os.path.exists(test.workpath('y.output'))) -test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n") + test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n") -test.run(arguments = 'bar' + _exe) + test.run(arguments = 'bar' + _exe) -test.fail_test(not os.path.exists(test.workpath('bar.output')) + test.fail_test(not os.path.exists(test.workpath('bar.output')) and not os.path.exists(test.workpath('y.output'))) -test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n") + test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n") test.pass_test() -- cgit v0.12