Skip to content

Commit

Permalink
add error struct for failed assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
p7g committed Jul 28, 2024
1 parent d4437db commit a3e5dbe
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/test.rbcvm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import sys;

let doc = docs.module("test", "Testing utilities.");

export function assert(cond) {
export struct AssertionError { message }

doc:add("struct", "AssertionError", "Error raised when an assertion fails.");

export function assert(cond, message="Failed assertion") {
if (!cond) {
sys.panic("Failed assertion");
sys.panic(AssertionError { message = message });
}
}

Expand Down

0 comments on commit a3e5dbe

Please sign in to comment.