Skip to content

Commit

Permalink
release v0.4.1
Browse files Browse the repository at this point in the history
- forgot to expose `(^Context) assert.sameType`
- fixed incorrect function depth tally causing location mismatch
  (not sure of this, will totally check again if any issues pop up)

implementation:
- added new test for `(^Context) assert.sameType`
  • Loading branch information
thacuber2a03 committed Sep 22, 2024
1 parent 1e9c871 commit 7075a41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions test.um
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ fn customLogic(T: ^toast::Context) {
if !assertSquare(T, 3, 10) { return }
}

fn assertTypes(T: ^toast::Context) {
if !T.assert.sameType(42, 90) { return }
if !T.assert.sameType("hello", "world") { return }
}

fn testToast(T: ^toast::Context) {
expected := map[str]bool{
"always pass": true,
"always fail": false,
"fake file": false,
"real file": true,
"custom assertion": true,
"custom logic": false
"custom logic": false,
"assert types": true
}

U := toast::newContext()
Expand All @@ -70,7 +76,8 @@ fn testToast(T: ^toast::Context) {
{ name: "fake file", func: failOnNonExistentFile },
{ name: "real file", func: passOnExistentFile },
{ name: "custom assertion", func: customAssert },
{ name: "custom logic", func: customLogic }
{ name: "custom logic", func: customLogic },
{ name: "assert types", func: assertTypes }
})
U.run(false)
fprintf(std::stderr(), "\n")
Expand Down
8 changes: 4 additions & 4 deletions toast.um
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "std.um"
//~~const VERSION
// The current version number of the library, formatted as specified by
// the [Semantic Versioning Specification](https://semver.org/).
const VERSION* = "0.4.0"
const VERSION* = "0.4.1"
//~~

type (
Expand Down Expand Up @@ -126,7 +126,7 @@ fn (c: ^Context) startCustom*() {
c.checkInvariants()
t := c.current
c.customAsserts = append(c.customAsserts, std::error(-1))
t.funcDepth += 2 // one more for this very function
t.funcDepth++
}

//~~fn (^Context) endCustom
Expand Down Expand Up @@ -213,12 +213,12 @@ fn (a: ^Assertions) isOk*(e: std::Err, msg: str = ""): bool {
// Asserts that `a` and `b` have the same type.
// If the resulting `bool` is false, the caller should return immediately.
// If `msg` is not `""`, prints an extra reason alongside the error.
fn (a: ^Assertions) sameType(va, vb: any, msg: str = ""): bool {
fn (a: ^Assertions) sameType*(va, vb: any, msg: str = ""): bool {
//~~
a.startAssertion()

if !selftypeeq(va, vb) {
s := sprintf("expected %v and %v to be compatible", va, vb)
s := sprintf("expected %v and %v to have the same type", va, vb)
if msg != "" { s += sprintf("\nreason: '%s'", msg)}
return a.failAssertion(s)
}
Expand Down

0 comments on commit 7075a41

Please sign in to comment.