<s> __revision__ = "<STR_LIT>" <EOL> import os . path <EOL> import string <EOL> import sys <EOL> import types <EOL> import unittest <EOL> import TestCmd <EOL> import SCons . Node . FS <EOL> import SCons . Scanner . Prog <EOL> test = TestCmd . TestCmd ( workdir = '<STR_LIT>' ) <EOL> test . subdir ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> libs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for h in libs : <EOL> test . write ( h , "<STR_LIT:\n>" ) <EOL> class DummyEnvironment : <EOL> def __init__ ( self , ** kw ) : <EOL> self . _dict = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . _dict . update ( kw ) <EOL> self . fs = SCons . Node . FS . FS ( test . workpath ( '<STR_LIT>' ) ) <EOL> def Dictionary ( self , * args ) : <EOL> if not args : <EOL> return self . _dict <EOL> elif len ( args ) == <NUM_LIT:1> : <EOL> return self . _dict [ args [ <NUM_LIT:0> ] ] <EOL> else : <EOL> return map ( lambda x , s = self : s . _dict [ x ] , args ) <EOL> def has_key ( self , key ) : <EOL> return self . Dictionary ( ) . has_key ( key ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . Dictionary ( ) [ key ] <EOL> def __setitem__ ( self , key , value ) : <EOL> self . Dictionary ( ) [ key ] = value <EOL> def __delitem__ ( self , key ) : <EOL> del self . Dictionary ( ) [ key ] <EOL> def subst ( self , s , target = None , source = None , conv = None ) : <EOL> try : <EOL> if s [ <NUM_LIT:0> ] == '<STR_LIT:$>' : <EOL> return self . _dict [ s [ <NUM_LIT:1> : ] ] <EOL> except IndexError : <EOL> return '<STR_LIT>' <EOL> return s <EOL> def subst_path ( self , path , target = None , source = None , conv = None ) : <EOL> if type ( path ) != type ( [ ] ) : <EOL> path = [ path ] <EOL> return map ( self . subst , path ) <EOL> def get_factory ( self , factory ) : <EOL> return factory or self . fs . File <EOL> def Dir ( self , filename ) : <EOL> return self . fs . Dir ( test . workpath ( filename ) ) <EOL> def File ( self , filename ) : <EOL> return self . fs . File ( test . workpath ( filename ) ) <EOL> class DummyNode : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def rexists ( self ) : <EOL> return <NUM_LIT:1> <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def deps_match ( deps , libs ) : <EOL> deps = map ( str , deps ) <EOL> deps . sort ( ) <EOL> libs . sort ( ) <EOL> return map ( os . path . normpath , deps ) == map ( os . path . normpath , libs ) <EOL> class ProgramScannerTestCase1 ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps_match ( deps , [ '<STR_LIT>' ] ) , map ( str , deps ) <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = '<STR_LIT>' ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps_match ( deps , [ '<STR_LIT>' ] ) , map ( str , deps ) <EOL> f1 = env . fs . File ( test . workpath ( '<STR_LIT>' ) ) <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = [ f1 ] ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps [ <NUM_LIT:0> ] is f1 , deps <EOL> f2 = env . fs . File ( test . workpath ( '<STR_LIT>' ) ) <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = f2 ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps [ <NUM_LIT:0> ] is f2 , deps <EOL> class ProgramScannerTestCase2 ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> env = DummyEnvironment ( LIBPATH = map ( test . workpath , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> LIBS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps_match ( deps , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , map ( str , deps ) <EOL> class ProgramScannerTestCase3 ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) , <EOL> test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = string . split ( '<STR_LIT>' ) ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps_match ( deps , [ '<STR_LIT>' , '<STR_LIT>' ] ) , map ( str , deps ) <EOL> class ProgramScannerTestCase5 ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> class SubstEnvironment ( DummyEnvironment ) : <EOL> def subst ( self , arg , target = None , source = None , conv = None , path = test . workpath ( "<STR_LIT>" ) ) : <EOL> if arg == "<STR_LIT>" : <EOL> return test . workpath ( "<STR_LIT>" ) <EOL> else : <EOL> return arg <EOL> env = SubstEnvironment ( LIBPATH = [ "<STR_LIT>" ] , <EOL> LIBS = string . split ( '<STR_LIT>' ) ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps_match ( deps , [ '<STR_LIT>' ] ) , map ( str , deps ) <EOL> class ProgramScannerTestCase6 ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = [ '<STR_LIT:foo>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> LIBPREFIXES = [ '<STR_LIT>' ] , <EOL> LIBSUFFIXES = [ '<STR_LIT>' ] ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps_match ( deps , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , map ( str , deps ) <EOL> class ProgramScannerTestCase7 ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = [ '<STR_LIT:foo>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> LIBPREFIXES = [ '<STR_LIT>' ] , <EOL> LIBSUFFIXES = [ '<STR_LIT>' ] , <EOL> LIBBAR = '<STR_LIT>' , <EOL> XYZ = '<STR_LIT>' ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps_match ( deps , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , map ( str , deps ) <EOL> class ProgramScannerTestCase8 ( unittest . TestCase ) : <EOL> def runTest ( self ) : <EOL> n1 = DummyNode ( '<STR_LIT>' ) <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = [ n1 ] , <EOL> LIBPREFIXES = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> LIBSUFFIXES = [ '<STR_LIT>' , '<STR_LIT:2>' ] ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( node_class = DummyNode ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps == [ n1 ] , deps <EOL> n2 = DummyNode ( '<STR_LIT>' ) <EOL> env = DummyEnvironment ( LIBPATH = [ test . workpath ( "<STR_LIT>" ) ] , <EOL> LIBS = [ n1 , [ n2 ] ] , <EOL> LIBPREFIXES = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> LIBSUFFIXES = [ '<STR_LIT>' , '<STR_LIT:2>' ] ) <EOL> s = SCons . Scanner . Prog . ProgramScanner ( node_class = DummyNode ) <EOL> path = s . path ( env ) <EOL> deps = s ( DummyNode ( '<STR_LIT>' ) , env , path ) <EOL> assert deps == [ n1 , n2 ] , deps <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( ProgramScannerTestCase1 ( ) ) <EOL> suite . addTest ( ProgramScannerTestCase2 ( ) ) <EOL> suite . addTest ( ProgramScannerTestCase3 ( ) ) <EOL> suite . addTest ( ProgramScannerTestCase5 ( ) ) <EOL> suite . addTest ( ProgramScannerTestCase6 ( ) ) <EOL> suite . addTest ( ProgramScannerTestCase7 ( ) ) <EOL> suite . addTest ( ProgramScannerTestCase8 ( ) ) <EOL> if hasattr ( types , '<STR_LIT>' ) : <EOL> code = """<STR_LIT>""" <EOL> exec code <EOL> return suite <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> runner = unittest . TextTestRunner ( ) <EOL> result = runner . run ( suite ( ) ) <EOL> if not result . wasSuccessful ( ) : <EOL> sys . exit ( <NUM_LIT:1> ) </s>
