summaryrefslogtreecommitdiffstats
path: root/Source/CTest
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-12-09 15:38:46 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-12-09 15:39:20 (GMT)
commit78c20892bfef6a961e780b0380c37537d1ee178b (patch)
tree96be00c28c5cb5f10df012e4d7fcf4228ffc7330 /Source/CTest
parent01e768850a4b250c5775e95c1568d59de07105de (diff)
parent7c5a120c38a90ee2ac262371410b5e31fd6f52be (diff)
downloadCMake-78c20892bfef6a961e780b0380c37537d1ee178b.zip
CMake-78c20892bfef6a961e780b0380c37537d1ee178b.tar.gz
CMake-78c20892bfef6a961e780b0380c37537d1ee178b.tar.bz2
Merge topic 'ctest-add_subdirectory'
7c5a120c38 Tests: Add case covering both ctest subdirectory commands 04deda1d2a CTest: Extract common implementation of add_subdirectory and subdirs Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !6795
Diffstat (limited to 'Source/CTest')
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx93
1 files changed, 38 insertions, 55 deletions
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 75777ab..5a3a8d0 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -81,6 +81,42 @@ public:
cmCTestTestHandler* TestHandler;
};
+bool ReadSubdirectory(std::string fname, cmExecutionStatus& status)
+{
+ 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 ?
+ testFilename = "CTestTestfile.cmake";
+ } else if (cmSystemTools::FileExists("DartTestfile.txt")) {
+ // does the DartTestfile.txt exist ?
+ testFilename = "DartTestfile.txt";
+ } else {
+ // No CTestTestfile? Who cares...
+ return true;
+ }
+ fname += "/";
+ fname += testFilename;
+ readit = status.GetMakefile().ReadDependentFile(fname);
+ }
+ if (!readit) {
+ status.SetError(cmStrCat("Could not find include file: ", fname));
+ return false;
+ }
+ return true;
+}
+
bool cmCTestSubdirCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
@@ -98,35 +134,7 @@ bool cmCTestSubdirCommand(std::vector<std::string> const& args,
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));
+ if (!ReadSubdirectory(std::move(fname), status)) {
return false;
}
}
@@ -144,32 +152,7 @@ bool cmCTestAddSubdirectoryCommand(std::vector<std::string> const& args,
std::string fname =
cmStrCat(cmSystemTools::GetCurrentWorkingDirectory(), '/', args[0]);
- if (!cmSystemTools::FileExists(fname)) {
- // No subdirectory? So what...
- return true;
- }
- bool readit = 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...
- return true;
- }
- fname += "/";
- fname += testFilename;
- readit = status.GetMakefile().ReadDependentFile(fname);
- }
- if (!readit) {
- status.SetError(cmStrCat("Could not find include file: ", fname));
- return false;
- }
- return true;
+ return ReadSubdirectory(std::move(fname), status);
}
class cmCTestAddTestCommand : public cmCTestCommand