Skip to content

Commit 04d05fa

Browse files
committed
tests: rename tests
1 parent 408fd72 commit 04d05fa

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

Diff for: revgrep_test.go

+28-28
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"testing"
1616
)
1717

18-
func setup(t *testing.T, stage, subdir string) (string, []byte) {
18+
func setup(t *testing.T, stage, subdir string) []byte {
1919
t.Helper()
2020

2121
wd, err := os.Getwd()
@@ -65,20 +65,18 @@ func setup(t *testing.T, stage, subdir string) (string, []byte) {
6565

6666
t.Logf("%s: go vet clean: %s", stage, string(goVetOutput))
6767

68-
return wd, goVetOutput
69-
}
70-
71-
func teardown(t *testing.T, wd string) {
72-
t.Helper()
68+
t.Cleanup(func() {
69+
err = os.Chdir(wd)
70+
if err != nil {
71+
t.Fatalf("could not chdir: %v", err)
72+
}
73+
})
7374

74-
err := os.Chdir(wd)
75-
if err != nil {
76-
t.Fatalf("could not chdir: %v", err)
77-
}
75+
return goVetOutput
7876
}
7977

80-
// TestCheckerRegexp tests line matching and extraction of issue.
81-
func TestCheckerRegexp(t *testing.T) {
78+
// Tests line matching and extraction of issue.
79+
func TestChecker_Check_Regexp(t *testing.T) {
8280
tests := []struct {
8381
regexp string
8482
line string
@@ -127,9 +125,9 @@ func TestCheckerRegexp(t *testing.T) {
127125
}
128126
}
129127

130-
// TestWholeFile tests Checker.WholeFiles will report any issues in files that have changes, even if
131-
// they are outside the diff.
132-
func TestWholeFiles(t *testing.T) {
128+
// Tests [Checker.WholeFiles] will report any issues in files that have changes,
129+
// even if they are outside the diff.
130+
func TestChecker_Check_WholeFiles(t *testing.T) {
133131
tests := []struct {
134132
name string
135133
line string
@@ -209,14 +207,15 @@ func TestChecker_Check_changesWriter(t *testing.T) {
209207

210208
for stage, test := range tests {
211209
t.Run(stage, func(t *testing.T) {
212-
prevwd, goVetOutput := setup(t, stage, test.subdir)
210+
goVetOutput := setup(t, stage, test.subdir)
213211

214212
var out bytes.Buffer
215213

216214
c := Checker{
217215
RevisionFrom: test.revFrom,
218216
RevisionTo: test.revTo,
219217
}
218+
220219
_, err := c.Check(context.Background(), bytes.NewBuffer(goVetOutput), &out)
221220
if err != nil {
222221
t.Errorf("%s: unexpected error: %v", stage, err)
@@ -227,7 +226,7 @@ func TestChecker_Check_changesWriter(t *testing.T) {
227226
scanner := bufio.NewScanner(&out)
228227
for scanner.Scan() {
229228
// Rewrite abs paths to for simpler matching
230-
line := rewriteAbs(scanner.Text())
229+
line := rewriteAbs(t, scanner.Text())
231230
lines = append(lines, strings.TrimPrefix(line, "./"))
232231
}
233232

@@ -248,21 +247,11 @@ func TestChecker_Check_changesWriter(t *testing.T) {
248247
if count != len(test.exp) {
249248
t.Errorf("%s: got %d, expected %d", stage, count, len(test.exp))
250249
}
251-
252-
teardown(t, prevwd)
253250
})
254251
}
255252
}
256253

257-
func rewriteAbs(line string) string {
258-
cwd, err := os.Getwd()
259-
if err != nil {
260-
panic(err)
261-
}
262-
return strings.TrimPrefix(line, cwd+string(filepath.Separator))
263-
}
264-
265-
func TestLinesChanged(t *testing.T) {
254+
func TestChecker_linesChanged(t *testing.T) {
266255
diff := []byte(`--- a/file.go
267256
+++ b/file.go
268257
@@ -1,1 +1,1 @@
@@ -297,3 +286,14 @@ func TestLinesChanged(t *testing.T) {
297286
t.Errorf("unexpected pos:\nhave: %#v\nwant: %#v", have, want)
298287
}
299288
}
289+
290+
func rewriteAbs(t *testing.T, line string) string {
291+
t.Helper()
292+
293+
cwd, err := os.Getwd()
294+
if err != nil {
295+
t.Fatal(err)
296+
}
297+
298+
return strings.TrimPrefix(line, cwd+string(filepath.Separator))
299+
}

0 commit comments

Comments
 (0)