Make the C*FILESUFFIX.py, LEX*.py and YACC*.py tests not dependent on the system...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 10 Mar 2002 19:39:12 +0000 (19:39 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 10 Mar 2002 19:39:12 +0000 (19:39 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@289 fdb21ef1-2011-0410-befe-b5e4ea1792b1

test/CFILESUFFIX.py
test/CXXFILESUFFIX.py
test/LEX.py
test/LEXFLAGS.py
test/YACC.py
test/YACCFLAGS.py

index 002a756ef8d498a84c84905d07601cd3ce1c93a2..5c046865a718da271285783bd2e2260470dfbb84 100644 (file)
@@ -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 = '.')
 
index 3dde9afc5ad29faff266f109e12024460fb51831..48c62a9812f6d604ad799be1bc2688d33c0e485e 100644 (file)
@@ -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 = '.')
 
index ec03ba261e0ecf1f89b5c175a90a859a5e2f7c5b..59a887d16f7fd1195b15e2d47f6d3c1d7b5ba623 100644 (file)
@@ -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()
index 4a2940e9af37f4f2e2e37bf87c1c6e47dbe0e0cd..b415495235140d1eb6b72efe82beac398f708825 100644 (file)
@@ -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()
index f7f8aaef6a2734aa1efc58c5ac20de307efbaba6..3e8ea35611bc1c2210d5161ddd436ab28a82e7a7 100644 (file)
@@ -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 <stdio.h>
 
@@ -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()
index 54d53919637dda6682f6f15f13533b2400f9325c..10c29ca0536350961fd30c3f5093de283d521d04 100644 (file)
@@ -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 <stdio.h>
 
@@ -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()