file_system.cpp 799 B

1234567891011121314151617181920212223
  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_system.h"
  5. namespace Carbon::Testing {
  6. auto AddFile(llvm::vfs::InMemoryFileSystem& fs, llvm::StringRef path)
  7. -> ErrorOr<Success> {
  8. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> file =
  9. llvm::MemoryBuffer::getFile(path);
  10. if (file.getError()) {
  11. return ErrorBuilder() << "Getting `" << path
  12. << "`: " << file.getError().message();
  13. }
  14. if (!fs.addFile(path, /*ModificationTime=*/0, std::move(*file))) {
  15. return ErrorBuilder() << "Duplicate file: `" << path << "`";
  16. }
  17. return Success();
  18. }
  19. } // namespace Carbon::Testing