Skip to content

Commit

Permalink
std/testing: add T.Logf
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 24, 2025
1 parent bc5c7ba commit 1b4dc41
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions std/testing/t.jule
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@
use "std/fmt"
use "std/unsafe"

enum status: byte {
Na: 0x0,
Skip: 0x1 << 0,
Fail: 0x1 << 1,
}
const statSkip = 1 << 0
const statFail = 1 << 1

// A test utility also used by the Jule runtime.
// It provides functionalities that facilitate the
// management and development of tests.
struct T {
mut s: status
mut s: int
}

impl T {
// Used by runtime.
// Reset all data.
fn reset(self) {
self.s = status.Na
self.s = 0
}

// Wrapper for internal logs.
Expand All @@ -34,29 +31,29 @@ impl T {
// Fails test.
// Does not breaks scope execution.
fn Fail(self) {
if self.s == status.Skip {
if self.s == statSkip {
panic("testing: T.fail: failed test that already skipped")
}
self.s = status.Fail
self.s = statFail
}

// Reports whether test is failed.
fn Failed(self): bool {
ret self.s == status.Fail
ret self.s == statFail
}

// Skip test.
// Does not breaks scope execution.
fn Skip(self) {
if self.s == status.Skip {
if self.s == statSkip {
panic("testing: T.skip: skipped test that already failed")
}
self.s = status.Skip
self.s = statSkip
}

// Reports whether test is skipped.
fn Skipped(self): bool {
ret self.s == status.Skip
ret self.s == statSkip
}

// Set status of test as failure if expression is evaluated false at runtime.
Expand All @@ -75,4 +72,9 @@ impl T {
self.println(fmt::Format(fmt, args...))
self.Fail()
}

// Logs message with no error, test status will not be affected.
fn Logf(self, fmt: str, args: ...any) {
self.println(fmt::Format(fmt, args...))
}
}

0 comments on commit 1b4dc41

Please sign in to comment.