Expanded SCons.Scanner.LaTeX.comment_re to not break on \%
[scons.git] / test / TEX / variant_dir.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 """
28 Test creation of a fully-featured TeX document (with bibliography
29 and index) in a variant_dir.
30
31 Test courtesy Rob Managan.
32 """
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 latex = test.where_is('latex')
39 if not latex:
40     test.skip_test("Could not find 'latex'; skipping test.\n")
41
42 test.subdir(['docs'])
43
44
45 test.write(['SConstruct'], """\
46 import os
47
48 env = Environment(ENV = { 'PATH' : os.environ['PATH'] },
49                   TOOLS = ['tex', 'latex', 'dvipdf'])
50 Export(['env'])
51
52 SConscript(os.path.join('docs', 'SConscript'),
53            variant_dir=os.path.join('mybuild','docs'),
54            duplicate=1)
55 """)
56
57
58 test.write(['docs', 'SConscript'], """\
59 Import('env')
60
61 test_dvi = env.DVI(source='test.tex')
62 testpdf = env.PDF(source=test_dvi)
63 """)
64
65
66 test.write(['docs', 'Fig1.ps'], """\
67 %!PS-Adobe-2.0 EPSF-2.0
68 %%Title: Fig1.fig
69 %%Creator: fig2dev Version 3.2 Patchlevel 4
70 %%CreationDate: Tue Apr 25 09:56:11 2006
71 %%For: managan@mangrove.llnl.gov (Rob Managan)
72 %%BoundingBox: 0 0 98 98
73 %%Magnification: 1.0000
74 %%EndComments
75 /$F2psDict 200 dict def
76 $F2psDict begin
77 $F2psDict /mtrx matrix put
78 /col-1 {0 setgray} bind def
79 /col0 {0.000 0.000 0.000 srgb} bind def
80
81 end
82 save
83 newpath 0 98 moveto 0 0 lineto 98 0 lineto 98 98 lineto closepath clip newpath
84 -24.9 108.2 translate
85 1 -1 scale
86
87 /cp {closepath} bind def
88 /ef {eofill} bind def
89 /gr {grestore} bind def
90 /gs {gsave} bind def
91 /rs {restore} bind def
92 /l {lineto} bind def
93 /m {moveto} bind def
94 /rm {rmoveto} bind def
95 /n {newpath} bind def
96 /s {stroke} bind def
97 /slc {setlinecap} bind def
98 /slj {setlinejoin} bind def
99 /slw {setlinewidth} bind def
100 /srgb {setrgbcolor} bind def
101 /sc {scale} bind def
102 /sf {setfont} bind def
103 /scf {scalefont} bind def
104 /tr {translate} bind def
105  /DrawEllipse {
106         /endangle exch def
107         /startangle exch def
108         /yrad exch def
109         /xrad exch def
110         /y exch def
111         /x exch def
112         /savematrix mtrx currentmatrix def
113         x y tr xrad yrad sc 0 0 1 startangle endangle arc
114         closepath
115         savematrix setmatrix
116         } def
117
118 /$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def
119 /$F2psEnd {$F2psEnteredState restore end} def
120
121 $F2psBegin
122 10 setmiterlimit
123  0.06299 0.06299 sc
124 %
125 % Fig objects follow
126
127 7.500 slw
128 % Ellipse
129 n 1170 945 766 766 0 360 DrawEllipse gs col0 s gr
130
131 $F2psEnd
132 rs
133 """)
134
135
136 test.write(['docs', 'Fig1.tex'],
137 r"""\begin{picture}(0,0)%
138 \includegraphics{Fig1.ps}%
139 \end{picture}%
140 \setlength{\unitlength}{4144sp}%
141 %
142 \begingroup\makeatletter\ifx\SetFigFont\undefined%
143 \gdef\SetFigFont#1#2#3#4#5{%
144   \reset@font\fontsize{#1}{#2pt}%
145   \fontfamily{#3}\fontseries{#4}\fontshape{#5}%
146   \selectfont}%
147 \fi\endgroup%
148 \begin{picture}(1548,1546)(397,-879)
149 \put(856,-196){\makebox(0,0)[lb]{\smash{\SetFigFont{12}{14.4}{\rmdefault}{\mddefault}{\updefault}{\color[rgb]{0,0,0}center $r_0$}%
150 }}}
151 \end{picture}
152 """)
153
154
155 test.write(['docs', 'test.bib'], """\
156 %% This BibTeX bibliography file was created using BibDesk.
157 %% http://bibdesk.sourceforge.net/
158
159
160 %% Created for Rob Managan at 2006-11-15 12:53:16 -0800 
161
162
163 %% Saved with string encoding Western (ASCII) 
164
165
166
167 @techreport{Managan:2006fk,
168         Author = {Robert Managan},
169         Date-Added = {2006-11-15 12:51:30 -0800},
170         Date-Modified = {2006-11-15 12:52:35 -0800},
171         Institution = {none},
172         Month = {November},
173         Title = {A Test Paper},
174         Year = {2006}}
175 """)
176
177
178 test.write(['docs', 'test.tex'],
179 r"""\documentclass{report}
180
181 \usepackage{graphicx}
182 \usepackage{epsfig,color} % for .tex version of figures if we go that way
183
184 \usepackage{makeidx}
185 \makeindex
186
187 \begin{document}
188  
189 \title{Report Title}
190
191 \author{A. N. Author}
192  
193 \maketitle 
194  
195 \begin{abstract}
196 there is no abstract
197 \end{abstract}
198
199 \tableofcontents
200 \listoffigures
201
202 \chapter{Introduction}
203
204 The introduction is short.
205
206 \index{Acknowledgements}
207
208 \section{Acknowledgements}
209
210 The Acknowledgements are show as well \cite{Managan:2006fk}.  
211
212 \index{Getting the Report}
213
214 To get a hard copy of this report call me.
215
216 \begin{figure}[htbp]
217 \begin{center}
218 \input{Fig1.tex} % testing figure variant that uses TeX labeling
219 \caption{Zone and Node indexing}
220 \label{fig1}
221 \end{center}
222 \end{figure}
223
224 All done now.
225
226 \bibliographystyle{unsrt}
227 \bibliography{test}
228 \newpage
229
230 \printindex
231
232 \end{document}
233 """)
234
235
236 # makeindex will write status messages to stderr (grrr...), so ignore it.
237 test.run(arguments = '.', stderr=None)
238
239
240 # All (?) the files we expect will get created in the variant_dir
241 # (mybuild/docs) and not in the srcdir (docs).
242 files = [
243     'test.aux',
244     'test.bbl',
245     'test.blg',
246     'test.dvi',
247     'test.idx',
248     'test.ilg',
249     'test.ind',
250     'test.lof',
251     'test.log',
252     'test.pdf',
253     'test.toc',
254 ]
255
256 for f in files:
257     test.must_exist(['mybuild', 'docs', f])
258     test.must_not_exist(['docs', f])
259
260
261 test.pass_test()
262
263 # Local Variables:
264 # tab-width:4
265 # indent-tabs-mode:nil
266 # End:
267 # vim: set expandtab tabstop=4 shiftwidth=4: