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.
28 _python_
= TestSCons
._python
_
30 test
= TestSCons
.TestSCons()
34 test
.write('mytex.py', r
"""
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():
48 test
.write('mylatex.py', r
"""
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():
62 test
.write('mydvips.py', r
"""
65 infile = open(sys.argv[3], 'r')
66 out_file = open(sys.argv[2], 'w')
67 for l in infile.readlines():
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')
85 test
.write('test1.tex', r
"""This is a .dvi test.
90 test
.write('test2.tex', r
"""This is a .tex test.
95 test
.write('test3.ltx', r
"""This is a .ltx test.
100 test
.write('test4.latex', r
"""This is a .latex test.
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')
119 test
.skip_test("Could not find 'latex'; skipping test(s).\n")
121 dvips
= test
.where_is('dvips')
123 test
.skip_test("Could not find 'dvips'; skipping test(s).\n")
125 test
.write("wrapper.py", """
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', """
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')
146 This is the %s TeX file.
151 \documentclass{letter}
153 This is the %s LaTeX file.
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'))
185 # indent-tabs-mode:nil
187 # vim: set expandtab tabstop=4 shiftwidth=4: