Variables testing: confirm space-containing values
[scons.git] / test / TEX / LATEXFLAGS.py
blob32e41dff0ae4fb5055c4f3f04ba6093eeed9143e
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 import os
28 import TestSCons
30 _python_ = TestSCons._python_
32 test = TestSCons.TestSCons()
36 test.write('mylatex.py', r"""
37 import getopt
38 import os
39 import sys
40 cmd_opts, args = getopt.getopt(sys.argv[1:], 'tx', [])
41 opt_string = ''
42 for opt, arg in cmd_opts:
43 opt_string = opt_string + ' ' + opt
44 base_name = os.path.splitext(args[0])[0]
45 with open(base_name+'.dvi', 'w') as ofp, open(args[0], 'r') as ifp:
46 ofp.write(opt_string + "\n")
47 for l in ifp.readlines():
48 if l[0] != '\\':
49 ofp.write(l)
50 sys.exit(0)
51 """)
53 test.write('SConstruct', """
54 env = Environment(LATEX = r'%(_python_)s mylatex.py',
55 LATEXFLAGS = '-x',
56 tools=['latex'])
57 env.DVI(target = 'test1.dvi', source = 'test1.ltx')
58 env.Clone(LATEXFLAGS = '-t').DVI(target = 'test2.dvi', source = 'test2.latex')
59 """ % locals())
61 test.write('test1.ltx', r"""This is a .ltx test.
62 \end
63 """)
65 test.write('test2.latex', r"""This is a .latex test.
66 \end
67 """)
69 test.run(arguments = '.', stderr = None)
71 test.must_match('test1.dvi', " -x\nThis is a .ltx test.\n", mode='r')
73 test.must_match('test2.dvi', " -t\nThis is a .latex test.\n", mode='r')
77 # TODO: split this test? Taking a skip here invalidates the above, too
78 latex = test.where_is('latex')
79 if latex:
81 test.file_fixture('wrapper.py')
83 test.write('SConstruct', """
84 import os
85 ENV = { 'PATH' : os.environ['PATH'] }
86 foo = Environment(ENV = ENV, LATEXFLAGS = '--output-comment Commentary')
87 latex = foo.Dictionary('LATEX')
88 bar = Environment(ENV = ENV, LATEX = r'%(_python_)s wrapper.py ' + latex)
89 foo.DVI(target = 'foo.dvi', source = 'foo.ltx')
90 bar.DVI(target = 'bar', source = 'bar.latex')
91 """ % locals())
93 latex = r"""
94 \documentclass{letter}
95 \begin{document}
96 This is the %s LaTeX file.
97 \end{document}
98 """
100 test.write('foo.ltx', latex % 'foo.ltx')
102 test.write('bar.latex', latex % 'bar.latex')
104 test.run(arguments = 'foo.dvi', stderr = None)
106 test.fail_test(os.path.exists(test.workpath('wrapper.out')))
108 test.fail_test(not os.path.exists(test.workpath('foo.dvi')))
110 test.run(arguments = 'bar.dvi', stderr = None)
112 test.must_match('wrapper.out', "wrapper.py\n", mode='r')
114 test.fail_test(not os.path.exists(test.workpath('bar.dvi')))
116 test.pass_test()
118 # Local Variables:
119 # tab-width:4
120 # indent-tabs-mode:nil
121 # End:
122 # vim: set expandtab tabstop=4 shiftwidth=4: