Variables testing: confirm space-containing values
[scons.git] / test / TEX / PDFTEX.py
blob0309fcebe22e391dc0d9ea10cdd8dfcb824ce720
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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__"
27 r"""
28 Validate that we can set the PDFTEX string to our own utility, that
29 the produced .dvi, .aux and .log files get removed by the -c option,
30 and that we can use this to wrap calls to the real latex utility.
31 """
33 import TestSCons
35 _python_ = TestSCons._python_
37 test = TestSCons.TestSCons()
41 test.write('mypdftex.py', r"""
42 import sys
43 import os
44 import getopt
45 cmd_opts, arg = getopt.getopt(sys.argv[2:], 'i:r:', [])
46 base_name = os.path.splitext(arg[0])[0]
47 with open(arg[0], 'r') as ifp:
48 with open(base_name+'.pdf', 'w') as pdf_file, \
49 open(base_name+'.aux', 'w') as aux_file, \
50 open(base_name+'.log', 'w') as log_file:
52 for l in ifp.readlines():
53 if l[0] != '\\':
54 pdf_file.write(l)
55 aux_file.write(l)
56 log_file.write(l)
57 sys.exit(0)
58 """)
60 test.write('SConstruct', """
61 env = Environment(PDFTEX = r'%(_python_)s mypdftex.py', tools=['pdftex'])
62 env.PDF(target = 'test.pdf', source = 'test.tex')
63 """ % locals())
65 test.write('test.tex', r"""This is a test.
66 \end
67 """)
69 test.run(arguments = 'test.pdf')
71 test.must_exist('test.pdf')
72 test.must_exist('test.aux')
73 test.must_exist('test.log')
75 test.run(arguments = '-c test.pdf')
77 test.must_not_exist('test.pdf')
78 test.must_not_exist('test.aux')
79 test.must_not_exist('test.log')
83 pdftex = test.where_is('pdftex')
85 if pdftex:
87 test.file_fixture('wrapper.py')
89 test.write('SConstruct', """
90 import os
91 ENV = { 'PATH' : os.environ['PATH'] }
92 foo = Environment(ENV = ENV)
93 pdftex = foo.Dictionary('PDFTEX')
94 bar = Environment(ENV = ENV, PDFTEX = r'%(_python_)s wrapper.py ' + pdftex)
95 foo.PDF(target = 'foo.pdf', source = 'foo.tex')
96 bar.PDF(target = 'bar', source = 'bar.tex')
97 """ % locals())
99 tex = r"""
100 This is the %s TeX file.
101 \end
104 test.write('foo.tex', tex % 'foo.tex')
106 test.write('bar.tex', tex % 'bar.tex')
108 test.run(arguments = 'foo.pdf', stderr = None)
110 test.must_not_exist('wrapper.out')
112 test.must_exist('foo.pdf')
114 test.run(arguments = 'bar.pdf', stderr = None)
116 test.must_exist('wrapper.out')
118 test.must_exist('bar.pdf')
120 test.pass_test()
122 # Local Variables:
123 # tab-width:4
124 # indent-tabs-mode:nil
125 # End:
126 # vim: set expandtab tabstop=4 shiftwidth=4: