@@ -224,12 +224,26 @@ class JUnitBootstrappers extends MiniPhase {
224224 val metadata = for (test <- tests) yield {
225225 val name = Literal (Constant (test.name.toString))
226226 val ignored = Literal (Constant (test.hasAnnotation(junitdefn.IgnoreAnnotClass )))
227- // TODO Handle @Test annotations with arguments
228- // val reifiedAnnot = New(mydefn.TestAnnotType, test.getAnnotation(mydefn.TestAnnotClass).get.arguments)
229227 val testAnnot = test.getAnnotation(junitdefn.TestAnnotClass ).get
230- if (testAnnot.arguments.nonEmpty)
231- ctx.error(" @Test annotations with arguments are not yet supported in Scala.js for dotty" , testAnnot.tree.sourcePos)
232- val reifiedAnnot = resolveConstructor(junitdefn.TestAnnotType , Nil )
228+
229+ val mappedArguments = testAnnot.arguments.flatMap{
230+ // Since classOf[...] in annotations would not be transformed, grab the resulting class constant here
231+ case NamedArg (expectedName : SimpleName , TypeApply (Ident (nme.classOf ), fstArg :: _))
232+ if expectedName.toString == " expected" => Some (clsOf(fstArg.tpe))
233+ // The only other valid argument to @Test annotations is timeout
234+ case NamedArg (timeoutName : TermName , timeoutLiteral : Literal )
235+ if timeoutName.toString == " timeout" => Some (timeoutLiteral)
236+ case other => {
237+ val shownName = other match {
238+ case NamedArg (name, _) => name.show(ctx)
239+ case other => other.show(ctx)
240+ }
241+ ctx.error(s " $shownName is an unsupported argument for the JUnit @Test annotation in this position " , other.sourcePos)
242+ None
243+ }
244+ }
245+
246+ val reifiedAnnot = resolveConstructor(junitdefn.TestAnnotType , mappedArguments)
233247 New (junitdefn.TestMetadataType , List (name, ignored, reifiedAnnot))
234248 }
235249 JavaSeqLiteral (metadata, TypeTree (junitdefn.TestMetadataType ))
0 commit comments