summaryrefslogtreecommitdiffstats
path: root/test/LEXFLAGS.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-03-10 19:39:12 (GMT)
committerSteven Knight <knight@baldmt.com>2002-03-10 19:39:12 (GMT)
commit3f2c0a0cb3e65e01263f315cc5d1a017537de1c9 (patch)
tree4a65a83ac6fbb477bc2f35b16540ac136d024831 /test/LEXFLAGS.py
parent952df96acecd62355d351976be1384f4e7d4bc17 (diff)
downloadSCons-3f2c0a0cb3e65e01263f315cc5d1a017537de1c9.zip
SCons-3f2c0a0cb3e65e01263f315cc5d1a017537de1c9.tar.gz
SCons-3f2c0a0cb3e65e01263f315cc5d1a017537de1c9.tar.bz2
Make the C*FILESUFFIX.py, LEX*.py and YACC*.py tests not dependent on the system's lex or yacc.
Diffstat (limited to 'test/LEXFLAGS.py')
-rw-r--r--test/LEXFLAGS.py64
1 files changed, 51 insertions, 13 deletions
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()