@@ -98,6 +98,34 @@ type Testing interface {
98
98
// println()
99
99
// }
100
100
// }
101
+ //
102
+ // # Conflicts
103
+ //
104
+ // A single analysis pass may offer two or more suggested fixes that
105
+ // (1) conflict but are nonetheless logically composable, (e.g.
106
+ // because both update the import declaration), or (2) are
107
+ // fundamentally incompatible (e.g. alternative fixes to the same
108
+ // statement).
109
+ //
110
+ // It is up to the driver to decide how to apply such fixes. A
111
+ // sophisticated driver could attempt to resolve conflicts of the
112
+ // first kind, but this test driver simply reports the fact of the
113
+ // conflict with the expectation that the user will split their tests
114
+ // into nonconflicting parts.
115
+ //
116
+ // Conflicts of the second kind can be avoided by giving the
117
+ // alternative fixes different names (SuggestedFix.Message) and using
118
+ // a multi-section .txtar file with a named section for each
119
+ // alternative fix.
120
+ //
121
+ // Analyzers that compute fixes from a textual diff of the
122
+ // before/after file contents (instead of directly from syntax tree
123
+ // positions) may produce fixes that, although logically
124
+ // non-conflicting, nonetheless conflict due to the particulars of the
125
+ // diff algorithm. In such cases it may suffice to introduce
126
+ // sufficient separation of the statements in the test input so that
127
+ // the computed diffs do not overlap. If that fails, break the test
128
+ // into smaller parts.
101
129
func RunWithSuggestedFixes (t Testing , dir string , a * analysis.Analyzer , patterns ... string ) []* Result {
102
130
r := Run (t , dir , a , patterns ... )
103
131
@@ -135,7 +163,7 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
135
163
continue
136
164
}
137
165
if _ , ok := fileContents [file ]; ! ok {
138
- contents , err := ioutil .ReadFile (file .Name ())
166
+ contents , err := os .ReadFile (file .Name ())
139
167
if err != nil {
140
168
t .Errorf ("error reading %s: %v" , file .Name (), err )
141
169
}
@@ -186,7 +214,7 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
186
214
found = true
187
215
out , err := diff .ApplyBytes (orig , edits )
188
216
if err != nil {
189
- t .Errorf ("%s: error applying fixes: %v" , file .Name (), err )
217
+ t .Errorf ("%s: error applying fixes: %v (see possible explanations at RunWithSuggestedFixes) " , file .Name (), err )
190
218
continue
191
219
}
192
220
// the file may contain multiple trailing
@@ -220,7 +248,7 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
220
248
221
249
out , err := diff .ApplyBytes (orig , catchallEdits )
222
250
if err != nil {
223
- t .Errorf ("%s: error applying fixes: %v" , file .Name (), err )
251
+ t .Errorf ("%s: error applying fixes: %v (see possible explanations at RunWithSuggestedFixes) " , file .Name (), err )
224
252
continue
225
253
}
226
254
want := string (ar .Comment )
0 commit comments