error_builders_test.cpp 766 B

1234567891011121314151617181920212223242526272829
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "explorer/common/error_builders.h"
  5. #include <gtest/gtest.h>
  6. #include "explorer/common/source_location.h"
  7. namespace Carbon::Testing {
  8. namespace {
  9. auto ToString(const Error& err) -> std::string {
  10. std::string result;
  11. llvm::raw_string_ostream out(result);
  12. err.Print(out);
  13. return result;
  14. }
  15. TEST(ErrorBuildersTest, ProgramError) {
  16. Error err = ProgramError(SourceLocation("x", 1)) << "test";
  17. EXPECT_EQ(err.location(), "x:1");
  18. EXPECT_EQ(err.message(), "test");
  19. EXPECT_EQ(ToString(err), "x:1: test");
  20. }
  21. } // namespace
  22. } // namespace Carbon::Testing