4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
34 import SCons.Scanner.LaTeX
36 test = TestCmd.TestCmd(workdir = '')
38 test.write('test1.latex',"""
46 test.write('test2.latex',"""
51 test.write('test3.latex',"""
52 \includegraphics{inc4.eps}
53 \includegraphics[width=60mm]{inc5.xyz}
58 test.write('inc1.tex',"\n")
59 test.write('inc2.tex',"\n")
60 test.write(['subdir', 'inc3.tex'], "\n")
61 test.write(['subdir', 'inc4.eps'], "\n")
62 test.write('inc5.xyz', "\n")
63 test.write('inc6.tex', "\n")
64 test.write('incNO.tex', "\n")
66 # define some helpers:
67 # copied from CTest.py
68 class DummyEnvironment(UserDict.UserDict):
69 def __init__(self, **kw):
70 UserDict.UserDict.__init__(self)
72 self.fs = SCons.Node.FS.FS(test.workpath(''))
74 def Dictionary(self, *args):
77 def subst(self, strSubst, target=None, source=None, conv=None):
78 if strSubst[0] == '$':
79 return self.data[strSubst[1:]]
82 def subst_list(self, strSubst, target=None, source=None, conv=None):
83 if strSubst[0] == '$':
84 return [self.data[strSubst[1:]]]
87 def subst_path(self, path, target=None, source=None, conv=None):
88 if type(path) != type([]):
90 return list(map(self.subst, path))
92 def get_calculator(self):
95 def get_factory(self, factory):
96 return factory or self.fs.File
98 def Dir(self, filename):
99 return self.fs.Dir(filename)
101 def File(self, filename):
102 return self.fs.File(filename)
104 if os.path.normcase('foo') == os.path.normcase('FOO'):
105 my_normpath = os.path.normcase
107 my_normpath = os.path.normpath
109 def deps_match(self, deps, headers):
111 scanned = list(map(my_normpath, list(map(str, deps))))
112 expect = list(map(my_normpath, headers))
113 self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned))
116 class LaTeXScannerTestCase1(unittest.TestCase):
118 env = DummyEnvironment(LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
119 s = SCons.Scanner.LaTeX.LaTeXScanner()
121 deps = s(env.File('test1.latex'), env, path)
122 headers = ['inc1.tex', 'inc2.tex', 'inc6.tex']
123 deps_match(self, deps, headers)
125 class LaTeXScannerTestCase2(unittest.TestCase):
127 env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")],LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
128 s = SCons.Scanner.LaTeX.LaTeXScanner()
130 deps = s(env.File('test2.latex'), env, path)
131 headers = ['inc1.tex', 'subdir/inc3.tex']
132 deps_match(self, deps, headers)
134 class LaTeXScannerTestCase3(unittest.TestCase):
136 env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")],LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
137 s = SCons.Scanner.LaTeX.LaTeXScanner()
139 deps = s(env.File('test3.latex'), env, path)
140 files = ['inc5.xyz', 'subdir/inc4.eps']
141 deps_match(self, deps, files)
145 suite = unittest.TestSuite()
146 suite.addTest(LaTeXScannerTestCase1())
147 suite.addTest(LaTeXScannerTestCase2())
148 suite.addTest(LaTeXScannerTestCase3())
151 if __name__ == "__main__":
152 runner = unittest.TextTestRunner()
153 result = runner.run(suite())
154 if not result.wasSuccessful():
159 # indent-tabs-mode:nil
161 # vim: set expandtab tabstop=4 shiftwidth=4: