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