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__"
33 import SCons.Scanner.LaTeX
35 test = TestCmd.TestCmd(workdir = '')
37 test.write('test1.latex',"""
45 test.write('test2.latex',"""
50 test.write('test3.latex',"""
51 \includegraphics{inc4.eps}
52 \includegraphics[width=60mm]{inc5.xyz}
57 test.write('inc1.tex',"\n")
58 test.write('inc2.tex',"\n")
59 test.write(['subdir', 'inc3.tex'], "\n")
60 test.write(['subdir', 'inc4.eps'], "\n")
61 test.write('inc5.xyz', "\n")
62 test.write('inc6.tex', "\n")
63 test.write('incNO.tex', "\n")
65 # define some helpers:
66 # copied from CTest.py
67 class DummyEnvironment(UserDict.UserDict):
68 def __init__(self, **kw):
69 UserDict.UserDict.__init__(self)
71 self.fs = SCons.Node.FS.FS(test.workpath(''))
73 def Dictionary(self, *args):
76 def subst(self, strSubst, target=None, source=None, conv=None):
77 if strSubst[0] == '$':
78 return self.data[strSubst[1:]]
81 def subst_list(self, strSubst, target=None, source=None, conv=None):
82 if strSubst[0] == '$':
83 return [self.data[strSubst[1:]]]
86 def subst_path(self, path, target=None, source=None, conv=None):
87 if not isinstance(path, list):
89 return list(map(self.subst, path))
91 def get_calculator(self):
94 def get_factory(self, factory):
95 return factory or self.fs.File
97 def Dir(self, filename):
98 return self.fs.Dir(filename)
100 def File(self, filename):
101 return self.fs.File(filename)
103 if os.path.normcase('foo') == os.path.normcase('FOO'):
104 my_normpath = os.path.normcase
106 my_normpath = os.path.normpath
108 def deps_match(self, deps, headers):
110 scanned = list(map(my_normpath, list(map(str, deps))))
111 expect = list(map(my_normpath, headers))
112 self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned))
115 class LaTeXScannerTestCase1(unittest.TestCase):
117 env = DummyEnvironment(LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
118 s = SCons.Scanner.LaTeX.LaTeXScanner()
120 deps = s(env.File('test1.latex'), env, path)
121 headers = ['inc1.tex', 'inc2.tex', 'inc6.tex']
122 deps_match(self, deps, headers)
124 class LaTeXScannerTestCase2(unittest.TestCase):
126 env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")],LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
127 s = SCons.Scanner.LaTeX.LaTeXScanner()
129 deps = s(env.File('test2.latex'), env, path)
130 headers = ['inc1.tex', 'subdir/inc3.tex']
131 deps_match(self, deps, headers)
133 class LaTeXScannerTestCase3(unittest.TestCase):
135 env = DummyEnvironment(TEXINPUTS=[test.workpath("subdir")],LATEXSUFFIXES = [".tex", ".ltx", ".latex"])
136 s = SCons.Scanner.LaTeX.LaTeXScanner()
138 deps = s(env.File('test3.latex'), env, path)
139 files = ['inc5.xyz', 'subdir/inc4.eps']
140 deps_match(self, deps, files)
144 suite = unittest.TestSuite()
145 suite.addTest(LaTeXScannerTestCase1())
146 suite.addTest(LaTeXScannerTestCase2())
147 suite.addTest(LaTeXScannerTestCase3())
150 if __name__ == "__main__":
151 runner = unittest.TextTestRunner()
152 result = runner.run(suite())
153 if not result.wasSuccessful():
158 # indent-tabs-mode:nil
160 # vim: set expandtab tabstop=4 shiftwidth=4: