Skip to content

Commit e3d92db

Browse files
committed
[DiagnosticVerifier] implement expected-expansion
Since freestanding macro expansion buffer names include the line number of their invocation, it can become quite fiddly to try to update a test file with multiple macro expansions. This adds the option to use an expected-expansion block and use a relative line number, nesting other expected diagnostic statements inside this block. Example syntax: ```swift let myVar = #myMacro /* expected-expansion@-2:1{{ expected-error@13:37{{I can't believe you've done this}} expected-note@14:38{{look at this and ponder your mistake}} }} */ ```
1 parent da56a52 commit e3d92db

File tree

5 files changed

+295
-136
lines changed

5 files changed

+295
-136
lines changed

include/swift/Frontend/DiagnosticVerifier.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef SWIFT_FRONTEND_DIAGNOSTIC_VERIFIER_H
1919
#define SWIFT_FRONTEND_DIAGNOSTIC_VERIFIER_H
2020

21+
#include "llvm/ADT/DenseMap.h"
2122
#include "llvm/ADT/SmallString.h"
2223
#include "swift/AST/DiagnosticConsumer.h"
2324
#include "swift/Basic/LLVM.h"
@@ -133,14 +134,25 @@ class DiagnosticVerifier : public DiagnosticConsumer {
133134
bool
134135
verifyUnknown(std::vector<CapturedDiagnosticInfo> &CapturedDiagnostics) const;
135136

137+
std::vector<llvm::SMDiagnostic> Errors;
138+
136139
/// verifyFile - After the file has been processed, check to see if we
137140
/// got all of the expected diagnostics and check to see if there were any
138141
/// unexpected ones.
139142
Result verifyFile(unsigned BufferID);
140143
unsigned parseExpectedDiagInfo(unsigned BufferID, StringRef MatchStart,
141-
std::vector<llvm::SMDiagnostic> &Errors,
142144
unsigned &PrevExpectedContinuationLine,
143-
ExpectedDiagnosticInfo &Expected) const;
145+
ExpectedDiagnosticInfo &Expected);
146+
void
147+
verifyDiagnostics(std::vector<ExpectedDiagnosticInfo> &ExpectedDiagnostics,
148+
unsigned BufferID);
149+
void verifyRemaining(std::vector<ExpectedDiagnosticInfo> &ExpectedDiagnostics,
150+
const char *FileStart);
151+
void addError(const char *Loc, const Twine &message,
152+
ArrayRef<llvm::SMFixIt> FixIts = {});
153+
154+
std::optional<LineColumnRange>
155+
parseExpectedFixItRange(StringRef &Str, unsigned DiagnosticLineNo);
144156

145157
bool checkForFixIt(const std::vector<ExpectedFixIt> &ExpectedAlts,
146158
const CapturedDiagnosticInfo &D, unsigned BufferID) const;
@@ -149,6 +161,8 @@ class DiagnosticVerifier : public DiagnosticConsumer {
149161
std::string renderFixits(ArrayRef<CapturedFixItInfo> ActualFixIts,
150162
unsigned BufferID, unsigned DiagnosticLineNo) const;
151163

164+
llvm::DenseMap<SourceLoc, unsigned> Expansions;
165+
152166
void printRemainingDiagnostics() const;
153167
};
154168

0 commit comments

Comments
 (0)