diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t6162-inheritance.check | 8 | ||||
-rw-r--r-- | test/files/run/t8574.scala | 27 | ||||
-rw-r--r-- | test/files/run/t8601-closure-elim.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8601-closure-elim.scala | 26 | ||||
-rw-r--r-- | test/files/run/t8601.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8601.scala | 15 | ||||
-rw-r--r-- | test/files/run/t8601b.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8601b.scala | 14 | ||||
-rw-r--r-- | test/files/run/t8601c.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8601c.scala | 12 | ||||
-rw-r--r-- | test/files/run/t8601d.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8601d.scala | 8 | ||||
-rw-r--r-- | test/files/run/t8601e.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8601e/StaticInit.class | bin | 0 -> 417 bytes | |||
-rw-r--r-- | test/files/run/t8601e/StaticInit.java | 8 | ||||
-rw-r--r-- | test/files/run/t8601e/Test.scala | 12 | ||||
-rw-r--r-- | test/junit/scala/StringContextTest.scala | 51 |
17 files changed, 180 insertions, 7 deletions
diff --git a/test/files/neg/t6162-inheritance.check b/test/files/neg/t6162-inheritance.check index 13c78030d9..c9f4ddaec1 100644 --- a/test/files/neg/t6162-inheritance.check +++ b/test/files/neg/t6162-inheritance.check @@ -7,12 +7,6 @@ object SubT extends T usage.scala:8: warning: inheritance from trait S in package t6126 is deprecated new S { ^ -usage.scala:3: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version. -class SubFoo extends Foo - ^ -usage.scala:5: warning: inheritance from trait T in package t6126 is deprecated -object SubT extends T - ^ error: No warnings can be incurred under -Xfatal-warnings. -5 warnings found +three warnings found one error found diff --git a/test/files/run/t8574.scala b/test/files/run/t8574.scala new file mode 100644 index 0000000000..8c23ada482 --- /dev/null +++ b/test/files/run/t8574.scala @@ -0,0 +1,27 @@ +import annotation._ + +@SerialVersionUID(42) @strictfp class Foo[@specialized(Int) T] extends Serializable { + def foo(t: T) = t +} + +object Test extends App { + def checkUID(cls: Class[_], expected: Long) = { + val actual = java.io.ObjectStreamClass.lookup(cls).getSerialVersionUID + assert(actual == expected, s"$actual != expected for ${cls}") + } + def checkStrictFp(cls: Class[_]) = { + import java.lang.reflect._ + for (m <- cls.getDeclaredMethods) { + val isStrict = Modifier.isStrict(m.getModifiers) + assert(isStrict, cls) + } + } + def check(x: AnyRef) { + checkUID(x.getClass, 42) + checkStrictFp(x.getClass) + } + + check(new Foo[String]) + check(new Foo[Int]) +} + diff --git a/test/files/run/t8601-closure-elim.flags b/test/files/run/t8601-closure-elim.flags new file mode 100644 index 0000000000..49d036a887 --- /dev/null +++ b/test/files/run/t8601-closure-elim.flags @@ -0,0 +1 @@ +-optimize diff --git a/test/files/run/t8601-closure-elim.scala b/test/files/run/t8601-closure-elim.scala new file mode 100644 index 0000000000..2c5b03af77 --- /dev/null +++ b/test/files/run/t8601-closure-elim.scala @@ -0,0 +1,26 @@ +import scala.tools.partest.BytecodeTest +import scala.tools.asm +import scala.tools.asm.util._ +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + val nullChecks = Set(asm.Opcodes.NEW) + + def show: Unit = { + def test(methodName: String) { + val classNode = loadClassNode("Foo") + val methodNode = getMethod(classNode, "b") + val ops = methodNode.instructions.iterator.asScala.map(_.getOpcode).toList + assert(!ops.contains(asm.Opcodes.NEW), ops)// should be allocation free if the closure is eliminiated + } + test("b") + } +} + +class Foo { + @inline final def a(x: Int => Int) = x(1) + final def b { + val delta = 0 + a(x => delta + 1) + } +} diff --git a/test/files/run/t8601.flags b/test/files/run/t8601.flags new file mode 100644 index 0000000000..1182725e86 --- /dev/null +++ b/test/files/run/t8601.flags @@ -0,0 +1 @@ +-optimize
\ No newline at end of file diff --git a/test/files/run/t8601.scala b/test/files/run/t8601.scala new file mode 100644 index 0000000000..e1afc23cc4 --- /dev/null +++ b/test/files/run/t8601.scala @@ -0,0 +1,15 @@ +object Test { + def idiv(x: Int): Unit = x / 0 + def ldiv(x: Long): Unit = x / 0 + def irem(x: Int): Unit = x % 0 + def lrem(x: Long): Unit = x % 0 + + def check(x: => Any) = try { x; sys.error("failed to throw divide by zero!") } catch { case _: ArithmeticException => } + + def main(args: Array[String]) { + check(idiv(1)) + check(ldiv(1L)) + check(irem(1)) + check(lrem(1L)) + } +} diff --git a/test/files/run/t8601b.flags b/test/files/run/t8601b.flags new file mode 100644 index 0000000000..1182725e86 --- /dev/null +++ b/test/files/run/t8601b.flags @@ -0,0 +1 @@ +-optimize
\ No newline at end of file diff --git a/test/files/run/t8601b.scala b/test/files/run/t8601b.scala new file mode 100644 index 0000000000..9c37ce33d6 --- /dev/null +++ b/test/files/run/t8601b.scala @@ -0,0 +1,14 @@ +object Test { + def len(x: Array[String]): Unit = x.length + def load(x: Array[String]): Unit = x(0) + def newarray(i: Int): Unit = new Array[Int](i) + + def check(x: => Any) = try { x; sys.error("failed to throw NPE!") } catch { case _: NullPointerException => } + def checkNegSize(x: => Any) = try { x; sys.error("failed to throw NegativeArraySizeException!") } catch { case _: NegativeArraySizeException => } + + def main(args: Array[String]) { + check(len(null)) // bug: did not NPE + check(load(null)) + checkNegSize(newarray(-1)) + } +} diff --git a/test/files/run/t8601c.flags b/test/files/run/t8601c.flags new file mode 100644 index 0000000000..1182725e86 --- /dev/null +++ b/test/files/run/t8601c.flags @@ -0,0 +1 @@ +-optimize
\ No newline at end of file diff --git a/test/files/run/t8601c.scala b/test/files/run/t8601c.scala new file mode 100644 index 0000000000..c487d6825e --- /dev/null +++ b/test/files/run/t8601c.scala @@ -0,0 +1,12 @@ +object Test { + def loadField(x: scala.runtime.IntRef): Unit = x.elem + def storeField(x: scala.runtime.IntRef): Unit = x.elem = 42 + + def check(x: => Any) = try { x; sys.error("failed to throw NPE!") } catch { case _: NullPointerException => } + + def main(args: Array[String]) { + check(loadField(null)) // bug: did not NPE under -Ydead-code + check(storeField(null)) + + } +} diff --git a/test/files/run/t8601d.flags b/test/files/run/t8601d.flags new file mode 100644 index 0000000000..1182725e86 --- /dev/null +++ b/test/files/run/t8601d.flags @@ -0,0 +1 @@ +-optimize
\ No newline at end of file diff --git a/test/files/run/t8601d.scala b/test/files/run/t8601d.scala new file mode 100644 index 0000000000..ac89963d67 --- /dev/null +++ b/test/files/run/t8601d.scala @@ -0,0 +1,8 @@ +object Test { + def monitor(x: AnyRef): Unit = {x.synchronized(()); ()} + def check(x: => Any) = try { x; sys.error("failed to throw NPE") } catch { case _: NullPointerException => } + + def main(args: Array[String]) { + check(monitor(null)) + } +} diff --git a/test/files/run/t8601e.flags b/test/files/run/t8601e.flags new file mode 100644 index 0000000000..49d036a887 --- /dev/null +++ b/test/files/run/t8601e.flags @@ -0,0 +1 @@ +-optimize diff --git a/test/files/run/t8601e/StaticInit.class b/test/files/run/t8601e/StaticInit.class Binary files differnew file mode 100644 index 0000000000..99a0e2a643 --- /dev/null +++ b/test/files/run/t8601e/StaticInit.class diff --git a/test/files/run/t8601e/StaticInit.java b/test/files/run/t8601e/StaticInit.java new file mode 100644 index 0000000000..7543ed98b8 --- /dev/null +++ b/test/files/run/t8601e/StaticInit.java @@ -0,0 +1,8 @@ +public class StaticInit { + static { + if ("".isEmpty()) { + throw new RuntimeException(); + } + } + public static int fld = 42; +} diff --git a/test/files/run/t8601e/Test.scala b/test/files/run/t8601e/Test.scala new file mode 100644 index 0000000000..838114f6a7 --- /dev/null +++ b/test/files/run/t8601e/Test.scala @@ -0,0 +1,12 @@ +class C { + def foo: Unit = {StaticInit.fld} +} + +object Test extends App { + try { + new C().foo + sys.error("StaticInit.<clinit> was not run!") + } catch { + case t: ExceptionInInitializerError => + } +} diff --git a/test/junit/scala/StringContextTest.scala b/test/junit/scala/StringContextTest.scala new file mode 100644 index 0000000000..5abfe90cd1 --- /dev/null +++ b/test/junit/scala/StringContextTest.scala @@ -0,0 +1,51 @@ + +package scala + +import org.junit.Test +import org.junit.Assert._ +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.tools.testing.AssertUtil._ + +@RunWith(classOf[JUnit4]) +class StringContextTest { + + import StringContext._ + + @Test def noEscape() = { + val s = "string" + val res = processEscapes(s) + assertEquals(s, res) + } + @Test def tabbed() = { + val s = """a\tb""" + val res = processEscapes(s) + assertEquals("a\tb", res) + } + @Test def quoted() = { + val s = """hello, \"world\"""" + val res = processEscapes(s) + assertEquals("""hello, "world"""", res) + } + @Test def octal() = { + val s = """\123cala""" + val res = treatEscapes(s) + assertEquals("Scala", res) + } + @Test def doubled() = { + val s = """\123cala\123yntax""" + val res = treatEscapes(s) + assertEquals("ScalaSyntax", res) + } + @Test def badly() = assertThrows[InvalidEscapeException] { + val s = """Scala\""" + val res = treatEscapes(s) + assertEquals("Scala", res) + } + @Test def noOctal() = assertThrows[InvalidEscapeException] { + val s = """\123cala""" + val res = processEscapes(s) + assertEquals("Scala", res) + } +} |