diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-14 17:54:31 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-24 09:25:05 +0100 |
commit | 65421290bbf0b7a5c76f8bdb09b63ef3166b3368 (patch) | |
tree | cf6b1e033718486d31d10e856047fbc5185119c2 /test/utils/cpp/tmp_dir.test.cpp | |
parent | e82785d6b5da237931288255481143f7b1430e51 (diff) | |
download | justbuild-65421290bbf0b7a5c76f8bdb09b63ef3166b3368.tar.gz |
Test TmpFile
Diffstat (limited to 'test/utils/cpp/tmp_dir.test.cpp')
-rw-r--r-- | test/utils/cpp/tmp_dir.test.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/utils/cpp/tmp_dir.test.cpp b/test/utils/cpp/tmp_dir.test.cpp index 0bc4d9d0..d1f89c11 100644 --- a/test/utils/cpp/tmp_dir.test.cpp +++ b/test/utils/cpp/tmp_dir.test.cpp @@ -96,4 +96,29 @@ TEST_CASE("tmp_dir", "[tmp_dir]") { REQUIRE(not FileSystemManager::Exists(child_1)); REQUIRE(not FileSystemManager::Exists(child_2)); } + + SECTION("temp files") { + auto parent_dir = TmpDir::Create(test_tempdir / "test_dir"); + REQUIRE(parent_dir != nullptr); + std::filesystem::path const parent = parent_dir->GetPath(); + + auto file = TmpDir::CreateFile(parent_dir); + REQUIRE(file != nullptr); + std::filesystem::path const file_path = file->GetPath(); + + REQUIRE(FileSystemManager::Exists(parent)); + REQUIRE(FileSystemManager::Exists(file_path)); + + // Kill the parent directory. File still retains a reference to the + // parent object, so parent should remain alive: + parent_dir = nullptr; + REQUIRE(FileSystemManager::Exists(parent)); + REQUIRE(FileSystemManager::Exists(file_path)); + + // Kill the file. Both the parent directory and the file should be + // deleted: + file = nullptr; + REQUIRE(not FileSystemManager::Exists(parent)); + REQUIRE(not FileSystemManager::Exists(file_path)); + } } |