Move 2.0 changes collected in branches/pending back to trunk for further
[scons.git] / test / TEX / LATEXFLAGS.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os
28
29 import TestSCons
30
31 _python_ = TestSCons._python_
32
33 test = TestSCons.TestSCons()
34
35
36
37 test.write('mylatex.py', r"""
38 import getopt
39 import os
40 import sys
41 cmd_opts, args = getopt.getopt(sys.argv[1:], 'tx', [])
42 opt_string = ''
43 for opt, arg in cmd_opts:
44     opt_string = opt_string + ' ' + opt
45 base_name = os.path.splitext(args[0])[0]
46 infile = open(args[0], 'rb')
47 out_file = open(base_name+'.dvi', 'wb')
48 out_file.write(opt_string + "\n")
49 for l in infile.readlines():
50     if l[0] != '\\':
51         out_file.write(l)
52 sys.exit(0)
53 """)
54
55 test.write('SConstruct', """
56 env = Environment(LATEX = r'%(_python_)s mylatex.py',
57                   LATEXFLAGS = '-x',
58                   tools=['latex'])
59 env.DVI(target = 'test1.dvi', source = 'test1.ltx')
60 env.Clone(LATEXFLAGS = '-t').DVI(target = 'test2.dvi', source = 'test2.latex')
61 """ % locals())
62
63 test.write('test1.ltx', r"""This is a .ltx test.
64 \end
65 """)
66
67 test.write('test2.latex', r"""This is a .latex test.
68 \end
69 """)
70
71 test.run(arguments = '.', stderr = None)
72
73 test.fail_test(test.read('test1.dvi') != " -x\nThis is a .ltx test.\n")
74
75 test.fail_test(test.read('test2.dvi') != " -t\nThis is a .latex test.\n")
76
77
78
79 latex = test.where_is('latex')
80
81 if latex:
82
83     test.write("wrapper.py", """import os
84 import sys
85 open('%s', 'wb').write("wrapper.py\\n")
86 os.system(" ".join(sys.argv[1:]))
87 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
88
89     test.write('SConstruct', """
90 import os
91 ENV = { 'PATH' : os.environ['PATH'] }
92 foo = Environment(ENV = ENV, LATEXFLAGS = '--output-comment Commentary')
93 latex = foo.Dictionary('LATEX')
94 bar = Environment(ENV = ENV, LATEX = r'%(_python_)s wrapper.py ' + latex)
95 foo.DVI(target = 'foo.dvi', source = 'foo.ltx')
96 bar.DVI(target = 'bar', source = 'bar.latex')
97 """ % locals())
98
99     latex = r"""
100 \documentclass{letter}
101 \begin{document}
102 This is the %s LaTeX file.
103 \end{document}
104 """
105
106     test.write('foo.ltx', latex % 'foo.ltx')
107
108     test.write('bar.latex', latex % 'bar.latex')
109
110     test.run(arguments = 'foo.dvi', stderr = None)
111
112     test.fail_test(os.path.exists(test.workpath('wrapper.out')))
113
114     test.fail_test(not os.path.exists(test.workpath('foo.dvi')))
115
116     test.run(arguments = 'bar.dvi', stderr = None)
117
118     test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
119
120     test.fail_test(not os.path.exists(test.workpath('bar.dvi')))
121
122 test.pass_test()
123
124 # Local Variables:
125 # tab-width:4
126 # indent-tabs-mode:nil
127 # End:
128 # vim: set expandtab tabstop=4 shiftwidth=4: