50 |
|
import junit.framework.AssertionFailedError; |
51 |
|
import junit.framework.Test; |
52 |
|
import junit.framework.TestCase; |
53 |
+ |
import junit.framework.TestResult; |
54 |
|
import junit.framework.TestSuite; |
55 |
|
|
56 |
|
/** |
161 |
|
Integer.getInteger("jsr166.runsPerTest", 1); |
162 |
|
|
163 |
|
/** |
164 |
+ |
* The number of repetitions of the test suite (for finding leaks?). |
165 |
+ |
*/ |
166 |
+ |
private static final int suiteRuns = |
167 |
+ |
Integer.getInteger("jsr166.suiteRuns", 1); |
168 |
+ |
|
169 |
+ |
/** |
170 |
|
* A filter for tests to run, matching strings of the form |
171 |
|
* methodName(className), e.g. "testInvokeAll5(ForkJoinPoolTest)" |
172 |
|
* Usefully combined with jsr166.runsPerTest. |
205 |
|
|
206 |
|
/** |
207 |
|
* Runs all JSR166 unit tests using junit.textui.TestRunner. |
201 |
– |
* Optional command line arg provides the number of iterations to |
202 |
– |
* repeat running the tests. |
208 |
|
*/ |
209 |
|
public static void main(String[] args) { |
210 |
+ |
main(suite(), args); |
211 |
+ |
} |
212 |
+ |
|
213 |
+ |
/** |
214 |
+ |
* Runs all unit tests in the given test suite. |
215 |
+ |
* Actual behavior influenced by jsr166.* system properties. |
216 |
+ |
*/ |
217 |
+ |
static void main(Test suite, String[] args) { |
218 |
|
if (useSecurityManager) { |
219 |
|
System.err.println("Setting a permissive security manager"); |
220 |
|
Policy.setPolicy(permissivePolicy()); |
221 |
|
System.setSecurityManager(new SecurityManager()); |
222 |
|
} |
223 |
< |
int iters = (args.length == 0) ? 1 : Integer.parseInt(args[0]); |
224 |
< |
|
225 |
< |
Test s = suite(); |
226 |
< |
for (int i = 0; i < iters; ++i) { |
214 |
< |
junit.textui.TestRunner.run(s); |
223 |
> |
for (int i = 0; i < suiteRuns; i++) { |
224 |
> |
TestResult result = junit.textui.TestRunner.run(suite); |
225 |
> |
if (!result.wasSuccessful()) |
226 |
> |
System.exit(1); |
227 |
|
System.gc(); |
228 |
|
System.runFinalization(); |
229 |
|
} |
218 |
– |
System.exit(0); |
230 |
|
} |
231 |
|
|
232 |
|
public static TestSuite newTestSuite(Object... suiteOrClasses) { |
276 |
|
public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } |
277 |
|
public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } |
278 |
|
public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } |
279 |
< |
public static boolean atLeastJava9() { |
269 |
< |
// As of 2014-05, java9 still uses 52.0 class file version |
270 |
< |
return JAVA_SPECIFICATION_VERSION.startsWith("1.9"); |
271 |
< |
} |
279 |
> |
public static boolean atLeastJava9() { return JAVA_CLASS_VERSION >= 53.0; } |
280 |
|
|
281 |
|
/** |
282 |
|
* Collects all JSR166 unit tests as one suite. |
572 |
|
public void threadAssertEquals(Object x, Object y) { |
573 |
|
try { |
574 |
|
assertEquals(x, y); |
575 |
< |
} catch (AssertionFailedError t) { |
576 |
< |
threadRecordFailure(t); |
577 |
< |
throw t; |
578 |
< |
} catch (Throwable t) { |
579 |
< |
threadUnexpectedException(t); |
575 |
> |
} catch (AssertionFailedError fail) { |
576 |
> |
threadRecordFailure(fail); |
577 |
> |
throw fail; |
578 |
> |
} catch (Throwable fail) { |
579 |
> |
threadUnexpectedException(fail); |
580 |
|
} |
581 |
|
} |
582 |
|
|
588 |
|
public void threadAssertSame(Object x, Object y) { |
589 |
|
try { |
590 |
|
assertSame(x, y); |
591 |
< |
} catch (AssertionFailedError t) { |
592 |
< |
threadRecordFailure(t); |
593 |
< |
throw t; |
591 |
> |
} catch (AssertionFailedError fail) { |
592 |
> |
threadRecordFailure(fail); |
593 |
> |
throw fail; |
594 |
|
} |
595 |
|
} |
596 |
|
|