Last active
November 13, 2019 05:00
-
-
Save abeln/8295eeb6d0980c545b9c65c8217fe751 to your computer and use it in GitHub Desktop.
Porting minitest to explicit nulls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/shared/src/main/scala/minitest/api/Result.scala b/shared/src/main/scala/minitest/api/Result.scala | |
index f681231..85aa4ab 100644 | |
--- a/shared/src/main/scala/minitest/api/Result.scala | |
+++ b/shared/src/main/scala/minitest/api/Result.scala | |
@@ -55,7 +55,7 @@ object Result { | |
} | |
} | |
- final case class Failure(msg: String, source: Option[Throwable], location: Option[SourceLocation]) | |
+ final case class Failure(msg: String | Null, source: Option[Throwable], location: Option[SourceLocation]) | |
extends Result[Nothing] { | |
def formatted(name: String, withColors: Boolean): String = | |
@@ -69,7 +69,7 @@ object Result { | |
val description = { | |
val name = source.getClass.getName | |
val className = name.substring(name.lastIndexOf(".") + 1) | |
- Option(source.getMessage).filterNot(_.isEmpty) | |
+ Option(source.getMessage).filterNot(_.nn.isEmpty) | |
.fold(className)(m => s"$className: $m") | |
} | |
@@ -92,7 +92,7 @@ object Result { | |
Result.Exception(other, None) | |
} | |
- private def formatError(name: String, msg: String, | |
+ private def formatError(name: String, msg: String | Null, | |
source: Option[Throwable], | |
location: Option[SourceLocation], | |
traceLimit: Option[Int], | |
diff --git a/shared/src/main/scala/minitest/api/exceptions.scala b/shared/src/main/scala/minitest/api/exceptions.scala | |
index d804bef..0c1833d 100644 | |
--- a/shared/src/main/scala/minitest/api/exceptions.scala | |
+++ b/shared/src/main/scala/minitest/api/exceptions.scala | |
@@ -19,10 +19,10 @@ package minitest.api | |
import scala.util.control.NonFatal | |
-abstract class MiniTestException(message: String, cause: Throwable) | |
+abstract class MiniTestException(message: String | Null, cause: Throwable | Null) | |
extends RuntimeException(message, cause) | |
-final class AssertionException(val message: String, val location: SourceLocation) | |
+final class AssertionException(val message: String | Null, val location: SourceLocation) | |
extends MiniTestException(message, null) | |
final class UnexpectedException(val reason: Throwable, val location: SourceLocation) | |
diff --git a/shared/src/main/scala/minitest/runner/ConsoleLogger.scala b/shared/src/main/scala/minitest/runner/ConsoleLogger.scala | |
index 94ad427..d5a5c13 100644 | |
--- a/shared/src/main/scala/minitest/runner/ConsoleLogger.scala | |
+++ b/shared/src/main/scala/minitest/runner/ConsoleLogger.scala | |
@@ -25,14 +25,14 @@ final class ConsoleLogger extends Logger { | |
def ansiCodesSupported(): Boolean = | |
withColors | |
- def error(msg: String): Unit = | |
+ def error(msg: String | Null): Unit = | |
print(msg) | |
- def warn(msg: String): Unit = | |
+ def warn(msg: String | Null): Unit = | |
print(msg) | |
- def info(msg: String): Unit = | |
+ def info(msg: String | Null): Unit = | |
print(msg) | |
- def debug(msg: String): Unit = | |
+ def debug(msg: String | Null): Unit = | |
print(msg) | |
- def trace(t: Throwable): Unit = | |
- t.printStackTrace(System.out) | |
+ def trace(t: Throwable | Null): Unit = | |
+ t.nn.printStackTrace(System.out) | |
} | |
diff --git a/shared/src/main/scala/minitest/runner/Framework.scala b/shared/src/main/scala/minitest/runner/Framework.scala | |
index db591a9..5a69582 100644 | |
--- a/shared/src/main/scala/minitest/runner/Framework.scala | |
+++ b/shared/src/main/scala/minitest/runner/Framework.scala | |
@@ -25,13 +25,15 @@ class Framework extends BaseFramework { | |
def options: Options = Options() | |
- def fingerprints(): Array[Fingerprint] = | |
+ // overriding method of type (): Array[sbt.testing.Fingerprint | JavaNull] | JavaNull | |
+ def fingerprints(): Array[Fingerprint | Null] = | |
Array(ModuleFingerprint) | |
- def runner(args: Array[String], remoteArgs: Array[String], testClassLoader: ClassLoader): Runner = | |
- new minitest.runner.Runner(args, remoteArgs, options, testClassLoader) | |
+ def runner(args: Array[String | Null] | Null, remoteArgs: Array[String | Null] | Null, testClassLoader: ClassLoader | Null): Runner = | |
+ new minitest.runner.Runner(args.nn, remoteArgs.nn, options, testClassLoader.nn) | |
- def slaveRunner(args: Array[String], remoteArgs: Array[String], testClassLoader: ClassLoader, send: String => Unit): Runner = | |
+ // overriding method of type Array[something | JavaNull] | JavaNull | |
+ def slaveRunner(args: Array[String | Null], remoteArgs: Array[String | Null], testClassLoader: ClassLoader, send: String => Unit): Runner = | |
runner(args, remoteArgs, testClassLoader) | |
} | |
diff --git a/shared/src/main/scala/minitest/runner/Runner.scala b/shared/src/main/scala/minitest/runner/Runner.scala | |
index 82a1cec..ab4bd9b 100644 | |
--- a/shared/src/main/scala/minitest/runner/Runner.scala | |
+++ b/shared/src/main/scala/minitest/runner/Runner.scala | |
@@ -20,24 +20,24 @@ package minitest.runner | |
import sbt.testing.{Runner => BaseRunner, Task => BaseTask, _} | |
final class Runner( | |
- val args: Array[String], | |
- val remoteArgs: Array[String], | |
+ val args: Array[String | Null], | |
+ val remoteArgs: Array[String | Null], | |
val options: Options, | |
classLoader: ClassLoader) | |
extends BaseRunner { | |
def done(): String = "" | |
- def tasks(list: Array[TaskDef]): Array[BaseTask] = { | |
- list.map(t => new Task(t, options, classLoader)) | |
+ def tasks(list: Array[TaskDef | Null] | Null): Array[BaseTask | Null] = { | |
+ list.nn.map(t => new Task(t.nn, options, classLoader)) | |
} | |
def receiveMessage(msg: String): Option[String] = { | |
None | |
} | |
- def serializeTask(task: BaseTask, serializer: TaskDef => String): String = | |
- serializer(task.taskDef()) | |
+ def serializeTask(task: BaseTask, serializer: TaskDef | Null => String): String = | |
+ serializer(task.taskDef().nn) | |
def deserializeTask(task: String, deserializer: String => TaskDef): BaseTask = | |
new Task(deserializer(task), options, classLoader) | |
diff --git a/shared/src/main/scala/minitest/runner/Task.scala b/shared/src/main/scala/minitest/runner/Task.scala | |
index 1fc6e83..edb809b 100644 | |
--- a/shared/src/main/scala/minitest/runner/Task.scala | |
+++ b/shared/src/main/scala/minitest/runner/Task.scala | |
@@ -29,7 +29,7 @@ final class Task(task: TaskDef, opts: Options, cl: ClassLoader) extends BaseTask | |
implicit val ec: ExecutionContext = DefaultExecutionContext | |
private[this] val console = if (opts.useSbtLogging) None else Some(Array(new ConsoleLogger)) | |
- def tags(): Array[String] = Array.empty | |
+ def tags(): Array[String | Null] = Array.empty | |
def taskDef(): TaskDef = task | |
def reportStart(name: String, loggers: Array[Logger]): Unit = { | |
@@ -47,8 +47,9 @@ final class Task(task: TaskDef, opts: Options, cl: ClassLoader) extends BaseTask | |
} | |
} | |
- def execute(eventHandler: EventHandler, loggers: Array[Logger], | |
+ def execute(eventHandler: EventHandler, _loggers: Array[Logger | Null], | |
continuation: Array[BaseTask] => Unit): Unit = { | |
+ val loggers = _loggers.map(x => x.nn) | |
def loop(props: Iterator[TestSpec[Unit, Unit]]): Future[Unit] = { | |
if (!props.hasNext) unit else { | |
@@ -77,9 +78,9 @@ final class Task(task: TaskDef, opts: Options, cl: ClassLoader) extends BaseTask | |
future.onComplete(_ => continuation(Array.empty)) | |
} | |
- def execute(eventHandler: EventHandler, loggers: Array[Logger]): Array[BaseTask] = { | |
+ def execute(eventHandler: EventHandler | Null, loggers: Array[Logger | Null] | Null): Array[BaseTask | Null] = { | |
val p = Promise[Unit]() | |
- execute(eventHandler, loggers, _ => p.success(())) | |
+ execute(eventHandler.nn, loggers.nn, _ => p.success(())) | |
Await.result(p.future, Duration.Inf) | |
Array.empty | |
} | |
@@ -122,7 +123,7 @@ final class Task(task: TaskDef, opts: Options, cl: ClassLoader) extends BaseTask | |
} | |
def selector(): Selector = { | |
- task.selectors().head | |
+ task.selectors().head.nn | |
} | |
def fingerprint(): Fingerprint = |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment