summaryrefslogtreecommitdiff
path: root/test/files/run/junitForwarders
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-08-31 11:08:26 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2016-09-01 22:38:08 +0200
commit50b71b6c829faabfaa46197572fc4ddd03b7e9c1 (patch)
treee82a4f08b0fafb555d03b0435b66b822911c1dd7 /test/files/run/junitForwarders
parenta980fded6806f83bebe2ced31ab1ed70926254b2 (diff)
downloadscala-50b71b6c829faabfaa46197572fc4ddd03b7e9c1.tar.gz
scala-50b71b6c829faabfaa46197572fc4ddd03b7e9c1.tar.bz2
scala-50b71b6c829faabfaa46197572fc4ddd03b7e9c1.zip
Emit mixin forwarders for JUnit-annotated trait methods by default
JUnit 4 does not support default methods. For better user experience, this commit makes the compiler generate mixin forwarders for inherited trait methods that carry a JUnit annotation. The -Yjunit-trait-methods-no-forwarders flag disables this behavior. This supersedes the scala-js/scala-2.12-junit-mixin-plugin compiler plugin.
Diffstat (limited to 'test/files/run/junitForwarders')
-rw-r--r--test/files/run/junitForwarders/C_1.scala15
-rw-r--r--test/files/run/junitForwarders/Test.java10
2 files changed, 25 insertions, 0 deletions
diff --git a/test/files/run/junitForwarders/C_1.scala b/test/files/run/junitForwarders/C_1.scala
new file mode 100644
index 0000000000..2af2026a61
--- /dev/null
+++ b/test/files/run/junitForwarders/C_1.scala
@@ -0,0 +1,15 @@
+trait T {
+ @org.junit.Test def foo = 0
+}
+
+class C extends T
+
+object Test extends App {
+ def check(c: Class[_], e: String) = {
+ val s = c.getDeclaredMethods.sortBy(_.getName).map(m => s"${m.getName} - ${m.getDeclaredAnnotations.mkString(", ")}").mkString(";")
+ assert(s == e, s"found: $s\nexpected: $e")
+ }
+ check(classOf[C], "foo - @org.junit.Test()")
+ // TODO scala-dev#213: should `foo$` really carry the @Test annotation?
+ check(classOf[T], "$init$ - ;foo - @org.junit.Test();foo$ - @org.junit.Test()")
+}
diff --git a/test/files/run/junitForwarders/Test.java b/test/files/run/junitForwarders/Test.java
new file mode 100644
index 0000000000..57c4d5b544
--- /dev/null
+++ b/test/files/run/junitForwarders/Test.java
@@ -0,0 +1,10 @@
+package org.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD})
+public @interface Test { }