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.Dir
36 # def __init__(self, name, fs):
38 # self.abspath = test.workpath(name)
42 # def Entry(self, name):
43 # return self.fs.Entry(name)
45 class DummyEnvironment:
46 def __init__(self, root):
47 self.fs = SCons.Node.FS.FS(root)
49 return self.fs.Dir(name)
50 def Entry(self, name):
51 return self.fs.Entry(name)
53 return self.fs.File(name)
54 def get_factory(self, factory):
55 return factory or self.fs.Entry
57 class DirScannerTestBase(unittest.TestCase):
59 self.test = TestCmd.TestCmd(workdir = '')
61 self.test.subdir('dir', ['dir', 'sub'])
63 self.test.write(['dir', 'f1'], "dir/f1\n")
64 self.test.write(['dir', 'f2'], "dir/f2\n")
65 self.test.write(['dir', '.sconsign'], "dir/.sconsign\n")
66 self.test.write(['dir', '.sconsign.bak'], "dir/.sconsign.bak\n")
67 self.test.write(['dir', '.sconsign.dat'], "dir/.sconsign.dat\n")
68 self.test.write(['dir', '.sconsign.db'], "dir/.sconsign.db\n")
69 self.test.write(['dir', '.sconsign.dblite'], "dir/.sconsign.dblite\n")
70 self.test.write(['dir', '.sconsign.dir'], "dir/.sconsign.dir\n")
71 self.test.write(['dir', '.sconsign.pag'], "dir/.sconsign.pag\n")
72 self.test.write(['dir', 'sub', 'f3'], "dir/sub/f3\n")
73 self.test.write(['dir', 'sub', 'f4'], "dir/sub/f4\n")
74 self.test.write(['dir', 'sub', '.sconsign'], "dir/.sconsign\n")
75 self.test.write(['dir', 'sub', '.sconsign.bak'], "dir/.sconsign.bak\n")
76 self.test.write(['dir', 'sub', '.sconsign.dat'], "dir/.sconsign.dat\n")
77 self.test.write(['dir', 'sub', '.sconsign.dblite'], "dir/.sconsign.dblite\n")
78 self.test.write(['dir', 'sub', '.sconsign.dir'], "dir/.sconsign.dir\n")
79 self.test.write(['dir', 'sub', '.sconsign.pag'], "dir/.sconsign.pag\n")
81 class DirScannerTestCase(DirScannerTestBase):
83 env = DummyEnvironment(self.test.workpath())
85 s = SCons.Scanner.Dir.DirScanner()
88 os.path.join('dir', 'f1'),
89 os.path.join('dir', 'f2'),
90 os.path.join('dir', 'sub'),
92 deps = s(env.Dir('dir'), env, ())
93 sss = list(map(str, deps))
94 assert sss == expect, sss
97 os.path.join('dir', 'sub', 'f3'),
98 os.path.join('dir', 'sub', 'f4'),
100 deps = s(env.Dir('dir/sub'), env, ())
101 sss = list(map(str, deps))
102 assert sss == expect, sss
104 class DirEntryScannerTestCase(DirScannerTestBase):
106 env = DummyEnvironment(self.test.workpath())
108 s = SCons.Scanner.Dir.DirEntryScanner()
110 deps = s(env.Dir('dir'), env, ())
111 sss = list(map(str, deps))
112 assert sss == [], sss
114 deps = s(env.Dir('dir/sub'), env, ())
115 sss = list(map(str, deps))
116 assert sss == [], sss
118 # Make sure we don't blow up if handed a non-Dir node.
119 deps = s(env.File('dir/f1'), env, ())
120 sss = list(map(str, deps))
121 assert sss == [], sss
124 suite = unittest.TestSuite()
125 suite.addTest(DirScannerTestCase())
126 suite.addTest(DirEntryScannerTestCase())
129 if __name__ == "__main__":
130 runner = unittest.TextTestRunner()
131 result = runner.run(suite())
132 if not result.wasSuccessful():
137 # indent-tabs-mode:nil
139 # vim: set expandtab tabstop=4 shiftwidth=4: