-
Notifications
You must be signed in to change notification settings - Fork 4
/
testing_test.go
61 lines (48 loc) · 1.24 KB
/
testing_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2019-2024 Vasiliy Vasilyuk. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package golden
import (
"fmt"
"regexp"
"strings"
)
var _ TestingTB = new(bufferTB)
type bufferTB struct {
logs []string
name string
}
func (m bufferTB) String() string {
return strings.Join(m.logs, "\n")
}
func (m bufferTB) Bytes() []byte {
return []byte(m.String())
}
func (m *bufferTB) Errorf(format string, args ...interface{}) {
m.Logf(format, args...)
m.Fail()
}
func (m *bufferTB) Fail() {
m.Logf("golden_test: method called %T.Fail()", m)
}
func (m *bufferTB) FailNow() {
msg := fmt.Sprintf("golden_test: method called %T.FailNow()", m)
m.Logf(msg)
panic(msg)
}
func (m *bufferTB) Fatalf(format string, args ...interface{}) {
m.Logf(format, args...)
m.FailNow()
}
func (m *bufferTB) Helper() {
m.Logf("golden_test: method called %T.Helper()", m)
}
func (m *bufferTB) Logf(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
re := regexp.MustCompile(`(?im)^\t?Error\ Trace\:([\S\s\n]+)^\t?Error\:`)
msg = re.ReplaceAllString(msg, "\tError Trace:\n\tError:")
m.logs = append(m.logs, msg)
}
func (m bufferTB) Name() string {
return m.name
}