Expanded SCons.Scanner.LaTeX.comment_re to not break on \%
[scons.git] / test / TEX / lstinputlisting.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 we re-run LaTeX when a source file in \lstinputlisting
29 changes.
30
31 Thanks to Stefan Hepp for the patch that fixed this.
32 """
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 pdflatex = test.where_is('pdflatex')
39
40 if not pdflatex:
41     test.skip_test("Could not find pdflatex; skipping test(s).\n")
42
43 test.write(['SConstruct'], """\
44 import os
45
46 DefaultEnvironment(ENV={'PATH':os.environ['PATH']})
47
48 PDF("test.tex")
49 """)
50
51 test.write(['test.tex'], r"""
52 \documentclass{article}
53 \usepackage{listings}
54
55 \begin{document}
56
57 \section{Listings}
58
59 \lstinputlisting{test.c}
60
61 \end{document}
62 """)
63
64 source_content = r"""
65 int main(int argc, char** argv) {
66     return %s;
67 }
68 """
69
70
71
72 test.write('test.c', source_content % '0')
73
74 test.run()
75
76 pdf_output_1 = test.read('test.pdf')
77
78
79
80 test.write('test.c', source_content % '1')
81
82 test.run()
83
84 pdf_output_2 = test.read('test.pdf')
85
86 # If the PDF file is the same as it was previously, then it didn't
87 # pick up the change from 1981 to 1982, so fail.
88 test.fail_test(pdf_output_1 == pdf_output_2)
89
90
91
92 # Double-check:  clean everything and rebuild from scratch, which
93 # should force the PDF file to be the 1982 version.
94
95 test.run(arguments = '-c')
96
97 test.run()
98
99 pdf_output_3 = test.read('test.pdf')
100
101
102
103 # If the PDF file is now different than the second run, modulo the
104 # creation timestamp and the ID and some other PDF garp, then something
105 # else odd has happened, so fail.
106
107 pdf_output_2 = test.normalize_pdf(pdf_output_2)
108 pdf_output_3 = test.normalize_pdf(pdf_output_3)
109
110 if pdf_output_2 != pdf_output_3:
111     import sys
112     test.write('test.normalized.2.pdf', pdf_output_2)
113     test.write('test.normalized.3.pdf', pdf_output_3)
114     sys.stdout.write("***** 2 and 3 are different!\n")
115     sys.stdout.write(test.diff_substr(pdf_output_2, pdf_output_3, 80, 80) + '\n')
116     sys.stdout.write("Output from run 2:\n")
117     sys.stdout.write(test.stdout(-2) + '\n')
118     sys.stdout.write("Output from run 3:\n")
119     sys.stdout.write(test.stdout() + '\n')
120     sys.stdout.flush()
121     test.fail_test()
122
123
124
125 test.pass_test()
126
127 # Local Variables:
128 # tab-width:4
129 # indent-tabs-mode:nil
130 # End:
131 # vim: set expandtab tabstop=4 shiftwidth=4: