Skip to content

Commit 02ebe0f

Browse files
committed
Make summary report come at the end of test suite
1 parent b5b6f5e commit 02ebe0f

File tree

4 files changed

+84
-21
lines changed

4 files changed

+84
-21
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.junit.experimental.categories.Category
99
import scala.util.matching.Regex
1010

1111
@Category(Array(classOf[ParallelTesting]))
12-
class CompilationTests extends ParallelTesting {
12+
class CompilationTests extends ParallelSummaryReport with ParallelTesting {
1313
import CompilationTests._
1414

1515
def isInteractive: Boolean = !sys.env.contains("DRONE")
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package dotty.tools.dotc;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.AfterClass;
5+
import java.util.ArrayDeque;
6+
7+
import dotty.tools.dotc.reporting.TestReporter;
8+
import dotty.tools.dotc.reporting.TestReporter$;
9+
10+
/** Note that while `ParallelTesting` runs in parallel, JUnit tests cannot with
11+
* this class
12+
*/
13+
public class ParallelSummaryReport {
14+
private static TestReporter rep = TestReporter.reporter(-1);
15+
private static ArrayDeque<String> failedTests = new ArrayDeque<>();
16+
private static ArrayDeque<String> reproduceInstructions = new ArrayDeque<>();
17+
private static int passed;
18+
private static int failed;
19+
20+
public final static void reportFailed() {
21+
failed++;
22+
}
23+
24+
public final static void reportPassed() {
25+
passed++;
26+
}
27+
28+
public final static void addFailedTest(String msg) {
29+
failedTests.offer(msg);
30+
}
31+
32+
public final static void addReproduceInstruction(String msg) {
33+
reproduceInstructions.offer(msg);
34+
}
35+
36+
@BeforeClass public final static void setup() {
37+
rep = TestReporter.reporter(-1);
38+
failedTests = new ArrayDeque<>();
39+
reproduceInstructions = new ArrayDeque<>();
40+
}
41+
42+
@AfterClass public final static void teardown() {
43+
rep.echo(
44+
"\n================================================================================" +
45+
"\nTest Report" +
46+
"\n================================================================================" +
47+
"\n" +
48+
passed + " passed, " + failed + " failed, " + (passed + failed) + " total" +
49+
"\n"
50+
);
51+
52+
failedTests
53+
.stream()
54+
.map(x -> " " + x)
55+
.forEach(rep::echo);
56+
57+
rep.flushToStdErr();
58+
59+
rep.echo("");
60+
61+
reproduceInstructions
62+
.stream()
63+
.forEach(rep::echo);
64+
65+
if (failed > 0) rep.flushToFile();
66+
}
67+
}

compiler/test/dotty/tools/dotc/ParallelTesting.scala

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import dotc.util.DiffUtil
3131
trait ParallelTesting {
3232

3333
import ParallelTesting._
34+
import ParallelSummaryReport._
3435

3536
/** If the running environment supports an interactive terminal, each `Test`
3637
* will be run with a progress bar and real time feedback
@@ -197,11 +198,8 @@ trait ParallelTesting {
197198
val errorMsg = testSource.buildInstructions(reporter.errorCount, reporter.warningCount)
198199
addFailureInstruction(errorMsg)
199200
failTestSource(testSource)
200-
reporter.echo(errorMsg)
201-
reporter.flushToFile()
202201
}
203202

204-
205203
/** Instructions on how to reproduce failed test source compilations */
206204
private[this] val reproduceInstructions = mutable.ArrayBuffer.empty[String]
207205
protected final def addFailureInstruction(ins: String): Unit =
@@ -210,7 +208,7 @@ trait ParallelTesting {
210208
/** The test sources that failed according to the implementing subclass */
211209
private[this] val failedTestSources = mutable.ArrayBuffer.empty[String]
212210
protected final def failTestSource(testSource: TestSource) = synchronized {
213-
failedTestSources.append(testSource.name)
211+
failedTestSources.append(testSource.name + " failed")
214212
fail()
215213
}
216214

@@ -345,21 +343,11 @@ trait ParallelTesting {
345343
throw new TimeoutException("Compiling targets timed out")
346344

347345
if (didFail) {
348-
echo {
349-
"""|
350-
|
351-
|
352-
|================================================================================
353-
|Test Report
354-
|================================================================================
355-
|Failing tests:""".stripMargin
356-
}
357-
failedTestSources.toSet.foreach { source: String =>
358-
echo(" " + source)
359-
}
360-
echo("")
361-
reproduceInstructions.iterator.foreach(echo)
346+
reportFailed()
347+
failedTestSources.toSet.foreach(addFailedTest)
348+
reproduceInstructions.iterator.foreach(addReproduceInstruction)
362349
}
350+
else reportPassed()
363351
}
364352
else echo {
365353
testFilter

compiler/test/dotty/tools/dotc/reporting/TestReporter.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
2727
final def flushToFile(): Unit =
2828
_messageBuf.iterator.foreach(filePrintln)
2929

30+
final def flushToStdErr(): Unit =
31+
_messageBuf.iterator.foreach(System.err.println)
32+
3033
final def inlineInfo(pos: SourcePosition): String =
3134
if (pos.exists) {
3235
if (pos.outer.exists)
@@ -78,6 +81,11 @@ object TestReporter {
7881
new PrintWriter(new FileOutputStream(new JFile(s"../tests-$timestamp.log"), true))
7982
}
8083

84+
def writeToLog(str: String) = {
85+
logWriter.println(str)
86+
logWriter.flush()
87+
}
88+
8189
def parallelReporter(lock: AnyRef, logLevel: Int): TestReporter = new TestReporter(
8290
new PrintWriter(Console.err, true),
8391
str => lock.synchronized {
@@ -89,13 +97,13 @@ object TestReporter {
8997

9098
def reporter(logLevel: Int): TestReporter = new TestReporter(
9199
new PrintWriter(Console.err, true),
92-
logWriter.println,
100+
writeToLog,
93101
logLevel
94102
)
95103

96104
def simplifiedReporter(writer: PrintWriter): TestReporter = new TestReporter(
97105
writer,
98-
logWriter.println,
106+
writeToLog,
99107
WARNING
100108
) {
101109
/** Prints the message with the given position indication in a simplified manner */

0 commit comments

Comments
 (0)