file_test_base_test.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "testing/file_test/file_test_base.h"
  5. #include <gmock/gmock.h>
  6. #include <gtest/gtest.h>
  7. #include <vector>
  8. #include "llvm/ADT/StringRef.h"
  9. #include "llvm/Support/raw_ostream.h"
  10. namespace Carbon::Testing {
  11. namespace {
  12. class FileTestBaseTest : public FileTestBase {
  13. public:
  14. explicit FileTestBaseTest(const std::filesystem::path& path)
  15. : FileTestBase(path) {}
  16. auto RunOverFile(llvm::raw_ostream& stdout, llvm::raw_ostream& stderr)
  17. -> bool override {
  18. auto filename = path().filename();
  19. if (filename == "example.carbon") {
  20. stdout << "something\n"
  21. "\n"
  22. "8: Line delta\n"
  23. "7: Negative line delta\n"
  24. "+*[]{}\n"
  25. "Foo baz\n";
  26. return true;
  27. } else if (filename == "fail_example.carbon") {
  28. stderr << "Oops\n";
  29. return false;
  30. } else {
  31. ADD_FAILURE() << "Unexpected file: " << filename;
  32. return false;
  33. }
  34. }
  35. };
  36. } // namespace
  37. auto RegisterFileTests(const std::vector<std::filesystem::path>& paths)
  38. -> void {
  39. FileTestBaseTest::RegisterTests("FileTestBaseTest", paths,
  40. [](const std::filesystem::path& path) {
  41. return new FileTestBaseTest(path);
  42. });
  43. }
  44. } // namespace Carbon::Testing