Mercurial > hg > truffle
comparison mx/mx_graal.py @ 16979:e9ff3e7055e5
mx: add unittest --blacklist.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Wed, 27 Aug 2014 17:43:48 +0200 |
parents | 87fc600ec586 |
children | ad10671d1bbd |
comparison
equal
deleted
inserted
replaced
16978:896b1bc1e48e | 16979:e9ff3e7055e5 |
---|---|
1057 if defaultAllVMArgs: | 1057 if defaultAllVMArgs: |
1058 return args, [] | 1058 return args, [] |
1059 else: | 1059 else: |
1060 return [], args | 1060 return [], args |
1061 | 1061 |
1062 def _run_tests(args, harness, annotations, testfile, whitelist, regex): | 1062 def _run_tests(args, harness, annotations, testfile, blacklist, whitelist, regex): |
1063 | 1063 |
1064 | 1064 |
1065 vmArgs, tests = _extract_VM_args(args) | 1065 vmArgs, tests = _extract_VM_args(args) |
1066 for t in tests: | 1066 for t in tests: |
1067 if t.startswith('-'): | 1067 if t.startswith('-'): |
1104 projs.add(p.name) | 1104 projs.add(p.name) |
1105 if not found: | 1105 if not found: |
1106 mx.log('warning: no tests matched by substring "' + t) | 1106 mx.log('warning: no tests matched by substring "' + t) |
1107 projectsCp = mx.classpath(projs) | 1107 projectsCp = mx.classpath(projs) |
1108 | 1108 |
1109 if blacklist: | |
1110 classes = [c for c in classes if not any((glob.match(c) for glob in blacklist))] | |
1111 | |
1109 if whitelist: | 1112 if whitelist: |
1110 classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] | 1113 classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] |
1111 | 1114 |
1112 if regex: | 1115 if regex: |
1113 classes = [c for c in classes if re.search(regex, c)] | 1116 classes = [c for c in classes if re.search(regex, c)] |
1117 for c in classes: | 1120 for c in classes: |
1118 f_testfile.write(c + '\n') | 1121 f_testfile.write(c + '\n') |
1119 f_testfile.close() | 1122 f_testfile.close() |
1120 harness(projectsCp, vmArgs) | 1123 harness(projectsCp, vmArgs) |
1121 | 1124 |
1122 def _unittest(args, annotations, prefixCp="", whitelist=None, verbose=False, enable_timing=False, regex=None, color=False, eager_stacktrace=False, gc_after_test=False): | 1125 def _unittest(args, annotations, prefixCp="", blacklist=None, whitelist=None, verbose=False, enable_timing=False, regex=None, color=False, eager_stacktrace=False, gc_after_test=False): |
1123 testfile = os.environ.get('MX_TESTFILE', None) | 1126 testfile = os.environ.get('MX_TESTFILE', None) |
1124 if testfile is None: | 1127 if testfile is None: |
1125 (_, testfile) = tempfile.mkstemp(".testclasses", "graal") | 1128 (_, testfile) = tempfile.mkstemp(".testclasses", "graal") |
1126 os.close(_) | 1129 os.close(_) |
1127 coreCp = mx.classpath(['com.oracle.graal.test']) | 1130 coreCp = mx.classpath(['com.oracle.graal.test']) |
1167 vm(prefixArgs + vmArgs + ['-cp', cp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + testclasses) | 1170 vm(prefixArgs + vmArgs + ['-cp', cp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + testclasses) |
1168 else: | 1171 else: |
1169 vm(prefixArgs + vmArgs + ['-cp', cp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + ['@' + testfile]) | 1172 vm(prefixArgs + vmArgs + ['-cp', cp, 'com.oracle.graal.test.GraalJUnitCore'] + coreArgs + ['@' + testfile]) |
1170 | 1173 |
1171 try: | 1174 try: |
1172 _run_tests(args, harness, annotations, testfile, whitelist, regex) | 1175 _run_tests(args, harness, annotations, testfile, blacklist, whitelist, regex) |
1173 finally: | 1176 finally: |
1174 if os.environ.get('MX_TESTFILE') is None: | 1177 if os.environ.get('MX_TESTFILE') is None: |
1175 os.remove(testfile) | 1178 os.remove(testfile) |
1176 | 1179 |
1177 _unittestHelpSuffix = """ | 1180 _unittestHelpSuffix = """ |
1178 Unittest options: | 1181 Unittest options: |
1179 | 1182 |
1183 --blacklist <file> run all testcases not specified in the blacklist | |
1180 --whitelist <file> run only testcases which are included | 1184 --whitelist <file> run only testcases which are included |
1181 in the given whitelist | 1185 in the given whitelist |
1182 --verbose enable verbose JUnit output | 1186 --verbose enable verbose JUnit output |
1183 --enable-timing enable JUnit test timing | 1187 --enable-timing enable JUnit test timing |
1184 --regex <regex> run only testcases matching a regular expression | 1188 --regex <regex> run only testcases matching a regular expression |
1219 description='run the JUnit tests', | 1223 description='run the JUnit tests', |
1220 add_help=False, | 1224 add_help=False, |
1221 formatter_class=RawDescriptionHelpFormatter, | 1225 formatter_class=RawDescriptionHelpFormatter, |
1222 epilog=_unittestHelpSuffix, | 1226 epilog=_unittestHelpSuffix, |
1223 ) | 1227 ) |
1228 parser.add_argument('--blacklist', help='run all testcases not specified in the blacklist', metavar='<path>') | |
1224 parser.add_argument('--whitelist', help='run testcases specified in whitelist only', metavar='<path>') | 1229 parser.add_argument('--whitelist', help='run testcases specified in whitelist only', metavar='<path>') |
1225 parser.add_argument('--verbose', help='enable verbose JUnit output', action='store_true') | 1230 parser.add_argument('--verbose', help='enable verbose JUnit output', action='store_true') |
1226 parser.add_argument('--enable-timing', help='enable JUnit test timing', action='store_true') | 1231 parser.add_argument('--enable-timing', help='enable JUnit test timing', action='store_true') |
1227 parser.add_argument('--regex', help='run only testcases matching a regular expression', metavar='<regex>') | 1232 parser.add_argument('--regex', help='run only testcases matching a regular expression', metavar='<regex>') |
1228 parser.add_argument('--color', help='enable color output', action='store_true') | 1233 parser.add_argument('--color', help='enable color output', action='store_true') |
1250 try: | 1255 try: |
1251 with open(join(_graal_home, parsed_args.whitelist)) as fp: | 1256 with open(join(_graal_home, parsed_args.whitelist)) as fp: |
1252 parsed_args.whitelist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')] | 1257 parsed_args.whitelist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')] |
1253 except IOError: | 1258 except IOError: |
1254 mx.log('warning: could not read whitelist: ' + parsed_args.whitelist) | 1259 mx.log('warning: could not read whitelist: ' + parsed_args.whitelist) |
1260 if parsed_args.blacklist: | |
1261 try: | |
1262 with open(join(_graal_home, parsed_args.blacklist)) as fp: | |
1263 parsed_args.blacklist = [re.compile(fnmatch.translate(l.rstrip())) for l in fp.readlines() if not l.startswith('#')] | |
1264 except IOError: | |
1265 mx.log('warning: could not read blacklist: ' + parsed_args.blacklist) | |
1255 | 1266 |
1256 _unittest(args, ['@Test', '@Parameters'], **parsed_args.__dict__) | 1267 _unittest(args, ['@Test', '@Parameters'], **parsed_args.__dict__) |
1257 | 1268 |
1258 def shortunittest(args): | 1269 def shortunittest(args): |
1259 """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}""" | 1270 """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}""" |