[ci skip] update generated files
[scons.git] / test / DVIPS / DVIPS.py
blob0e688ae00674e7732e3a75d568394b815abddaf3
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 TestSCons
28 _python_ = TestSCons._python_
30 test = TestSCons.TestSCons()
34 test.write('mytex.py', r"""
35 import os
36 import sys
37 import getopt
38 cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
39 base_name = os.path.splitext(arg[0])[0]
40 infile = open(arg[0], 'r')
41 out_file = open(base_name+'.dvi', 'w')
42 for l in infile.readlines():
43 if l[:4] != '#tex':
44 out_file.write(l)
45 sys.exit(0)
46 """)
48 test.write('mylatex.py', r"""
49 import os
50 import sys
51 import getopt
52 cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
53 base_name = os.path.splitext(arg[0])[0]
54 infile = open(arg[0], 'r')
55 out_file = open(base_name+'.dvi', 'w')
56 for l in infile.readlines():
57 if l[:6] != '#latex':
58 out_file.write(l)
59 sys.exit(0)
60 """)
62 test.write('mydvips.py', r"""
63 import os
64 import sys
65 infile = open(sys.argv[3], 'r')
66 out_file = open(sys.argv[2], 'w')
67 for l in infile.readlines():
68 if l[:6] != '#dvips':
69 out_file.write(l)
70 sys.exit(0)
71 """)
73 test.write('SConstruct', """
74 env = Environment(TEX = r'%(_python_)s mytex.py',
75 LATEX = r'%(_python_)s mylatex.py',
76 DVIPS = r'%(_python_)s mydvips.py',
77 tools=['tex', 'latex', 'dvips'])
78 dvi = env.DVI(target = 'test1.dvi', source = 'test1.tex')
79 env.PostScript(target = 'test1.ps', source = dvi)
80 env.PostScript(target = 'test2.ps', source = 'test2.tex')
81 env.PostScript(target = 'test3.ps', source = 'test3.ltx')
82 env.PostScript(target = 'test4.ps', source = 'test4.latex')
83 """ % locals())
85 test.write('test1.tex', r"""This is a .dvi test.
86 #tex
87 #dvips
88 """)
90 test.write('test2.tex', r"""This is a .tex test.
91 #tex
92 #dvips
93 """)
95 test.write('test3.ltx', r"""This is a .ltx test.
96 #latex
97 #dvips
98 """)
100 test.write('test4.latex', r"""This is a .latex test.
101 #latex
102 #dvips
103 """)
105 test.run(arguments = '.', stderr = None)
107 test.must_match('test1.ps', "This is a .dvi test.\n", mode='r')
109 test.must_match('test2.ps', "This is a .tex test.\n", mode='r')
111 test.must_match('test3.ps', "This is a .ltx test.\n", mode='r')
113 test.must_match('test4.ps', "This is a .latex test.\n", mode='r')
116 # TODO: split this test? Taking a skip here invalidates the above, too
117 latex = test.where_is('latex')
118 if not latex:
119 test.skip_test("Could not find 'latex'; skipping test(s).\n")
121 dvips = test.where_is('dvips')
122 if not dvips:
123 test.skip_test("Could not find 'dvips'; skipping test(s).\n")
125 test.write("wrapper.py", """
126 import subprocess
127 import sys
128 cmd = " ".join(sys.argv[1:])
129 open('%s', 'a').write("%%s\\n" %% cmd)
130 subprocess.run(cmd, shell=True)
131 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
133 test.write('SConstruct', """
134 import os
135 ENV = { 'PATH' : os.environ['PATH'] }
136 foo = Environment(ENV = ENV)
137 dvips = foo.Dictionary('DVIPS')
138 bar = Environment(ENV = ENV, DVIPS = r'%(_python_)s wrapper.py ' + dvips)
139 foo.PostScript(target = 'foo.ps', source = 'foo.tex')
140 bar.PostScript(target = 'bar1', source = 'bar1.tex')
141 bar.PostScript(target = 'bar2', source = 'bar2.ltx')
142 bar.PostScript(target = 'bar3', source = 'bar3.latex')
143 """ % locals())
145 tex = r"""
146 This is the %s TeX file.
147 \end
150 latex = r"""
151 \documentclass{letter}
152 \begin{document}
153 This is the %s LaTeX file.
154 \end{document}
157 test.write('foo.tex', tex % 'foo.tex')
158 test.write('bar1.tex', tex % 'bar1.tex')
159 test.write('bar2.ltx', latex % 'bar2.ltx')
160 test.write('bar3.latex', latex % 'bar3.latex')
162 test.run(arguments = 'foo.dvi', stderr = None)
164 test.must_not_exist(test.workpath('wrapper.out'))
166 test.must_exist(test.workpath('foo.dvi'))
168 test.run(arguments = 'bar1.ps bar2.ps bar3.ps', stderr = None)
170 expect = """dvips -o bar1.ps bar1.dvi
171 dvips -o bar2.ps bar2.dvi
172 dvips -o bar3.ps bar3.dvi
175 test.must_match('wrapper.out', expect, mode='r')
177 test.must_exist(test.workpath('bar1.ps'))
178 test.must_exist(test.workpath('bar2.ps'))
179 test.must_exist(test.workpath('bar3.ps'))
181 test.pass_test()
183 # Local Variables:
184 # tab-width:4
185 # indent-tabs-mode:nil
186 # End:
187 # vim: set expandtab tabstop=4 shiftwidth=4: