-
Notifications
You must be signed in to change notification settings - Fork 10
/
settings.go
50 lines (43 loc) · 1.33 KB
/
settings.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
// Copyright (c) The Test Authors
// SPDX-License-Identifier: MPL-2.0
package test
import (
"github.com/google/go-cmp/cmp"
)
// Settings are used to manage a collection of Setting values used to modify
// the behavior of a test case assertion. Currently supports specifying custom
// error output content, and custom cmp.Option comparators / transforms.
//
// Use Cmp for specifying custom cmp.Option values.
//
// Use Sprint, Sprintf, Values, Func for specifying custom failure output messages.
type Settings struct {
postScripts []PostScript
cmpOptions []cmp.Option
}
// A Setting changes the behavior of a test case assertion.
type Setting func(s *Settings)
// Cmp enables configuring cmp.Option values for modifying the behavior of the
// cmp.Equal function. Custom cmp.Option values control how the cmp.Equal function
// determines equality between the two objects.
//
// https://github.com/google/go-cmp/blob/master/cmp/options.go#L16
func Cmp(options ...cmp.Option) Setting {
return func(s *Settings) {
s.cmpOptions = append(s.cmpOptions, options...)
}
}
func options(settings ...Setting) []cmp.Option {
s := new(Settings)
for _, setting := range settings {
setting(s)
}
return s.cmpOptions
}
func scripts(settings ...Setting) []PostScript {
s := new(Settings)
for _, setting := range settings {
setting(s)
}
return s.postScripts
}