diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t8630.check | 7 | ||||
-rw-r--r-- | test/files/neg/t8630.scala | 1 | ||||
-rw-r--r-- | test/files/run/analyzerPlugins.check | 13 | ||||
-rw-r--r-- | test/files/run/icode-reader-dead-code.check | 19 | ||||
-rw-r--r-- | test/files/run/icode-reader-dead-code.scala | 82 | ||||
-rw-r--r-- | test/files/run/repl-javap-app.check | 14 | ||||
-rw-r--r-- | test/files/run/repl-javap-app.scala | 11 | ||||
-rw-r--r-- | test/files/run/t7974.check | 29 | ||||
-rw-r--r-- | test/files/run/t7974/Test.scala | 2 | ||||
-rw-r--r-- | test/files/run/t8346.check | 6 | ||||
-rw-r--r-- | test/files/run/t8346.scala | 34 | ||||
-rw-r--r-- | test/files/run/t8607.scala | 36 | ||||
-rw-r--r-- | test/files/run/t8637.check | 0 | ||||
-rw-r--r-- | test/files/run/t8637.scala | 9 | ||||
-rw-r--r-- | test/junit/scala/collection/IndexedSeqOptimizedTest.scala | 16 | ||||
-rw-r--r-- | test/junit/scala/collection/IteratorTest.scala | 8 | ||||
-rw-r--r-- | test/junit/scala/reflect/internal/NamesTest.scala | 95 | ||||
-rw-r--r-- | test/junit/scala/reflect/internal/util/SourceFileTest.scala | 5 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala | 104 | ||||
-rw-r--r-- | test/junit/scala/tools/testing/AssertUtil.scala | 17 |
20 files changed, 458 insertions, 50 deletions
diff --git a/test/files/neg/t8630.check b/test/files/neg/t8630.check new file mode 100644 index 0000000000..98b084b153 --- /dev/null +++ b/test/files/neg/t8630.check @@ -0,0 +1,7 @@ +t8630.scala:1: error: '{' expected but 'abstract' found. +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) } + ^ +t8630.scala:1: error: '}' expected but eof found. +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) } + ^ +two errors found diff --git a/test/files/neg/t8630.scala b/test/files/neg/t8630.scala new file mode 100644 index 0000000000..ea25227452 --- /dev/null +++ b/test/files/neg/t8630.scala @@ -0,0 +1 @@ +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) }
\ No newline at end of file diff --git a/test/files/run/analyzerPlugins.check b/test/files/run/analyzerPlugins.check index e3ab554d4c..9803465ddc 100644 --- a/test/files/run/analyzerPlugins.check +++ b/test/files/run/analyzerPlugins.check @@ -19,7 +19,7 @@ canAdaptAnnotations(Trees$Typed, Any) [1] canAdaptAnnotations(Trees$Typed, Int) [1] lub(List(Int @testAnn, Int)) [1] pluginsPt(?, Trees$Annotated) [7] -pluginsPt(?, Trees$Apply) [9] +pluginsPt(?, Trees$Apply) [8] pluginsPt(?, Trees$ApplyImplicitView) [2] pluginsPt(?, Trees$Assign) [7] pluginsPt(?, Trees$Block) [4] @@ -31,13 +31,13 @@ pluginsPt(?, Trees$Literal) [16] pluginsPt(?, Trees$New) [5] pluginsPt(?, Trees$PackageDef) [1] pluginsPt(?, Trees$Return) [1] -pluginsPt(?, Trees$Select) [48] +pluginsPt(?, Trees$Select) [47] pluginsPt(?, Trees$Super) [2] pluginsPt(?, Trees$This) [20] -pluginsPt(?, Trees$TypeApply) [4] +pluginsPt(?, Trees$TypeApply) [3] pluginsPt(?, Trees$TypeBoundsTree) [2] pluginsPt(?, Trees$TypeDef) [1] -pluginsPt(?, Trees$TypeTree) [39] +pluginsPt(?, Trees$TypeTree) [38] pluginsPt(?, Trees$Typed) [1] pluginsPt(?, Trees$ValDef) [21] pluginsPt(Any, Trees$Literal) [2] @@ -98,7 +98,6 @@ pluginsTyped(()String, Trees$Ident) [1] pluginsTyped(()String, Trees$TypeApply) [1] pluginsTyped(()scala.annotation.Annotation, Trees$Select) [1] pluginsTyped(()testAnn, Trees$Select) [10] -pluginsTyped(()type, Trees$TypeApply) [1] pluginsTyped((str: String)A <and> (param: Double)A, Trees$Select) [1] pluginsTyped((x$1: Any)Boolean <and> (x: Double)Boolean <and> (x: Float)Boolean <and> (x: Long)Boolean <and> (x: Int)Boolean <and> (x: Char)Boolean <and> (x: Short)Boolean <and> (x: Byte)Boolean, Trees$Select) [1] pluginsTyped((x$1: Int)Unit, Trees$Select) [1] @@ -173,7 +172,7 @@ pluginsTyped(Unit, Trees$Literal) [5] pluginsTyped(Unit, Trees$TypeTree) [1] pluginsTyped([A](xs: A*)List[A], Trees$Select) [1] pluginsTyped([T <: Int]=> Int, Trees$Select) [1] -pluginsTyped([T0]()T0, Trees$Select) [2] +pluginsTyped([T0]()T0, Trees$Select) [1] pluginsTyped([T](xs: Array[T])scala.collection.mutable.WrappedArray[T], Trees$Select) [1] pluginsTyped(annotation.type, Trees$Select) [4] pluginsTyped(math.type, Trees$Select) [9] @@ -190,7 +189,5 @@ pluginsTyped(testAnn, Trees$New) [5] pluginsTyped(testAnn, Trees$This) [1] pluginsTyped(testAnn, Trees$TypeTree) [2] pluginsTyped(testAnn.super.type, Trees$Super) [1] -pluginsTyped(type, Trees$Apply) [1] pluginsTyped(type, Trees$Select) [1] -pluginsTyped(type, Trees$TypeTree) [1] pluginsTypedReturn(return f, String) [1] diff --git a/test/files/run/icode-reader-dead-code.check b/test/files/run/icode-reader-dead-code.check new file mode 100644 index 0000000000..d1739fed3b --- /dev/null +++ b/test/files/run/icode-reader-dead-code.check @@ -0,0 +1,19 @@ +Bytecode for method f + L0 + LINENUMBER 4 L0 + ICONST_1 + IRETURN + L1 + LOCALVARIABLE this Lp/A; L0 L1 0 + MAXSTACK = 1 + MAXLOCALS = 1 +Bytecode for method f + L0 + LINENUMBER 4 L0 + ICONST_1 + ATHROW + IRETURN + L1 + LOCALVARIABLE this Lp/A; L0 L1 0 + MAXSTACK = 1 + MAXLOCALS = 1 diff --git a/test/files/run/icode-reader-dead-code.scala b/test/files/run/icode-reader-dead-code.scala new file mode 100644 index 0000000000..00ba58829f --- /dev/null +++ b/test/files/run/icode-reader-dead-code.scala @@ -0,0 +1,82 @@ +import java.io.{FileOutputStream, FileInputStream} + +import scala.tools.asm.{ClassWriter, Opcodes, ClassReader} +import scala.tools.asm.tree.{InsnNode, ClassNode} +import scala.tools.nsc.backend.jvm.AsmUtils +import scala.tools.partest.DirectTest +import scala.collection.JavaConverters._ + +/** + * Test that the ICodeReader does not crash if the bytecode of a method has unreachable code. + */ +object Test extends DirectTest { + def code: String = ??? + + def show(): Unit = { + // The bytecode of f will be modified using ASM by `addDeadCode` + val aCode = + """ + |package p + |class A { + | @inline final def f = 1 + |} + """.stripMargin + + val bCode = + """ + |package p + |class B { + | def g = (new A()).f + |} + """.stripMargin + + compileString(newCompiler("-usejavacp"))(aCode) + + addDeadCode() + + // If inlining fails, the compiler will issue an inliner warning that is not present in the + // check file + compileString(newCompiler("-usejavacp", "-optimise"))(bCode) + } + + def readClass(file: String) = { + val cnode = new ClassNode() + val is = new FileInputStream(file) + val reader = new ClassReader(is) + reader.accept(cnode, 0) + is.close() + cnode + } + + def writeClass(file: String, cnode: ClassNode): Unit = { + val writer = new ClassWriter(0) + cnode.accept(writer) + + val os = new FileOutputStream(file) + os.write(writer.toByteArray) + os.close() + } + + def addDeadCode() { + val file = (testOutput / "p" / "A.class").path + val cnode = readClass(file) + val method = cnode.methods.asScala.find(_.name == "f").head + + AsmUtils.traceMethod(method) + + val insns = method.instructions + val it = insns.iterator() + while (it.hasNext) { + val in = it.next() + if (in.getOpcode == Opcodes.IRETURN) { + // Insert an ATHROW before the IRETURN. The IRETURN will then be dead code. + // The ICodeReader should not crash if there's dead code. + insns.insert(in.getPrevious, new InsnNode(Opcodes.ATHROW)) + } + } + + AsmUtils.traceMethod(method) + + writeClass(file, cnode) + } +} diff --git a/test/files/run/repl-javap-app.check b/test/files/run/repl-javap-app.check index 490860585c..b7e806cc0b 100644 --- a/test/files/run/repl-javap-app.check +++ b/test/files/run/repl-javap-app.check @@ -1,4 +1,5 @@ #partest java6 +Welcome to Scala Type in expressions to have them evaluated. Type :help for more information. @@ -6,9 +7,9 @@ scala> :javap -app MyApp$ public final void delayedEndpoint$MyApp$1(); Code: Stack=2, Locals=1, Args_size=1 - 0: getstatic #61; //Field scala/Console$.MODULE$:Lscala/Console$; - 3: ldc #63; //String Hello, delayed world. - 5: invokevirtual #67; //Method scala/Console$.println:(Ljava/lang/Object;)V + 0: getstatic #XX; //Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX; //String Hello, delayed world. + 5: invokevirtual #XX; //Method scala/Console$.println:(Ljava/lang/Object;)V 8: return LocalVariableTable: Start Length Slot Name Signature @@ -16,6 +17,7 @@ public final void delayedEndpoint$MyApp$1(); scala> #partest !java6 +Welcome to Scala Type in expressions to have them evaluated. Type :help for more information. @@ -24,9 +26,9 @@ scala> :javap -app MyApp$ flags: ACC_PUBLIC, ACC_FINAL Code: stack=2, locals=1, args_size=1 - 0: getstatic #61 // Field scala/Console$.MODULE$:Lscala/Console$; - 3: ldc #63 // String Hello, delayed world. - 5: invokevirtual #67 // Method scala/Console$.println:(Ljava/lang/Object;)V + 0: getstatic #XX // Field scala/Console$.MODULE$:Lscala/Console$; + 3: ldc #XX // String Hello, delayed world. + 5: invokevirtual #XX // Method scala/Console$.println:(Ljava/lang/Object;)V 8: return LocalVariableTable: Start Length Slot Name Signature diff --git a/test/files/run/repl-javap-app.scala b/test/files/run/repl-javap-app.scala index be04920be1..ad6076c2d5 100644 --- a/test/files/run/repl-javap-app.scala +++ b/test/files/run/repl-javap-app.scala @@ -7,4 +7,15 @@ object MyApp extends App { object Test extends ReplTest { def code = ":javap -app MyApp$" + + override def welcoming = true + + // The constant pool indices are not the same for GenASM / GenBCode, so + // replacing the exact numbers by XX. + lazy val hasConstantPoolRef = """(.*)(#\d\d)(.*)""".r + + override def normalize(s: String) = s match { + case hasConstantPoolRef(start, ref, end) => start + "#XX" + end + case _ => super.normalize(s) + } } diff --git a/test/files/run/t7974.check b/test/files/run/t7974.check index 0be496d8d0..d8152d3286 100644 --- a/test/files/run/t7974.check +++ b/test/files/run/t7974.check @@ -1,6 +1,5 @@ public class Symbols { - // compiled from: Symbols.scala @@ -18,20 +17,14 @@ public class Symbols { // access flags 0x9 public static <clinit>()V - L0 - LINENUMBER 2 L0 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic1" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; PUTSTATIC Symbols.symbol$1 : Lscala/Symbol; - L1 - LINENUMBER 3 L1 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic2" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; PUTSTATIC Symbols.symbol$2 : Lscala/Symbol; - L2 - LINENUMBER 5 L2 GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; LDC "Symbolic3" INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; @@ -42,63 +35,41 @@ public class Symbols { // access flags 0x1 public someSymbol1()Lscala/Symbol; - L0 - LINENUMBER 2 L0 GETSTATIC Symbols.symbol$1 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public someSymbol2()Lscala/Symbol; - L0 - LINENUMBER 3 L0 GETSTATIC Symbols.symbol$2 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public sameSymbol1()Lscala/Symbol; - L0 - LINENUMBER 4 L0 GETSTATIC Symbols.symbol$1 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public someSymbol3()Lscala/Symbol; - L0 - LINENUMBER 5 L0 ALOAD 0 GETFIELD Symbols.someSymbol3 : Lscala/Symbol; ARETURN - L1 - LOCALVARIABLE this LSymbols; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public <init>()V - L0 - LINENUMBER 6 L0 ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V - L1 - LINENUMBER 5 L1 ALOAD 0 GETSTATIC Symbols.symbol$3 : Lscala/Symbol; PUTFIELD Symbols.someSymbol3 : Lscala/Symbol; RETURN - L2 - LOCALVARIABLE this LSymbols; L0 L2 0 MAXSTACK = 2 MAXLOCALS = 1 } diff --git a/test/files/run/t7974/Test.scala b/test/files/run/t7974/Test.scala index 433d9061a7..29d2b9cb64 100644 --- a/test/files/run/t7974/Test.scala +++ b/test/files/run/t7974/Test.scala @@ -6,7 +6,7 @@ import scala.tools.nsc.util.stringFromWriter object Test extends BytecodeTest { def show { - val classNode = loadClassNode("Symbols", skipDebugInfo = false) + val classNode = loadClassNode("Symbols", skipDebugInfo = true) val textifier = new Textifier classNode.accept(new TraceClassVisitor(null, textifier, null)) diff --git a/test/files/run/t8346.check b/test/files/run/t8346.check new file mode 100644 index 0000000000..1ba5c31abe --- /dev/null +++ b/test/files/run/t8346.check @@ -0,0 +1,6 @@ +BitSet: List(invariant, invariant, invariant, invariant) +HashSet: List(covariant (true), covariant (true), covariant (true), covariant (true)) +ListSet: List(covariant (true), covariant (true), covariant (true), covariant (true)) +SortedSet: List(invariant, invariant, invariant, invariant) +TreeSet: List(invariant, invariant, invariant, invariant) +ValueSet: invariant diff --git a/test/files/run/t8346.scala b/test/files/run/t8346.scala new file mode 100644 index 0000000000..5f3df84174 --- /dev/null +++ b/test/files/run/t8346.scala @@ -0,0 +1,34 @@ +object Test extends App { + import reflect.ClassTag + + object SomeEnum extends Enumeration { + val one, two, three, four = Value + } + + def sctor[A <: Set[Int]](f: Int => A)(implicit A: ClassTag[A]) + : (String, Int => Set[Int]) = + (A.runtimeClass.getSimpleName, f) + + val inits: Seq[(String, Int => Set[Int])] = { + import collection.immutable.{Seq => _, _} + Seq(sctor(BitSet(_)), + sctor(HashSet(_)), + sctor(ListSet(_)), + sctor(SortedSet(_)), + sctor(TreeSet(_))) + } + + def sVarInfo[A](sa: Set[A]): String = { + val saa = sa.toSet[Any] + if (sa eq saa) s"""covariant (${(saa + "hi") contains "hi"})""" + else "invariant" + } + + inits foreach {case (name, singleton) => + print(s"${name}: ") + val one = singleton(1) + println(Seq(2,3,4).scanLeft(one)(_ + _) map sVarInfo toList) + } + + println(s"ValueSet: ${sVarInfo(SomeEnum.values)}") +} diff --git a/test/files/run/t8607.scala b/test/files/run/t8607.scala new file mode 100644 index 0000000000..1b8ef9bbd0 --- /dev/null +++ b/test/files/run/t8607.scala @@ -0,0 +1,36 @@ +package p1 { + private[p1] trait B extends Any { + def a: Any = "" + } + + class C(val value: Int) extends AnyVal with B { + // def b = "" + } +} + +object Test { + def main(args: Array[String]) { + val c = new p1.C(42) + c.a + /* + new p1.C.<init>( + c.$asInstanceOf[scala.this.Int]() + ).a(); + + + new p1.C.<init>( + new p1.C.<init>( + c.$asInstanceOf[scala.this.Int]() + ).$asInstanceOf[ErasedValueType(class C, scala.this.Int)]() + .$asInstanceOf[scala.this.Int]() + ).a(); + + new p1.C.<init>( + new p1.C.<init>(c) + .$asInstanceOf[scala.this.Int]() + .$asInstanceOf[scala.this.Int]() + ).a(); + + */ + } +} diff --git a/test/files/run/t8637.check b/test/files/run/t8637.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/t8637.check diff --git a/test/files/run/t8637.scala b/test/files/run/t8637.scala new file mode 100644 index 0000000000..99c8d4c413 --- /dev/null +++ b/test/files/run/t8637.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.currentMirror +import scala.tools.reflect.ToolBox + +object Test extends App { + val tb = currentMirror.mkToolBox() + tb.compile(q"true > true") + tb.typecheck(q"true > true") +}
\ No newline at end of file diff --git a/test/junit/scala/collection/IndexedSeqOptimizedTest.scala b/test/junit/scala/collection/IndexedSeqOptimizedTest.scala new file mode 100644 index 0000000000..e5382907af --- /dev/null +++ b/test/junit/scala/collection/IndexedSeqOptimizedTest.scala @@ -0,0 +1,16 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert._ +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class IndexedSeqOptimizedTest { + + @Test + def notThrowsAnExceptionInLastIndexOf() { + assertEquals(0, (Array(2): collection.mutable.WrappedArray[Int]).lastIndexWhere(_ => true, 1)) + assertEquals(2, "abc123".lastIndexWhere(_.isLetter, 6)) + } +} diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala index cb7cbb40bc..b7a9805c9f 100644 --- a/test/junit/scala/collection/IteratorTest.scala +++ b/test/junit/scala/collection/IteratorTest.scala @@ -17,4 +17,12 @@ class IteratorTest { slidingIt.next assertEquals("Counter should be one, that means we didn't look further than needed", 1, counter) } + + @Test def groupedIteratorIsLazyWhenPadded(): Unit = { + var counter = 0 + def it = new Iterator[Int] { var i = 0 ; def hasNext = { counter = i; true } ; def next = { i += 1; i } } + val slidingIt = it sliding 2 withPadding -1 + slidingIt.next + assertEquals("Counter should be one, that means we didn't look further than needed", 1, counter) + } } diff --git a/test/junit/scala/reflect/internal/NamesTest.scala b/test/junit/scala/reflect/internal/NamesTest.scala new file mode 100644 index 0000000000..549c10abed --- /dev/null +++ b/test/junit/scala/reflect/internal/NamesTest.scala @@ -0,0 +1,95 @@ +package scala.reflect.internal + +import scala.tools.testing.AssertUtil._ +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import org.junit.Assert._ +import scala.tools.nsc.symtab.SymbolTableForUnitTesting + +@RunWith(classOf[JUnit4]) +class NamesTest { + object symbolTable extends SymbolTableForUnitTesting + import symbolTable._ + + val h1 = newTermName("hai") + val h2 = newTermName("hai") + val f = newTermName("fisch") + + val h1y = h1.toTypeName + val h2y = newTypeName("hai") + val fy = newTypeName("fisch") + + val uy = newTypeName("uhu") + val u = uy.toTermName // calling toTermName after constructing a typeName. This tests the fact + // that creating a typeName always also first creates a termName. There is + // an assertion for that in toTermName. + + @Test + def termNamesAreHashConsed() { + assertTrue(h1 eq h2) + assertEquals(h1, h2) + assertTrue(h1 ne f) + assertTrue(h1 != f) + } + + @Test + def termNamesNotEqualsTypeNames() { + assert(h1 ne h1y) + assert(h1 != h1y) + assert(h2 ne h2y) + assert(h2 != h2y) + } + + @Test + def termNamesTypeNamesSameRange() { + assert(h1.start == h1y.start && h1.length == h1y.length) + assert(h2.start == h2y.start && h2.length == h2y.length) + assert(u.start == uy.start && u.length == uy.length) + } + + @Test + def testLookupTypeName() { + assert(lookupTypeName("hai".toCharArray) eq h1y) + assert(lookupTypeName("fisch".toCharArray) eq fy) + assert(lookupTypeName("uhu".toCharArray) eq uy) + + assertThrows[AssertionError](lookupTypeName("dog".toCharArray), _ contains "not yet created") + val d = newTermName("dog") + assertThrows[AssertionError](lookupTypeName("dog".toCharArray), _ contains "not yet created") + val dy = d.toTypeName + assert(lookupTypeName("dog".toCharArray) eq dy) + } + + @Test + def emptyName() { + val z = newTermName("") + val zy = z.toTypeName + assertEquals(z.toString, "") + assertEquals(zy.toString, "") + assert(z eq newTermName("")) + assert(zy eq newTypeName("")) + } + + @Test + def subNameTest() { + val i = f.subName(1, f.length) + assert(i.start == (f.start + 1) && i.length == (f.length - 1)) + assert(f.subName(0, f.length) eq f) + + val iy = fy.subName(1, fy.length) + assert(iy.start == (fy.start + 1) && iy.length == (fy.length - 1)) + assert(fy.subName(0, fy.length) eq fy) + + assert(f.subName(1,1) eq newTermName("")) + assert(f.subName(1, 0) eq newTermName("")) + + assertThrows[IllegalArgumentException](f.subName(0 - f.start - 1, 1)) + } + + @Test + def stringEqualsTest() { + assert(h1 string_== h2) + assert(h1 string_== h1y) + } +} diff --git a/test/junit/scala/reflect/internal/util/SourceFileTest.scala b/test/junit/scala/reflect/internal/util/SourceFileTest.scala index 903e705ba2..cad23eba14 100644 --- a/test/junit/scala/reflect/internal/util/SourceFileTest.scala +++ b/test/junit/scala/reflect/internal/util/SourceFileTest.scala @@ -17,6 +17,11 @@ class SourceFileTest { assertFalse(file.isEndOfLine(Int.MaxValue)) } + @Test def si8630_lineToString(): Unit = { + val code = "abc " + assertEquals(code, new BatchSourceFile("", code).lineToString(0)) + } + @Test def si8205_lineToString(): Unit = { assertEquals("", lineContentOf("", 0)) diff --git a/test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala b/test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala new file mode 100644 index 0000000000..b592d06501 --- /dev/null +++ b/test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala @@ -0,0 +1,104 @@ +package scala.tools.nsc +package backend.jvm + +import scala.tools.testing.AssertUtil._ +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import scala.tools.asm.Opcodes +import org.junit.Assert._ + +@RunWith(classOf[JUnit4]) +class BTypesTest { + val g: Global = new Global(new Settings()) + + val btypes = new BTypes[g.type](g) { + def chrs = g.chrs + override type BTypeName = g.TypeName + override def createNewName(s: String) = g.newTypeName(s) + } + + import btypes._ + + val jls = "java/lang/String" + val jlo = "java/lang/Object" + + val o = ClassBType(jlo) + val s = ClassBType(jls) + val oArr = ArrayBType(o) + val method = MethodBType(List(oArr, INT, DOUBLE, s), UNIT) + + @Test + def classBTypesEquality() { + val s1 = ClassBType(jls) + val s2 = ClassBType(jls) + val o = ClassBType(jlo) + assertEquals(s1, s2) + assertEquals(s1.hashCode, s2.hashCode) + assert(s1 != o) + assert(s2 != o) + } + + @Test + def classBTypeRequiresInternalName() { + assertThrows[AssertionError](ClassBType(s"L$jls;"), _ contains "Descriptor instead of internal name") + } + + @Test + def typedOpcodes() { + assert(UNIT.typedOpcode(Opcodes.IALOAD) == Opcodes.IALOAD) + assert(INT.typedOpcode(Opcodes.IALOAD) == Opcodes.IALOAD) + assert(BOOL.typedOpcode(Opcodes.IALOAD) == Opcodes.BALOAD) + assert(BYTE.typedOpcode(Opcodes.IALOAD) == Opcodes.BALOAD) + assert(CHAR.typedOpcode(Opcodes.IALOAD) == Opcodes.CALOAD) + assert(SHORT.typedOpcode(Opcodes.IALOAD) == Opcodes.SALOAD) + assert(FLOAT.typedOpcode(Opcodes.IALOAD) == Opcodes.FALOAD) + assert(LONG.typedOpcode(Opcodes.IALOAD) == Opcodes.LALOAD) + assert(DOUBLE.typedOpcode(Opcodes.IALOAD) == Opcodes.DALOAD) + assert(ClassBType(jls).typedOpcode(Opcodes.IALOAD) == Opcodes.AALOAD) + + assert(UNIT.typedOpcode(Opcodes.IRETURN) == Opcodes.RETURN) + assert(BOOL.typedOpcode(Opcodes.IRETURN) == Opcodes.IRETURN) + assert(CHAR.typedOpcode(Opcodes.IRETURN) == Opcodes.IRETURN) + assert(BYTE.typedOpcode(Opcodes.IRETURN) == Opcodes.IRETURN) + assert(SHORT.typedOpcode(Opcodes.IRETURN) == Opcodes.IRETURN) + assert(INT.typedOpcode(Opcodes.IRETURN) == Opcodes.IRETURN) + assert(FLOAT.typedOpcode(Opcodes.IRETURN) == Opcodes.FRETURN) + assert(LONG.typedOpcode(Opcodes.IRETURN) == Opcodes.LRETURN) + assert(DOUBLE.typedOpcode(Opcodes.IRETURN) == Opcodes.DRETURN) + assert(ClassBType(jls).typedOpcode(Opcodes.IRETURN) == Opcodes.ARETURN) + } + + @Test + def descriptors() { + assert(o.descriptor == "Ljava/lang/Object;") + assert(s.descriptor == "Ljava/lang/String;") + assert(oArr.descriptor == "[Ljava/lang/Object;") + assert(method.descriptor == "([Ljava/lang/Object;IDLjava/lang/String;)V") + } + + @Test + def toAsmTypeTest() { + for (t <- List(o, s, oArr, method, INT, UNIT, DOUBLE)) { + assertEquals(o.descriptor, o.toASMType.getDescriptor) + } + } + + @Test + def parseMethodDescriptorTest() { + val descriptors = List( + "()V", + "(ID)I", + "([[I[D)[D", + s"(L$jls;[L$jlo;)[[L$jls;", + s"(IL$jlo;)L$jls;" + ) + for (d <- descriptors) { + assertEquals(d, MethodBType(d).descriptor) + } + + // class types in method descriptor need surrounding 'L' and ';' + assertThrows[MatchError](MethodBType("(java/lang/String)V"), _ == "j (of class java.lang.Character)") + assertThrows[AssertionError](MethodBType("I"), _ contains "Not a valid method descriptor") + } +} diff --git a/test/junit/scala/tools/testing/AssertUtil.scala b/test/junit/scala/tools/testing/AssertUtil.scala index 9efac64a97..9a97c5114f 100644 --- a/test/junit/scala/tools/testing/AssertUtil.scala +++ b/test/junit/scala/tools/testing/AssertUtil.scala @@ -5,15 +5,20 @@ package testing * that are ultimately based on junit.Assert primitives. */ object AssertUtil { - /** Check if exception T (or a subclass) was thrown during evaluation of f. - * If any other exception or throwable is found instead it will be re-thrown. + /** + * Check if throwable T (or a subclass) was thrown during evaluation of f, and that its message + * satisfies the `checkMessage` predicate. + * If any other exception will be re-thrown. */ - def assertThrows[T <: Exception](f: => Any)(implicit manifest: Manifest[T]): Unit = + def assertThrows[T <: Throwable](f: => Any, + checkMessage: String => Boolean = s => true) + (implicit manifest: Manifest[T]): Unit = { try f catch { - case e: Exception => - val clazz = manifest.erasure.asInstanceOf[Class[T]] + case e: Throwable if checkMessage(e.getMessage) => + val clazz = manifest.runtimeClass if (!clazz.isAssignableFrom(e.getClass)) throw e } -}
\ No newline at end of file + } +} |