Skip to content

Commit 3c419db

Browse files
committed
Adapt DottyBytecodeTest to the new output handling
Also stop extending DottyTest because I don't understand the weird way it handles context. We'll need to clean up all that stuff some day.
1 parent 818dbbd commit 3c419db

File tree

2 files changed

+21
-38
lines changed

2 files changed

+21
-38
lines changed

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package dotty.tools
1+
package dotty
2+
package tools
23
package backend.jvm
34

45
import dotc.core.Contexts.{Context, ContextBase}
6+
import dotc.core.Comments.{ContextDoc, ContextDocstrings}
57
import dotc.core.Phases.Phase
68
import dotc.Compiler
79

@@ -11,19 +13,13 @@ import asm._
1113
import asm.tree._
1214
import scala.collection.JavaConverters._
1315

14-
import io.JavaClassPath
16+
import io.{AbstractFile, JavaClassPath, VirtualDirectory}
1517
import scala.collection.JavaConverters._
1618
import scala.tools.asm.{ClassWriter, ClassReader}
1719
import scala.tools.asm.tree._
1820
import java.io.{File => JFile, InputStream}
1921

20-
class TestGenBCode(val outDir: String) extends GenBCode {
21-
override def phaseName: String = "testGenBCode"
22-
val virtualDir = new Directory(outDir, None)
23-
override def outputDir(implicit ctx: Context) = virtualDir
24-
}
25-
26-
trait DottyBytecodeTest extends DottyTest {
22+
trait DottyBytecodeTest {
2723
import AsmNode._
2824
import ASMConverters._
2925

@@ -45,32 +41,23 @@ trait DottyBytecodeTest extends DottyTest {
4541
val javaString = "java/lang/String"
4642
}
4743

48-
private def bCodeCheckingComp(testPhase: TestGenBCode)(check: Directory => Unit) = {
49-
class AssertionChecker extends Phase {
50-
def phaseName = "assertionChecker"
51-
def run(implicit ctx: Context): Unit = check(testPhase.virtualDir)
52-
}
53-
new Compiler {
54-
override protected def backendPhases: List[List[Phase]] =
55-
List(testPhase) ::
56-
List(new AssertionChecker) ::
57-
Nil
58-
}
44+
def initCtx = {
45+
val ctx0 = (new ContextBase).initialCtx.fresh
46+
val outputDir = new VirtualDirectory("<DottyBytecodeTest output>")
47+
ctx0.setSetting(ctx0.settings.classpath, Jars.dottyLib)
48+
ctx0.setProperty(ContextDoc, new ContextDocstrings)
49+
ctx0.setSetting(ctx0.settings.outputDir, outputDir)
5950
}
6051

61-
private def outPath(obj: Any) =
62-
"/genBCodeTest" + math.abs(obj.hashCode) + System.currentTimeMillis
63-
6452
/** Checks source code from raw string */
65-
def checkBCode(source: String)(assertion: Directory => Unit) = {
66-
val comp = bCodeCheckingComp(new TestGenBCode(outPath(source)))(assertion)
67-
comp.newRun.compile(source)
68-
}
53+
def checkBCode(source: String)(checkOutput: AbstractFile => Unit): Unit = {
54+
implicit val ctx: Context = initCtx
55+
56+
val compiler = new Compiler
57+
val run = compiler.newRun
58+
compiler.newRun.compile(source)
6959

70-
/** Checks actual _files_ referenced in `sources` list */
71-
def checkBCode(sources: List[String])(assertion: Directory => Unit) = {
72-
val comp = bCodeCheckingComp(new TestGenBCode(outPath(sources)))(assertion)
73-
comp.newRun.compile(sources)
60+
checkOutput(ctx.settings.outputDir.value)
7461
}
7562

7663
protected def loadClassNode(input: InputStream, skipDebugInfo: Boolean = true): ClassNode = {

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ class SimplifyPosTests extends SimplifyTests(optimise = true)
1111
class SimplifyNegTests extends SimplifyTests(optimise = false)
1212

1313
abstract class SimplifyTests(val optimise: Boolean) extends DottyBytecodeTest {
14-
override protected def initializeCtx(c: FreshContext): Unit = {
15-
super.initializeCtx(c)
16-
if (optimise) {
17-
val flags = Array("-optimise") // :+ "-Xprint:simplify"
18-
val summary = CompilerCommand.distill(flags)(c)
19-
c.setSettings(summary.sstate)
20-
}
14+
override def initCtx = {
15+
val ctx0 = super.initCtx
16+
ctx0.setSetting(ctx0.settings.optimise, optimise)
2117
}
2218

2319
def check(source: String, expected: String, shared: String = ""): Unit = {

0 commit comments

Comments
 (0)