comparison mx/commands.py @ 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 0cad5096735e
children eeb80dcd60d8
comparison
equal deleted inserted replaced
10605:f0551e15a416 10606:a6c0ae38e05e
704 704
705 matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0 705 matches = lambda line : len([a for a in annotations if line == a or line.startswith(a + '(')]) != 0
706 return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses) 706 return p.find_classes_with_matching_source_line(pkgRoot, matches, includeInnerClasses)
707 707
708 def _run_tests(args, harness, annotations, testfile): 708 def _run_tests(args, harness, annotations, testfile):
709 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] 709 tests = [a for a in args if a[0] != '@' ]
710 neg = [a[1:] for a in args if a[0] == '-']
711 vmArgs = [a[1:] for a in args if a[0] == '@'] 710 vmArgs = [a[1:] for a in args if a[0] == '@']
712 711
713 def containsAny(c, substrings): 712 def containsAny(c, substrings):
714 for s in substrings: 713 for s in substrings:
715 if s in c: 714 if s in c:
716 return True 715 return True
717 return False 716 return False
718 717
719 classes = [] 718 if len(tests) == 0:
719 mx.abort('no tests specified')
720
721 candidates = []
720 for p in mx.projects(): 722 for p in mx.projects():
721 if mx.java().javaCompliance < p.javaCompliance: 723 if mx.java().javaCompliance < p.javaCompliance:
722 continue 724 continue
723 classes += _find_classes_with_annotations(p, None, annotations).keys() 725 candidates += _find_classes_with_annotations(p, None, annotations).keys()
724 726
725 if len(pos) != 0: 727 classes = []
726 classes = [c for c in classes if containsAny(c, pos)] 728 for t in tests:
727 if len(neg) != 0: 729 if t.startswith('-'):
728 classes = [c for c in classes if not containsAny(c, neg)] 730 mx.abort('VM option needs @ prefix (i.e., @' + t + ')')
731
732 found = False
733 for c in candidates:
734 if t in c:
735 found = True
736 classes.append(c)
737 if not found:
738 mx.log('warning: no tests matched by substring "' + t)
729 739
730 projectscp = mx.classpath([pcp.name for pcp in mx.projects() if pcp.javaCompliance <= mx.java().javaCompliance]) 740 projectscp = mx.classpath([pcp.name for pcp in mx.projects() if pcp.javaCompliance <= mx.java().javaCompliance])
731 741
732 if len(classes) != 0: 742 if len(classes) != 0:
733 f_testfile = open(testfile, 'w') 743 f_testfile = open(testfile, 'w')
762 os.remove(testfile) 772 os.remove(testfile)
763 773
764 _unittestHelpSuffix = """ 774 _unittestHelpSuffix = """
765 775
766 If filters are supplied, only tests whose fully qualified name 776 If filters are supplied, only tests whose fully qualified name
767 includes a filter as a substring are run. Negative filters are 777 includes a filter as a substring are run.
768 those with a '-' prefix.
769 778
770 Options with a '@' prefix are passed to the VM. 779 Options with a '@' prefix are passed to the VM.
771 780
772 For example, this command line: 781 For example, this command line:
773 782