summaryrefslogtreecommitdiffstats
path: root/test/YACC
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2007-01-07 07:23:05 (GMT)
committerSteven Knight <knight@baldmt.com>2007-01-07 07:23:05 (GMT)
commit8f79b64540d5c6b8c9ca36f1a4ebcaf4d9df3d98 (patch)
tree05e6aee9b46b530443e01bbb762b68775a6bb0ff /test/YACC
parentc4d04b3b45e7b71a1b28053b90084bcf2fdf9c0e (diff)
downloadSCons-8f79b64540d5c6b8c9ca36f1a4ebcaf4d9df3d98.zip
SCons-8f79b64540d5c6b8c9ca36f1a4ebcaf4d9df3d98.tar.gz
SCons-8f79b64540d5c6b8c9ca36f1a4ebcaf4d9df3d98.tar.bz2
Merged revisions 1738-1754,1756 via svnmerge from
http://scons.tigris.org/svn/scons/branches/core ........ r1741 | stevenknight | 2006-12-16 22:51:07 -0600 (Sat, 16 Dec 2006) | 1 line 0.96.D527 - Give the f90 and f95 Tool modules knowledge of how to build source files of earlier Fortran versions. ........ r1742 | stevenknight | 2006-12-16 23:22:54 -0600 (Sat, 16 Dec 2006) | 1 line 0.96.D528 - Better handling of timestamp fallback if there's no md5 module. ........ r1743 | stevenknight | 2006-12-17 00:21:31 -0600 (Sun, 17 Dec 2006) | 1 line 0.96.D529 - Fix portability of new tests on systems that don't have TeX installed. ........ r1744 | stevenknight | 2006-12-19 15:30:16 -0600 (Tue, 19 Dec 2006) | 1 line 0.96.D530 - Eliminate the ListBuilder subclass in favor of using the Executor's target lists. ........ r1745 | stevenknight | 2006-12-19 18:54:26 -0600 (Tue, 19 Dec 2006) | 1 line 0.96.D531 - Eliminate of MultiStepBuilder as a separate Builder subclass. ........ r1746 | garyo | 2006-12-21 13:21:08 -0600 (Thu, 21 Dec 2006) | 1 line Minor doc fix, thanks to Douglas Landgraf. ........ r1747 | stevenknight | 2006-12-21 17:13:55 -0600 (Thu, 21 Dec 2006) | 1 line 0.96.D533 - Add CFLAGS for options common to C/C++. (Gary Oberbrunner) ........ r1748 | stevenknight | 2007-01-03 19:48:05 -0600 (Wed, 03 Jan 2007) | 1 line 0.96.D534 - Fix signature storage when targets are retrieved from CacheDir(). ........ r1749 | stevenknight | 2007-01-04 16:48:47 -0600 (Thu, 04 Jan 2007) | 1 line 0.96.D535 - Teach the lex and yacc tools about target files generated by different flex/bison options, and about Objective C suffixes. (Pupeno) ........ r1750 | stevenknight | 2007-01-04 17:14:38 -0600 (Thu, 04 Jan 2007) | 1 line 0.96.D536 - Refactor duplicate disambiguation logic in Entry.get_contents(). ........ r1751 | stevenknight | 2007-01-05 13:00:54 -0600 (Fri, 05 Jan 2007) | 1 line 0.96.D537 - Fix lprof regression from 0.96.92. ........ r1752 | stevenknight | 2007-01-05 20:43:48 -0600 (Fri, 05 Jan 2007) | 1 line 0.96.D538 - Fix caching of Builder suffix matching (to fix lprof regression). ........ r1753 | stevenknight | 2007-01-06 00:03:16 -0600 (Sat, 06 Jan 2007) | 1 line 0.96.D539 - Fix --include-dir when using MinGW. (Paul) ........ r1754 | stevenknight | 2007-01-06 00:24:53 -0600 (Sat, 06 Jan 2007) | 1 line 0.96.D540 - Make bootstrap.py something useful to execute SCons out of a source directory. ........ r1756 | stevenknight | 2007-01-06 21:32:11 -0600 (Sat, 06 Jan 2007) | 1 line 0.96.D541 - Update the Copyright year string to include 2007. Automate updating the month+year string in man page title headers. Fix hard-coded __revision__ strings that crept into some older tests. ........
Diffstat (limited to 'test/YACC')
-rw-r--r--test/YACC/YACC.py154
-rw-r--r--test/YACC/YACCFLAGS.py76
-rw-r--r--test/YACC/YACCVCGFILESUFFIX.py87
-rw-r--r--test/YACC/live.py165
4 files changed, 268 insertions, 214 deletions
diff --git a/test/YACC/YACC.py b/test/YACC/YACC.py
index d3bc679..bef959f 100644
--- a/test/YACC/YACC.py
+++ b/test/YACC/YACC.py
@@ -65,155 +65,25 @@ sys.exit(0)
test.write('SConstruct', """
env = Environment(YACC = r'%(_python_)s myyacc.py', tools=['default', 'yacc'])
-env.Program(target = 'aaa', source = 'aaa.y')
-env.Program(target = 'bbb', source = 'bbb.yacc')
+env.CFile(target = 'aaa', source = 'aaa.y')
+env.CFile(target = 'bbb', source = 'bbb.yacc')
+env.CXXFile(target = 'ccc', source = 'ccc.yy')
+env.CFile(target = 'ddd', source = 'ddd.ym')
""" % locals())
-test.write('aaa.y', r"""
-int
-main(int argc, char *argv[])
-{
- argv[argc++] = "--";
- printf("YACC\n");
- printf("aaa.y\n");
- exit (0);
-}
-""")
-
-test.write('bbb.yacc', r"""
-int
-main(int argc, char *argv[])
-{
- argv[argc++] = "--";
- printf("YACC\n");
- printf("bbb.yacc\n");
- exit (0);
-}
-""")
+test.write('aaa.y', "aaa.y\nYACC\n")
+test.write('bbb.yacc', "bbb.yacc\nYACC\n")
+test.write('ccc.yy', "ccc.yacc\nYACC\n")
+test.write('ddd.ym', "ddd.yacc\nYACC\n")
test.run(arguments = '.', stderr = None)
-test.run(program = test.workpath('aaa' + _exe), stdout = "myyacc.py\naaa.y\n")
-test.run(program = test.workpath('bbb' + _exe), stdout = "myyacc.py\nbbb.yacc\n")
-
-
-
-yacc = test.where_is('yacc')
-
-if yacc:
-
- 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', """
-foo = Environment(YACCFLAGS='-d')
-yacc = foo.Dictionary('YACC')
-bar = Environment(YACC = r'%(_python_)s wrapper.py ' + yacc)
-foo.Program(target = 'foo', source = 'foo.y')
-bar.Program(target = 'bar', source = 'bar.y')
-foo.Program(target = 'hello', source = ['hello.cpp'])
-foo.CXXFile(target = 'file.cpp', source = ['file.yy'], YACCFLAGS='-d')
-foo.CFile(target = 'not_foo', source = 'foo.y')
-""" % locals())
-
- yacc = r"""
-%%{
-#include <stdio.h>
-
-main()
-{
- yyparse();
-}
-
-yyerror(s)
-char *s;
-{
- fprintf(stderr, "%%s\n", s);
- return 0;
-}
-
-yylex()
-{
- int c;
-
- c = fgetc(stdin);
- return (c == EOF) ? 0 : c;
-}
-%%}
-%%%%
-input: letter newline { printf("%s\n"); };
-letter: 'a' | 'b';
-newline: '\n';
-"""
-
- test.write("file.yy", """\
-%token GRAPH_T NODE_T EDGE_T DIGRAPH_T EDGEOP_T SUBGRAPH_T
-
-%pure_parser
-
-%%
-graph: GRAPH_T
- ;
-
-%%
-""")
-
- test.write("hello.cpp", """\
-#include "file.hpp"
-
-int main()
-{
-}
-""")
-
- test.write('foo.y', yacc % 'foo.y')
-
- test.write('bar.y', yacc % 'bar.y')
-
- # Build the foo program
- test.run(arguments = 'foo' + _exe, stderr = None)
-
- test.up_to_date(arguments = 'foo' + _exe)
-
- test.fail_test(os.path.exists(test.workpath('wrapper.out')))
-
- test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
-
- test.fail_test(not os.path.exists(test.workpath('foo.h')))
-
- test.run(arguments = '-c .')
-
- test.fail_test(os.path.exists(test.workpath('foo.h')))
-
- #
- test.run(arguments = 'not_foo.c')
-
- test.up_to_date(arguments = 'not_foo.c')
-
- test.fail_test(os.path.exists(test.workpath('foo.h')))
- test.fail_test(not os.path.exists(test.workpath('not_foo.h')))
-
- test.run(arguments = '-c .')
-
- test.fail_test(os.path.exists(test.workpath('not_foo.h')))
-
- #
- test.run(arguments = 'bar' + _exe)
-
- test.up_to_date(arguments = 'bar' + _exe)
-
- test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
+test.must_match('aaa.c', "aaa.y\nmyyacc.py\n")
+test.must_match('bbb.c', "bbb.yacc\nmyyacc.py\n")
+test.must_match('ccc.cc', "ccc.yacc\nmyyacc.py\n")
+test.must_match('ddd.m', "ddd.yacc\nmyyacc.py\n")
- test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n")
- #
- test.run(arguments = '.')
- test.up_to_date(arguments = '.')
test.pass_test()
diff --git a/test/YACC/YACCFLAGS.py b/test/YACC/YACCFLAGS.py
index a94bc8f..b7e2167 100644
--- a/test/YACC/YACCFLAGS.py
+++ b/test/YACC/YACCFLAGS.py
@@ -65,83 +65,15 @@ test.write('SConstruct', """
env = Environment(YACC = r'%(_python_)s myyacc.py',
YACCFLAGS = '-x',
tools=['yacc', '%(linker)s', '%(compiler)s'])
-env.Program(target = 'aaa', source = 'aaa.y')
+env.CFile(target = 'aaa', source = 'aaa.y')
""" % locals())
-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 = test.where_is('yacc')
-
-if yacc:
-
- 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"""
-%%{
-#include <stdio.h>
-
-main()
-{
- yyparse();
-}
-
-yyerror(s)
-char *s;
-{
- fprintf(stderr, "%%s\n", s);
- return 0;
-}
-
-yylex()
-{
- int c;
-
- c = fgetc(stdin);
- return (c == EOF) ? 0 : c;
-}
-%%}
-%%%%
-input: letter newline { printf("%s\n"); };
-letter: 'a' | 'b';
-newline: '\n';
-"""
-
- test.write('foo.y', yacc % 'foo.y')
-
- test.write('bar.y', yacc % 'bar.y')
-
- test.run(arguments = 'foo' + _exe, stderr = None)
-
- test.fail_test(os.path.exists(test.workpath('foo.output'))
- or os.path.exists(test.workpath('y.output')))
+test.write('aaa.y', "aaa.y\nYACCFLAGS\n")
- test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
+test.run('.', stderr = None)
- test.run(arguments = 'bar' + _exe)
+test.must_match('aaa.c', "aaa.y\n -x\n")
- 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.pass_test()
diff --git a/test/YACC/YACCVCGFILESUFFIX.py b/test/YACC/YACCVCGFILESUFFIX.py
new file mode 100644
index 0000000..b05471a
--- /dev/null
+++ b/test/YACC/YACCVCGFILESUFFIX.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# 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__"
+
+"""
+Test setting the YACCVCGFILESUFFIX variable.
+"""
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+
+
+
+test.write('myyacc.py', """\
+import getopt
+import os.path
+import string
+import sys
+vcg = None
+opts, args = getopt.getopt(sys.argv[1:], 'go:')
+for o, a in opts:
+ if o == '-g':
+ vcg = 1
+ elif o == '-o':
+ outfile = open(a, 'wb')
+for f in args:
+ infile = open(f, 'rb')
+ for l in filter(lambda l: l != '/*yacc*/\\n', infile.readlines()):
+ outfile.write(l)
+outfile.close()
+if vcg:
+ base, ext = os.path.splitext(args[0])
+ open(base+'.vcgsuffix', 'wb').write(string.join(sys.argv)+'\\n')
+sys.exit(0)
+""")
+
+test.write('SConstruct', """
+env = Environment(tools=['default', 'yacc'],
+ YACC = r'%(_python_)s myyacc.py',
+ YACCVCGFILESUFFIX = '.vcgsuffix')
+env.CXXFile(target = 'aaa', source = 'aaa.yy')
+env.CXXFile(target = 'bbb', source = 'bbb.yy', YACCFLAGS = '-g')
+""" % locals())
+
+test.write('aaa.yy', "aaa.yy\n/*yacc*/\n")
+test.write('bbb.yy', "bbb.yy\n/*yacc*/\n")
+
+test.run(arguments = '.')
+
+test.must_match('aaa.cc', "aaa.yy\n")
+test.must_not_exist('aaa.vcg')
+test.must_not_exist('aaa.vcgsuffix')
+
+test.must_match('bbb.cc', "bbb.yy\n")
+test.must_not_exist('bbb.vcg')
+test.must_match('bbb.vcgsuffix', "myyacc.py -g -o bbb.cc bbb.yy\n")
+
+test.up_to_date(arguments = '.')
+
+
+
+test.pass_test()
diff --git a/test/YACC/live.py b/test/YACC/live.py
new file mode 100644
index 0000000..4934570
--- /dev/null
+++ b/test/YACC/live.py
@@ -0,0 +1,165 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# 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__"
+
+"""
+Test YACC and YACCFLAGS with a live yacc compiler.
+"""
+
+import string
+
+import TestSCons
+
+_exe = TestSCons._exe
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+
+yacc = test.where_is('yacc') or test.where_is('bison')
+
+if not yacc:
+ test.skip_test('No yacc or bison found; skipping test.\n')
+
+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', """
+foo = Environment(YACCFLAGS='-d')
+yacc = foo.Dictionary('YACC')
+bar = Environment(YACC = r'%(_python_)s wrapper.py ' + yacc)
+foo.Program(target = 'foo', source = 'foo.y')
+bar.Program(target = 'bar', source = 'bar.y')
+foo.Program(target = 'hello', source = ['hello.cpp'])
+foo.CXXFile(target = 'file.cpp', source = ['file.yy'], YACCFLAGS='-d')
+foo.CFile(target = 'not_foo', source = 'foo.y')
+""" % locals())
+
+yacc = r"""
+%%{
+#include <stdio.h>
+
+main()
+{
+ yyparse();
+}
+
+yyerror(s)
+char *s;
+{
+ fprintf(stderr, "%%s\n", s);
+ return 0;
+}
+
+yylex()
+{
+ int c;
+
+ c = fgetc(stdin);
+ return (c == EOF) ? 0 : c;
+}
+%%}
+%%%%
+input: letter newline { printf("%s\n"); };
+letter: 'a' | 'b';
+newline: '\n';
+"""
+
+test.write("file.yy", """\
+%token GRAPH_T NODE_T EDGE_T DIGRAPH_T EDGEOP_T SUBGRAPH_T
+
+%pure_parser
+
+%%
+graph: GRAPH_T
+ ;
+
+%%
+""")
+
+test.write("hello.cpp", """\
+#include "file.hpp"
+
+int main()
+{
+}
+""")
+
+test.write('foo.y', yacc % 'foo.y')
+
+test.write('bar.y', yacc % 'bar.y')
+
+
+
+test.run(arguments = 'foo' + _exe, stderr = None)
+
+test.up_to_date(arguments = 'foo' + _exe)
+
+test.must_not_exist(test.workpath('wrapper.out'))
+
+test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
+
+test.must_exist(test.workpath('foo.h'))
+
+test.run(arguments = '-c .')
+
+test.must_not_exist(test.workpath('foo.h'))
+
+
+
+test.run(arguments = 'not_foo.c')
+
+test.up_to_date(arguments = 'not_foo.c')
+
+test.must_not_exist(test.workpath('foo.h'))
+test.must_exist(test.workpath('not_foo.h'))
+
+test.run(arguments = '-c .')
+
+test.must_not_exist(test.workpath('not_foo.h'))
+
+
+
+test.run(arguments = 'bar' + _exe)
+
+test.up_to_date(arguments = 'bar' + _exe)
+
+test.must_match(test.workpath('wrapper.out'), "wrapper.py\n")
+
+test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n")
+
+
+
+test.run(arguments = '.')
+
+test.up_to_date(arguments = '.')
+
+
+
+test.pass_test()