From 91020237d64f53b2fa6e2b5bf155a1d8bfbdb547 Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Tue, 8 Oct 2013 12:54:25 +0100 Subject: Adding documentation and a couple of tests --- QMTest/TestSCons.py | 6 +- doc/man/scons.xml | 5 +- test/CacheDir/option--cr.py | 138 ++++++++++++++++++++++++++++++++++++++++++ test/option/debug-multiple.py | 86 ++++++++++++++++++++++++++ 4 files changed, 230 insertions(+), 5 deletions(-) create mode 100644 test/CacheDir/option--cr.py create mode 100644 test/option/debug-multiple.py diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py index 84cc60f..c45ef5e 100644 --- a/QMTest/TestSCons.py +++ b/QMTest/TestSCons.py @@ -1131,9 +1131,9 @@ SConscript( sconscript ) self.run(program = python, stdin = """\ import os, sys try: - py_ver = 'python%d.%d' % sys.version_info[:2] + py_ver = 'python%d.%d' % sys.version_info[:2] except AttributeError: - py_ver = 'python' + sys.version[:3] + py_ver = 'python' + sys.version[:3] print os.path.join(sys.prefix, 'include', py_ver) print os.path.join(sys.prefix, 'lib', py_ver, 'config') print py_ver @@ -1357,7 +1357,7 @@ class TimeSCons(TestSCons): options = kw.get('options', '') if additional is not None: options += additional - kw['options'] = options + ' --debug=memory --debug=time' + kw['options'] = options + ' --debug=memory,time' def startup(self, *args, **kw): """ diff --git a/doc/man/scons.xml b/doc/man/scons.xml index 947d86d..80bbd44 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -671,8 +671,9 @@ directory. --debug=type Debug the build process. -type -specifies what type of debugging: +type[,type...] +specifies what type of debugging. Multiple types may be specified, +separated by commas. The following types are valid: diff --git a/test/CacheDir/option--cr.py b/test/CacheDir/option--cr.py new file mode 100644 index 0000000..de6bbc8 --- /dev/null +++ b/test/CacheDir/option--cr.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the --cache-readonly option when retrieving derived files from a +CacheDir. It should retrieve as normal but not update files. +""" + +import os.path +import shutil + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir('cache', 'src') + +test.write(['src', 'SConstruct'], """ +def cat(env, source, target): + target = str(target[0]) + open('cat.out', 'ab').write(target + "\\n") + f = open(target, "wb") + for src in source: + f.write(open(str(src), "rb").read()) + f.close() +env = Environment(BUILDERS={'Cat':Builder(action=cat)}) +env.Cat('aaa.out', 'aaa.in') +env.Cat('bbb.out', 'bbb.in') +env.Cat('ccc.out', 'ccc.in') +env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out']) +CacheDir(r'%s') +""" % test.workpath('cache')) + +test.write(['src', 'aaa.in'], "aaa.in\n") +test.write(['src', 'bbb.in'], "bbb.in\n") +test.write(['src', 'ccc.in'], "ccc.in\n") + +# Verify that a normal build works correctly, and clean up. +# This should populate the cache with our derived files. +test.run(chdir = 'src', arguments = '.') + +test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n") +test.must_match(['src', 'cat.out'], "aaa.out\nbbb.out\nccc.out\nall\n") + +test.up_to_date(chdir = 'src', arguments = '.') + +test.run(chdir = 'src', arguments = '-c .') +test.unlink(['src', 'cat.out']) + +# Verify that we now retrieve the derived files from cache, +# not rebuild them. Then clean up. +test.run(chdir = 'src', arguments = '--cache-readonly .', + stdout = test.wrap_stdout("""\ +Retrieved `aaa.out' from cache +Retrieved `bbb.out' from cache +Retrieved `ccc.out' from cache +Retrieved `all' from cache +""")) + +test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n") +test.must_not_exist(test.workpath('src', 'cat.out')) + +test.up_to_date(chdir = 'src', arguments = '.') + +test.run(chdir = 'src', arguments = '-c .') + +# What we do now is to change one of the files and rebuild +test.write(['src', 'aaa.in'], "aaa.rebuild\n") + +# This should just rebuild aaa.out (and all) +test.run(chdir = 'src', + arguments = '--cache-readonly .', + stdout = test.wrap_stdout("""\ +cat(["aaa.out"], ["aaa.in"]) +Retrieved `bbb.out' from cache +Retrieved `ccc.out' from cache +cat(["all"], ["aaa.out", "bbb.out", "ccc.out"]) +""")) + +test.must_match(['src', 'all'], "aaa.rebuild\nbbb.in\nccc.in\n") +# cat.out contains only the things we built (not got from cache) +test.must_match(['src', 'cat.out'], "aaa.out\nall\n") + +test.up_to_date(chdir = 'src', arguments = '.') + +test.run(chdir = 'src', arguments = '-c .') +test.unlink(['src', 'cat.out']) + +# Verify that aaa.out contents weren't updated with the last build +# Then clean up. +test.run(chdir = 'src', + arguments = '--cache-readonly .', + stdout = test.wrap_stdout("""\ +cat(["aaa.out"], ["aaa.in"]) +Retrieved `bbb.out' from cache +Retrieved `ccc.out' from cache +cat(["all"], ["aaa.out", "bbb.out", "ccc.out"]) +""")) + +test.must_match(['src', 'all'], "aaa.rebuild\nbbb.in\nccc.in\n") +test.must_match(['src', 'cat.out'], "aaa.out\nall\n") + +test.up_to_date(chdir = 'src', arguments = '.') + +test.run(chdir = 'src', arguments = '-c .') +test.unlink(['src', 'cat.out']) + +# All done. +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/option/debug-multiple.py b/test/option/debug-multiple.py new file mode 100644 index 0000000..f5bbdf0 --- /dev/null +++ b/test/option/debug-multiple.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that --debug can take multiple options +""" + +import re + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +def cat(target, source, env): + open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read()) +env = Environment(BUILDERS={'Cat':Builder(action=Action(cat))}) +env.Cat('file.out', 'file.in') +""") + +test.write('file.in', "file.in\n") + +# Just check that object counts for some representative classes +# show up in the output. + +def find_object_count(s, stdout): + re_string = '\d+ +\d+ %s' % re.escape(s) + return re.search(re_string, stdout) + +objects = [ + 'Action.CommandAction', + 'Builder.BuilderBase', + 'Environment.Base', + 'Executor.Executor', + 'Node.FS', + 'Node.FS.Base', + 'Node.Node', +] + +for args in ['--debug=prepare,count', '--debug=count,prepare']: + test.run(arguments = args) + stdout = test.stdout() + missing = [o for o in objects if find_object_count(o, stdout) is None] + + if missing: + print "Missing the following object lines from '%s' output:" % args + print "\t", ' '.join(missing) + print "STDOUT ==========" + print stdout + test.fail_test(1) + + if 'Preparing target file.out...' not in stdout: + print "Missing 'Preparing' lines from '%s' output:" % args + print "STDOUT ==========" + print stdout + test.fail_test(1) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: -- cgit v0.12