18
18
#include " swift/Basic/SourceManager.h"
19
19
#include " swift/Parse/Lexer.h"
20
20
#include " llvm/Support/FileSystem.h"
21
+ #include " llvm/Support/FormatVariadic.h"
21
22
#include " llvm/Support/MemoryBuffer.h"
22
23
#include " llvm/Support/raw_ostream.h"
23
24
@@ -52,7 +53,8 @@ namespace {
52
53
// This is the message string with escapes expanded.
53
54
std::string MessageStr;
54
55
unsigned LineNo = ~0U ;
55
-
56
+ Optional<unsigned > ColumnNo;
57
+
56
58
std::vector<ExpectedFixIt> Fixits;
57
59
58
60
ExpectedDiagnosticInfo (const char *ExpectedStart,
@@ -127,6 +129,12 @@ DiagnosticVerifier::findDiagnostic(const ExpectedDiagnosticInfo &Expected,
127
129
I->getFilename () != BufferName)
128
130
continue ;
129
131
132
+ // If a specific column was expected, verify it. Add one to the captured
133
+ // index so expected column numbers correspond to printed output.
134
+ if (Expected.ColumnNo .hasValue () &&
135
+ I->getColumnNo () + 1 != (int )*Expected.ColumnNo )
136
+ continue ;
137
+
130
138
// Verify the classification and string.
131
139
if (I->getKind () != Expected.Classification ||
132
140
I->getMessage ().find (Expected.MessageStr ) == StringRef::npos)
@@ -262,10 +270,14 @@ bool DiagnosticVerifier::verifyFile(unsigned BufferID,
262
270
continue ;
263
271
}
264
272
273
+ ExpectedDiagnosticInfo Expected (DiagnosticLoc, ExpectedClassification);
265
274
int LineOffset = 0 ;
275
+
266
276
if (TextStartIdx > 0 && MatchStart[0 ] == ' @' ) {
267
- if (MatchStart[1 ] != ' +' && MatchStart[1 ] != ' -' ) {
268
- addError (MatchStart.data (), " expected '+'/'-' for line offset" );
277
+ if (MatchStart[1 ] != ' +' && MatchStart[1 ] != ' -' &&
278
+ MatchStart[1 ] != ' :' ) {
279
+ addError (MatchStart.data (),
280
+ " expected '+'/'-' for line offset, or ':' for column" );
269
281
continue ;
270
282
}
271
283
StringRef Offs;
@@ -285,13 +297,27 @@ bool DiagnosticVerifier::verifyFile(unsigned BufferID,
285
297
TextStartIdx = 0 ;
286
298
}
287
299
288
- if (Offs.getAsInteger (10 , LineOffset)) {
289
- addError (MatchStart.data (), " expected line offset before '{{'" );
290
- continue ;
300
+ size_t ColonIndex = Offs.find (' :' );
301
+ // Check whether a line offset was provided
302
+ if (ColonIndex != 0 ) {
303
+ StringRef LineOffs = Offs.slice (0 , ColonIndex);
304
+ if (LineOffs.getAsInteger (10 , LineOffset)) {
305
+ addError (MatchStart.data (), " expected line offset before '{{'" );
306
+ continue ;
307
+ }
291
308
}
292
- }
293
309
294
- ExpectedDiagnosticInfo Expected (DiagnosticLoc, ExpectedClassification);
310
+ // Check whether a column was provided
311
+ if (ColonIndex != StringRef::npos) {
312
+ Offs = Offs.slice (ColonIndex + 1 , Offs.size ());
313
+ int Column = 0 ;
314
+ if (Offs.getAsInteger (10 , Column)) {
315
+ addError (MatchStart.data (), " expected column before '{{'" );
316
+ continue ;
317
+ }
318
+ Expected.ColumnNo = Column;
319
+ }
320
+ }
295
321
296
322
unsigned Count = 1 ;
297
323
if (TextStartIdx > 0 ) {
@@ -532,12 +558,20 @@ bool DiagnosticVerifier::verifyFile(unsigned BufferID,
532
558
}
533
559
534
560
if (I == CapturedDiagnostics.end ()) continue ;
535
-
536
- auto StartLoc = SMLoc::getFromPointer (expected.MessageRange .begin ());
537
- auto EndLoc = SMLoc::getFromPointer (expected.MessageRange .end ());
538
-
539
- llvm::SMFixIt fixIt (llvm::SMRange{ StartLoc, EndLoc }, I->getMessage ());
540
- addError (expected.MessageRange .begin (), " incorrect message found" , fixIt);
561
+
562
+ if (I->getMessage ().find (expected.MessageStr ) == StringRef::npos) {
563
+ auto StartLoc = SMLoc::getFromPointer (expected.MessageRange .begin ());
564
+ auto EndLoc = SMLoc::getFromPointer (expected.MessageRange .end ());
565
+
566
+ llvm::SMFixIt fixIt (llvm::SMRange{StartLoc, EndLoc}, I->getMessage ());
567
+ addError (expected.MessageRange .begin (), " incorrect message found" , fixIt);
568
+ } else {
569
+ // The difference must be only in the column
570
+ addError (expected.MessageRange .begin (),
571
+ llvm::formatv (" message found at column {0} but was expected to "
572
+ " appear at column {1}" ,
573
+ I->getColumnNo () + 1 , *expected.ColumnNo ));
574
+ }
541
575
CapturedDiagnostics.erase (I);
542
576
ExpectedDiagnostics.erase (ExpectedDiagnostics.begin ()+i);
543
577
}
0 commit comments