changeset 10606:a6c0ae38e05e

more robust command line checking for unittest (at cost of removing support for negative filters)
author Doug Simon <doug.simon@oracle.com>
date Thu, 04 Jul 2013 14:53:28 +0200
parents f0551e15a416
children dd5a042811f6
files mx/commands.py
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mx/commands.py	Thu Jul 04 13:39:40 2013 +0200
+++ b/mx/commands.py	Thu Jul 04 14:53:28 2013 +0200
@@ -706,8 +706,7 @@
     return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses)
 
 def _run_tests(args, harness, annotations, testfile):
-    pos = [a for a in args if a[0] != '-' and a[0] != '@' ]
-    neg = [a[1:] for a in args if a[0] == '-']
+    tests = [a for a in args if a[0] != '@' ]
     vmArgs = [a[1:] for a in args if a[0] == '@']
 
     def containsAny(c, substrings):
@@ -715,17 +714,28 @@
             if s in c:
                 return True
         return False
+    
+    if len(tests) == 0:
+        mx.abort('no tests specified')
 
-    classes = []
+    candidates = []
     for p in mx.projects():
         if mx.java().javaCompliance < p.javaCompliance:
             continue
-        classes += _find_classes_with_annotations(p, None, annotations).keys()
+        candidates += _find_classes_with_annotations(p, None, annotations).keys()
 
-        if len(pos) != 0:
-            classes = [c for c in classes if containsAny(c, pos)]
-        if len(neg) != 0:
-            classes = [c for c in classes if not containsAny(c, neg)]
+    classes = []
+    for t in tests:
+        if t.startswith('-'):
+            mx.abort('VM option needs @ prefix (i.e., @' + t + ')')
+            
+        found = False
+        for c in candidates:
+            if t in c:
+                found = True
+                classes.append(c)
+        if not found:
+            mx.log('warning: no tests matched by substring "' + t)
 
     projectscp = mx.classpath([pcp.name for pcp in mx.projects() if pcp.javaCompliance <= mx.java().javaCompliance])
 
@@ -764,8 +774,7 @@
 _unittestHelpSuffix = """
 
     If filters are supplied, only tests whose fully qualified name
-    includes a filter as a substring are run. Negative filters are
-    those with a '-' prefix.
+    includes a filter as a substring are run.
     
     Options with a '@' prefix are passed to the VM.