Skip to content

Commit

Permalink
Change arguments of direct Fail method
Browse files Browse the repository at this point in the history
  • Loading branch information
bayashi committed Dec 14, 2023
1 parent 0613c5a commit f7825c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ So easy and fair, isn't this?

You shouldn't need to spend your time anymore to show fail report.

And, there is a shortcut function instead of builder interface. Below lines are same.
And, there is a shortcut function, direct `Fail`, instead of builder interface. Below lines are same.

```go
w.Got(g).Expect(e).Fail(t, "Not same")
w.Fail(t, "Not same", e, g)
w.Fail(t, "Not same", g, e)
```

See [Witness Package reference](https://pkg.go.dev/github.com/bayashi/witness) for more details.
Expand Down
21 changes: 16 additions & 5 deletions witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,26 @@ func setRawForReport(w *Witness, r *report.Failure) *report.Failure {
}

// Fail is shortcut method. These are same expression.
// witness.Got(got).Fail(t, reason)
// witness.Fail(t, reason, got)
//
// Fail with 2 values cases are below
// witness.Got(got).Expect(expect).Fail(t, reason)
// witness.Fail(t, reason, expect, got)
func Fail(t *testing.T, reason string, expect any, got any) {
Got(got).Expect(expect).Fail(t, reason)
// witness.Fail(t, reason, got, expect)
func Fail(t *testing.T, reason string, got any, expect ...any) {
if len(expect) == 0 {
Got(got).Fail(t, reason)
} else {
Got(got).Expect(expect[0]).Fail(t, reason)
}
}

func FailNow(t *testing.T, reason string, expect any, got any) {
Got(got).Expect(expect).FailNow(t, reason)
func FailNow(t *testing.T, reason string, got any, expect ...any) {
if len(expect) == 0 {
Got(got).FailNow(t, reason)
} else {
Got(got).Expect(expect[0]).FailNow(t, reason)
}
}

// Diff is to get a diff string of 2 objects for debugging in test
Expand Down

0 comments on commit f7825c7

Please sign in to comment.