summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-05-20 16:07:25 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2016-05-20 16:44:37 +0200
commit64fdae87975f019d3821ca943852df37d50db801 (patch)
tree20f5b7e744e75dee0a1c5ddb749e8e0157185dd9
parent2537027195fd1702bbd12ba8e9d6cb3262b03482 (diff)
downloadscala-64fdae87975f019d3821ca943852df37d50db801.tar.gz
scala-64fdae87975f019d3821ca943852df37d50db801.tar.bz2
scala-64fdae87975f019d3821ca943852df37d50db801.zip
All JUnit tests pass without bootstrap (when run in intellij, sbt)
-rw-r--r--test/junit/scala/lang/primitives/BoxUnboxTest.scala203
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/BTypesFromClassfileTest.scala6
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala6
3 files changed, 123 insertions, 92 deletions
diff --git a/test/junit/scala/lang/primitives/BoxUnboxTest.scala b/test/junit/scala/lang/primitives/BoxUnboxTest.scala
index 23c9326989..e4911f1af5 100644
--- a/test/junit/scala/lang/primitives/BoxUnboxTest.scala
+++ b/test/junit/scala/lang/primitives/BoxUnboxTest.scala
@@ -1,11 +1,10 @@
package scala.lang.primitives
-import org.junit.Test
import org.junit.Assert._
+import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
-import scala.tools.testing.AssertUtil._
import scala.tools.testing.RunTesting
object BoxUnboxTest {
@@ -16,80 +15,100 @@ object BoxUnboxTest {
class BoxUnboxTest extends RunTesting {
import runner._
- def genericNull[T] = null.asInstanceOf[T] // allowed, see SI-4437, point 2
-
@Test
def boxUnboxInt(): Unit = {
- val b = new Integer(1)
- val u = 1
-
- assertEquals(1.toInt, u)
-
- assertEquals(Predef.int2Integer(1), b)
- assertEquals(1: Integer, b)
- assertEquals(Int.box(1), b)
- assertEquals(1.asInstanceOf[Object], b)
-
- assertThrows[ClassCastException]("".asInstanceOf[Integer])
-
- assertEquals(Predef.Integer2int(b), u)
- assertEquals(b: Int, u)
- assertEquals(Int.unbox(b), u)
- assertEquals(b.asInstanceOf[Int], u)
- assertEquals(b.intValue, u)
- assertEquals(b.toInt, u)
- intWrapper(b).toInt
-
- assertThrows[ClassCastException](Int.unbox(""))
- assertThrows[ClassCastException]("".asInstanceOf[Int])
-
- // null unboxing in various positions
-
- val n1 = Int.unbox(null)
- assertEquals(n1, 0)
- val n2 = Predef.Integer2int(null)
- assertEquals(n2, 0)
- val n3 = (null: Integer): Int
- assertEquals(n3, 0)
- val n4 = null.asInstanceOf[Int]
- assertEquals(n4, 0)
- val n5 = null.asInstanceOf[Int] == 0
- assertTrue(n5)
- val n6 = null.asInstanceOf[Int] == null
- assertFalse(n6)
- val n7 = null.asInstanceOf[Int] != 0
- assertFalse(n7)
- val n8 = null.asInstanceOf[Int] != null
- assertTrue(n8)
-
- val mp = new java.util.HashMap[Int, Int]
- val n9 = mp.get(0)
- assertEquals(n9, 0)
- val n10 = mp.get(0) == null // SI-602
- assertThrows[AssertionError](assertFalse(n10)) // should not throw
-
- def f(a: Any) = "" + a
- val n11 = f(null.asInstanceOf[Int])
- assertEquals(n11, "0")
+ // Once we use 2.12.0-M5 as starr, this code can be run directly in the JUnit test.
+ // Some fixes not yet available in M4 make the test fail when compiled with M4.
+ val code =
+ """import scala.tools.testing.AssertUtil._
+ |import org.junit.Assert._
+ |
+ |def genericNull[T] = null.asInstanceOf[T] // allowed, see SI-4437, point 2
+ |
+ |val b = new Integer(1)
+ |val u = 1
+ |
+ |assertEquals(1.toInt, u)
+ |
+ |assertEquals(Predef.int2Integer(1), b)
+ |assertEquals(1: Integer, b)
+ |assertEquals(Int.box(1), b)
+ |assertEquals(1.asInstanceOf[Object], b)
+ |
+ |assertThrows[ClassCastException]("".asInstanceOf[Integer])
+ |
+ |assertEquals(Predef.Integer2int(b), u)
+ |assertEquals(b: Int, u)
+ |assertEquals(Int.unbox(b), u)
+ |assertEquals(b.asInstanceOf[Int], u)
+ |assertEquals(b.intValue, u)
+ |assertEquals(b.toInt, u)
+ |intWrapper(b).toInt
+ |
+ |assertThrows[ClassCastException](Int.unbox(""))
+ |assertThrows[ClassCastException]("".asInstanceOf[Int])
+ |
+ |// null unboxing in various positions
+ |
+ |val n1 = Int.unbox(null)
+ |assertEquals(n1, 0)
+ |val n2 = Predef.Integer2int(null)
+ |assertEquals(n2, 0)
+ |val n3 = (null: Integer): Int
+ |assertEquals(n3, 0)
+ |val n4 = null.asInstanceOf[Int]
+ |assertEquals(n4, 0)
+ |val n5 = null.asInstanceOf[Int] == 0
+ |assertTrue(n5)
+ |val n6 = null.asInstanceOf[Int] == null
+ |assertFalse(n6)
+ |val n7 = null.asInstanceOf[Int] != 0
+ |assertFalse(n7)
+ |val n8 = null.asInstanceOf[Int] != null
+ |assertTrue(n8)
+ |
+ |val mp = new java.util.HashMap[Int, Int]
+ |val n9 = mp.get(0)
+ |assertEquals(n9, 0)
+ |val n10 = mp.get(0) == null // SI-602
+ |assertThrows[AssertionError](assertFalse(n10)) // should not throw
+ |
+ |def f(a: Any) = "" + a
+ |val n11 = f(null.asInstanceOf[Int])
+ |assertEquals(n11, "0")
+ |
+ |def n12 = genericNull[Int]
+ |assertEquals(n12, 0)
+ """.stripMargin
- def n12 = genericNull[Int]
- assertEquals(n12, 0)
+ run[Unit](code)
}
@Test
def numericConversions(): Unit = {
- val i1 = 1L.asInstanceOf[Int]
- assertEquals(i1, 1)
- assertThrows[ClassCastException] {
- val i2 = (1L: Any).asInstanceOf[Int] // SI-1448, should not throw. see also SI-4437 point 1.
- assertEquals(i2, 1)
- }
+ // Once we use 2.12.0-M5 as starr, this code can be run directly in the JUnit test.
+ val code =
+ """import scala.tools.testing.AssertUtil._
+ |import org.junit.Assert._
+ |
+ |val i1 = 1L.asInstanceOf[Int]
+ |assertEquals(i1, 1)
+ |assertThrows[ClassCastException] {
+ | val i2 = (1L: Any).asInstanceOf[Int] // SI-1448, should not throw. see also SI-4437 point 1.
+ | assertEquals(i2, 1)
+ |}
+ """.stripMargin
+ run[Unit](code)
}
@Test
def boxUnboxBoolean(): Unit = {
- val n1 = Option(null.asInstanceOf[Boolean])
- assertEquals(n1, Some(false))
+ // Once we use 2.12.0-M5 as starr, this code can be run directly in the JUnit test.
+ val code =
+ """val n1 = Option(null.asInstanceOf[Boolean])
+ |n1
+ """.stripMargin
+ assertEquals(run[Option[Boolean]](code), Some(false))
}
@Test
@@ -99,33 +118,41 @@ class BoxUnboxTest extends RunTesting {
// as Any. passing a Unit as Any makes the compiler go through another layer of boxing, so it
// can hide some bugs (where we actually have a null, but the compiler makes it a ()).
- var v = 0
- def eff() = { v = 1 }
- def chk() = { assert(v == 1); v = 0 }
-
- val b = runtime.BoxedUnit.UNIT
-
- assert(eff() == b); chk()
- assert(Unit.box(eff()) == b); chk()
- assert(().asInstanceOf[Object] == b)
-
- Unit.unbox({eff(); b}); chk()
- Unit.unbox({eff(); null}); chk()
- assertThrows[ClassCastException](Unit.unbox({eff(); ""})); chk()
-
- val n1 = null.asInstanceOf[Unit]
- assert(n1 == b)
-
- val n2 = null.asInstanceOf[Unit] == b
- assert(n2)
-
- def f(a: Any) = "" + a
- val n3 = f(null.asInstanceOf[Unit])
- assertEquals(n3, "()")
+ // Once we use 2.12.0-M5 as starr, this code can be run directly in the JUnit test.
+ val code =
+ """import scala.tools.testing.AssertUtil._
+ |import org.junit.Assert._
+ |
+ |var v = 0
+ |def eff() = { v = 1 }
+ |def chk() = { assert(v == 1); v = 0 }
+ |
+ |val b = runtime.BoxedUnit.UNIT
+ |
+ |assert(eff() == b); chk()
+ |assert(Unit.box(eff()) == b); chk()
+ |assert(().asInstanceOf[Object] == b)
+ |
+ |Unit.unbox({eff(); b}); chk()
+ |Unit.unbox({eff(); null}); chk()
+ |assertThrows[ClassCastException](Unit.unbox({eff(); ""})); chk()
+ |
+ |val n1 = null.asInstanceOf[Unit]
+ |assert(n1 == b)
+ |
+ |val n2 = null.asInstanceOf[Unit] == b
+ |assert(n2)
+ |
+ |def f(a: Any) = "" + a
+ |val n3 = f(null.asInstanceOf[Unit])
+ |assertEquals(n3, "()")
+ """.stripMargin
+ run[Unit](code)
}
@Test
def t9671(): Unit = {
+ // Once we use 2.12.0-M5 as starr, this code can be run directly in the JUnit test.
val code =
"""import scala.lang.primitives.BoxUnboxTest.VCI
|
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/BTypesFromClassfileTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/BTypesFromClassfileTest.scala
index 1169871ecd..e7aea71e72 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/BTypesFromClassfileTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/BTypesFromClassfileTest.scala
@@ -2,7 +2,7 @@ package scala.tools.nsc
package backend.jvm
package opt
-import org.junit.Test
+import org.junit.{Ignore, Test}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -83,7 +83,9 @@ class BTypesFromClassfileTest extends BytecodeTesting {
sameBType(fromSymbol, fromClassfile)
}
- @Test
+ // Can be enabled when using 2.12.0-M5 as starr. This test works under a full boostrap, but not
+ // when compiled with M4.
+ @Test @Ignore
def compareClassBTypes(): Unit = {
// Note that not only these classes are tested, but also all their parents and all nested
// classes in their InnerClass attributes.
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala
index 24e889cf18..4e014d4529 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala
@@ -3,7 +3,7 @@ package backend.jvm
package opt
import org.junit.Assert._
-import org.junit.Test
+import org.junit.{Ignore, Test}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -1488,7 +1488,9 @@ class InlinerTest extends BytecodeTesting {
assertSameSummary(getMethod(c, "t"), List(NEW, "<init>", ICONST_1, IRETURN)) // ICONST_1, U.f is inlined (not T.f)
}
- @Test
+ // Can be enabled when using 2.12.0-M5 as starr. This test works under a full boostrap, but not
+ // when compiled with M4.
+ @Test @Ignore
def inlineArrayForeach(): Unit = {
val code =
"""class C {