5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Test YACC and YACCFLAGS with a live yacc compiler.
33 _python_
= TestSCons
._python
_
35 test
= TestSCons
.TestSCons()
37 yacc
= test
.where_is('yacc') or test
.where_is('bison') or test
.where_is('win_bison')
40 test
.skip_test('No yacc or bison found; skipping test.\n')
42 test
.file_fixture('wrapper.py')
44 test
.write('SConstruct', """
45 DefaultEnvironment(tools=[])
46 foo = Environment(YACCFLAGS='-d', tools=['default', 'yacc'])
47 yacc = foo.Dictionary('YACC')
48 bar = Environment(YACC=r'%(_python_)s wrapper.py ' + yacc, tools=['default', 'yacc'])
49 foo.Program(target='foo', source='foo.y')
50 bar.Program(target='bar', source='bar.y')
51 foo.Program(target='hello', source=['hello.cpp'])
52 foo.CXXFile(target='file.cpp', source=['file.yy'], YACCFLAGS='-d')
53 foo.CFile(target='not_foo', source='foo.y')
71 fprintf(stderr, "%%s\n", s);
80 return (c == EOF) ? 0 : c;
84 input: letter newline { printf("%s\n"); };
89 test
.write("file.yy", """\
90 %token GRAPH_T NODE_T EDGE_T DIGRAPH_T EDGEOP_T SUBGRAPH_T
99 # Apparently, OS X now creates file.hpp like everybody else
100 # I have no idea when it changed; it was fixed in 10.4
102 #if sys.platform[:6] == 'darwin':
103 # file_hpp = 'file.cpp.h'
105 # file_hpp = 'file.hpp'
106 file_hpp
= 'file.hpp'
108 test
.write("hello.cpp", """\
109 #include "%(file_hpp)s"
116 test
.write('foo.y', yacc
% 'foo.y')
118 test
.write('bar.y', yacc
% 'bar.y')
122 test
.run(arguments
= 'foo' + _exe
, stderr
= None)
124 test
.up_to_date(arguments
= 'foo' + _exe
)
126 test
.must_not_exist(test
.workpath('wrapper.out'))
128 test
.run(program
= test
.workpath('foo'), stdin
= "a\n", stdout
= "foo.y\n")
130 test
.must_exist(test
.workpath('foo.h'))
132 test
.run(arguments
= '-c .')
134 test
.must_not_exist(test
.workpath('foo.h'))
138 test
.run(arguments
= 'not_foo.c')
140 test
.up_to_date(arguments
= 'not_foo.c')
142 test
.must_not_exist(test
.workpath('foo.h'))
143 test
.must_exist(test
.workpath('not_foo.h'))
145 test
.run(arguments
= '-c .')
147 test
.must_not_exist(test
.workpath('not_foo.h'))
151 test
.run(arguments
= 'bar' + _exe
)
153 test
.up_to_date(arguments
= 'bar' + _exe
)
155 test
.must_match(test
.workpath('wrapper.out'), "wrapper.py\n")
157 test
.run(program
= test
.workpath('bar'), stdin
= "b\n", stdout
= "bar.y\n")
161 test
.run(arguments
= '.')
163 test
.up_to_date(arguments
= '.')
171 # indent-tabs-mode:nil
173 # vim: set expandtab tabstop=4 shiftwidth=4: