Skip to content

Commit

Permalink
chore(api): restore the OrFail method to the Assertion interface (#25)
Browse files Browse the repository at this point in the history
This change restores API compatibility by restoring the `OrFail()`
method to the `Assertion` interface, and marking it as deprecated in
favor of the new `Now()` method.

Signed-off-by: Arik Kfir <[email protected]>
  • Loading branch information
arikkfir committed Jun 23, 2024
1 parent 8446c0b commit e91b2de
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ func (a *asserter) Will(m Matcher) Assertion {
}

type Assertion interface {

// Now will perform the assertion and fail immediately if it mismatches.
Now()

// Deprecated: OrFail is a synonym for Now.
OrFail()

// For will continually perform the assertion until the given duration has passed or until it mismatches. If it
// mismatched once, the assertion is considered failed.
For(duration time.Duration, interval time.Duration)
Expand All @@ -132,6 +134,17 @@ type assertion struct {
desc string
}

//go:noinline
func (a *assertion) OrFail() {
GetHelper(a.t).Helper()
if a.evaluated {
panic("assertion already evaluated")
} else {
a.evaluated = true
}
a.matcher.Assert(a, a.actuals...)
}

//go:noinline
func (a *assertion) Now() {
GetHelper(a.t).Helper()
Expand Down

0 comments on commit e91b2de

Please sign in to comment.