mock_test.gno
1.40 Kb ยท 61 lines
1package uassert_test
2
3import (
4 "fmt"
5 "testing"
6
7 "gno.land/p/demo/uassert"
8)
9
10type mockTestingT struct {
11 fmt string
12 args []any
13}
14
15// --- interface mock
16
17var _ uassert.TestingT = (*mockTestingT)(nil)
18
19func (mockT *mockTestingT) Helper() { /* noop */ }
20func (mockT *mockTestingT) Skip(args ...any) { /* not implmented */ }
21func (mockT *mockTestingT) Fail() { /* not implmented */ }
22func (mockT *mockTestingT) FailNow() { /* not implmented */ }
23func (mockT *mockTestingT) Logf(fmt string, args ...any) { /* noop */ }
24
25func (mockT *mockTestingT) Fatalf(fmt string, args ...any) {
26 mockT.fmt = "fatal: " + fmt
27 mockT.args = args
28}
29
30func (mockT *mockTestingT) Errorf(fmt string, args ...any) {
31 mockT.fmt = "error: " + fmt
32 mockT.args = args
33}
34
35// --- helpers
36
37func (mockT *mockTestingT) actualString() string {
38 res := fmt.Sprintf(mockT.fmt, mockT.args...)
39 mockT.reset()
40 return res
41}
42
43func (mockT *mockTestingT) reset() {
44 mockT.fmt = ""
45 mockT.args = nil
46}
47
48func (mockT *mockTestingT) equals(t *testing.T, expected string) {
49 actual := mockT.actualString()
50
51 if expected != actual {
52 t.Errorf("mockT differs:\n- expected: %s\n- actual: %s\n", expected, actual)
53 }
54}
55
56func (mockT *mockTestingT) empty(t *testing.T) {
57 if mockT.fmt != "" || mockT.args != nil {
58 actual := mockT.actualString()
59 t.Errorf("mockT should be empty, got %s", actual)
60 }
61}