Vampire
01/13/2025, 10:27 AMfun beValid(): Matcher<PathLike> {
return Matcher { path ->
MatcherResult(
validate(YAML.parse(readFile(path, utf8))),
{ "..." },
{ "..." }
)
}
}
just in workingLeoColman
01/13/2025, 1:02 PMvalidate
?LeoColman
01/13/2025, 1:02 PMLeoColman
01/13/2025, 1:03 PMVampire
01/13/2025, 1:04 PMreadFile
is the suspending callVampire
01/13/2025, 1:06 PMreadFile(path.join(dataDir, "foo.yml"), utf8) should beValid()
but it would be nicer to have path.join(dataDir, "foo.yml") should beValid()
.Vampire
01/13/2025, 1:08 PMbeValid()
suspend, this does not help as I need the data
argument for the suspending call.
And the Matcher.invoke
does not take a suspending function.Vampire
01/13/2025, 1:09 PMMatcher.test
is also not suspendingEmil Kantis
01/13/2025, 3:54 PMreadFile
outside of the matcher? I.e
path should beValid()
-> readFile(path) should beValid()
Vampire
01/13/2025, 4:00 PMphldavies
01/13/2025, 4:07 PMsuspend fun PathLike.shouldBeValid() { readFile(this, utf8) should beValid() }
helper to make it nicer at the callsite - i.e. path.shouldBeValid()
LeoColman
01/13/2025, 4:07 PMAndI wonder why it isn't. I think it probably should be. @sam?is also not suspendingMatcher.test
sam
01/13/2025, 4:10 PMsam
01/13/2025, 4:10 PMVampire
01/13/2025, 4:13 PMshouldBeValid
is a nice idea, thanks.phldavies
01/13/2025, 4:15 PMSuspendingMatcher
type and equivalent suspend infix fun <T> T.should(matcher: SuspendingMatcher<T>)
be useful for those assertions? only usable from a suspend callsite of course (so no junit)sam
01/13/2025, 4:17 PMVampire
01/13/2025, 4:20 PM"foo.yml".shouldBeValid()
with
private suspend fun String.shouldBeValid(dataDir: String = goodDir): String {
readFile(path.join(dataDir, this), utf8) should beValid()
return this
}
private suspend fun String.shouldNotBeValid(dataDir: String = badDir): String {
readFile(path.join(dataDir, this), utf8) shouldNot beValid()
return this
}
(the parameters are mostly just for now when testing intentional test failure to see the proper error messages. 🙂)Vampire
01/13/2025, 4:21 PMSuspendingMatcher
might indeed be helpfulVampire
01/13/2025, 4:23 PMshould
as SuspendingMatcher
is more specific than Any
.
Besides that as far as I can see should
accepts Matcher
, not Any
, but other than that it should be the same.sam
01/14/2025, 3:06 AM