diff options
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/classfile-format-51.scala | 8 | ||||
-rw-r--r-- | test/files/run/classfile-format-52.check | 2 | ||||
-rw-r--r-- | test/files/run/classfile-format-52.scala | 77 | ||||
-rw-r--r-- | test/files/run/t6481.check | 4 | ||||
-rw-r--r-- | test/files/run/t6481.scala | 13 | ||||
-rw-r--r-- | test/files/run/t7398.scala | 11 | ||||
-rw-r--r-- | test/files/run/t7558.scala | 9 |
7 files changed, 113 insertions, 11 deletions
diff --git a/test/files/run/classfile-format-51.scala b/test/files/run/classfile-format-51.scala index 9b1e612f4f..378caa7936 100644 --- a/test/files/run/classfile-format-51.scala +++ b/test/files/run/classfile-format-51.scala @@ -112,12 +112,12 @@ object Driver { System.setErr(System.out) try { // this test is only valid under JDK 1.7+ - // cheat a little by using 'ScalaVersion' because it can parse java versions just as well - val requiredJavaVersion = ScalaVersion("1.7") - val executingJavaVersion = ScalaVersion(System.getProperty("java.specification.version")) - if (executingJavaVersion >= requiredJavaVersion) { + testUnderJavaAtLeast("1.7") { generateClass() compile() + () + } otherwise { + () } } finally diff --git a/test/files/run/classfile-format-52.check b/test/files/run/classfile-format-52.check new file mode 100644 index 0000000000..5d24ef03cc --- /dev/null +++ b/test/files/run/classfile-format-52.check @@ -0,0 +1,2 @@ +hello from publicMethod +hello from staticMethod diff --git a/test/files/run/classfile-format-52.scala b/test/files/run/classfile-format-52.scala new file mode 100644 index 0000000000..7afa09ae0b --- /dev/null +++ b/test/files/run/classfile-format-52.scala @@ -0,0 +1,77 @@ +import java.io.{File, FileOutputStream} + +import scala.tools.nsc.settings.ScalaVersion +import scala.tools.partest._ +import scala.tools.asm +import asm.{AnnotationVisitor, ClassWriter, FieldVisitor, Handle, MethodVisitor, Opcodes} +import Opcodes._ + +// This test ensures that we can read JDK 8 (classfile format 52) files, including those +// with default methods. To do that it first uses ASM to generate an interface called +// HasDefaultMethod. Then it runs a normal compile on Scala source that extends that +// interface. Any failure will be dumped to std out. +// +// By it's nature the test can only work on JDK 8+ because under JDK 7- the +// interface won't verify. +object Test extends DirectTest { + override def extraSettings: String = "-optimise -usejavacp -d " + testOutput.path + " -cp " + testOutput.path + + def generateInterface() { + val interfaceName = "HasDefaultMethod" + val methodType = "()Ljava/lang/String;" + + val cw = new ClassWriter(0) + cw.visit(52, ACC_PUBLIC+ACC_ABSTRACT+ACC_INTERFACE, interfaceName, null, "java/lang/Object", null) + + def createMethod(flags:Int, name: String) { + val method = cw.visitMethod(flags, name, methodType, null, null) + method.visitCode() + method.visitLdcInsn(s"hello from $name") + method.visitInsn(ARETURN) + method.visitMaxs(1, 1) + method.visitEnd() + } + + createMethod(ACC_PUBLIC, "publicMethod") + createMethod(ACC_PUBLIC+ACC_STATIC, "staticMethod") + createMethod(ACC_PRIVATE, "privateMethod") + + cw.visitEnd() + val bytes = cw.toByteArray() + + val fos = new FileOutputStream(new File(s"${testOutput.path}/$interfaceName.class")) + try + fos write bytes + finally + fos.close() + + } + + def code = +""" +class Driver extends HasDefaultMethod { + println(publicMethod()) + println(HasDefaultMethod.staticMethod()) +} +""" + + override def show(): Unit = { + // redirect err to out, for logging + val prevErr = System.err + System.setErr(System.out) + try { + // this test is only valid under JDK 1.8+ + testUnderJavaAtLeast("1.8") { + generateInterface() + compile() + Class.forName("Driver").newInstance() + () + } otherwise { + println("hello from publicMethod") + println("hello from staticMethod") + } + } + finally + System.setErr(prevErr) + } +} diff --git a/test/files/run/t6481.check b/test/files/run/t6481.check new file mode 100644 index 0000000000..7ec29631b1 --- /dev/null +++ b/test/files/run/t6481.check @@ -0,0 +1,4 @@ +delayed init +new foo(1, 2) +delayed init +new foo(b = 2, a = 1) diff --git a/test/files/run/t6481.scala b/test/files/run/t6481.scala new file mode 100644 index 0000000000..125da3b15a --- /dev/null +++ b/test/files/run/t6481.scala @@ -0,0 +1,13 @@ +abstract class foo(a: Int, b: Int) extends scala.DelayedInit { + def delayedInit(x: => Unit) { + println("delayed init"); + x + } +} + +object Test { + def main(args: Array[String]) { + new foo(1, 2) { println("new foo(1, 2)") } + new foo(b = 2, a = 1) { println("new foo(b = 2, a = 1)") } + } +} diff --git a/test/files/run/t7398.scala b/test/files/run/t7398.scala index e4090f7db3..dd59697b71 100644 --- a/test/files/run/t7398.scala +++ b/test/files/run/t7398.scala @@ -3,14 +3,11 @@ import scala.tools.partest._ object Test extends CompilerTest { import global._ - def javaVersion = scala.util.Properties.javaVersion - def isJavaEight = javaVersion startsWith "1.8" // This way we auto-pass on non-java8 since there's nothing to check - override lazy val units = { - val res: List[CompilationUnit] = if (isJavaEight) javaCompilationUnits(global)(defaultMethodSource) else Nil - val word = if (isJavaEight) "Attempting" else "Skipping" - log(s"$word java8-specific test under java version $javaVersion") - res + override lazy val units: List[CompilationUnit] = testUnderJavaAtLeast("1.8") { + javaCompilationUnits(global)(defaultMethodSource) + } otherwise { + Nil } private def defaultMethodSource = """ diff --git a/test/files/run/t7558.scala b/test/files/run/t7558.scala new file mode 100644 index 0000000000..bfcaaba5cc --- /dev/null +++ b/test/files/run/t7558.scala @@ -0,0 +1,9 @@ +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + import scala.tools.reflect.ToolBox + val tb = cm.mkToolBox() + val t = { var x = "ab".toList; u.reify { x = x.reverse; x }.tree } + val evaluated = tb.eval(t) + assert(evaluated == "ba".toList, evaluated) +} |