diff options
Diffstat (limited to 'test/option')
-rw-r--r-- | test/option/debug-memoizer.py | 80 | ||||
-rw-r--r-- | test/option/debug-nomemoizer.py | 34 | ||||
-rw-r--r-- | test/option/profile.py | 6 |
3 files changed, 71 insertions, 49 deletions
diff --git a/test/option/debug-memoizer.py b/test/option/debug-memoizer.py index c9f001c..33f0f4d 100644 --- a/test/option/debug-memoizer.py +++ b/test/option/debug-memoizer.py @@ -33,7 +33,23 @@ import string import TestSCons -test = TestSCons.TestSCons() +test = TestSCons.TestSCons(match = TestSCons.match_re) + +# Find out if we support metaclasses (Python 2.2 and later). + +class M: + def __init__(cls, name, bases, cls_dict): + cls.has_metaclass = 1 + +class A: + __metaclass__ = M + +try: + has_metaclass = A.has_metaclass +except AttributeError: + has_metaclass = None + + test.write('SConstruct', """ def cat(target, source, env): @@ -50,21 +66,47 @@ test.write('file.in', "file.in\n") # change this test... expect = [ "Memoizer (memory cache) hits and misses", - "Dir.exists()", + "Base.stat()", + "Dir.srcdir_list()", "File.exists()", - "SConsEnvironment.Detect()", + "FS._doLookup()", + "Node._children_get()", ] +expect_no_metaclasses = """ +scons: warning: memoization is not supported in this version of Python \\(no metaclasses\\) +""" + TestSCons.file_expr + + +if has_metaclass: + + def run_and_check(test, args, desc): + test.run(arguments = args) + stdout = test.stdout() + missing = filter(lambda e, s=stdout: string.find(s, e) == -1, expect) + if missing: + print "Missing the following strings in the %s output:" % desc + print " " + string.join(missing, "\n ") + print "STDOUT ============" + print stdout + test.fail_test() + +else: + + def run_and_check(test, args, desc): + test.run(arguments = args, stderr = expect_no_metaclasses) + stdout = test.stdout() + present = filter(lambda e, s=stdout: string.find(s, e) != -1, expect) + if present: + print "The following unexpected strings are present in the %s output:" % desc + print " " + string.join(present, "\n ") + print "STDOUT ============" + print stdout + test.fail_test() + + for args in ['-h --debug=memoizer', '--debug=memoizer']: - test.run(arguments = args) - stdout = test.stdout() - missing = filter(lambda e, s=stdout: string.find(s, e) == -1, expect) - if missing: - print "Missing the following strings in the command line '%s' output:" % args - print " " + string.join(missing, "\n ") - print "STDOUT ============" - print stdout - test.fail_test(1) + run_and_check(test, args, "command line '%s'" % args) test.must_match('file.out', "file.in\n") @@ -72,17 +114,13 @@ test.must_match('file.out', "file.in\n") test.unlink("file.out") + + os.environ['SCONSFLAGS'] = '--debug=memoizer' -test.run() -stdout = test.stdout() -missing = filter(lambda e, s=stdout: string.find(s, e) == -1, expect) -if missing: - print "Missing the following strings in the SCONSFLAGS=--debug=memoizer output:" - print " " + string.join(missing, "\n ") - print "STDOUT ============" - print stdout - test.fail_test(1) +run_and_check(test, '', 'SCONSFLAGS=--debug=memoizer') + +test.must_match('file.out', "file.in\n") diff --git a/test/option/debug-nomemoizer.py b/test/option/debug-nomemoizer.py index 633a46d..3a927e5 100644 --- a/test/option/debug-nomemoizer.py +++ b/test/option/debug-nomemoizer.py @@ -25,19 +25,12 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" """ -Test calling the --debug=nomemoizer option. +Test calling the (deprecated) --debug=nomemoizer option. """ -import pstats -import string -import StringIO -import sys - import TestSCons -test = TestSCons.TestSCons() - -scons_prof = test.workpath('scons.prof') +test = TestSCons.TestSCons(match = TestSCons.match_re) test.write('SConstruct', """ def cat(target, source, env): @@ -48,25 +41,12 @@ env.Cat('file.out', 'file.in') test.write('file.in', "file.in\n") -test.run(arguments = "--profile=%s --debug=nomemoizer " % scons_prof) - -stats = pstats.Stats(scons_prof) -stats.sort_stats('time') - -try: - save_stdout = sys.stdout - sys.stdout = StringIO.StringIO() - - stats.strip_dirs().print_stats() +expect = """ +scons: warning: The --debug=nomemoizer option is deprecated and has no effect. +""" + TestSCons.file_expr - s = sys.stdout.getvalue() -finally: - sys.stdout = save_stdout +test.run(arguments = "--debug=nomemoizer", stderr = expect) -test.fail_test(string.find(s, '_MeMoIZeR_init') != -1) -test.fail_test(string.find(s, '_MeMoIZeR_reset') != -1) -test.fail_test(string.find(s, 'Count_cache_get') != -1) -test.fail_test(string.find(s, 'Count_cache_get_self') != -1) -test.fail_test(string.find(s, 'Count_cache_get_one') != -1) +test.must_match('file.out', "file.in\n") test.pass_test() diff --git a/test/option/profile.py b/test/option/profile.py index 9207066..eb6b394 100644 --- a/test/option/profile.py +++ b/test/option/profile.py @@ -24,7 +24,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import pstats import string import StringIO import sys @@ -33,6 +32,11 @@ import TestSCons test = TestSCons.TestSCons() +try: + import pstats +except ImportError: + test.skip_test('No pstats module, skipping test.\n') + test.write('SConstruct', """\ Command('file.out', 'file.in', Copy("$TARGET", "$SOURCE")) """) |