Skip to content

Commit

Permalink
refactor: unify usage of parens for Scala 3
Browse files Browse the repository at this point in the history
Scala 3 doesn't allow to call method with parentheses without them. Normally class can extends trait/interface and overwrite their def's using val/override val no matter if def was declared with or without parentheses. However for Scala 3 this is no llonger true. This PR uses a workaround with underscores.
  • Loading branch information
Kamil Podsiadlo committed Jan 22, 2022
1 parent 6c9ca3d commit 32b32d2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 24 deletions.
6 changes: 3 additions & 3 deletions munit/non-jvm/src/main/scala/munit/Framework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import munit.internal.junitinterface.CustomRunners
import munit.internal.junitinterface.JUnitFramework

class Framework extends JUnitFramework {
override val name = "munit"
val munitFingerprint = new CustomFingerprint("munit.Suite", isModule = false)
override def name(): String = "munit"
val munitFingerprint = new CustomFingerprint("munit.Suite", _isModule = false)
val customRunners = new CustomRunners(
List(
munitFingerprint,
new CustomFingerprint("munit.Suite", isModule = true)
new CustomFingerprint("munit.Suite", _isModule = true)
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import sbt.testing.SubclassFingerprint

class CustomFingerprint(
val suite: String,
val isModule: Boolean
_isModule: Boolean
) extends SubclassFingerprint {
override def isModule(): Boolean = _isModule
override def superclassName(): String = suite
override def requireNoArgConstructor(): Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import sbt.testing._

final class JUnitEvent(
taskDef: TaskDef,
val fullyQualifiedName: String,
val status: Status,
val selector: Selector,
val throwable: OptionalThrowable = new OptionalThrowable,
val duration: Long = -1L
_fullyQualifiedName: String,
_status: Status,
_selector: Selector,
_throwable: OptionalThrowable = new OptionalThrowable,
_duration: Long = -1L
) extends Event {
def fingerprint: Fingerprint = taskDef.fingerprint
override def status(): Status = _status
override def selector(): Selector = _selector
override def throwable(): OptionalThrowable = _throwable
override def duration(): Long = _duration
override def fullyQualifiedName(): String = _fullyQualifiedName
override def fingerprint(): Fingerprint = taskDef.fingerprint()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sbt.testing._

abstract class JUnitFramework extends Framework {

val name: String = "Scala.js JUnit test framework"
override def name(): String = "Scala.js JUnit test framework"

def customRunners: CustomRunners

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class JUnitReporter(
throwable: OptionalThrowable = new OptionalThrowable
): Unit = {
val testName =
taskDef.fullyQualifiedName + "." +
taskDef.fullyQualifiedName() + "." +
settings.decodeName(method)
val selector = new TestSelector(testName)
eventHandler.handle(
Expand Down Expand Up @@ -215,7 +215,7 @@ final class JUnitReporter(

private def findTestFileName(trace: Array[StackTraceElement]): String =
trace
.find(_.getClassName == taskDef.fullyQualifiedName)
.find(_.getClassName == taskDef.fullyQualifiedName())
.map(_.getFileName)
.orNull

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ import munit.internal.PlatformCompat

final class JUnitRunner(
val args: Array[String],
val remoteArgs: Array[String],
_remoteArgs: Array[String],
runSettings: RunSettings,
classLoader: ClassLoader,
customRunners: CustomRunners
) extends Runner {
PlatformCompat.setThisClassLoader(classLoader)

def tasks(taskDefs: Array[TaskDef]): Array[Task] =
override def remoteArgs(): Array[String] = _remoteArgs

override def tasks(taskDefs: Array[TaskDef]): Array[Task] =
taskDefs.map(new JUnitTask(_, runSettings, classLoader))

def done(): String = ""
override def done(): String = ""

def serializeTask(task: Task, serializer: TaskDef => String): String =
serializer(task.taskDef)
override def serializeTask(
task: Task,
serializer: TaskDef => String
): String =
serializer(task.taskDef())

def deserializeTask(task: String, deserializer: String => TaskDef): Task =
override def deserializeTask(
task: String,
deserializer: String => TaskDef
): Task =
new JUnitTask(deserializer(task), runSettings, classLoader)

def receiveMessage(msg: String): Option[String] = None
override def receiveMessage(msg: String): Option[String] = None
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import scala.concurrent.ExecutionContext.Implicits.global
* under the hood and stay consistent with JVM JUnit.
*/
final class JUnitTask(
val taskDef: TaskDef,
_taskDef: TaskDef,
runSettings: RunSettings,
classLoader: ClassLoader
) extends Task {

def tags: Array[String] = Array.empty
override def taskDef(): TaskDef = _taskDef
override def tags(): Array[String] = Array.empty

def execute(
eventHandler: EventHandler,
Expand All @@ -36,12 +37,12 @@ final class JUnitTask(
loggers: Array[Logger],
continuation: Array[Task] => Unit
): Unit = {
PlatformCompat.newRunner(taskDef, classLoader) match {
PlatformCompat.newRunner(taskDef(), classLoader) match {
case None =>
case Some(runner) =>
runner.filter(runSettings.tags)
val reporter =
new JUnitReporter(eventHandler, loggers, runSettings, taskDef)
new JUnitReporter(eventHandler, loggers, runSettings, taskDef())
val notifier: RunNotifier = new MUnitRunNotifier(reporter)
runner.runAsync(notifier).foreach(_ => continuation(Array()))
}
Expand Down

0 comments on commit 32b32d2

Please sign in to comment.