|
1 | 1 | package dotty.tools.languageserver |
2 | 2 |
|
3 | 3 | import org.junit.Test |
4 | | -import java.lang.reflect.InvocationTargetException |
5 | | -import java.util.concurrent.TimeUnit |
6 | 4 |
|
7 | | -import scala.concurrent.{Await, Future} |
8 | | -import scala.concurrent.duration.Duration |
9 | | -import scala.concurrent.ExecutionContext.Implicits.global |
| 5 | +import java.lang.reflect.InvocationTargetException |
10 | 6 |
|
11 | 7 | // TODO remove this and use JUnit to run the tests |
12 | 8 | object Main { |
13 | 9 | def main(args: Array[String]): Unit = { |
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 | | - } |
| 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 | + } |
39 | 34 | } |
40 | 35 | } |
41 | 36 |
|
42 | | - Await.ready(Future.sequence(tests), Duration.Inf) |
| 37 | + val time = (System.currentTimeMillis() - t0).toDouble / 1000 |
43 | 38 |
|
44 | | - if (failed != 0) { |
45 | | - System.err.println(s"Failed $failed tests") |
| 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") |
46 | 49 | System.exit(1) |
47 | 50 | } |
48 | | - println(Console.GREEN + s"Passed all $passed tests" + Console.RESET) |
49 | 51 | } |
50 | 52 |
|
51 | 53 | private def testsClasses = List( |
52 | | - classOf[SymbolTest], |
53 | | - classOf[RenameTest], |
54 | | - classOf[ReferencesTest], |
55 | | - classOf[DocumentSymbolTest], |
56 | | - classOf[DefinitionTest], |
57 | 54 | classOf[HighlightTest], |
58 | 55 | classOf[CompletionTest], |
| 56 | + classOf[DefinitionTest], |
59 | 57 | classOf[HoverTest], |
| 58 | + classOf[ReferencesTest], |
| 59 | + classOf[RenameTest], |
| 60 | + classOf[DocumentSymbolTest], |
| 61 | + classOf[SymbolTest], |
60 | 62 | ) |
61 | 63 | } |
0 commit comments