Repository navigation
Expand file tree
/
Copy pathaccount_test.go
More file actions
167 lines (155 loc) · 7.04 KB
/
Copy pathaccount_test.go
File metadata and controls
167 lines (155 loc) · 7.04 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package exec
import (
"strings"
"testing"
"unicode/utf8"
)
// A WORKER'S OWN COMMANDS AND THE FINISHED TREE'S CHECKS ARE TWO DIFFERENT
// FACTS. Both account renderings keep them under their own headings so a reader
// can tell what the leaf ran from what the closing photograph found.
func TestAnAccountNamesWhatTheWorkRanItself(t *testing.T) {
account := &Account{
Files: []FileChange{{Path: "main.go", Change: ChangeChanged, Added: 1}},
Commands: []string{"go build ./...", "go test ./internal/shaped/"},
CommandsRun: 2,
Checks: []Check{{Command: "go test ./...", Passed: true}},
}
for name, rendered := range map[string]string{
"report": account.Report(),
"lines": strings.Join(account.Lines(), "\n"),
} {
commandAt := strings.Index(rendered, "What the work ran itself:")
checkAt := strings.Index(rendered, "What the work ran to check itself, and what each one found:")
if commandAt < 0 || checkAt < 0 || commandAt > checkAt {
t.Errorf("%s does not keep the leaf's commands ahead of the separate check block:\n%s", name, rendered)
}
for _, command := range account.Commands {
if !strings.Contains(rendered, " "+command) {
t.Errorf("%s does not name command %q:\n%s", name, command, rendered)
}
}
if !strings.Contains(rendered, " passed: go test ./...") {
t.Errorf("%s lost what the closing check found:\n%s", name, rendered)
}
}
cut := &Account{
Files: []FileChange{{Path: "main.go", Change: ChangeChanged}},
Commands: []string{"newest"},
CommandsRun: 4,
}
if report := cut.Report(); !strings.Contains(report, "and 3 earlier commands, in the run's own record") {
t.Errorf("the bounded command list does not say what it left out:\n%s", report)
}
}
// AN ACCOUNT OF CHANGED FILES MUST SAY WHEN NOTHING CHECKED THEM. Silence here
// made a leaf that ran nothing read exactly like one whose check had nothing to
// report, while an account that carries a real check must not claim the absence.
func TestAnAccountWithNoCheckSaysSoRatherThanLeavingItOut(t *testing.T) {
account := &Account{Files: []FileChange{{Path: "main.go", Change: ChangeChanged, Added: 1}}}
if report := account.Report(); !strings.Contains(report, noCheckWords) {
t.Errorf("report omitted the measured absence of a check:\n%s", report)
}
if summary := account.Summary(); !strings.Contains(summary, noCheckWords) {
t.Errorf("summary omitted the measured absence of a check: %q", summary)
}
checked := &Account{
Files: []FileChange{{Path: "main.go", Change: ChangeChanged, Added: 1}},
Checks: []Check{{Command: "go test ./...", Passed: true}},
}
if report := checked.Report(); strings.Contains(report, noCheckWords) {
t.Errorf("an account with a check also says none ran:\n%s", report)
}
if summary := checked.Summary(); strings.Contains(summary, noCheckWords) {
t.Errorf("a summary with a check also says none ran: %q", summary)
}
}
// A COMMAND THAT LOOKS LIKE A TEST IS NEVER EVIDENCE THAT A CHECK PASSED. Its
// output was not parsed by the closing photograph, so Verified must continue to
// answer from Checks alone.
func TestCommandsAreNotChecks(t *testing.T) {
account := &Account{Commands: []string{"go test ./..."}, CommandsRun: 1}
if account.Verified() {
t.Fatal("a shell command made the account read as checked")
}
}
// AN UNREAD READING IS NOT A MEASURED ABSENCE, AND THE ACCOUNT MUST NOT SPELL
// IT AS ONE.
//
// [Account.rows] reaches its no-check branch whenever Checks is empty, and
// ranChecks empties Checks from four different worlds. In three of them a
// command demonstrably RAN on the finished tree and its answer could not be
// understood — the strategy would not start a second time, the suite failed to
// collect, the command was killed at its ceiling before naming a check
// (photograph.go). Saying "no check was run" of those is a guess wearing the
// words of a measurement, and the same outcome carries Verification.Unread, so
// a reader got both sentences at once: the revision pass renders that one while
// the gate renders these lines.
//
// The fourth world — nothing was ever asked of the tree — is the one the
// exception to the emptiness law was written for, and it keeps it.
func TestAReadingThatCouldNotBeReadSaysThatAndNotThatNothingRan(t *testing.T) {
files := []FileChange{{Path: "main.go", Change: ChangeChanged, Added: 1}}
for _, world := range []struct {
what string
unread string
}{
{
what: "the strategy would not start a second time",
unread: "the finished tree could not be read: `go test ./...` could not be started a second time",
},
{
what: "the suite failed to collect",
unread: "`pytest` ran on the finished tree and its suite failed to collect, so no check of it ran",
},
{
what: "it was killed at its ceiling",
unread: "`go test ./...` ran on the finished tree and was killed at its ceiling of 5m without naming a single check",
},
} {
account := &Account{Files: files, Unread: world.unread}
report := account.Report()
if strings.Contains(report, noCheckWords) {
t.Errorf("%s: the report calls an unread reading a measured absence:\n%s", world.what, report)
}
if !strings.Contains(report, world.unread) {
t.Errorf("%s: the report does not say why the tree could not be read:\n%s", world.what, report)
}
summary := account.Summary()
if strings.Contains(summary, noCheckWords) {
t.Errorf("%s: the summary calls an unread reading a measured absence: %q", world.what, summary)
}
if !strings.Contains(summary, world.unread) {
t.Errorf("%s: the summary does not say why the tree could not be read: %q", world.what, summary)
}
}
// AND THE WORLD THE EXCEPTION WAS WRITTEN FOR IS UNTOUCHED. Nothing was
// asked of the tree, so there is nothing to explain and the measured
// absence stands. That world reaches here with an empty Unread even when
// verify.Reading carried one, because [AccountFor] only carries the
// sentence when a baseline was Taken — "this project declares no way of
// checking itself" is the absence, not an explanation of a failure to read.
nothing := &Account{Files: files}
if report := nothing.Report(); !strings.Contains(report, noCheckWords) {
t.Errorf("a run that attempted no reading lost the measured absence:\n%s", report)
}
if summary := nothing.Summary(); !strings.Contains(summary, noCheckWords) {
t.Errorf("a run that attempted no reading lost the measured absence: %q", summary)
}
}
// A COMMAND IS CUT AT A CHARACTER BOUNDARY, because this list is read by a
// person now. [snip] used to slice bytes, which put a broken rune in front of
// them at exactly ranArgumentBytes.
func TestABoundedCommandIsNotCutThroughACharacter(t *testing.T) {
// A run of three-byte runes, so any byte-sliced cut lands mid-character.
long := strings.Repeat("日", 200)
cut := snip(long, ranArgumentBytes)
if !utf8.ValidString(cut) {
t.Fatalf("a clipped command is not valid UTF-8: %q", cut)
}
if !strings.HasSuffix(cut, "…") {
t.Errorf("a clipped command does not say it was clipped: %q", cut)
}
if len(cut) > ranArgumentBytes+len("…") {
t.Errorf("a clipped command outran its ceiling: %d bytes", len(cut))
}
}