5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Test YACC and YACCFLAGS with a live yacc compiler.
34 _python_ = TestSCons._python_
36 test = TestSCons.TestSCons()
38 yacc = test.where_is('yacc') or test.where_is('bison')
41 test.skip_test('No yacc or bison found; skipping test.\n')
43 test.write("wrapper.py",
46 open('%s', 'wb').write("wrapper.py\\n")
47 os.system(" ".join(sys.argv[1:]))
48 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
50 test.write('SConstruct', """
51 foo = Environment(YACCFLAGS='-d')
52 yacc = foo.Dictionary('YACC')
53 bar = Environment(YACC = r'%(_python_)s wrapper.py ' + yacc)
54 foo.Program(target = 'foo', source = 'foo.y')
55 bar.Program(target = 'bar', source = 'bar.y')
56 foo.Program(target = 'hello', source = ['hello.cpp'])
57 foo.CXXFile(target = 'file.cpp', source = ['file.yy'], YACCFLAGS='-d')
58 foo.CFile(target = 'not_foo', source = 'foo.y')
73 fprintf(stderr, "%%s\n", s);
82 return (c == EOF) ? 0 : c;
86 input: letter newline { printf("%s\n"); };
91 test.write("file.yy", """\
92 %token GRAPH_T NODE_T EDGE_T DIGRAPH_T EDGEOP_T SUBGRAPH_T
103 # Apparently, OS X now creates file.hpp like everybody else
104 # I have no idea when it changed; it was fixed in 10.4
106 #if sys.platform[:6] == 'darwin':
107 # file_hpp = 'file.cpp.h'
109 # file_hpp = 'file.hpp'
110 file_hpp = 'file.hpp'
112 test.write("hello.cpp", """\
113 #include "%(file_hpp)s"
120 test.write('foo.y', yacc % 'foo.y')
122 test.write('bar.y', yacc % 'bar.y')
126 test.run(arguments = 'foo' + _exe, stderr = None)
128 test.up_to_date(arguments = 'foo' + _exe)
130 test.must_not_exist(test.workpath('wrapper.out'))
132 test.run(program = test.workpath('foo'), stdin = "a\n", stdout = "foo.y\n")
134 test.must_exist(test.workpath('foo.h'))
136 test.run(arguments = '-c .')
138 test.must_not_exist(test.workpath('foo.h'))
142 test.run(arguments = 'not_foo.c')
144 test.up_to_date(arguments = 'not_foo.c')
146 test.must_not_exist(test.workpath('foo.h'))
147 test.must_exist(test.workpath('not_foo.h'))
149 test.run(arguments = '-c .')
151 test.must_not_exist(test.workpath('not_foo.h'))
155 test.run(arguments = 'bar' + _exe)
157 test.up_to_date(arguments = 'bar' + _exe)
159 test.must_match(test.workpath('wrapper.out'), "wrapper.py\n")
161 test.run(program = test.workpath('bar'), stdin = "b\n", stdout = "bar.y\n")
165 test.run(arguments = '.')
167 test.up_to_date(arguments = '.')
175 # indent-tabs-mode:nil
177 # vim: set expandtab tabstop=4 shiftwidth=4: