added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / DVIPDF / DVIPDF.py
blob1c017a931a1c0edc323fe6ad829760aa99512d80
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('mydvipdf.py', r"""
64 import os
65 import sys
66 import getopt
67 cmd_opts, arg = getopt.getopt(sys.argv[1:], 'i:r:', [])
68 infile = open(arg[0], 'r')
69 out_file = open(arg[1], 'w')
70 for l in infile.readlines():
71 if l[:7] != '#dvipdf':
72 out_file.write(l)
73 sys.exit(0)
74 """)
76 test.write('SConstruct', """
77 env = Environment(TEX = r'%(_python_)s mytex.py',
78 LATEX = r'%(_python_)s mylatex.py',
79 DVIPDF = r'%(_python_)s mydvipdf.py',
80 tools=['latex', 'tex', 'dvipdf'])
81 dvi = env.DVI(target = 'test1.dvi', source = 'test1.tex')
82 env.DVI(target = 'test2.dvi', source = 'test2.tex')
83 env.PDF(target = 'test1.pdf', source = dvi)
84 env.PDF(target = 'test2.pdf', source = 'test2.dvi')
85 """ % locals())
87 test.write('test1.tex', r"""This is a .dvi test.
88 #tex
89 #dvipdf
90 """)
92 test.write('test2.tex', r"""This is a .tex test.
93 #tex
94 #dvipdf
95 """)
97 test.run(arguments = '.', stderr = None)
99 test.must_match('test1.pdf', "This is a .dvi test.\n", mode='r')
101 test.must_match('test2.pdf', "This is a .tex test.\n", mode='r')
105 dvipdf = test.where_is('dvipdf')
106 tex = test.where_is('tex')
108 if dvipdf and tex:
110 test.write("wrapper.py", """\
111 import subprocess
112 import sys
113 cmd = " ".join(sys.argv[1:])
114 open('%s', 'a').write("%%s\\n" %% cmd)
115 subprocess.run(cmd, shell=True)
116 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
118 test.write('SConstruct', """
119 import os
120 foo = Environment(ENV = { 'PATH' : os.environ['PATH'] })
121 dvipdf = foo.Dictionary('DVIPDF')
122 bar = Environment(ENV = { 'PATH' : os.environ['PATH'] },
123 DVIPDF = r'%(_python_)s wrapper.py ' + dvipdf)
124 foo.PDF(target = 'foo.pdf',
125 source = foo.DVI(target = 'foo.dvi', source = 'foo.tex'))
126 bar.PDF(target = 'bar.pdf',
127 source = bar.DVI(target = 'bar.dvi', source = 'bar.tex'))
128 foo.PDF(target = 'xxx.pdf', source = 'xxx.tex')
129 """ % locals())
131 tex = r"""
132 This is the %s TeX file.
133 \end
136 test.write('foo.tex', tex % 'foo.tex')
138 test.write('xxx.tex', tex % 'xxx.tex')
140 test.write('bar.tex', tex % 'bar.tex')
142 test.run(arguments = 'foo.pdf', stderr = None)
144 test.must_not_exist(test.workpath('wrapper.out'))
146 test.must_exist(test.workpath('foo.pdf'))
148 test.run(arguments = 'xxx.pdf', stderr = None)
150 test.must_not_exist(test.workpath('wrapper.out'))
152 test.must_not_exist(test.workpath('xxx.dvi'))
154 test.run(arguments = 'bar.pdf', stderr = None)
156 test.must_match('wrapper.out', "dvipdf bar.dvi bar.pdf\n")
158 test.must_exist(test.workpath('bar.pdf'))
160 test.pass_test()
162 # Local Variables:
163 # tab-width:4
164 # indent-tabs-mode:nil
165 # End:
166 # vim: set expandtab tabstop=4 shiftwidth=4: