|
1 | 1 | package dotty.tools.languageserver
|
2 | 2 |
|
3 | 3 | import org.junit.Test
|
4 |
| - |
5 | 4 | import java.lang.reflect.InvocationTargetException
|
| 5 | +import java.util.concurrent.TimeUnit |
| 6 | + |
| 7 | +import scala.concurrent.{Await, Future} |
| 8 | +import scala.concurrent.duration.Duration |
| 9 | +import scala.concurrent.ExecutionContext.Implicits.global |
6 | 10 |
|
7 | 11 | // TODO remove this and use JUnit to run the tests
|
8 | 12 | object Main {
|
9 | 13 | def main(args: Array[String]): Unit = {
|
10 |
| - var testsFailed = 0 |
11 |
| - for (clazz <- testsClasses) { |
12 |
| - val t0 = System.currentTimeMillis() |
13 |
| - var passed = 0 |
14 |
| - var failed = 0 |
15 |
| - println(s"Starting tests in ${clazz.getSimpleName}") |
16 |
| - for (method <- clazz.getMethods.sortBy(_.getName)) { |
17 |
| - if (method.getAnnotation(classOf[Test]) ne null) { |
18 |
| - print(s"Testing $clazz.${method.getName} ") |
19 |
| - try { |
20 |
| - method.invoke(clazz.getConstructor().newInstance()) |
21 |
| - println(Console.GREEN + "passed" + Console.RESET) |
22 |
| - passed += 1 |
23 |
| - } catch { |
24 |
| - case ex: InvocationTargetException => |
25 |
| - ex.getCause match { |
26 |
| - case ex1: AssertionError => |
27 |
| - println(Console.RED + "failed" + Console.RESET) |
28 |
| - System.err.println(s"${method.getName} failed with") |
29 |
| - ex1.printStackTrace() |
30 |
| - failed += 1 |
31 |
| - case _ => throw ex.getCause |
32 |
| - } |
33 |
| - } |
| 14 | + var failed = 0 |
| 15 | + var passed = 0 |
| 16 | + val tests = |
| 17 | + for { |
| 18 | + clazz <- testsClasses |
| 19 | + method <- clazz.getMethods.sortBy(_.getName) |
| 20 | + if method.getAnnotation(classOf[Test]) ne null |
| 21 | + } yield { |
| 22 | + Future { |
| 23 | + println(s"Testing ${clazz.getCanonicalName}.${method.getName} ") |
| 24 | + try { |
| 25 | + method.invoke(clazz.getConstructor().newInstance()) |
| 26 | + println(s"Testing ${clazz.getCanonicalName}.${method.getName} " + Console.GREEN + "passed" + Console.RESET) |
| 27 | + passed += 1 |
| 28 | + } catch { |
| 29 | + case ex: InvocationTargetException => |
| 30 | + ex.getCause match { |
| 31 | + case ex1: AssertionError => |
| 32 | + println(s"Testing ${clazz.getCanonicalName}.${method.getName} " + Console.RED + "failed" + Console.RESET) |
| 33 | + System.err.println(s"${method.getName} failed with") |
| 34 | + ex1.printStackTrace() |
| 35 | + failed += 1 |
| 36 | + case _ => throw ex.getCause |
| 37 | + } |
| 38 | + } |
34 | 39 | }
|
35 | 40 | }
|
36 | 41 |
|
37 |
| - val time = (System.currentTimeMillis() - t0).toDouble / 1000 |
| 42 | + Await.ready(Future.sequence(tests), Duration.Inf) |
38 | 43 |
|
39 |
| - if (failed == 0) { |
40 |
| - println(s"${Console.GREEN}Passed all $passed tests${Console.RESET} in ${time}s") |
41 |
| - } else { |
42 |
| - testsFailed += 1 |
43 |
| - System.err.println(s"Passed $passed, ${Console.RED}failed $failed${Console.RESET}, total ${passed + failed} in ${time}s") |
44 |
| - } |
45 |
| - println() |
46 |
| - } |
47 |
| - if (testsFailed != 0) { |
48 |
| - System.err.println(s"Failed $testsFailed tests") |
| 44 | + if (failed != 0) { |
| 45 | + System.err.println(s"Failed $failed tests") |
49 | 46 | System.exit(1)
|
50 | 47 | }
|
| 48 | + println(Console.GREEN + s"Passed all $passed tests" + Console.RESET) |
51 | 49 | }
|
52 | 50 |
|
53 | 51 | private def testsClasses = List(
|
| 52 | + classOf[SymbolTest], |
| 53 | + classOf[RenameTest], |
| 54 | + classOf[ReferencesTest], |
| 55 | + classOf[DocumentSymbolTest], |
| 56 | + classOf[DefinitionTest], |
54 | 57 | classOf[HighlightTest],
|
55 | 58 | classOf[CompletionTest],
|
56 |
| - classOf[DefinitionTest], |
57 | 59 | classOf[HoverTest],
|
58 |
| - classOf[ReferencesTest], |
59 |
| - classOf[RenameTest], |
60 |
| - classOf[DocumentSymbolTest], |
61 |
| - classOf[SymbolTest], |
62 | 60 | )
|
63 | 61 | }
|
0 commit comments