file_test_base_test.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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(llvm::StringRef path) : FileTestBase(path) {}
  15. auto RunOverFile(llvm::raw_ostream& stdout, llvm::raw_ostream& stderr)
  16. -> bool override {
  17. if (filename() == "example.carbon") {
  18. stdout << "something\n"
  19. "\n"
  20. "8: Line delta\n"
  21. "7: Negative line delta\n"
  22. "+*[]{}\n"
  23. "Foo baz\n";
  24. return true;
  25. } else if (filename() == "fail_example.carbon") {
  26. stderr << "Oops\n";
  27. return false;
  28. } else {
  29. ADD_FAILURE() << "Unexpected file: " << path().str();
  30. return false;
  31. }
  32. }
  33. };
  34. } // namespace
  35. auto RegisterFileTests(const std::vector<llvm::StringRef>& paths) -> void {
  36. FileTestBaseTest::RegisterTests(
  37. "FileTestBaseTest", paths,
  38. [](llvm::StringRef path) { return new FileTestBaseTest(path); });
  39. }
  40. } // namespace Carbon::Testing