[ci skip] update generated files
[scons.git] / test / YACC / YACC_GRAPH_FILE_SUFFIX.py
blob58e7628533699396952086591eb68421e4400824
1 #!/usr/bin/env python
3 # MIT License
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.
26 """
27 Test setting the YACC_GRAPH_FILE_SUFFIX variable.
28 Also that if both YACCVCGFILESUFFIX and YACC_GRAPH_FILE_SUFFIX are set,
29 then YACCVCGFILESUFFIX will be ignored.
30 """
32 import TestSCons
34 _python_ = TestSCons._python_
36 test = TestSCons.TestSCons()
38 test.write('myyacc.py', """\
39 import getopt
40 import os.path
41 import sys
43 vcg = None
44 opts, args = getopt.getopt(sys.argv[1:], 'go:')
45 for o, a in opts:
46 if o == '-g':
47 vcg = 1
48 elif o == '-o':
49 outfile = open(a, 'wb')
50 for f in args:
51 with open(f, 'rb') as infile:
52 for l in [l for l in infile.readlines() if l != b'/*yacc*/\\n']:
53 outfile.write(l)
54 outfile.close()
55 if vcg:
56 base, ext = os.path.splitext(args[0])
57 with open(base + '.graph_suffix', 'wb') as outfile:
58 outfile.write((" ".join(sys.argv) + '\\n').encode())
59 sys.exit(0)
60 """)
62 test.write('SConstruct', """
63 DefaultEnvironment(tools=[])
64 env = Environment(
65 tools=['default', 'yacc'],
66 YACC=r'%(_python_)s myyacc.py',
67 YACCVCGFILESUFFIX='.vcg_obsolete',
68 YACC_GRAPH_FILE_SUFFIX='.graph_suffix',
70 env.CXXFile(target='aaa', source='aaa.yy')
71 env.CXXFile(target='bbb', source='bbb.yy', YACCFLAGS='-g')
72 """ % locals())
74 test.write('aaa.yy', "aaa.yy\n/*yacc*/\n")
75 test.write('bbb.yy', "bbb.yy\n/*yacc*/\n")
77 test.run(arguments='.')
79 test.must_match('aaa.cc', "aaa.yy\n")
80 test.must_not_exist('aaa.vcg')
81 test.must_not_exist('aaa.graph_suffix')
83 test.must_match('bbb.cc', "bbb.yy\n")
84 test.must_not_exist('bbb.vcg')
85 test.must_not_exist('bbb.vcg_obsolete')
86 test.must_contain('bbb.graph_suffix', "myyacc.py -g -o bbb.cc bbb.yy\n")
88 test.up_to_date(arguments='.')
90 test.pass_test()
92 # Local Variables:
93 # tab-width:4
94 # indent-tabs-mode:nil
95 # End:
96 # vim: set expandtab tabstop=4 shiftwidth=4: