--- /dev/null
+__revision__ = "Scanner/ScannerTests.py __REVISION__ __DATE__ __DEVELOPER__"
+
+import unittest
+import scons.Scanner
+import sys
+
+class ScannerTestBase:
+
+ def func(self, filename, env):
+ self.filename = filename
+ self.env = env
+ return self.deps
+
+ def error_func(self, filename, env):
+ self.fail("the wrong function was called")
+
+ def test(self, scanner, env, filename, deps):
+ self.deps = deps
+ deps = scanner.scan(filename, env)
+
+ self.failUnless(self.filename == filename, "the filename was passed incorrectly")
+ self.failUnless(self.env == env, "the environment was passed incorrectly")
+ self.failUnless(self.deps == deps, "the dependencies were returned incorrectly")
+
+class DummyEnvironment:
+ pass
+
+
+class ScannerPositionalTestCase(ScannerTestBase, unittest.TestCase):
+ "Test the Scanner class using the position argument"
+ def runTest(self):
+ s = scons.Scanner.Scanner(self.func)
+ env = DummyEnvironment()
+ env.ARGUMENT = "arg1"
+ self.test(s, env, 'f1.cpp', ['f1.h', 'f2.h'])
+
+class ScannerKeywordTestCase(ScannerTestBase, unittest.TestCase):
+ "Test the Scanner class using the keyword argument"
+ def runTest(self):
+ s = scons.Scanner.Scanner(function = self.func)
+ env = DummyEnvironment()
+ env.ARGUMENT = "arg1"
+ self.test(s, env, 'f1.cpp', ['f1.h', 'f2.h'])
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(ScannerPositionalTestCase())
+ suite.addTest(ScannerKeywordTestCase())
+ return suite
+
+if __name__ == "__main__":
+ runner = unittest.TextTestRunner()
+ result = runner.run(suite())
+ if not result.wasSuccessful():
+ sys.exit(1)
+
+
--- /dev/null
+"""scons.Scanner
+
+The Scanner package for the scons software construction utility.
+
+"""
+
+__revision__ = "Scanner/__init__.py __REVISION__ __DATE__ __DEVELOPER__"
+
+__version__ = "__VERSION__"
+
+class Scanner:
+
+ def __init__(self, function):
+ """
+ Construct a new scanner object given a scanner function.
+
+ The only argument to this method is a function taking two arguments
+ and returning a list of strings. The functions first argument will
+ be the name of a file that should be scanned for dependencies, the
+ second argument will be an Environment object and
+ the returned list of should contain the file names of all the
+ direct dependencies of this file.
+
+ Examples:
+
+ s = Scanner(my_scanner_function)
+
+ s = Scanner(function = my_scanner_function)
+
+ """
+
+ # Note: this class could easily work with scanner functions that take
+ # something other than a filename as an argument (e.g. a database
+ # node) and a dependencies list that aren't file names. All that
+ # would need to be changed is the documentation.
+
+ self.function = function
+
+ def scan(self, filename, env):
+ """
+ This method does the actually scanning. 'filename' is the filename
+ that will be passed to the scanner function, and 'env' is the
+ environment that will be passed to the scanner function. A list of
+ dependencies will be returned.
+ """
+
+ return self.function(filename, env)
+
+
+
+