Merge pull request #4674 from bdbaddog/fix_2281_Aliases_ignore_pre_post_add_actions
[scons.git] / test / DVIPS / DVIPSFLAGS.py
blobf2e6ba99b30f192055c77f0b2c3744ff52fa7458
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 import TestSCons
29 _python_ = TestSCons._python_
31 test = TestSCons.TestSCons()
35 test.write('mytex.py', r"""
36 import os
37 import sys
38 import getopt
39 cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
40 base_name = os.path.splitext(arg[0])[0]
41 infile = open(arg[0], 'r')
42 out_file = open(base_name+'.dvi', 'w')
43 for l in infile.readlines():
44 if l[:4] != '#tex':
45 out_file.write(l)
46 sys.exit(0)
47 """)
49 test.write('mylatex.py', r"""
50 import os
51 import sys
52 import getopt
53 cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
54 base_name = os.path.splitext(arg[0])[0]
55 infile = open(arg[0], 'r')
56 out_file = open(base_name+'.dvi', 'w')
57 for l in infile.readlines():
58 if l[:6] != '#latex':
59 out_file.write(l)
60 sys.exit(0)
61 """)
63 test.write('mydvips.py', r"""
64 import getopt
65 import os
66 import sys
67 cmd_opts, args = getopt.getopt(sys.argv[1:], 'o:x', [])
68 opt_string = ''
69 for opt, arg in cmd_opts:
70 if opt == '-o': outfile = arg
71 else: opt_string = opt_string + ' ' + opt
72 infile = open(args[0], 'r')
73 out_file = open(outfile, 'w')
74 out_file.write(opt_string + "\n")
75 for l in infile.readlines():
76 if l[:6] != '#dvips':
77 out_file.write(l)
78 sys.exit(0)
79 """)
81 test.write('SConstruct', """
82 env = Environment(TEX = r'%(_python_)s mytex.py',
83 LATEX = r'%(_python_)s mylatex.py',
84 DVIPS = r'%(_python_)s mydvips.py', DVIPSFLAGS = '-x',
85 tools=['tex', 'latex', 'dvips'])
86 dvi = env.DVI(target = 'test1.dvi', source = 'test1.tex')
87 env.PostScript(target = 'test1.ps', source = dvi)
88 env.PostScript(target = 'test2.ps', source = 'test2.tex')
89 env.PostScript(target = 'test3.ps', source = 'test3.ltx')
90 env.PostScript(target = 'test4.ps', source = 'test4.latex')
91 """ % locals())
93 test.write('test1.tex', r"""This is a .dvi test.
94 #tex
95 #dvips
96 """)
98 test.write('test2.tex', r"""This is a .tex test.
99 #tex
100 #dvips
101 """)
103 test.write('test3.ltx', r"""This is a .ltx test.
104 #latex
105 #dvips
106 """)
108 test.write('test4.latex', r"""This is a .latex test.
109 #latex
110 #dvips
111 """)
113 test.run(arguments = '.', stderr = None)
115 test.must_match('test1.ps', " -x\nThis is a .dvi test.\n", mode='r')
117 test.must_match('test2.ps', " -x\nThis is a .tex test.\n", mode='r')
119 test.must_match('test3.ps', " -x\nThis is a .ltx test.\n", mode='r')
121 test.must_match('test4.ps', " -x\nThis is a .latex test.\n", mode='r')
124 dvips = test.where_is('dvips')
126 if dvips:
128 test.write("wrapper.py", """
129 import subprocess
130 import sys
131 cmd = " ".join(sys.argv[1:])
132 with open('%s', 'a') as f:
133 f.write("%%s\\n" %% cmd)
134 subprocess.run(cmd, shell=True)
135 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
137 test.write('SConstruct', """
138 import os
139 ENV = {'PATH' : os.environ['PATH']}
140 foo = Environment(ENV = ENV, DVIPSFLAGS = '-N')
141 dvips = foo.Dictionary('DVIPS')
142 bar = Environment(ENV = ENV,DVIPS = r'%(_python_)s wrapper.py ' + dvips)
143 foo.PostScript(target = 'foo.ps', source = 'foo.tex')
144 bar.PostScript(target = 'bar1', source = 'bar1.tex')
145 bar.PostScript(target = 'bar2', source = 'bar2.ltx')
146 bar.PostScript(target = 'bar3', source = 'bar3.latex')
147 """ % locals())
149 tex = r"""
150 This is the %s TeX file.
151 \end
154 latex = r"""
155 \documentclass{letter}
156 \begin{document}
157 This is the %s LaTeX file.
158 \end{document}
161 test.write('foo.tex', tex % 'foo.tex')
162 test.write('bar1.tex', tex % 'bar1.tex')
163 test.write('bar2.ltx', latex % 'bar2.ltx')
164 test.write('bar3.latex', latex % 'bar3.latex')
166 test.run(arguments='foo.dvi', stderr=None)
168 test.must_not_exist(test.workpath('wrapper.out'))
170 test.must_exist(test.workpath('foo.dvi'))
172 test.run(arguments='bar1.ps bar2.ps bar3.ps', stderr=None)
174 expect = """dvips -o bar1.ps bar1.dvi
175 dvips -o bar2.ps bar2.dvi
176 dvips -o bar3.ps bar3.dvi
179 test.must_match('wrapper.out', expect, mode='r')
181 test.must_exist(test.workpath('bar1.ps'))
182 test.must_exist(test.workpath('bar2.ps'))
183 test.must_exist(test.workpath('bar3.ps'))
185 test.pass_test()
187 # Local Variables:
188 # tab-width:4
189 # indent-tabs-mode:nil
190 # End:
191 # vim: set expandtab tabstop=4 shiftwidth=4: