I'm trying to write a property that basically states "it should either not throw an exception, or throw one of a list of possible exceptions" using ScalaTest and it's GeneratorDrivenPropertyChecks
which in turn uses scalatest. The issue is that I wasn't able to combine the noException
with an logical or, so the best I could come with is this ugly test:
it should "not throw unexpected exceptions" in {
forAll { (s: String) =>
try { parse(s) }
catch { case e:Throwable => e shouldBe a [ParsingFailedException] }
true shouldBe true // prevent compile error
}}
What I would like to see instead would read more like
it should "not throw unexpected exceptions" in {
forAll { (s: String) => {
(noException should Be thrownBy) or (a [ParsingFailedException] shouldBe thrownBy) { parse(s) }
}}