Remove (lots) more unnecessary imports.
[scons.git] / test / TEX / makeindex.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 Validate that use of \makeindex in TeX source files causes SCons to be
29 aware of the necessary created index files.
30
31 Test configuration courtesy Joel B. Mohler.
32 """
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 pdflatex = test.where_is('pdflatex')
39 makeindex = test.where_is('makeindex')
40
41 if not pdflatex or not makeindex:
42     test.skip_test("Could not find pdflatex or makeindex; skipping test(s).\n")
43
44 test.write('SConstruct', """\
45 import os
46 env = Environment(tools = ['pdftex', 'dvipdf', 'tex', 'latex'],
47                   ENV = {'PATH' : os.environ['PATH']})
48 env.PDF( "no_index.tex" )
49 env.PDF( "simple.tex" )
50 """)
51
52 test.write('no_index.tex', r"""
53 \documentclass{article}
54
55 \begin{document}
56 Nothing to see here, move along!
57 \end{document}
58 """)
59
60 test.write('simple.tex', r"""
61 \documentclass{article}
62 \usepackage{makeidx}
63 \makeindex
64
65 \begin{document}
66 \section{Test 1}
67 I would like to \index{index} this.
68
69 \section{test 2}
70 I'll index \index{this} as well.
71
72 \printindex
73 \end{document}
74 """)
75
76 # Bleah, makeindex seems to print a bunch of diagnostic stuff on stderr,
77 # so we have to ignore it.
78 test.run(arguments = '.', stderr=None)
79
80 test.must_exist(test.workpath('simple.aux'))
81 test.must_exist(test.workpath('simple.idx'))
82 test.must_exist(test.workpath('simple.ilg'))
83 test.must_exist(test.workpath('simple.ind'))
84
85 test.must_exist(test.workpath('no_index.aux'))
86
87 test.must_not_exist(test.workpath('no_index.idx'))
88 test.must_not_exist(test.workpath('no_index.ilg'))
89 test.must_not_exist(test.workpath('no_index.ind'))
90
91 test.run(arguments = '-c .')
92
93 x = "Could not remove 'no_index.aux': No such file or directory"
94 test.must_not_contain_any_line(test.stdout(), [x])
95 x = "Could not remove 'simple.aux': No such file or directory"
96 test.must_not_contain_any_line(test.stdout(), [x])
97
98 test.must_not_exist(test.workpath('simple.aux'))
99 test.must_not_exist(test.workpath('simple.idx'))
100 test.must_not_exist(test.workpath('simple.ilg'))
101 test.must_not_exist(test.workpath('simple.ind'))
102
103 test.must_not_exist(test.workpath('no_index.aux'))
104
105 test.pass_test()