summaryrefslogtreecommitdiff
path: root/test/junit/scala/tools/nsc/transform
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-05-23 10:17:15 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-05-23 10:17:15 +1000
commit2e40aa5871859b9ab6bdc03d56a81746fa90b1e5 (patch)
tree44db43073e3d974fc5ced61de278abd45b8e1227 /test/junit/scala/tools/nsc/transform
parenta79b9b7220c87ba21b374eda25702c7bc446dc29 (diff)
parente26835c01254ecb4d9b4fa3a8bbe9c835f808a38 (diff)
downloadscala-2e40aa5871859b9ab6bdc03d56a81746fa90b1e5.tar.gz
scala-2e40aa5871859b9ab6bdc03d56a81746fa90b1e5.tar.bz2
scala-2e40aa5871859b9ab6bdc03d56a81746fa90b1e5.zip
Merge pull request #5180 from lrytz/junit-pass
Clean up JUnit tests, make sure they pass without bootstrap [ci: last-only]
Diffstat (limited to 'test/junit/scala/tools/nsc/transform')
-rw-r--r--test/junit/scala/tools/nsc/transform/delambdafy/DelambdafyTest.scala16
-rw-r--r--test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala69
2 files changed, 39 insertions, 46 deletions
diff --git a/test/junit/scala/tools/nsc/transform/delambdafy/DelambdafyTest.scala b/test/junit/scala/tools/nsc/transform/delambdafy/DelambdafyTest.scala
index e4bf038f32..609f481721 100644
--- a/test/junit/scala/tools/nsc/transform/delambdafy/DelambdafyTest.scala
+++ b/test/junit/scala/tools/nsc/transform/delambdafy/DelambdafyTest.scala
@@ -1,17 +1,15 @@
package scala.tools.nsc.transform.delambdafy
-import scala.reflect.io.Path.jfile2path
-import scala.tools.nsc.backend.jvm.CodeGenTools.getGeneratedClassfiles
-import scala.tools.nsc.backend.jvm.CodeGenTools.makeSourceFile
-import scala.tools.nsc.backend.jvm.CodeGenTools.newCompilerWithoutVirtualOutdir
-import scala.tools.nsc.io.AbstractFile
-import scala.tools.testing.TempDir
-
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
+import scala.reflect.io.Path.jfile2path
+import scala.tools.nsc.io.AbstractFile
+import scala.tools.testing.BytecodeTesting._
+import scala.tools.testing.TempDir
+
@RunWith(classOf[JUnit4])
class DelambdafyTest {
def compileToMultipleOutputWithDelamdbafyMethod(): List[(String, Array[Byte])] = {
@@ -55,9 +53,9 @@ object Delambdafy {
val extraArgs = "-Ydelambdafy:method"
val argsWithOutDir = extraArgs + s" -d $outDirPath -cp $outDirPath"
val compiler = newCompilerWithoutVirtualOutdir(extraArgs = argsWithOutDir)
- compiler.settings.outputDirs.add(srcFile.file, outDir)
+ compiler.global.settings.outputDirs.add(srcFile.file, outDir)
- new compiler.Run().compileSources(List(srcFile))
+ new compiler.global.Run().compileSources(List(srcFile))
val classfiles = getGeneratedClassfiles(outDir)
outDir.delete()
diff --git a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
index aa83520efb..b6e8d4fbf2 100644
--- a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
+++ b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala
@@ -1,26 +1,21 @@
package scala.tools.nsc
package transform.patmat
+import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import org.junit.Test
-import scala.tools.asm.Opcodes._
-import org.junit.Assert._
+import scala.tools.asm.Opcodes._
import scala.tools.nsc.backend.jvm.AsmUtils._
-import scala.tools.nsc.backend.jvm.CodeGenTools
-import scala.tools.testing.AssertUtil._
-
-import CodeGenTools._
-import scala.tools.partest.ASMConverters
-import ASMConverters._
-import scala.tools.testing.ClearAfterClass
+import scala.tools.testing.BytecodeTesting
+import scala.tools.testing.BytecodeTesting._
@RunWith(classOf[JUnit4])
-class PatmatBytecodeTest extends ClearAfterClass {
- val compiler = cached("compiler", () => newCompiler())
+class PatmatBytecodeTest extends BytecodeTesting {
val optCompiler = cached("optCompiler", () => newCompiler(extraArgs = "-Yopt:l:project"))
+ import compiler._
+
@Test
def t6956(): Unit = {
val code =
@@ -43,9 +38,9 @@ class PatmatBytecodeTest extends ClearAfterClass {
|}
""".stripMargin
- val List(c) = compileClasses(compiler)(code)
- assert(getSingleMethod(c, "s1").instructions.count(_.opcode == TABLESWITCH) == 1, textify(c))
- assert(getSingleMethod(c, "s2").instructions.count(_.opcode == TABLESWITCH) == 1, textify(c))
+ val c = compileClass(code)
+ assert(getInstructions(c, "s1").count(_.opcode == TABLESWITCH) == 1, textify(c))
+ assert(getInstructions(c, "s2").count(_.opcode == TABLESWITCH) == 1, textify(c))
}
@Test
@@ -71,9 +66,9 @@ class PatmatBytecodeTest extends ClearAfterClass {
|}
""".stripMargin
- val List(c) = compileClasses(compiler)(code)
- assert(getSingleMethod(c, "s1").instructions.count(_.opcode == TABLESWITCH) == 1, textify(c))
- assert(getSingleMethod(c, "s2").instructions.count(_.opcode == TABLESWITCH) == 1, textify(c))
+ val c = compileClass(code)
+ assert(getInstructions(c, "s1").count(_.opcode == TABLESWITCH) == 1, textify(c))
+ assert(getInstructions(c, "s2").count(_.opcode == TABLESWITCH) == 1, textify(c))
}
@Test
@@ -86,9 +81,9 @@ class PatmatBytecodeTest extends ClearAfterClass {
| }
|}
""".stripMargin
- val c = compileClasses(optCompiler)(code).head
+ val c :: _ = optCompiler.compileClasses(code)
- assertSameSummary(getSingleMethod(c, "a"), List(
+ assertSameSummary(getMethod(c, "a"), List(
NEW, DUP, ICONST_1, LDC, "<init>",
"y", ARETURN))
}
@@ -103,8 +98,8 @@ class PatmatBytecodeTest extends ClearAfterClass {
| }
|}
""".stripMargin
- val c = compileClasses(optCompiler)(code).head
- assert(!getSingleMethod(c, "a").instructions.exists(i => i.opcode == IFNULL || i.opcode == IFNONNULL), textify(findAsmMethod(c, "a")))
+ val c :: _ = optCompiler.compileClasses(code)
+ assert(!getInstructions(c, "a").exists(i => i.opcode == IFNULL || i.opcode == IFNONNULL), textify(getAsmMethod(c, "a")))
}
@Test
@@ -117,8 +112,8 @@ class PatmatBytecodeTest extends ClearAfterClass {
| }
|}
""".stripMargin
- val c = compileClasses(optCompiler)(code).head
- assertSameSummary(getSingleMethod(c, "a"), List(
+ val c :: _ = optCompiler.compileClasses(code)
+ assertSameSummary(getMethod(c, "a"), List(
NEW, DUP, ICONST_1, "boxToInteger", LDC, "<init>", ASTORE /*1*/,
ALOAD /*1*/, "y", ASTORE /*2*/,
ALOAD /*1*/, "x", INSTANCEOF, IFNE /*R*/,
@@ -138,7 +133,7 @@ class PatmatBytecodeTest extends ClearAfterClass {
| }
|}
""".stripMargin
- val c = compileClasses(optCompiler)(code, allowMessage = _.msg.contains("may not be exhaustive")).head
+ val c = optCompiler.compileClass(code, allowMessage = _.msg.contains("may not be exhaustive"))
val expected = List(
ALOAD /*1*/ , INSTANCEOF /*::*/ , IFEQ /*A*/ ,
@@ -147,8 +142,8 @@ class PatmatBytecodeTest extends ClearAfterClass {
-1 /*A*/ , NEW /*MatchError*/ , DUP, ALOAD /*1*/ , "<init>", ATHROW,
-1 /*B*/ , ILOAD, IRETURN)
- assertSameSummary(getSingleMethod(c, "a"), expected)
- assertSameSummary(getSingleMethod(c, "b"), expected)
+ assertSameSummary(getMethod(c, "a"), expected)
+ assertSameSummary(getMethod(c, "b"), expected)
}
@Test
@@ -170,18 +165,18 @@ class PatmatBytecodeTest extends ClearAfterClass {
| def t9 = { val C(a, _) = C("hi", 23); a.toString }
|}
""".stripMargin
- val List(c, cMod) = compileClasses(optCompiler)(code)
- assertSameSummary(getSingleMethod(c, "t1"), List(ICONST_1, ICONST_2, IADD, IRETURN))
- assertSameSummary(getSingleMethod(c, "t2"), List(ICONST_1, IRETURN))
- assertInvokedMethods(getSingleMethod(c, "t3"), List("C.tplCall", "scala/Tuple2._1", "scala/Tuple2._2$mcI$sp", "scala/MatchError.<init>", "java/lang/String.length"))
- assertInvokedMethods(getSingleMethod(c, "t4"), List("C.tplCall", "scala/Tuple2._2$mcI$sp", "scala/MatchError.<init>"))
- assertNoInvoke(getSingleMethod(c, "t5"))
- assertSameSummary(getSingleMethod(c, "t6"), List(BIPUSH, IRETURN))
+ val List(c, cMod) = optCompiler.compileClasses(code)
+ assertSameSummary(getMethod(c, "t1"), List(ICONST_1, ICONST_2, IADD, IRETURN))
+ assertSameSummary(getMethod(c, "t2"), List(ICONST_1, IRETURN))
+ assertInvokedMethods(getMethod(c, "t3"), List("C.tplCall", "scala/Tuple2._1", "scala/Tuple2._2$mcI$sp", "scala/MatchError.<init>", "java/lang/String.length"))
+ assertInvokedMethods(getMethod(c, "t4"), List("C.tplCall", "scala/Tuple2._2$mcI$sp", "scala/MatchError.<init>"))
+ assertNoInvoke(getMethod(c, "t5"))
+ assertSameSummary(getMethod(c, "t6"), List(BIPUSH, IRETURN))
// MatchError reachable because of the type pattern `s: String`
- assertInvokedMethods(getSingleMethod(c, "t7"), List("C.a", "C.b", "scala/MatchError.<init>", "java/lang/String.length"))
- assertSameSummary(getSingleMethod(c, "t8"), List(ALOAD, "b", IRETURN))
+ assertInvokedMethods(getMethod(c, "t7"), List("C.a", "C.b", "scala/MatchError.<init>", "java/lang/String.length"))
+ assertSameSummary(getMethod(c, "t8"), List(ALOAD, "b", IRETURN))
// C allocation not eliminated - constructor may have side-effects.
- assertSameSummary(getSingleMethod(c, "t9"), List(NEW, DUP, LDC, BIPUSH, "<init>", "a", "toString", ARETURN))
+ assertSameSummary(getMethod(c, "t9"), List(NEW, DUP, LDC, BIPUSH, "<init>", "a", "toString", ARETURN))
}
}