Remove (lots) more unnecessary imports.
[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 import os
56 env = Environment(tools = ['pdftex', 'dvipdf', 'dvips', 'tex', 'latex'],
57                   ENV = {'PATH' : os.environ['PATH']},
58                   BUILD_DIR = '#build/docs')
59
60 # Use 'duplicate=1' because LaTeX toolchain does not work properly for
61 # input/output files outside of the current directory
62
63 env.VariantDir('$BUILD_DIR', 'docs', duplicate=1)
64 env.SConscript('$BUILD_DIR/SConscript', exports = ['env'])
65 """)
66
67 test.write(['docs', 'SConscript'], """\
68 Import('env')
69 envc = env.Clone()
70
71 test_dvi = envc.DVI(source='test.tex')
72 test_ps = envc.PostScript(source='test.tex')
73 test_pdf = envc.PDF(source='test.tex')
74
75 envc.Default(test_dvi)
76 envc.Default(test_ps)
77 envc.Default(test_pdf)
78 """)
79
80 test.write(['docs', 'my.bib'], """\
81 @ARTICLE{Mikhin,
82    author = "Dmitry {\uppercase{Y}u}. Mikhin",
83    title = "Blah!",
84    journal = "Some yellow paper",
85    year = "2007",
86    volume = "7",
87    number = "3",
88    pages = "1--2"
89 }
90 """)
91
92 tex_input = r"""\documentclass{article}
93
94 \title{BUG IN SCONS}
95
96 \author{Dmitry Yu. Mikhin}
97
98 \begin{document}
99
100 \maketitle
101
102
103 \begin{abstract}
104 \noindent A bug in BibTeX processing?
105 \end{abstract}
106
107
108 \section{The problem}
109
110 Provide a citation here: \cite{Mikhin}.
111
112
113 \bibliography{my}
114 \bibliographystyle{unsrtnat}
115
116 \end{document}
117 """
118
119 test.write(['docs', 'test.tex'], tex_input)
120
121 test.run(stderr=None)
122
123 pdf_output_1 = test.read(['build', 'docs', 'test.pdf'])
124 ps_output_1 = test.read(['build', 'docs', 'test.ps'])
125
126 # Adding blank lines will cause SCons to re-run the builds, but the
127 # actual contents of the output files should be the same modulo
128 # the CreationDate header and some other PDF garp.
129 test.write(['docs', 'test.tex'], tex_input + "\n\n\n")
130
131 test.run(stderr=None)
132
133 pdf_output_2 = test.read(['build', 'docs', 'test.pdf'])
134 ps_output_2 = test.read(['build', 'docs', 'test.ps'])
135
136
137
138 pdf_output_1 = test.normalize_pdf(pdf_output_1)
139 pdf_output_2 = test.normalize_pdf(pdf_output_2)
140
141 if pdf_output_1 != pdf_output_2:
142     import sys
143     test.write(['build', 'docs', 'test.normalized.1.pdf'], pdf_output_1)
144     test.write(['build', 'docs', 'test.normalized.2.pdf'], pdf_output_2)
145     sys.stdout.write("***** 1.pdf and 2.pdf are different!\n")
146     sys.stdout.write(test.diff_substr(pdf_output_1, pdf_output_2, 80, 80) + '\n')
147     sys.stdout.write("Output from run 1:\n")
148     sys.stdout.write(test.stdout(-1) + '\n')
149     sys.stdout.write("Output from run 2:\n")
150     sys.stdout.write(test.stdout() + '\n')
151     sys.stdout.flush()
152     test.fail_test()
153
154 if ps_output_1 != ps_output_2:
155     import sys
156     sys.stdout.write("***** 1.ps and 2.ps are different!\n")
157     sys.stdout.write(test.diff_substr(ps_output_1, ps_output_2, 80, 80) + '\n')
158     sys.stdout.write("Output from run 1:\n")
159     sys.stdout.write(test.stdout(-1) + '\n')
160     sys.stdout.write("Output from run 2:\n")
161     sys.stdout.write(test.stdout() + '\n')
162     sys.stdout.flush()
163     test.fail_test()
164
165
166
167 test.pass_test()