@@ -25,6 +25,7 @@ import (
25
25
26
26
func TestApplyFixes (t * testing.T ) {
27
27
testenv .NeedsGoPackages (t )
28
+ testenv .RedirectStderr (t ) // associated checker.Run output with this test
28
29
29
30
files := map [string ]string {
30
31
"rename/test.go" : `package rename
@@ -83,6 +84,7 @@ var otherAnalyzer = &analysis.Analyzer{ // like analyzer but with a different Na
83
84
}
84
85
85
86
func run (pass * analysis.Pass ) (interface {}, error ) {
87
+ // TODO(adonovan): replace this entangled test with something completely data-driven.
86
88
const (
87
89
from = "bar"
88
90
to = "baz"
@@ -108,16 +110,46 @@ func run(pass *analysis.Pass) (interface{}, error) {
108
110
}
109
111
switch pass .Pkg .Name () {
110
112
case conflict :
111
- edits = append (edits , []analysis.TextEdit {
112
- {Pos : ident .Pos () - 1 , End : ident .End (), NewText : []byte (to )},
113
- {Pos : ident .Pos (), End : ident .End () - 1 , NewText : []byte (to )},
114
- {Pos : ident .Pos (), End : ident .End (), NewText : []byte ("lorem ipsum" )},
115
- }... )
113
+ // Conflicting edits are legal, so long as they appear in different fixes.
114
+ pass .Report (analysis.Diagnostic {
115
+ Pos : ident .Pos (),
116
+ End : ident .End (),
117
+ Message : msg ,
118
+ SuggestedFixes : []analysis.SuggestedFix {{
119
+ Message : msg , TextEdits : []analysis.TextEdit {
120
+ {Pos : ident .Pos () - 1 , End : ident .End (), NewText : []byte (to )},
121
+ },
122
+ }},
123
+ })
124
+ pass .Report (analysis.Diagnostic {
125
+ Pos : ident .Pos (),
126
+ End : ident .End (),
127
+ Message : msg ,
128
+ SuggestedFixes : []analysis.SuggestedFix {{
129
+ Message : msg , TextEdits : []analysis.TextEdit {
130
+ {Pos : ident .Pos (), End : ident .End () - 1 , NewText : []byte (to )},
131
+ },
132
+ }},
133
+ })
134
+ pass .Report (analysis.Diagnostic {
135
+ Pos : ident .Pos (),
136
+ End : ident .End (),
137
+ Message : msg ,
138
+ SuggestedFixes : []analysis.SuggestedFix {{
139
+ Message : msg , TextEdits : []analysis.TextEdit {
140
+ {Pos : ident .Pos (), End : ident .End (), NewText : []byte ("lorem ipsum" )},
141
+ },
142
+ }},
143
+ })
144
+ return
145
+
116
146
case duplicate :
147
+ // Duplicate (non-insertion) edits are disallowed,
148
+ // so this is a buggy analyzer, and validatedFixes should reject it.
117
149
edits = append (edits , edits ... )
118
150
case other :
119
151
if pass .Analyzer .Name == other {
120
- edits [0 ].Pos = edits [ 0 ]. Pos + 1 // shift by one to mismatch analyzer and other
152
+ edits [0 ].Pos ++ // shift by one to mismatch analyzer and other
121
153
}
122
154
}
123
155
pass .Report (analysis.Diagnostic {
@@ -133,6 +165,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
133
165
134
166
func TestRunDespiteErrors (t * testing.T ) {
135
167
testenv .NeedsGoPackages (t )
168
+ testenv .RedirectStderr (t ) // associate checker.Run output with this test
136
169
137
170
files := map [string ]string {
138
171
"rderr/test.go" : `package rderr
@@ -360,4 +393,7 @@ hello from other
360
393
if ! ran {
361
394
t .Error ("analyzer did not run" )
362
395
}
396
+
397
+ // TODO(adonovan): test that fixes are applied to the
398
+ // pass.ReadFile virtual file tree.
363
399
}
0 commit comments