Gary Oberbrunner avatar Gary Oberbrunner committed 672a2af Merge

Merged in carandraug/scons (pull request #67).
Added test for CheckContext custom result types.
Also allow test.must_match() to take a match type.

Comments (0)

Files changed (3)

QMTest/TestCommon.py

         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:

src/engine/SCons/SConf.py

         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.

test/Configure/custom-tests.py

     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())
 test.run()
 
 test.checkLogAndStdout(["Executing MyTest ... "],
-                      ["yes"],
+                       ["yes"],
                       [[(('.c', NCR), (_obj, NCR)),
                         (('.c', NCR), (_obj, NCF)),
                         (('.c', NCR), (_obj, NCR), (_exe, NCR)),
 
 test.run()
 
+# Try again to check caching
 test.checkLogAndStdout(["Executing MyTest ... "],
                       ["yes"],
                       [[(('.c', CR), (_obj, CR)),
                         (('', 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:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.