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.Dir
37 # def __init__(self, name, fs):
39 # self.abspath = test.workpath(name)
43 # def Entry(self, name):
44 # return self.fs.Entry(name)
46 class DummyEnvironment:
47 def __init__(self, root):
48 self.fs = SCons.Node.FS.FS(root)
50 return self.fs.Dir(name)
51 def Entry(self, name):
52 return self.fs.Entry(name)
54 return self.fs.File(name)
55 def get_factory(self, factory):
56 return factory or self.fs.Entry
58 class DirScannerTestBase(unittest.TestCase):
60 self.test = TestCmd.TestCmd(workdir = '')
62 self.test.subdir('dir', ['dir', 'sub'])
64 self.test.write(['dir', 'f1'], "dir/f1\n")
65 self.test.write(['dir', 'f2'], "dir/f2\n")
66 self.test.write(['dir', '.sconsign'], "dir/.sconsign\n")
67 self.test.write(['dir', '.sconsign.bak'], "dir/.sconsign.bak\n")
68 self.test.write(['dir', '.sconsign.dat'], "dir/.sconsign.dat\n")
69 self.test.write(['dir', '.sconsign.db'], "dir/.sconsign.db\n")
70 self.test.write(['dir', '.sconsign.dblite'], "dir/.sconsign.dblite\n")
71 self.test.write(['dir', '.sconsign.dir'], "dir/.sconsign.dir\n")
72 self.test.write(['dir', '.sconsign.pag'], "dir/.sconsign.pag\n")
73 self.test.write(['dir', 'sub', 'f3'], "dir/sub/f3\n")
74 self.test.write(['dir', 'sub', 'f4'], "dir/sub/f4\n")
75 self.test.write(['dir', 'sub', '.sconsign'], "dir/.sconsign\n")
76 self.test.write(['dir', 'sub', '.sconsign.bak'], "dir/.sconsign.bak\n")
77 self.test.write(['dir', 'sub', '.sconsign.dat'], "dir/.sconsign.dat\n")
78 self.test.write(['dir', 'sub', '.sconsign.dblite'], "dir/.sconsign.dblite\n")
79 self.test.write(['dir', 'sub', '.sconsign.dir'], "dir/.sconsign.dir\n")
80 self.test.write(['dir', 'sub', '.sconsign.pag'], "dir/.sconsign.pag\n")
82 class DirScannerTestCase(DirScannerTestBase):
84 env = DummyEnvironment(self.test.workpath())
86 s = SCons.Scanner.Dir.DirScanner()
89 os.path.join('dir', 'f1'),
90 os.path.join('dir', 'f2'),
91 os.path.join('dir', 'sub'),
93 deps = s(env.Dir('dir'), env, ())
95 assert sss == expect, sss
98 os.path.join('dir', 'sub', 'f3'),
99 os.path.join('dir', 'sub', 'f4'),
101 deps = s(env.Dir('dir/sub'), env, ())
103 assert sss == expect, sss
105 class DirEntryScannerTestCase(DirScannerTestBase):
107 env = DummyEnvironment(self.test.workpath())
109 s = SCons.Scanner.Dir.DirEntryScanner()
111 deps = s(env.Dir('dir'), env, ())
113 assert sss == [], sss
115 deps = s(env.Dir('dir/sub'), env, ())
117 assert sss == [], sss
119 # Make sure we don't blow up if handed a non-Dir node.
120 deps = s(env.File('dir/f1'), env, ())
122 assert sss == [], sss
125 suite = unittest.TestSuite()
126 suite.addTest(DirScannerTestCase())
127 suite.addTest(DirEntryScannerTestCase())
130 if __name__ == "__main__":
131 runner = unittest.TextTestRunner()
132 result = runner.run(suite())
133 if not result.wasSuccessful():
138 # indent-tabs-mode:nil
140 # vim: set expandtab tabstop=4 shiftwidth=4: