mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:54:47 +01:00
Merge type of diagnostic and its substitutions. (#366)
This commit is contained in:
@@ -21,15 +21,14 @@ struct FakeDiagnostic {
|
||||
// selection of the message.
|
||||
static constexpr llvm::StringLiteral Message = "{0}";
|
||||
|
||||
struct Substitutions {
|
||||
std::string message;
|
||||
};
|
||||
static auto Format(const Substitutions& substitutions) -> std::string {
|
||||
std::string message;
|
||||
|
||||
auto Format() -> std::string {
|
||||
// Work around a bug in Clang's unused const variable warning by marking it
|
||||
// used here with a no-op.
|
||||
static_cast<void>(ShortName);
|
||||
|
||||
return llvm::formatv(Message.data(), substitutions.message).str();
|
||||
return llvm::formatv(Message.data(), message).str();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -55,21 +54,18 @@ TEST(DiagTest, EmitWarnings) {
|
||||
reported.push_back(diagnostic.message);
|
||||
});
|
||||
|
||||
emitter.EmitWarningIf<FakeDiagnostic>(
|
||||
[](FakeDiagnostic::Substitutions& diagnostic) {
|
||||
diagnostic.message = "M1";
|
||||
return true;
|
||||
});
|
||||
emitter.EmitWarningIf<FakeDiagnostic>(
|
||||
[](FakeDiagnostic::Substitutions& diagnostic) {
|
||||
diagnostic.message = "M2";
|
||||
return false;
|
||||
});
|
||||
emitter.EmitWarningIf<FakeDiagnostic>(
|
||||
[](FakeDiagnostic::Substitutions& diagnostic) {
|
||||
diagnostic.message = "M3";
|
||||
return true;
|
||||
});
|
||||
emitter.EmitWarningIf<FakeDiagnostic>([](FakeDiagnostic& diagnostic) {
|
||||
diagnostic.message = "M1";
|
||||
return true;
|
||||
});
|
||||
emitter.EmitWarningIf<FakeDiagnostic>([](FakeDiagnostic& diagnostic) {
|
||||
diagnostic.message = "M2";
|
||||
return false;
|
||||
});
|
||||
emitter.EmitWarningIf<FakeDiagnostic>([](FakeDiagnostic& diagnostic) {
|
||||
diagnostic.message = "M3";
|
||||
return true;
|
||||
});
|
||||
|
||||
EXPECT_THAT(reported, ElementsAre("M1", "M3"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user