summaryrefslogtreecommitdiff
path: root/src/compiler
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 /src/compiler
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 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/settings/Warnings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/Mixin.scala10
2 files changed, 8 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala
index 7ef606b6ef..047ea3c751 100644
--- a/src/compiler/scala/tools/nsc/settings/Warnings.scala
+++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala
@@ -25,7 +25,7 @@ trait Warnings {
// currently considered too noisy for general use
val warnUnusedImport = BooleanSetting("-Ywarn-unused-import", "Warn when imports are unused.")
- val nowarnDefaultJunitMethods = BooleanSetting("-Ynowarn-default-junit-methods", "Don't warn when a JUnit @Test method is generated as a default method (not supported in JUnit 4).")
+ val junitTraitMethodsNoForwarders = BooleanSetting("-Yjunit-trait-methods-no-forwarders", "Don't generate forwarders for JUnit annotated trait methods (JUnit 4 does not support default methods).")
// Experimental lint warnings that are turned off, but which could be turned on programmatically.
// They are not activated by -Xlint and can't be enabled on the command line because they are not
diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala
index f8e6b630d1..58f32b9aca 100644
--- a/src/compiler/scala/tools/nsc/transform/Mixin.scala
+++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala
@@ -286,12 +286,16 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
case _ => false
}
- if (existsCompetingMethod(clazz.baseClasses))
+ def generateJUnitForwarder: Boolean = {
+ !settings.junitTraitMethodsNoForwarders &&
+ member.annotations.nonEmpty &&
+ JUnitAnnotations.exists(annot => annot.exists && member.hasAnnotation(annot))
+ }
+
+ if (existsCompetingMethod(clazz.baseClasses) || generateJUnitForwarder)
genForwarder(required = true)
else if (settings.XgenMixinForwarders)
genForwarder(required = false)
- else if (!settings.nowarnDefaultJunitMethods && JUnitTestClass.exists && member.hasAnnotation(JUnitTestClass))
- warning(member.pos, "JUnit tests in traits that are compiled as default methods are not executed by JUnit 4. JUnit 5 will fix this issue.")
}
case _ =>