mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 22:02:37 +01:00
Followup for #2490 The switch of DiagnosticMessage to have DiagnosticMessage means we don't need to use unique_ptr. This means that copy constructors are implicit again and don't need to be avoided, but per discussion still keeping with moves. Comments on HandleDiagnostic try to capture the use of moves there. I'm keeping DiagnosticLevel at the top-level, and adding some checking that notes are actually Notes. Also, adding MakeMessage to unify some of the logic (this has particularly been bugging me around format_fn, and I ran into it here because of the Diagnostic -> DiagnosticMessage change). The addition of NoTypeDeduction is intended to avoid some duplicative comments that'd been piling up. Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
59 lines
2.0 KiB
C++
59 lines
2.0 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TOOLCHAIN_DIAGNOSTICS_MOCKS_H_
|
|
#define CARBON_TOOLCHAIN_DIAGNOSTICS_MOCKS_H_
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include "toolchain/diagnostics/diagnostic_emitter.h"
|
|
|
|
namespace Carbon::Testing {
|
|
|
|
class MockDiagnosticConsumer : public DiagnosticConsumer {
|
|
public:
|
|
MOCK_METHOD(void, HandleDiagnostic, (Diagnostic diagnostic), (override));
|
|
};
|
|
|
|
MATCHER_P(IsDiagnosticMessage, matcher, "") {
|
|
const Diagnostic& diag = arg;
|
|
return testing::ExplainMatchResult(
|
|
matcher, diag.message.format_fn(diag.message), result_listener);
|
|
}
|
|
|
|
inline auto IsDiagnostic(testing::Matcher<DiagnosticKind> kind,
|
|
testing::Matcher<DiagnosticLevel> level,
|
|
testing::Matcher<int> line_number,
|
|
testing::Matcher<int> column_number,
|
|
testing::Matcher<std::string> message) {
|
|
return testing::AllOf(
|
|
testing::Field("level", &Diagnostic::level, level),
|
|
testing::Field(
|
|
"message", &Diagnostic::message,
|
|
testing::AllOf(
|
|
testing::Field("kind", &DiagnosticMessage::kind, kind),
|
|
testing::Field(
|
|
&DiagnosticMessage::location,
|
|
testing::AllOf(
|
|
testing::Field("line_number",
|
|
&DiagnosticLocation::line_number,
|
|
line_number),
|
|
testing::Field("column_number",
|
|
&DiagnosticLocation::column_number,
|
|
column_number))))),
|
|
IsDiagnosticMessage(message));
|
|
}
|
|
|
|
} // namespace Carbon::Testing
|
|
|
|
namespace Carbon {
|
|
|
|
// Printing helpers for tests.
|
|
void PrintTo(const Diagnostic& diagnostic, std::ostream* os);
|
|
void PrintTo(DiagnosticLevel level, std::ostream* os);
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_TOOLCHAIN_DIAGNOSTICS_MOCKS_H_
|