Variables cleanup: core
[scons.git] / test / TEX / bibtex-latex-rerun.py
blob7334f1eabc8b604680fd287098adef53bc7f0696
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 r"""
28 Verify that we re-run LaTeX after running BibTeX in response to
29 changes in a .bib file.
31 Thanks to Rob Managan for the patch that fixed this, and to Joel B. Mohler
32 for code clean up and packaging the test case.
33 """
35 import TestSCons
37 test = TestSCons.TestSCons()
39 pdflatex = test.where_is('pdflatex')
41 if not pdflatex:
42 test.skip_test("Could not find 'pdflatex'; skipping test(s).\n")
44 test.write(['SConstruct'], """\
45 import os
46 env = Environment(tools=['pdftex', 'tex'])
47 env.PDF( 'bibtest.tex' )
48 """)
50 sources_tex_content = r"""
51 \documentclass{article}
52 \begin{document}
53 Learn about %s cool math in \cite{koblitz:elliptic_curves}.
54 \bibliographystyle{alpha}
55 \bibliography{sources}
56 \end{document}
57 """
59 sources_bib_content = r"""
60 @book{koblitz:elliptic_curves,
61 author = "Neal Koblitz",
62 title = "Elliptic Curves and Modular Forms",
63 year = "%s",
64 publisher = "Springer-Verlag New York Inc."
66 """
70 test.write(['bibtest.tex'], sources_tex_content % "")
71 test.write('sources.bib', sources_bib_content % '1981')
73 test.run()
75 pdf_output_1 = test.read('bibtest.pdf')
77 # Change tex, but don't change bib. In this case, pdf should still be rebuilt.
78 test.write(['bibtest.tex'], sources_tex_content % "really")
79 test.run()
80 pdf_output_1a = test.read('bibtest.pdf')
81 # If the PDF file is the same as it was previously, then it didn't
82 # pick up the change in the tex file, so fail.
83 test.fail_test(pdf_output_1 == pdf_output_1a)
86 # Change bib.
87 test.write(['bibtest.tex'], sources_tex_content % "")
88 test.write('sources.bib', sources_bib_content % '1982')
90 test.run()
92 pdf_output_2 = test.read('bibtest.pdf')
94 # If the PDF file is the same as it was previously, then it didn't
95 # pick up the change from 1981 to 1982, so fail.
96 test.fail_test(pdf_output_1 == pdf_output_2)
100 # Double-check: clean everything and rebuild from scratch, which
101 # should force the PDF file to be the 1982 version.
103 test.run(arguments = '-c')
105 test.run()
107 pdf_output_3 = test.read('bibtest.pdf')
111 # If the PDF file is now different than the second run, modulo the
112 # creation timestamp and the ID and some other PDF garp, then something
113 # else odd has happened, so fail.
115 pdf_output_2 = test.normalize_pdf(pdf_output_2)
116 pdf_output_3 = test.normalize_pdf(pdf_output_3)
118 if pdf_output_2 != pdf_output_3:
119 import sys
120 test.write('bibtest.normalized.2.pdf', pdf_output_2)
121 test.write('bibtest.normalized.3.pdf', pdf_output_3)
122 sys.stdout.write("***** 2 and 3 are different!\n")
123 sys.stdout.write(test.diff_substr(pdf_output_2, pdf_output_3, 80, 80) + '\n')
124 sys.stdout.write("Output from run 2:\n")
125 sys.stdout.write(test.stdout(-2) + '\n')
126 sys.stdout.write("Output from run 3:\n")
127 sys.stdout.write(test.stdout() + '\n')
128 sys.stdout.flush()
129 test.fail_test()
133 test.pass_test()
135 # Local Variables:
136 # tab-width:4
137 # indent-tabs-mode:nil
138 # End:
139 # vim: set expandtab tabstop=4 shiftwidth=4: