Skip to content

Commit bcdacee

Browse files
committed
Remove need for java written summary reporter
1 parent f891b22 commit bcdacee

10 files changed

+222
-205
lines changed

compiler/test/dotc/tests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ class tests extends CompilerTest {
210210
private val stdlibFiles: List[String] = StdLibSources.whitelisted
211211

212212
@Test def compileStdLib =
213-
if (!generatePartestFiles)
214-
compileList("compileStdLib", stdlibFiles, "-migration" :: "-Yno-inline" :: scala2mode)
213+
compileList("compileStdLib", stdlibFiles, "-migration" :: "-Yno-inline" :: scala2mode)
214+
215215
@Test def compileMixed = compileLine(
216216
"""../tests/pos/B.scala
217217
|../scala-scala/src/library/scala/collection/immutable/Seq.scala

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

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package dotty
22
package tools
33
package dotc
44

5-
import org.junit.Test
5+
import org.junit.{ Test, BeforeClass, AfterClass }
66

77
import scala.util.matching.Regex
88
import scala.concurrent.duration._
99

10-
import vulpix.{ ParallelTesting, SummaryReport }
10+
import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration }
1111

12-
class CompilationTests extends SummaryReport with ParallelTesting {
12+
class CompilationTests extends ParallelTesting {
13+
import TestConfiguration._
1314
import CompilationTests._
1415

1516
// Test suite configuration --------------------------------------------------
@@ -252,65 +253,6 @@ class CompilationTests extends SummaryReport with ParallelTesting {
252253
}
253254

254255
object CompilationTests {
255-
implicit val defaultOutputDir: String = "../out/"
256-
257-
implicit class RichStringArray(val xs: Array[String]) extends AnyVal {
258-
def and(args: String*): Array[String] = {
259-
val argsArr: Array[String] = args.toArray
260-
xs ++ argsArr
261-
}
262-
}
263-
264-
val noCheckOptions = Array(
265-
"-pagewidth", "120",
266-
"-color:never"
267-
)
268-
269-
val checkOptions = Array(
270-
"-Yno-deep-subtypes",
271-
"-Yno-double-bindings",
272-
"-Yforce-sbt-phases"
273-
)
274-
275-
val classPath = {
276-
val paths = Jars.dottyTestDeps map { p =>
277-
val file = new java.io.File(p)
278-
assert(
279-
file.exists,
280-
s"""|File "$p" couldn't be found. Run `packageAll` from build tool before
281-
|testing.
282-
|
283-
|If running without sbt, test paths need to be setup environment variables:
284-
|
285-
| - DOTTY_LIBRARY
286-
| - DOTTY_COMPILER
287-
| - DOTTY_INTERFACES
288-
| - DOTTY_EXTRAS
289-
|
290-
|Where these all contain locations, except extras which is a colon
291-
|separated list of jars.
292-
|
293-
|When compiling with eclipse, you need the sbt-interfaces jar, put
294-
|it in extras."""
295-
)
296-
file.getAbsolutePath
297-
} mkString (":")
298-
299-
Array("-classpath", paths)
300-
}
301-
302-
private val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef")
303-
304-
val defaultOptions = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath
305-
val allowDeepSubtypes = defaultOptions diff Array("-Yno-deep-subtypes")
306-
val allowDoubleBindings = defaultOptions diff Array("-Yno-double-bindings")
307-
val picklingOptions = defaultOptions ++ Array(
308-
"-Xprint-types",
309-
"-Ytest-pickler",
310-
"-Ystop-after:pickler",
311-
"-Yprintpos"
312-
)
313-
val scala2Mode = defaultOptions ++ Array("-language:Scala2")
314-
val explicitUTF8 = defaultOptions ++ Array("-encoding", "UTF8")
315-
val explicitUTF16 = defaultOptions ++ Array("-encoding", "UTF16")
256+
implicit val summaryReport: SummaryReporting = new SummaryReport
257+
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
316258
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,22 @@ object TestReporter {
110110
val rep = new TestReporter(writer, writeToLog, WARNING) {
111111
/** Prints the message with the given position indication in a simplified manner */
112112
override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = {
113-
val msg = s"${m.pos.line + 1}: " + m.contained.kind + extra
114-
val extraInfo = inlineInfo(m.pos)
113+
def report() = {
114+
val msg = s"${m.pos.line + 1}: " + m.contained.kind + extra
115+
val extraInfo = inlineInfo(m.pos)
115116

116-
writer.println(msg)
117-
_messageBuf.append(msg)
117+
writer.println(msg)
118+
_messageBuf.append(msg)
118119

119-
if (extraInfo.nonEmpty) {
120-
writer.println(extraInfo)
121-
_messageBuf.append(extraInfo)
120+
if (extraInfo.nonEmpty) {
121+
writer.println(extraInfo)
122+
_messageBuf.append(extraInfo)
123+
}
124+
}
125+
m match {
126+
case m: Error => report()
127+
case m: Warning => report()
128+
case _ => ()
122129
}
123130
}
124131
}

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import scala.io.Source._
99
import scala.reflect.io.Directory
1010
import org.junit.Test
1111
import reporting.TestReporter
12+
import vulpix.TestConfiguration
1213

1314
class PatmatExhaustivityTest {
1415
val testsDir = "../tests/patmat"
1516
// stop-after: patmatexhaust-huge.scala crash compiler
16-
val options = List("-color:never", "-Ystop-after:splitter", "-Ycheck-all-patmat") ++ CompilationTests.classPath
17+
val options = List("-color:never", "-Ystop-after:splitter", "-Ycheck-all-patmat") ++ TestConfiguration.classPath
1718

1819
private def compileFile(file: File) = {
1920
val stringBuffer = new StringWriter()

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import dotc.{ Driver, Compiler }
3232
trait ParallelTesting extends RunnerOrchestration { self =>
3333

3434
import ParallelTesting._
35-
import SummaryReport._
3635

3736
/** If the running environment supports an interactive terminal, each `Test`
3837
* will be run with a progress bar and real time feedback
@@ -183,7 +182,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
183182
/** Each `Test` takes the `testSources` and performs the compilation and assertions
184183
* according to the implementing class "neg", "run" or "pos".
185184
*/
186-
private abstract class Test(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean) { test =>
185+
private abstract class Test(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit val summaryReport: SummaryReporting) { test =>
186+
187+
import summaryReport._
188+
187189
protected final val realStdout = System.out
188190
protected final val realStderr = System.err
189191

@@ -426,7 +428,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
426428
}
427429
}
428430

429-
private final class PosTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)
431+
private final class PosTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
430432
extends Test(testSources, times, threadLimit, suppressAllOutput) {
431433
protected def encapsulatedCompilation(testSource: TestSource) = new LoggedRunnable {
432434
def checkTestSource(): Unit = tryCompile(testSource) {
@@ -465,12 +467,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
465467
}
466468
}
467469

468-
private final class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)
470+
private final class RunTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
469471
extends Test(testSources, times, threadLimit, suppressAllOutput) {
470472
private[this] var didAddNoRunWarning = false
471473
private[this] def addNoRunWarning() = if (!didAddNoRunWarning) {
472474
didAddNoRunWarning = true
473-
SummaryReport.addStartingMessage {
475+
summaryReport.addStartingMessage {
474476
"""|WARNING
475477
|-------
476478
|Run tests were only compiled, not run - this is due to `dotty.tests.norun`
@@ -593,7 +595,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
593595
}
594596
}
595597

596-
private final class NegTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)
598+
private final class NegTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
597599
extends Test(testSources, times, threadLimit, suppressAllOutput) {
598600
protected def encapsulatedCompilation(testSource: TestSource) = new LoggedRunnable {
599601
def checkTestSource(): Unit = tryCompile(testSource) {
@@ -849,7 +851,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
849851
* compilation without generating errors and that they do not crash the
850852
* compiler
851853
*/
852-
def checkCompile(): this.type = {
854+
def checkCompile()(implicit summaryReport: SummaryReporting): this.type = {
853855
val test = new PosTest(targets, times, threadLimit, shouldFail).executeTestSuite()
854856

855857
if (!shouldFail && test.didFail) {
@@ -866,7 +868,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
866868
* correct amount of errors at the correct positions. It also makes sure
867869
* that none of these tests crash the compiler
868870
*/
869-
def checkExpectedErrors(): this.type = {
871+
def checkExpectedErrors()(implicit summaryReport: SummaryReporting): this.type = {
870872
val test = new NegTest(targets, times, threadLimit, shouldFail).executeTestSuite()
871873

872874
if (!shouldFail && test.didFail) {
@@ -884,7 +886,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
884886
* the compiler; it also makes sure that all tests can run with the
885887
* expected output
886888
*/
887-
def checkRuns(): this.type = {
889+
def checkRuns()(implicit summaryReport: SummaryReporting): this.type = {
888890
val test = new RunTest(targets, times, threadLimit, shouldFail).executeTestSuite()
889891

890892
if (!shouldFail && test.didFail) {

compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ trait RunnerOrchestration {
4343
def safeMode: Boolean
4444

4545
/** Running a `Test` class's main method from the specified `dir` */
46-
def runMain(classPath: String): Status = monitor.runMain(classPath)
46+
def runMain(classPath: String)(implicit summaryReport: SummaryReporting): Status =
47+
monitor.runMain(classPath)
4748

4849
private[this] val monitor = new RunnerMonitor
4950

@@ -57,7 +58,8 @@ trait RunnerOrchestration {
5758
*/
5859
private class RunnerMonitor {
5960

60-
def runMain(classPath: String): Status = withRunner(_.runMain(classPath))
61+
def runMain(classPath: String)(implicit summaryReport: SummaryReporting): Status =
62+
withRunner(_.runMain(classPath))
6163

6264
private class Runner(private var process: Process) {
6365
private[this] var childStdout: BufferedReader = _
@@ -81,8 +83,16 @@ trait RunnerOrchestration {
8183
childStdin = null
8284
}
8385

86+
/** Did add hook to kill the child VMs? */
87+
private[this] var didAddCleanupCallback = false
88+
8489
/** Blocks less than `maxDuration` while running `Test.main` from `dir` */
85-
def runMain(classPath: String): Status = {
90+
def runMain(classPath: String)(implicit summaryReport: SummaryReporting): Status = {
91+
if (!didAddCleanupCallback) {
92+
// If for some reason the test runner (i.e. sbt) doesn't kill the VM, we
93+
// need to clean up ourselves.
94+
summaryReport.addCleanup(killAll)
95+
}
8696
assert(process ne null,
8797
"Runner was killed and then reused without setting a new process")
8898

@@ -127,9 +137,9 @@ trait RunnerOrchestration {
127137
// Handle failure of the VM:
128138
status match {
129139
case _: Success if safeMode => respawn()
140+
case _: Success => // no need to respawn sub process
130141
case _: Failure => respawn()
131142
case Timeout => respawn()
132-
case _ => ()
133143
}
134144
status
135145
}
@@ -182,8 +192,5 @@ trait RunnerOrchestration {
182192

183193
// On shutdown, we need to kill all runners:
184194
sys.addShutdownHook(killAll())
185-
// If for some reason the test runner (i.e. sbt) doesn't kill the VM, we
186-
// need to clean up ourselves.
187-
SummaryReport.addCleanup(killAll)
188195
}
189196
}

compiler/test/dotty/tools/vulpix/SummaryReport.java

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)