summaryrefslogtreecommitdiff
path: root/test/junit/scala/tools/nsc/backend/jvm/IndySammyTest.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/junit/scala/tools/nsc/backend/jvm/IndySammyTest.scala')
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/IndySammyTest.scala42
1 files changed, 14 insertions, 28 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/IndySammyTest.scala b/test/junit/scala/tools/nsc/backend/jvm/IndySammyTest.scala
index b9e45a7dc9..2bcbcc870c 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/IndySammyTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/IndySammyTest.scala
@@ -2,34 +2,20 @@ package scala.tools.nsc
package backend.jvm
import org.junit.Assert.assertEquals
+import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import org.junit.Test
import scala.tools.asm.Opcodes._
-import scala.tools.asm.tree._
import scala.tools.nsc.reporters.StoreReporter
-import CodeGenTools._
-import scala.tools.partest.ASMConverters
-import ASMConverters._
-
-import scala.tools.testing.ClearAfterClass
-
-object IndySammyTest extends ClearAfterClass.Clearable {
- var _compiler = newCompiler()
+import scala.tools.partest.ASMConverters._
+import scala.tools.testing.BytecodeTesting
+import scala.tools.testing.BytecodeTesting._
- def compile(scalaCode: String, javaCode: List[(String, String)] = Nil, allowMessage: StoreReporter#Info => Boolean = _ => false): List[ClassNode] =
- compileClasses(_compiler)(scalaCode, javaCode, allowMessage)
-
- def clear(): Unit = { _compiler = null }
-}
@RunWith(classOf[JUnit4])
-class IndySammyTest extends ClearAfterClass {
- ClearAfterClass.stateToClear = IndySammyTest
- import IndySammyTest._
-
- val compiler = _compiler
+class IndySammyTest extends BytecodeTesting {
+ import compiler._
def funClassName(from: String, to: String) = s"Fun$from$to"
def classPrologue(from: String, to: String) =
@@ -53,13 +39,13 @@ class IndySammyTest extends ClearAfterClass {
def test(from: String, to: String, arg: String, body: String => String = x => x)
(expectedSig: String, lamBody: List[Instruction], appArgs: List[Instruction], ret: Instruction)
(allowMessage: StoreReporter#Info => Boolean = _ => false) = {
- val cls = compile(s"${classPrologue(from, to)}")
- val methodNodes = compileMethods(compiler)(lamDef(from, to, body) +";"+ appDef(arg), allowMessage)
+ val List(funClass, vcClass, vcCompanion) = compileClasses(s"${classPrologue(from, to)}")
+ val c = compileClass(s"class C { ${lamDef(from, to, body)}; ${appDef(arg)} }", allowMessage = allowMessage)
- val applySig = cls.head.methods.get(0).desc
- val anonfun = methodNodes.find(_.name contains "$anonfun$").map(convertMethod).get
- val lamInsn = methodNodes.find(_.name == "lam").map(instructionsFromMethod).get.dropNonOp
- val applyInvoke = methodNodes.find(_.name == "app").map(convertMethod).get
+ val applySig = getAsmMethod(funClass, "apply").desc
+ val anonfun = getMethod(c, "C$$$anonfun$1")
+ val lamInsn = getInstructions(c, "lam").dropNonOp
+ val applyInvoke = getMethod(c, "app")
assertEquals(expectedSig, applySig)
assert(lamInsn.length == 2 && lamInsn.head.isInstanceOf[InvokeDynamic], lamInsn)
@@ -72,7 +58,7 @@ class IndySammyTest extends ClearAfterClass {
}
// def testSpecial(lam: String, lamTp: String, arg: String)(allowMessage: StoreReporter#Info => Boolean = _ => false) = {
-// val cls = compile("trait Special[@specialized A] { def apply(a: A): A}" )
+// val cls = compileClasses("trait Special[@specialized A] { def apply(a: A): A}" )
// val methodNodes = compileMethods(compiler)(s"def lam : $lamTp = $lam" +";"+ appDef(arg), allowMessage)
//
// val anonfun = methodNodes.filter(_.name contains "$anonfun$").map(convertMethod)
@@ -154,7 +140,7 @@ class IndySammyTest extends ClearAfterClass {
// Tests ThisReferringMethodsTraverser
@Test
def testStaticIfNoThisReference: Unit = {
- val methodNodes = compileMethods(compiler)("def foo = () => () => () => 42")
+ val methodNodes = compileAsmMethods("def foo = () => () => () => 42")
methodNodes.forall(m => !m.name.contains("anonfun") || (m.access & ACC_STATIC) == ACC_STATIC)
}
}