Add scripted test

This commit is contained in:
Iulian Dragos 2023-08-17 15:56:04 +02:00
parent 18353f1ca8
commit 8c9600249e
No known key found for this signature in database
GPG Key ID: A38C8E571FA4621E
3 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,39 @@
commandProgress += new ExecuteProgress2 {
override def beforeCommand(cmd: String, state: State): Unit = {
EventLog.logs += (s"BEFORE: $cmd")
// assert that `state` is the current state indeed
assert(state.currentCommand.isDefined)
assert(state.currentCommand.get.commandLine == cmd)
}
override def afterCommand(cmd: String, result: Either[Throwable, State]): Unit = {
EventLog.logs += (s"AFTER: $cmd")
result.left.foreach(EventLog.errors +=)
}
override def initial(): Unit = {}
override def afterRegistered(
task: Task[_],
allDeps: Iterable[Task[_]],
pendingDeps: Iterable[Task[_]]
): Unit = {}
override def afterReady(task: Task[_]): Unit = {}
override def beforeWork(task: Task[_]): Unit = {}
override def afterWork[A](task: Task[A], result: Either[Task[A], Result[A]]): Unit = {}
override def afterCompleted[A](task: Task[A], result: Result[A]): Unit = {}
override def afterAllCompleted(results: RMap[Task, Result]): Unit = {}
override def stop(): Unit = {}
}
val check = taskKey[Unit]("Check basic command events")
val checkParseError = taskKey[Unit]("Check that parse error is recorded")
check := {
def hasEvent(cmd: String): Boolean =
EventLog.logs.contains(s"BEFORE: $cmd") && EventLog.logs.contains(s"AFTER: $cmd")
assert(hasEvent("compile"), "Missing command event `compile`")
assert(hasEvent("+compile"), "Missing command event `+compile`")
}
checkParseError := {
assert(EventLog.errors.exists(_.getMessage.toLowerCase.contains("not a valid command")))
}

View File

@ -0,0 +1,8 @@
import scala.collection.mutable.ListBuffer
object EventLog {
val logs = ListBuffer.empty[String]
val errors = ListBuffer.empty[Throwable]
def reset(): Unit = logs.clear()
}

View File

@ -0,0 +1,5 @@
> compile
> +compile
> check
-> asdf
> checkParseError