Fix check for too-old Visual Studio with non-x86 arch; thanks to Roberto De Vecchi.
[scons.git] / src / test_interrupts.py
index d18bece63b8eab184398a7a6643abaf02ee0511c..0c7c4df3dedbc2d5ae245cffddd96043cd86214b 100644 (file)
@@ -62,14 +62,28 @@ else:
     scons_lib_dir = os.path.join(cwd, 'build', 'scons')
     MANIFEST = os.path.join(scons_lib_dir, 'MANIFEST')
 
-files = string.split(open(MANIFEST).read())
-files = filter(lambda f: f[-3:] == '.py', files)
+# We expect precisely this many uncaught KeyboardInterrupt exceptions
+# from the files in the following dictionary.
+
+expected_uncaught = {
+    'engine/SCons/Job.py' :             5,
+    'engine/SCons/Script/Main.py' :     1,
+    'engine/SCons/Taskmaster.py' :      3,
+}
+
+try:
+    fp = open(MANIFEST)
+except IOError:
+    test.skip_test('%s does not exist; skipping test.\n' % MANIFEST)
+else:
+    files = string.split(fp.read())
+    files = filter(lambda f: f[-3:] == '.py', files)
 
 # some regexps to parse the python files
 tryexc_pat = re.compile(
 r'^(?P<try_or_except>(?P<indent> *)(try|except)( [^\n]*)?:.*)',re.MULTILINE)
 keyboardint_pat = re.compile(r' *except +([^,],)*KeyboardInterrupt([ ,][^\n]*)?:[^\n]*')
-exceptall_pat   = re.compile(r' *except *:[^\n]*')
+exceptall_pat   = re.compile(r' *except(?: *| +Exception *, *[^: ]+):[^\n]*')
 
 uncaughtKeyboardInterrupt = 0
 for f in files:
@@ -89,6 +103,7 @@ for f in files:
         line_num = 1 + string.count(contents[:match.start()], '\n')
         indent_list.append( (line_num, match.group('try_or_except') ) )
         try_except_lines[match.group('indent')] = indent_list
+    uncaught_this_file = []
     for indent in try_except_lines.keys():
         exc_keyboardint_seen = 0
         exc_all_seen = 0
@@ -98,22 +113,34 @@ for f in files:
             m2 = exceptall_pat.match(statement)
             if string.find(statement, indent + 'try') == 0:
                 if exc_all_seen and not exc_keyboardint_seen:
-                    uncaughtKeyboardInterrupt = 1
-                    print "File %s:%d: Uncaught KeyboardInterrupt!" % (f,line)
+                    uncaught_this_file.append(line)
                 exc_keyboardint_seen = 0
                 exc_all_seen = 0
                 line = l
                 #print " -> reset"
-            elif not m1 is None:
+            elif m1 is not None:
                 exc_keyboardint_seen = 1
                 #print " -> keyboard -> ", m1.groups()
-            elif not m2 is None:
+            elif m2 is not None:
                 exc_all_seen = 1
                 #print " -> all -> ", m2.groups()
             else:
                 pass
                 #print "Warning: unknown statement %s" % statement
+    expected_num = expected_uncaught.get(f, 0)
+    if expected_num != len(uncaught_this_file):
+        uncaughtKeyboardInterrupt = 1
+        msg = "%s:  expected %d uncaught interrupts, got %d:"
+        print msg % (f, expected_num, len(uncaught_this_file))
+        for line in uncaught_this_file:
+            print "  File %s:%d: Uncaught KeyboardInterrupt!" % (f,line)
 
 test.fail_test(uncaughtKeyboardInterrupt)
 
 test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: