Skip to content

Commit 57f5a9e

Browse files
committed
review: tests
1 parent 6791ae1 commit 57f5a9e

File tree

7 files changed

+271
-214
lines changed

7 files changed

+271
-214
lines changed

pkg/lint/lintersdb/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
284284
WithPresets(linter.PresetStyle, linter.PresetTest).
285285
WithLoadForGoAnalysis().
286286
WithURL("https://github.com/mbilski/exhaustivestruct").
287-
Deprecated("Owner seems to abandon linter.", "v1.46.0", "exhaustruct"),
287+
Deprecated("The owner seems to have abandoned the linter.", "v1.46.0", "exhaustruct"),
288288

289289
linter.NewConfig(golinters.NewExhaustruct(exhaustructCfg)).
290290
WithSince("v1.46.0").
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
linters-settings:
2+
exhaustivestruct:
3+
struct-patterns:
4+
- '*.ExhaustiveStructCustom'
5+
- '*.ExhaustiveStructCustom2'

test/testdata/configs/exhaustruct.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
exhaustruct:
3+
include: ".*\\.ExhaustructCustom$"
4+
exclude: ".*\\.ExhaustructCustom2"

test/testdata/exhaustivestruct.go

+31-25
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
1-
//args: -Eexhaustivestruct
1+
// args: -Eexhaustivestruct --internal-cmd-test
22
package testdata
33

44
import "time"
55

6-
type Test struct {
6+
type ExhaustiveStruct struct {
77
A string
88
B int
99
c bool // private field inside the same package are not ignored
1010
D float64
1111
E time.Time
1212
}
1313

14-
var pass = Test{
15-
A: "a",
16-
B: 0,
17-
c: false,
18-
D: 1.0,
19-
E: time.Now(),
20-
}
14+
func exhaustiveStruct() {
15+
// pass
16+
_ = ExhaustiveStruct{
17+
A: "a",
18+
B: 0,
19+
c: false,
20+
D: 1.0,
21+
E: time.Now(),
22+
}
2123

22-
var failPrivate = Test{ // ERROR "c is missing in Test"
23-
A: "a",
24-
B: 0,
25-
D: 1.0,
26-
E: time.Now(),
27-
}
24+
// failPrivate
25+
_ = ExhaustiveStruct{ // ERROR "c is missing in ExhaustiveStruct"
26+
A: "a",
27+
B: 0,
28+
D: 1.0,
29+
E: time.Now(),
30+
}
2831

29-
var fail = Test{ // ERROR "B is missing in Test"
30-
A: "a",
31-
c: false,
32-
D: 1.0,
33-
E: time.Now(),
34-
}
32+
// fail
33+
_ = ExhaustiveStruct{ // ERROR "B is missing in ExhaustiveStruct"
34+
A: "a",
35+
c: false,
36+
D: 1.0,
37+
E: time.Now(),
38+
}
3539

36-
var failMultiple = Test{ // ERROR "B, D are missing in Test"
37-
A: "a",
38-
c: false,
39-
E: time.Now(),
40+
// failMultiple
41+
_ = ExhaustiveStruct{ // ERROR "B, D are missing in ExhaustiveStruct"
42+
A: "a",
43+
c: false,
44+
E: time.Now(),
45+
}
4046
}
+97-81
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,129 @@
1-
//args: -Eexhaustivestruct
2-
//config: linters-settings.exhaustivestruct.struct-patterns=*.Test1,*.Test3
1+
// args: -Eexhaustivestruct --internal-cmd-test
2+
// config_path: testdata/configs/exhaustivestruct.yml
33
package testdata
44

55
import "time"
66

7-
type Test1 struct {
7+
type ExhaustiveStructCustom struct {
88
A string
99
B int
1010
c bool // private field inside the same package are not ignored
1111
D float64
1212
E time.Time
1313
}
1414

15-
var passTest1 = Test1{
16-
A: "a",
17-
B: 0,
18-
c: false,
19-
D: 1.0,
20-
E: time.Now(),
21-
}
22-
23-
var failTest1 = Test1{ // ERROR "B is missing in Test"
24-
A: "a",
25-
c: false,
26-
D: 1.0,
27-
E: time.Now(),
28-
}
29-
30-
var failMultipleTest1 = Test1{ // ERROR "B, D are missing in Test"
31-
A: "a",
32-
c: false,
33-
E: time.Now(),
34-
}
15+
func exhaustiveStructCustom() {
16+
// pass
17+
_ = ExhaustiveStructCustom{
18+
A: "a",
19+
B: 0,
20+
c: false,
21+
D: 1.0,
22+
E: time.Now(),
23+
}
24+
25+
// fail
26+
_ = ExhaustiveStructCustom{ // ERROR "B is missing in ExhaustiveStructCustom"
27+
A: "a",
28+
c: false,
29+
D: 1.0,
30+
E: time.Now(),
31+
}
32+
33+
// failMultiple
34+
_ = ExhaustiveStructCustom{ // ERROR "B, D are missing in ExhaustiveStructCustom"
35+
A: "a",
36+
c: false,
37+
E: time.Now(),
38+
}
39+
40+
// failPrivate
41+
_ = ExhaustiveStructCustom{ // ERROR "c is missing in ExhaustiveStructCustom"
42+
A: "a",
43+
B: 0,
44+
D: 1.0,
45+
E: time.Now(),
46+
}
3547

36-
var failPrivateTest1 = Test1{ // ERROR "c is missing in Test"
37-
A: "a",
38-
B: 0,
39-
D: 1.0,
40-
E: time.Now(),
4148
}
4249

43-
type Test2 struct {
50+
type ExhaustiveStructCustom1 struct {
4451
A string
4552
B int
4653
c bool // private field inside the same package are not ignored
4754
D float64
4855
E time.Time
4956
}
5057

51-
var passTest2 = Test1{
52-
A: "a",
53-
B: 0,
54-
c: false,
55-
D: 1.0,
56-
E: time.Now(),
57-
}
58-
59-
var failTest2 = Test2{
60-
A: "a",
61-
c: false,
62-
D: 1.0,
63-
E: time.Now(),
64-
}
65-
66-
var failMultipleTest2 = Test2{
67-
A: "a",
68-
c: false,
69-
E: time.Now(),
70-
}
71-
72-
var failPrivateTest2 = Test2{
73-
A: "a",
74-
B: 0,
75-
D: 1.0,
76-
E: time.Now(),
58+
func exhaustiveStructCustom1() {
59+
_ = ExhaustiveStructCustom1{
60+
A: "a",
61+
B: 0,
62+
c: false,
63+
D: 1.0,
64+
E: time.Now(),
65+
}
66+
67+
_ = ExhaustiveStructCustom1{
68+
A: "a",
69+
c: false,
70+
D: 1.0,
71+
E: time.Now(),
72+
}
73+
74+
_ = ExhaustiveStructCustom1{
75+
A: "a",
76+
c: false,
77+
E: time.Now(),
78+
}
79+
80+
_ = ExhaustiveStructCustom1{
81+
A: "a",
82+
B: 0,
83+
D: 1.0,
84+
E: time.Now(),
85+
}
7786
}
7887

79-
type Test3 struct {
88+
type ExhaustiveStructCustom2 struct {
8089
A string
8190
B int
8291
c bool // private field inside the same package are not ignored
8392
D float64
8493
E time.Time
8594
}
8695

87-
var passTest3 = Test3{
88-
A: "a",
89-
B: 0,
90-
c: false,
91-
D: 1.0,
92-
E: time.Now(),
93-
}
94-
95-
var failTest3 = Test3{ // ERROR "B is missing in Test"
96-
A: "a",
97-
c: false,
98-
D: 1.0,
99-
E: time.Now(),
100-
}
101-
102-
var failMultipleTest3 = Test3{ // ERROR "B, D are missing in Test"
103-
A: "a",
104-
c: false,
105-
E: time.Now(),
106-
}
96+
func exhaustiveStructCustom2() {
97+
// pass
98+
_ = ExhaustiveStructCustom2{
99+
A: "a",
100+
B: 0,
101+
c: false,
102+
D: 1.0,
103+
E: time.Now(),
104+
}
105+
106+
// fail
107+
_ = ExhaustiveStructCustom2{ // ERROR "B is missing in ExhaustiveStructCustom2"
108+
A: "a",
109+
c: false,
110+
D: 1.0,
111+
E: time.Now(),
112+
}
113+
114+
// failMultiple
115+
_ = ExhaustiveStructCustom2{ // ERROR "B, D are missing in ExhaustiveStructCustom2"
116+
A: "a",
117+
c: false,
118+
E: time.Now(),
119+
}
120+
121+
// failPrivate
122+
_ = ExhaustiveStructCustom2{ // ERROR "c is missing in ExhaustiveStructCustom2"
123+
A: "a",
124+
B: 0,
125+
D: 1.0,
126+
E: time.Now(),
127+
}
107128

108-
var failPrivateTest3 = Test3{ // ERROR "c is missing in Test"
109-
A: "a",
110-
B: 0,
111-
D: 1.0,
112-
E: time.Now(),
113129
}

test/testdata/exhaustruct.go

+32-25
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
//args: -Eexhaustruct
1+
// args: -Eexhaustruct
22
package testdata
33

44
import "time"
55

6-
type Test struct {
6+
type Exhaustruct struct {
77
A string
88
B int
99
c bool // private field inside the same package are not ignored
1010
D float64
1111
E time.Time
1212
}
1313

14-
var pass = Test{
15-
A: "a",
16-
B: 0,
17-
c: false,
18-
D: 1.0,
19-
E: time.Now(),
20-
}
14+
func exhaustruct() {
15+
// pass
16+
_ = Exhaustruct{
17+
A: "a",
18+
B: 0,
19+
c: false,
20+
D: 1.0,
21+
E: time.Now(),
22+
}
2123

22-
var failPrivate = Test{ // ERROR "c is missing in Test"
23-
A: "a",
24-
B: 0,
25-
D: 1.0,
26-
E: time.Now(),
27-
}
24+
// failPrivate
25+
_ = Exhaustruct{ // ERROR "c is missing in Exhaustruct"
26+
A: "a",
27+
B: 0,
28+
D: 1.0,
29+
E: time.Now(),
30+
}
2831

29-
var fail = Test{ // ERROR "B is missing in Test"
30-
A: "a",
31-
c: false,
32-
D: 1.0,
33-
E: time.Now(),
34-
}
32+
// fail
33+
_ = Exhaustruct{ // ERROR "B is missing in Exhaustruct"
34+
A: "a",
35+
c: false,
36+
D: 1.0,
37+
E: time.Now(),
38+
}
39+
40+
// failMultiple
41+
_ = Exhaustruct{ // ERROR "B, D are missing in Exhaustruct"
42+
A: "a",
43+
c: false,
44+
E: time.Now(),
45+
}
3546

36-
var failMultiple = Test{ // ERROR "B, D are missing in Test"
37-
A: "a",
38-
c: false,
39-
E: time.Now(),
4047
}

0 commit comments

Comments
 (0)