diff options
author | Gary Oberbrunner <garyo@oberbrunner.com> | 2013-03-17 00:43:54 (GMT) |
---|---|---|
committer | Gary Oberbrunner <garyo@oberbrunner.com> | 2013-03-17 00:43:54 (GMT) |
commit | e8f1182787dc7f1187759224830815a85a5e3446 (patch) | |
tree | 59b29967d98fea2403c729c0aa31e98d2c39d227 | |
parent | 1d3de8cda278418e624c7c808e12ab069d514c69 (diff) | |
parent | ede4ee9b3306ca546c2f04bcabff9f970ed1cb9a (diff) | |
download | SCons-e8f1182787dc7f1187759224830815a85a5e3446.zip SCons-e8f1182787dc7f1187759224830815a85a5e3446.tar.gz SCons-e8f1182787dc7f1187759224830815a85a5e3446.tar.bz2 |
Merged in carandraug/scons (pull request #67).
Added test for CheckContext custom result types.
Also allow test.must_match() to take a match type.
-rw-r--r-- | QMTest/TestCommon.py | 6 | ||||
-rw-r--r-- | src/engine/SCons/SConf.py | 15 | ||||
-rw-r--r-- | test/Configure/custom-tests.py | 90 |
3 files changed, 97 insertions, 14 deletions
diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py index 6d47149..6eeda5e 100644 --- a/QMTest/TestCommon.py +++ b/QMTest/TestCommon.py @@ -460,15 +460,17 @@ class TestCommon(TestCmd): print "Missing one of: `%s'" % "', `".join(missing) self.fail_test(missing) - def must_match(self, file, expect, mode = 'rb'): + def must_match(self, file, expect, mode = 'rb', match=None): """Matches the contents of the specified file (first argument) against the expected contents (second argument). The expected contents are a list of lines or a string which will be split on newlines. """ file_contents = self.read(file, mode) + if not match: + match = self.match try: - self.fail_test(not self.match(file_contents, expect)) + self.fail_test(not match(file_contents, expect)) except KeyboardInterrupt: raise except: diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py index 0506f80..f3a3545 100644 --- a/src/engine/SCons/SConf.py +++ b/src/engine/SCons/SConf.py @@ -776,19 +776,16 @@ class CheckContext(object): self.did_show_result = 0 def Result(self, res): - """Inform about the result of the test. res may be an integer or a - string. In case of an integer, the written text will be 'yes' or 'no'. + """Inform about the result of the test. If res is not a string, displays + 'yes' or 'no' depending on whether res is evaluated as true or false. The result is only displayed when self.did_show_result is not set. """ - if isinstance(res, (int, bool)): - if res: - text = "yes" - else: - text = "no" - elif isinstance(res, str): + if isinstance(res, str): text = res + elif res: + text = "yes" else: - raise TypeError("Expected string, int or bool, got " + str(type(res))) + text = "no" if self.did_show_result == 0: # Didn't show result yet, do it now. diff --git a/test/Configure/custom-tests.py b/test/Configure/custom-tests.py index 9cefa2d..f79ea0d 100644 --- a/test/Configure/custom-tests.py +++ b/test/Configure/custom-tests.py @@ -69,13 +69,13 @@ def CheckCustom(test): resOK = resOK and retActOK and int(outputActOK)==0 resFAIL = retCompileFAIL or retLinkFAIL or retRunFAIL or outputRunFAIL!="" resFAIL = resFAIL or retActFAIL or outputActFAIL!="" - test.Result( int(resOK and not resFAIL) ) + test.Result( resOK and not resFAIL ) return resOK and not resFAIL env = Environment() import os env.AppendENVPath('PATH', os.environ['PATH']) -conf = Configure( env, custom_tests={'CheckCustom' : CheckCustom} ) +conf = Configure( env, custom_tests={'CheckCustom' : CheckCustom} ) conf.CheckCustom() env = conf.Finish() """ % locals()) @@ -83,7 +83,7 @@ env = conf.Finish() test.run() test.checkLogAndStdout(["Executing MyTest ... "], - ["yes"], + ["yes"], [[(('.c', NCR), (_obj, NCR)), (('.c', NCR), (_obj, NCF)), (('.c', NCR), (_obj, NCR), (_exe, NCR)), @@ -96,6 +96,7 @@ test.checkLogAndStdout(["Executing MyTest ... "], test.run() +# Try again to check caching test.checkLogAndStdout(["Executing MyTest ... "], ["yes"], [[(('.c', CR), (_obj, CR)), @@ -108,6 +109,89 @@ test.checkLogAndStdout(["Executing MyTest ... "], (('', CF),)]], "config.log", ".sconf_temp", "SConstruct") +# Test other customs: +test.write('SConstruct', """\ +def CheckList(test): + test.Message( 'Display of list ...' ) + res = [1, 2, 3, 4] + test.Result( res ) + return res + +def CheckEmptyList(test): + test.Message( 'Display of empty list ...' ) + res = list() + test.Result( res ) + return res + +def CheckRandomStr(test): + test.Message( 'Display of random string ...' ) + res = "a random string" + test.Result( res ) + return res + +def CheckEmptyStr(test): + test.Message( 'Display of empty string ...' ) + res = "" + test.Result( res ) + return res + +def CheckDict(test): + test.Message( 'Display of dictionary ...' ) + res = {"key1" : 1, "key2" : "text"} + test.Result( res ) + return res + +def CheckEmptyDict(test): + test.Message( 'Display of empty dictionary ...' ) + res = dict + test.Result( res ) + return res + +env = Environment() +import os +env.AppendENVPath('PATH', os.environ['PATH']) +conf = Configure( env, custom_tests={'CheckList' : CheckList, + 'CheckEmptyList' : CheckEmptyList, + 'CheckRandomStr' : CheckRandomStr, + 'CheckEmptyStr' : CheckEmptyStr, + 'CheckDict' : CheckDict, + 'CheckEmptyDict' : CheckEmptyDict} ) +conf.CheckList() +conf.CheckEmptyList() +conf.CheckRandomStr() +conf.CheckEmptyStr() +conf.CheckDict() +conf.CheckEmptyDict() +env = conf.Finish() +""" % locals()) + +test.run() + +test.must_match('config.log', +""".* +.* +scons: Configure: Display of list ... +scons: Configure: \(cached\) yes + +scons: Configure: Display of empty list ... +scons: Configure: \(cached\) no + +scons: Configure: Display of random string ... +scons: Configure: \(cached\) a random string + +scons: Configure: Display of empty string ... +scons: Configure: \(cached\). + +scons: Configure: Display of dictionary ... +scons: Configure: \(cached\) yes + +scons: Configure: Display of empty dictionary ... +scons: Configure: \(cached\) yes + + +""", +match=TestSCons.match_re) + test.pass_test() # Local Variables: |