summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Oberbrunner <garyo@oberbrunner.com>2013-03-16 20:43:54 -0400
committerGary Oberbrunner <garyo@oberbrunner.com>2013-03-16 20:43:54 -0400
commit20ffcc46d0c59fa4e3273498474917b90114d308 (patch)
tree0385ae6a8c918d1de23233517d9ca61d7bdd0bcf
parent7a2957207183b2c7366c7a62ce5e52bc15af1172 (diff)
parent9ab7a260c35b362fbd91255c5ec32e20deb7e28d (diff)
downloadscons-20ffcc46d0c59fa4e3273498474917b90114d308.tar.gz
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.py6
-rw-r--r--src/engine/SCons/SConf.py15
-rw-r--r--test/Configure/custom-tests.py90
3 files changed, 97 insertions, 14 deletions
diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py
index 6d47149b..6eeda5e1 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 0506f806..f3a35454 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 9cefa2da..f79ea0d4 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: