Tests: Add cases covering our mkdtemp code paths
* `cmSystemTools::MakeTempDirectory` is our own code. * `uv_fs_mkdtemp` requires patching to backport to platforms not supported by upstream libuv.
This commit is contained in:
parent
ec24f910d8
commit
f189e64126
@ -33,6 +33,7 @@ set(CMakeLib_TESTS
|
||||
testFindPackageCommand.cxx
|
||||
testUVHandlePtr.cxx
|
||||
testUVJobServerClient.cxx
|
||||
testUVPatches.cxx
|
||||
testUVProcessChain.cxx
|
||||
testUVRAII.cxx
|
||||
testUVStreambuf.cxx
|
||||
|
@ -96,11 +96,34 @@ static bool testStrVersCmp()
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool testMakeTempDirectory()
|
||||
{
|
||||
std::cout << "testMakeTempDirectory()\n";
|
||||
|
||||
static std::string const kTemplate = "testMakeTempDirectory-XXXXXX";
|
||||
std::string tempDir = kTemplate;
|
||||
cmsys::Status status = cmSystemTools::MakeTempDirectory(tempDir);
|
||||
if (!status) {
|
||||
std::cout << "cmSystemTools::MakeTempDirectory failed on \"" << tempDir
|
||||
<< "\": " << status.GetString() << '\n';
|
||||
return false;
|
||||
}
|
||||
if (!cmSystemTools::FileIsDirectory(tempDir)) {
|
||||
std::cout << "cmSystemTools::MakeTempDirectory did not create \""
|
||||
<< tempDir << '\n';
|
||||
return false;
|
||||
}
|
||||
cmSystemTools::RemoveADirectory(tempDir);
|
||||
ASSERT_TRUE(tempDir != kTemplate);
|
||||
return true;
|
||||
}
|
||||
|
||||
int testSystemTools(int /*unused*/, char* /*unused*/[])
|
||||
{
|
||||
return runTests({
|
||||
testUpperCase,
|
||||
testVersionCompare,
|
||||
testStrVersCmp,
|
||||
testMakeTempDirectory,
|
||||
});
|
||||
}
|
||||
|
46
Tests/CMakeLib/testUVPatches.cxx
Normal file
46
Tests/CMakeLib/testUVPatches.cxx
Normal file
@ -0,0 +1,46 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
|
||||
#include <cmConfigure.h> // IWYU pragma: keep
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <cm3p/uv.h>
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
#include "testCommon.h"
|
||||
|
||||
static bool test_uv_fs_mkdtemp()
|
||||
{
|
||||
std::cout << "test_uv_fs_mkdtemp()\n";
|
||||
static std::string const kTemplate = "test-uv_fs_mkdtemp-XXXXXX";
|
||||
std::string tempDir;
|
||||
uv_fs_t tempDirReq;
|
||||
tempDirReq.data = &tempDir;
|
||||
uv_loop_t* loop = uv_default_loop();
|
||||
int r =
|
||||
uv_fs_mkdtemp(loop, &tempDirReq, kTemplate.c_str(), [](uv_fs_t* req) {
|
||||
if (req->data && req->path) {
|
||||
*static_cast<std::string*>(req->data) = req->path;
|
||||
}
|
||||
});
|
||||
ASSERT_EQUAL(r, 0);
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
uv_fs_req_cleanup(&tempDirReq);
|
||||
if (!cmSystemTools::FileIsDirectory(tempDir)) {
|
||||
std::cout << "cmSystemTools::MakeTempDirectory did not create \""
|
||||
<< tempDir << '\n';
|
||||
return false;
|
||||
}
|
||||
cmSystemTools::RemoveADirectory(tempDir);
|
||||
ASSERT_TRUE(tempDir != kTemplate);
|
||||
return true;
|
||||
}
|
||||
|
||||
int testUVPatches(int /*unused*/, char* /*unused*/[])
|
||||
{
|
||||
return runTests({
|
||||
test_uv_fs_mkdtemp,
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user