-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinvocations_test.go
84 lines (71 loc) · 1.52 KB
/
invocations_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) The Test Authors
// SPDX-License-Identifier: MPL-2.0
package test
import (
"strings"
"testing"
)
type testScript struct {
label string
content string
}
func (ts *testScript) Label() string {
return ts.label
}
func (ts *testScript) Content() string {
return ts.content
}
type internalTest struct {
t *testing.T
trigger bool
helper bool
exp string
capture string
}
func (it *internalTest) TestPostScript(value string) Setting {
return func(s *Settings) {
s.postScripts = append(s.postScripts, &testScript{
label: "label: " + value,
content: "content: " + value,
})
}
}
func (it *internalTest) Helper() {
it.helper = true
}
func (it *internalTest) assert() {
if !it.helper {
it.t.Fatal("should be marked as helper")
}
if !it.trigger {
it.t.Fatalf("condition expected to trigger; did not")
}
if !strings.Contains(it.capture, it.exp) {
it.t.Fatalf("expected message %q in output, got %q", it.exp, it.capture)
}
}
func (it *internalTest) assertNot() {
if !it.helper {
it.t.Fatal("should be marked as helper")
}
if it.trigger {
it.t.Fatalf("condition expected not to trigger; it did\ngot message %q in output", it.capture)
}
}
func (it *internalTest) post() {
if !strings.Contains(it.capture, "PostScript |") {
it.t.Fatal("expected post-script output")
}
}
func newCase(t *testing.T, msg string) *internalTest {
return &internalTest{
t: t,
trigger: false,
exp: msg,
}
}
func newCapture(t *testing.T) *internalTest {
return &internalTest{
t: t,
}
}