diff --git a/libstd/src/std/test.inko b/libstd/src/std/test.inko index c26a9c267..f99a83786 100644 --- a/libstd/src/std/test.inko +++ b/libstd/src/std/test.inko @@ -165,6 +165,21 @@ class pub Test { @failures.push(Failure.new(format(err), 'no value is thrown')) } } + + # Asserts that an expression (which may throw) equals the given value. + fn pub mut try_equal[T: Equal + fmt::Format, E: fmt::Format]( + block: fn !! E -> T, + expected: ref T + ) { + let got = try block.call else (err) { + @failures.push(Failure.new(format(err), format(expected))) + return + } + + if got == expected { return } + + @failures.push(Failure.new(format(got), format(expected))) + } } # A type used for reporting test progress.