install_paths_test_helpers.cpp 1.1 KB

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 "toolchain/install/install_paths_test_helpers.h"
  5. #include "testing/base/global_exe_path.h"
  6. namespace Carbon::Testing {
  7. // Prepares the VFS with prelude files from the real filesystem. Primarily for
  8. // tests.
  9. auto AddPreludeFilesToVfs(InstallPaths install_paths,
  10. llvm::vfs::InMemoryFileSystem* vfs) -> void {
  11. // Load the prelude into the test VFS.
  12. auto real_fs = llvm::vfs::getRealFileSystem();
  13. auto prelude = install_paths.ReadPreludeManifest();
  14. CARBON_CHECK(prelude.ok(), "{0}", prelude.error());
  15. for (const auto& path : *prelude) {
  16. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> file =
  17. real_fs->getBufferForFile(path);
  18. CARBON_CHECK(file, "Error getting file: {0}", file.getError().message());
  19. bool added = vfs->addFile(path, /*ModificationTime=*/0, std::move(*file));
  20. CARBON_CHECK(added, "Duplicate file: {0}", path);
  21. }
  22. }
  23. } // namespace Carbon::Testing