mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 11:50:09 +01:00
This should clean up our top level directory and the build patterns. No non-mechanical edits here. Just injecting `toolchain/` and `TOOLCHAIN_` and then running formatting tools.
58 lines
1.8 KiB
C++
58 lines
1.8 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 TOOLCHAIN_DIAGNOSTICS_MOCKS_H_
|
|
#define TOOLCHAIN_DIAGNOSTICS_MOCKS_H_
|
|
|
|
#include "gmock/gmock.h"
|
|
#include "toolchain/diagnostics/diagnostic_emitter.h"
|
|
|
|
namespace Carbon {
|
|
namespace Testing {
|
|
|
|
class MockDiagnosticConsumer : public DiagnosticConsumer {
|
|
public:
|
|
// TODO: Use `MOCK_METHOD` once it's available.
|
|
MOCK_METHOD1(HandleDiagnostic, void(const Diagnostic& diagnostic));
|
|
};
|
|
|
|
// Matcher `DiagnosticAt` matches the location of a diagnostic.
|
|
MATCHER_P2(DiagnosticAt, line, column, "") {
|
|
const Diagnostic& diag = arg;
|
|
const Diagnostic::Location& loc = diag.location;
|
|
if (loc.line_number != line) {
|
|
*result_listener << "\nExpected diagnostic on line " << line
|
|
<< " but diagnostic is on line " << loc.line_number << ".";
|
|
return false;
|
|
}
|
|
if (loc.column_number != column) {
|
|
*result_listener << "\nExpected diagnostic on column " << column
|
|
<< " but diagnostic is on column " << loc.column_number
|
|
<< ".";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
auto DiagnosticLevel(Diagnostic::Level level) -> auto {
|
|
return testing::Field(&Diagnostic::level, level);
|
|
}
|
|
|
|
template <typename Matcher>
|
|
auto DiagnosticMessage(Matcher&& inner_matcher) -> auto {
|
|
return testing::Field(&Diagnostic::message,
|
|
std::forward<Matcher&&>(inner_matcher));
|
|
}
|
|
|
|
template <typename Matcher>
|
|
auto DiagnosticShortName(Matcher&& inner_matcher) -> auto {
|
|
return testing::Field(&Diagnostic::short_name,
|
|
std::forward<Matcher&&>(inner_matcher));
|
|
}
|
|
|
|
} // namespace Testing
|
|
} // namespace Carbon
|
|
|
|
#endif // TOOLCHAIN_DIAGNOSTICS_MOCKS_H_
|