mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-22 14:23:10 -05:00
Merge topic 'ctest-add_subdirectory'
7c5a120c38Tests: Add case covering both ctest subdirectory commands04deda1d2aCTest: Extract common implementation of add_subdirectory and subdirs Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !6795
This commit is contained in:
@@ -81,75 +81,20 @@ public:
|
||||
cmCTestTestHandler* TestHandler;
|
||||
};
|
||||
|
||||
bool cmCTestSubdirCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
bool ReadSubdirectory(std::string fname, cmExecutionStatus& status)
|
||||
{
|
||||
if (args.empty()) {
|
||||
status.SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
|
||||
for (std::string const& arg : args) {
|
||||
std::string fname;
|
||||
|
||||
if (cmSystemTools::FileIsFullPath(arg)) {
|
||||
fname = arg;
|
||||
} else {
|
||||
fname = cmStrCat(cwd, '/', arg);
|
||||
}
|
||||
|
||||
if (!cmSystemTools::FileIsDirectory(fname)) {
|
||||
// No subdirectory? So what...
|
||||
continue;
|
||||
}
|
||||
bool readit = false;
|
||||
{
|
||||
cmWorkingDirectory workdir(fname);
|
||||
if (workdir.Failed()) {
|
||||
status.SetError("Failed to change directory to " + fname + " : " +
|
||||
std::strerror(workdir.GetLastResult()));
|
||||
return false;
|
||||
}
|
||||
const char* testFilename;
|
||||
if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
|
||||
// does the CTestTestfile.cmake exist ?
|
||||
testFilename = "CTestTestfile.cmake";
|
||||
} else if (cmSystemTools::FileExists("DartTestfile.txt")) {
|
||||
// does the DartTestfile.txt exist ?
|
||||
testFilename = "DartTestfile.txt";
|
||||
} else {
|
||||
// No CTestTestfile? Who cares...
|
||||
continue;
|
||||
}
|
||||
fname += "/";
|
||||
fname += testFilename;
|
||||
readit = status.GetMakefile().ReadDependentFile(fname);
|
||||
}
|
||||
if (!readit) {
|
||||
status.SetError(cmStrCat("Could not load include file: ", fname));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmCTestAddSubdirectoryCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
if (args.empty()) {
|
||||
status.SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string fname =
|
||||
cmStrCat(cmSystemTools::GetCurrentWorkingDirectory(), '/', args[0]);
|
||||
|
||||
if (!cmSystemTools::FileExists(fname)) {
|
||||
// No subdirectory? So what...
|
||||
return true;
|
||||
}
|
||||
bool readit = false;
|
||||
{
|
||||
cmWorkingDirectory workdir(fname);
|
||||
if (workdir.Failed()) {
|
||||
status.SetError("Failed to change directory to " + fname + " : " +
|
||||
std::strerror(workdir.GetLastResult()));
|
||||
return false;
|
||||
}
|
||||
const char* testFilename;
|
||||
if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
|
||||
// does the CTestTestfile.cmake exist ?
|
||||
@@ -172,6 +117,44 @@ bool cmCTestAddSubdirectoryCommand(std::vector<std::string> const& args,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmCTestSubdirCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
if (args.empty()) {
|
||||
status.SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
|
||||
for (std::string const& arg : args) {
|
||||
std::string fname;
|
||||
|
||||
if (cmSystemTools::FileIsFullPath(arg)) {
|
||||
fname = arg;
|
||||
} else {
|
||||
fname = cmStrCat(cwd, '/', arg);
|
||||
}
|
||||
|
||||
if (!ReadSubdirectory(std::move(fname), status)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmCTestAddSubdirectoryCommand(std::vector<std::string> const& args,
|
||||
cmExecutionStatus& status)
|
||||
{
|
||||
if (args.empty()) {
|
||||
status.SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string fname =
|
||||
cmStrCat(cmSystemTools::GetCurrentWorkingDirectory(), '/', args[0]);
|
||||
|
||||
return ReadSubdirectory(std::move(fname), status);
|
||||
}
|
||||
|
||||
class cmCTestAddTestCommand : public cmCTestCommand
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -85,6 +85,38 @@ subdirs()
|
||||
endfunction()
|
||||
run_BadCTestTestfile()
|
||||
|
||||
function(run_Subdirectories)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Subdirectories)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
|
||||
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
|
||||
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/add_subdirectory")
|
||||
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/add_subdirectory/sub")
|
||||
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/subdirs")
|
||||
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/subdirs/sub")
|
||||
file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
|
||||
add_subdirectory(add_subdirectory)
|
||||
subdirs(subdirs)
|
||||
")
|
||||
file(WRITE "${RunCMake_TEST_BINARY_DIR}/add_subdirectory/CTestTestfile.cmake" "
|
||||
add_test(add_subdirectory \"${CMAKE_COMMAND}\" -E echo add_subdirectory)
|
||||
add_subdirectory(sub)
|
||||
")
|
||||
file(WRITE "${RunCMake_TEST_BINARY_DIR}/add_subdirectory/sub/CTestTestfile.cmake" "
|
||||
add_test(add_subdirectory.sub \"${CMAKE_COMMAND}\" -E echo add_subdirectory.sub)
|
||||
")
|
||||
file(WRITE "${RunCMake_TEST_BINARY_DIR}/subdirs/CTestTestfile.cmake" "
|
||||
add_test(subdirs \"${CMAKE_COMMAND}\" -E echo subdirs)
|
||||
subdirs(sub)
|
||||
")
|
||||
file(WRITE "${RunCMake_TEST_BINARY_DIR}/subdirs/sub/CTestTestfile.cmake" "
|
||||
add_test(subdirs.sub \"${CMAKE_COMMAND}\" -E echo subdirs.sub)
|
||||
")
|
||||
|
||||
run_cmake_command(Subdirectories ${CMAKE_CTEST_COMMAND} -N)
|
||||
endfunction()
|
||||
run_Subdirectories()
|
||||
|
||||
function(run_MergeOutput)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MergeOutput)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
^Test project [^
|
||||
]*/Tests/RunCMake/CTestCommandLine/Subdirectories
|
||||
Test #1: add_subdirectory
|
||||
Test #2: add_subdirectory\.sub
|
||||
Test #3: subdirs
|
||||
Test #4: subdirs\.sub
|
||||
+
|
||||
Total Tests: 4$
|
||||
Reference in New Issue
Block a user