Просмотр исходного кода

Add a Diagnostic printer for tests. (#1087)

Jon Meow 4 лет назад
Родитель
Сommit
2296ceb56c
3 измененных файлов с 26 добавлено и 0 удалено
  1. 1 0
      toolchain/diagnostics/BUILD
  2. 18 0
      toolchain/diagnostics/mocks.cpp
  3. 7 0
      toolchain/diagnostics/mocks.h

+ 1 - 0
toolchain/diagnostics/BUILD

@@ -22,6 +22,7 @@ cc_library(
 cc_library(
     name = "mocks",
     testonly = 1,
+    srcs = ["mocks.cpp"],
     hdrs = ["mocks.h"],
     deps = [
         ":diagnostic_emitter",

+ 18 - 0
toolchain/diagnostics/mocks.cpp

@@ -0,0 +1,18 @@
+// 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
+
+#include "toolchain/diagnostics/mocks.h"
+
+namespace Carbon {
+
+void PrintTo(const Diagnostic& diagnostic, std::ostream* os) {
+  *os << "Diagnostic{"
+      << (diagnostic.level == Diagnostic::Level::Error ? "Error" : "Warning")
+      << ", " << diagnostic.location.file_name << ":"
+      << diagnostic.location.line_number << ":"
+      << diagnostic.location.column_number << ", "
+      << diagnostic.short_name.str() << ", " << diagnostic.message << "}";
+}
+
+}  // namespace Carbon

+ 7 - 0
toolchain/diagnostics/mocks.h

@@ -53,4 +53,11 @@ auto DiagnosticShortName(Matcher&& inner_matcher) -> auto {
 
 }  // namespace Carbon::Testing
 
+namespace Carbon {
+
+// Printing helper for tests.
+void PrintTo(const Diagnostic& diagnostic, std::ostream* os);
+
+}  // namespace Carbon
+
 #endif  // TOOLCHAIN_DIAGNOSTICS_MOCKS_H_