test for load/unload transformations

This commit is contained in:
Mark Harrah 2011-07-15 15:48:36 -04:00
parent bf4d2a7a65
commit 966926a624
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,26 @@
{
val loadCount = AttributeKey[Int]("load-count")
val unloadCount = AttributeKey[Int]("unload-count")
def f(key: AttributeKey[Int]) = (s: State) => {
val previous = s get key getOrElse 0
s.put(key, previous + 1)
}
seq(
onLoad in Global ~= (f(loadCount) compose _),
onUnload in Global ~= (f(unloadCount) compose _)
)
}
InputKey[Unit]("check-count") <<= inputTask { argsTask =>
(argsTask, state) map { (args, s) =>
def get(label: String) = s get AttributeKey[Int](label) getOrElse 0
val loadCount = get("load-count")
val unloadCount = get("unload-count")
val expectedLoad = args(0).toInt
val expectedUnload = args(1).toInt
assert(expectedLoad == loadCount, "Expected load count: " + expectedLoad + ", got: " + loadCount)
assert(expectedUnload == unloadCount, "Expected unload count: " + expectedUnload + ", got: " + unloadCount)
}
}

View File

@ -0,0 +1,8 @@
> check-count 1 0
> check-count 1 0
> reload
> check-count 2 1
> set maxErrors := 1
> check-count 3 2
> reboot
> check-count 1 0