-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprovider.go
More file actions
68 lines (53 loc) · 1.32 KB
/
provider.go
File metadata and controls
68 lines (53 loc) · 1.32 KB
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
62
63
64
65
66
67
68
package assert
import (
"fmt"
"testing"
)
func New(t *testing.T) *Provider {
return setupImpl(t, theLogger)
}
type Provider struct {
logFacade *logFacade
}
func (p *Provider) That(actual interface{}) *AnyType {
return &AnyType{p.logFacade, actual}
}
func (p *Provider) ThatBool(actual bool) *Bool {
return &Bool{p.logFacade, actual}
}
func (p *Provider) ThatInt(actual int) *Int {
return &Int{p.logFacade, actual}
}
func (p *Provider) ThatInt64(actual int64) *Int64 {
return &Int64{p.logFacade, actual}
}
func (p *Provider) ThatUint64(actual uint64) *Uint64 {
return &Uint64{p.logFacade, actual}
}
func (p *Provider) ThatFloat(actual float64) *Float {
return &Float{p.logFacade, actual}
}
func (p *Provider) ThatComplex(actual complex128) *Complex {
return &Complex{p.logFacade, actual}
}
func (p *Provider) ThatString(actual string) *String {
return &String{p.logFacade, actual}
}
type testingT interface {
Fail()
}
type logFacade struct {
t testingT
logger errorLogger
}
func setupImpl(t testingT, logger errorLogger) *Provider {
return &Provider{&logFacade{t, logger}}
}
func logIfFalse(lf *logFacade, condition bool, format string, args ...interface{}) {
if lf != nil && !condition {
location := provideLocation(3)
message := fmt.Sprintf(format, args...)
lf.logger.Log(location, message)
lf.t.Fail()
}
}