Merged revisions 2647-2719 via svnmerge from
[scons.git] / test / TEX / auxiliaries.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 Verify that sections of LaTeX output that use auxiliary files (a
29 bibliography in our configuration below) are consistent when re-run
30 after modifying the input file.
31
32 This checks for a bug that was triggered by the presence of auxiliary
33 files which were detected by SCons but then removed prior to invoking
34 TeX, causing the auxiliary sections to be excluded from the output.
35 That was fixed (courtesy Joel B. Mohler) by making all the relevant
36 auxiliary files Precious().
37
38 Test configuration courtesy Dmitry Mikhin.
39 """
40
41 import TestSCons
42
43 test = TestSCons.TestSCons()
44
45 dvips = test.where_is('dvips')
46 latex = test.where_is('latex')
47
48 if not dvips or not latex:
49     test.skip_test("Could not find dvips or latex; skipping test(s).\n")
50
51
52 test.subdir(['docs'])
53
54 test.write(['SConstruct'], """\
55 env = Environment(tools = ['pdftex', 'dvipdf', 'dvips', 'tex', 'latex'],
56                   ENV = {},
57                   BUILD_DIR = '#build/docs')
58
59 # Use 'duplicate=1' because LaTeX toolchain does not work properly for
60 # input/output files outside of the current directory
61
62 env.VariantDir('$BUILD_DIR', 'docs', duplicate=1)
63 env.SConscript('$BUILD_DIR/SConscript', exports = ['env'])
64 """)
65
66 test.write(['docs', 'SConscript'], """\
67 Import('env')
68 envc = env.Clone()
69
70 test_dvi = envc.DVI(source='test.tex')
71 test_ps = envc.PostScript(source='test.tex')
72 test_pdf = envc.PDF(source='test.tex')
73
74 envc.Default(test_dvi)
75 envc.Default(test_ps)
76 envc.Default(test_pdf)
77 """)
78
79 test.write(['docs', 'my.bib'], """\
80 @ARTICLE{Mikhin,
81    author = "Dmitry {\uppercase{Y}u}. Mikhin",
82    title = "Blah!",
83    journal = "Some yellow paper",
84    year = "2007",
85    volume = "7",
86    number = "3",
87    pages = "1--2"
88 }
89 """)
90
91 tex_input = r"""\documentclass{article}
92
93 \title{BUG IN SCONS}
94
95 \author{Dmitry Yu. Mikhin}
96
97 \begin{document}
98
99 \maketitle
100
101
102 \begin{abstract}
103 \noindent A bug in BibTeX processing?
104 \end{abstract}
105
106
107 \section{The problem}
108
109 Provide a citation here: \cite{Mikhin}.
110
111
112 \bibliography{my}
113 \bibliographystyle{unsrtnat}
114
115 \end{document}
116 """
117
118 test.write(['docs', 'test.tex'], tex_input)
119
120 test.run(stderr=None)
121
122 pdf_output_1 = test.read(['build', 'docs', 'test.pdf'])
123 ps_output_1 = test.read(['build', 'docs', 'test.ps'])
124
125 # Adding blank lines will cause SCons to re-run the builds, but the
126 # actual contents of the output files should be the same modulo
127 # the CreationDate header and some other PDF garp.
128 test.write(['docs', 'test.tex'], tex_input + "\n\n\n")
129
130 test.run(stderr=None)
131
132 pdf_output_2 = test.read(['build', 'docs', 'test.pdf'])
133 ps_output_2 = test.read(['build', 'docs', 'test.ps'])
134
135
136
137 pdf_output_1 = test.normalize_pdf(pdf_output_1)
138 pdf_output_2 = test.normalize_pdf(pdf_output_2)
139
140 if pdf_output_1 != pdf_output_2:
141     import sys
142     test.write(['build', 'docs', 'test.normalized.1.pdf'], pdf_output_1)
143     test.write(['build', 'docs', 'test.normalized.2.pdf'], pdf_output_2)
144     sys.stdout.write("***** 1.pdf and 2.pdf are different!\n")
145     sys.stdout.write(test.diff_substr(pdf_output_1, pdf_output_2, 80, 80) + '\n')
146     sys.stdout.write("Output from run 1:\n")
147     sys.stdout.write(test.stdout(-1) + '\n')
148     sys.stdout.write("Output from run 2:\n")
149     sys.stdout.write(test.stdout() + '\n')
150     sys.stdout.flush()
151     test.fail_test()
152
153 if ps_output_1 != ps_output_2:
154     import sys
155     sys.stdout.write("***** 1.ps and 2.ps are different!\n")
156     sys.stdout.write(test.diff_substr(ps_output_1, ps_output_2, 80, 80) + '\n')
157     sys.stdout.write("Output from run 1:\n")
158     sys.stdout.write(test.stdout(-1) + '\n')
159     sys.stdout.write("Output from run 2:\n")
160     sys.stdout.write(test.stdout() + '\n')
161     sys.stdout.flush()
162     test.fail_test()
163
164
165
166 test.pass_test()