Mercurial > hg > graal-jvmci-8
comparison mx/mx_graal.py @ 15555:8c19ffc672fd
mx unittest: add support for regular expressions.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Thu, 08 May 2014 11:52:20 +0200 |
parents | d250613801fb |
children | cb2f3c49deb2 |
comparison
equal
deleted
inserted
replaced
15554:cf994cc23b54 | 15555:8c19ffc672fd |
---|---|
902 if defaultAllVMArgs: | 902 if defaultAllVMArgs: |
903 return args, [] | 903 return args, [] |
904 else: | 904 else: |
905 return [], args | 905 return [], args |
906 | 906 |
907 def _run_tests(args, harness, annotations, testfile, whitelist): | 907 def _run_tests(args, harness, annotations, testfile, whitelist, regex): |
908 | 908 |
909 | 909 |
910 vmArgs, tests = _extract_VM_args(args) | 910 vmArgs, tests = _extract_VM_args(args) |
911 for t in tests: | 911 for t in tests: |
912 if t.startswith('-'): | 912 if t.startswith('-'): |
937 projectscp = mx.classpath(projs) | 937 projectscp = mx.classpath(projs) |
938 | 938 |
939 if whitelist: | 939 if whitelist: |
940 classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] | 940 classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] |
941 | 941 |
942 if regex: | |
943 classes = [c for c in classes if re.search(regex, c)] | |
944 | |
942 if len(classes) != 0: | 945 if len(classes) != 0: |
943 f_testfile = open(testfile, 'w') | 946 f_testfile = open(testfile, 'w') |
944 for c in classes: | 947 for c in classes: |
945 f_testfile.write(c + '\n') | 948 f_testfile.write(c + '\n') |
946 f_testfile.close() | 949 f_testfile.close() |
947 harness(projectscp, vmArgs) | 950 harness(projectscp, vmArgs) |
948 | 951 |
949 def _unittest(args, annotations, prefixcp="", whitelist=None, verbose=False, enable_timing=False): | 952 def _unittest(args, annotations, prefixcp="", whitelist=None, verbose=False, enable_timing=False, regex=None): |
950 mxdir = dirname(__file__) | 953 mxdir = dirname(__file__) |
951 name = 'JUnitWrapper' | 954 name = 'JUnitWrapper' |
952 javaSource = join(mxdir, name + '.java') | 955 javaSource = join(mxdir, name + '.java') |
953 javaClass = join(mxdir, name + '.class') | 956 javaClass = join(mxdir, name + '.class') |
954 testfile = os.environ.get('MX_TESTFILE', None) | 957 testfile = os.environ.get('MX_TESTFILE', None) |
977 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + testclasses) | 980 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + testclasses) |
978 else: | 981 else: |
979 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp + os.pathsep + mxdir, name] + [testfile] + coreArgs) | 982 vm(prefixArgs + vmArgs + ['-cp', prefixcp + corecp + ':' + projectscp + os.pathsep + mxdir, name] + [testfile] + coreArgs) |
980 | 983 |
981 try: | 984 try: |
982 _run_tests(args, harness, annotations, testfile, whitelist) | 985 _run_tests(args, harness, annotations, testfile, whitelist, regex) |
983 finally: | 986 finally: |
984 if os.environ.get('MX_TESTFILE') is None: | 987 if os.environ.get('MX_TESTFILE') is None: |
985 os.remove(testfile) | 988 os.remove(testfile) |
986 | 989 |
987 _unittestHelpSuffix = """ | 990 _unittestHelpSuffix = """ |
988 Unittest options: | 991 Unittest options: |
989 | 992 |
990 --whitelist run only testcases which are included | 993 --whitelist <file> run only testcases which are included |
991 in the given whitelist | 994 in the given whitelist |
992 --verbose enable verbose JUnit output | 995 --verbose enable verbose JUnit output |
993 --enable-timing enable JUnit test timing | 996 --enable-timing enable JUnit test timing |
997 --regex <regex> run only testcases matching a regular expression | |
994 | 998 |
995 To avoid conflicts with VM options '--' can be used as delimiter. | 999 To avoid conflicts with VM options '--' can be used as delimiter. |
996 | 1000 |
997 If filters are supplied, only tests whose fully qualified name | 1001 If filters are supplied, only tests whose fully qualified name |
998 includes a filter as a substring are run. | 1002 includes a filter as a substring are run. |
1028 epilog=_unittestHelpSuffix, | 1032 epilog=_unittestHelpSuffix, |
1029 ) | 1033 ) |
1030 parser.add_argument('--whitelist', help='run testcases specified in whitelist only', metavar='<path>') | 1034 parser.add_argument('--whitelist', help='run testcases specified in whitelist only', metavar='<path>') |
1031 parser.add_argument('--verbose', help='enable verbose JUnit output', action='store_true') | 1035 parser.add_argument('--verbose', help='enable verbose JUnit output', action='store_true') |
1032 parser.add_argument('--enable-timing', help='enable JUnit test timing', action='store_true') | 1036 parser.add_argument('--enable-timing', help='enable JUnit test timing', action='store_true') |
1037 parser.add_argument('--regex', help='run only testcases matching a regular expression', metavar='<regex>') | |
1033 | 1038 |
1034 ut_args = [] | 1039 ut_args = [] |
1035 delimiter = False | 1040 delimiter = False |
1036 # check for delimiter | 1041 # check for delimiter |
1037 while len(args) > 0: | 1042 while len(args) > 0: |
1054 with open(join(_graal_home, parsed_args.whitelist)) as fp: | 1059 with open(join(_graal_home, parsed_args.whitelist)) as fp: |
1055 whitelist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')] | 1060 whitelist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')] |
1056 except IOError: | 1061 except IOError: |
1057 mx.log('warning: could not read whitelist: ' + parsed_args.whitelist) | 1062 mx.log('warning: could not read whitelist: ' + parsed_args.whitelist) |
1058 | 1063 |
1059 _unittest(args, ['@Test', '@Parameters'], whitelist=whitelist, verbose=parsed_args.verbose, enable_timing=parsed_args.enable_timing) | 1064 _unittest(args, ['@Test', '@Parameters'], whitelist=whitelist, verbose=parsed_args.verbose, enable_timing=parsed_args.enable_timing, regex=parsed_args.regex) |
1060 | 1065 |
1061 def shortunittest(args): | 1066 def shortunittest(args): |
1062 """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}""" | 1067 """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}""" |
1063 | 1068 |
1064 args = ['--whitelist', 'test/whitelist_shortunittest.txt'] + args | 1069 args = ['--whitelist', 'test/whitelist_shortunittest.txt'] + args |