1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Use execvp in fs::RecursiveDelete()

This commit is contained in:
sfan5 2024-10-10 17:40:06 +02:00 committed by GitHub
parent 3f5a58a4e5
commit c8f1efebea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 69 additions and 35 deletions

View file

@ -42,6 +42,7 @@ public:
void testSafeWriteToFile();
void testCopyFileContents();
void testNonExist();
void testRecursiveDelete();
};
static TestFileSys g_test_instance;
@ -56,6 +57,7 @@ void TestFileSys::runTests(IGameDef *gamedef)
TEST(testSafeWriteToFile);
TEST(testCopyFileContents);
TEST(testNonExist);
TEST(testRecursiveDelete);
}
////////////////////////////////////////////////////////////////////////////////
@ -338,3 +340,32 @@ void TestFileSys::testNonExist()
auto ifs = open_ifstream(path.c_str(), false);
UASSERT(!ifs.good());
}
void TestFileSys::testRecursiveDelete()
{
std::string dirs[2];
dirs[0] = getTestTempDirectory() + DIR_DELIM "a";
dirs[1] = dirs[0] + DIR_DELIM "b";
std::string files[2] = {
dirs[0] + DIR_DELIM "file1",
dirs[1] + DIR_DELIM "file2"
};
for (auto &it : dirs)
fs::CreateDir(it);
for (auto &it : files)
open_ofstream(it.c_str(), false).close();
for (auto &it : dirs)
UASSERT(fs::IsDir(it));
for (auto &it : files)
UASSERT(fs::IsFile(it));
UASSERT(fs::RecursiveDelete(dirs[0]));
for (auto &it : dirs)
UASSERT(!fs::IsDir(it));
for (auto &it : files)
UASSERT(!fs::IsFile(it));
}