Skip to content

Commit

Permalink
track actual assertion/pass/fail point
Browse files Browse the repository at this point in the history
  • Loading branch information
thacuber2a03 committed Jun 21, 2024
1 parent ef5ccd0 commit 2180203
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions toast.um
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TestInfo* = struct {
func: TestFn
result: std::Err
time: real
depth: uint
}
//~~

Expand Down Expand Up @@ -81,11 +82,10 @@ fn (c: ^Context) fail*(msg: str, code: int = -1) {
std::assert(t != null, "attempt to call fail() outside of a test case")

s := c.bold("X")
if !c.compactOutput {
s = sprintf("test '%s': %s", t.name, msg)
}
if !c.compactOutput { s = sprintf("test '%s': %s", t.name, msg) }
eprint(c.red(s))

t.depth++
t.result = std::error(code, msg)
}

Expand All @@ -97,11 +97,10 @@ fn (c: ^Context) pass*(msg: str = "") {
std::assert(t != null, "attempt to call pass() outside of a test case")

s := "O"
if !c.compactOutput {
s = sprintf("test '%s': %s", t.name, msg)
}
if !c.compactOutput { s = sprintf("test '%s': %s", t.name, msg) }
eprint(c.green(s))

t.depth++
t.result = std::error(0, msg)
}

Expand All @@ -115,6 +114,7 @@ fn (a: ^Assertions) isTrue*(cond: bool, msg: str = ""): bool {
std::assert(t != null, "attempt to call an assertion outside of a test case")

if t.result.code == 0 && !cond {
t.depth++
s := "assertion failed!"
if msg != "" { s += sprintf(" reason: '%s'", msg) }
c.fail(s)
Expand Down Expand Up @@ -219,7 +219,7 @@ fn (c: ^Context) run*(quitIfErr: bool = true): bool {
t.name, t.result.msg
)

pos := t.result.trace[0]
pos := t.result.trace[t.depth]

eprintln(sprintf(
"%s\nat file %s, line %i, took %fms\n",
Expand Down

0 comments on commit 2180203

Please sign in to comment.