Add testDirPath() for finding directories with test files

The same as testFilePath(), just for directories.
This commit is contained in:
Martchus 2020-09-23 22:49:33 +02:00
parent 0b267c7959
commit dd41762b70
2 changed files with 32 additions and 4 deletions

View File

@ -233,16 +233,34 @@ TestApplication::~TestApplication()
* 3. The subdirectory "testfiles" within the source directory, if it could be determined via "srcref"-file. * 3. The subdirectory "testfiles" within the source directory, if it could be determined via "srcref"-file.
* 4. The subdirectory "testfiles" within present working directory. * 4. The subdirectory "testfiles" within present working directory.
*/ */
string TestApplication::testFilePath(const string &relativeTestFilePath) const std::string TestApplication::testFilePath(const std::string &relativeTestFilePath) const
{ {
string path; std::string path;
for (const auto &testFilesPath : m_testFilesPaths) { for (const auto &testFilesPath : m_testFilesPaths) {
if (fileExists(path = testFilesPath + relativeTestFilePath)) { if (fileExists(path = testFilesPath + relativeTestFilePath)) {
return path; return path;
} }
} }
throw runtime_error("The testfile \"" % relativeTestFilePath % "\" can not be located. Was looking under:" throw std::runtime_error("The test file \"" % relativeTestFilePath % "\" can not be located. Was looking under:"
+ joinStrings(m_testFilesPaths, "\n", false, string(), relativeTestFilePath)); + joinStrings(m_testFilesPaths, "\n", false, std::string(), relativeTestFilePath));
}
/*!
* \brief Returns the full path of the test directory with the specified \a relativeTestDirPath.
*
* This is the same as TestApplication::testFilePath() but for directories. Checkout the documentation of
* TestApplication::testFilePath() for details about the lookup.
*/
std::string TestApplication::testDirPath(const std::string &relativeTestDirPath) const
{
std::string path;
for (const auto &testFilesPath : m_testFilesPaths) {
if (dirExists(path = testFilesPath + relativeTestDirPath)) {
return path;
}
}
throw std::runtime_error("The test directory \"" % relativeTestDirPath % "\" can not be located. Was looking under:"
+ joinStrings(m_testFilesPaths, "\n", false, std::string(), relativeTestDirPath));
} }
/*! /*!

View File

@ -28,6 +28,7 @@ public:
// helper for tests // helper for tests
std::string testFilePath(const std::string &relativeTestFilePath) const; std::string testFilePath(const std::string &relativeTestFilePath) const;
std::string testDirPath(const std::string &relativeTestDirPath) const;
std::string workingCopyPath(const std::string &relativeTestFilePath, WorkingCopyMode mode = WorkingCopyMode::CreateCopy) const; std::string workingCopyPath(const std::string &relativeTestFilePath, WorkingCopyMode mode = WorkingCopyMode::CreateCopy) const;
std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath,
WorkingCopyMode mode = WorkingCopyMode::CreateCopy) const; WorkingCopyMode mode = WorkingCopyMode::CreateCopy) const;
@ -149,6 +150,15 @@ inline CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &relative
return TestApplication::instance()->testFilePath(relativeTestFilePath); return TestApplication::instance()->testFilePath(relativeTestFilePath);
} }
/*!
* \brief Convenience function to invoke TestApplication::testDirPath().
* \remarks A TestApplication must be present.
*/
inline CPP_UTILITIES_EXPORT std::string testDirPath(const std::string &relativeTestDirPath)
{
return TestApplication::instance()->testDirPath(relativeTestDirPath);
}
/*! /*!
* \brief Convenience function to invoke TestApplication::workingCopyPath(). * \brief Convenience function to invoke TestApplication::workingCopyPath().
* \remarks A TestApplication must be present. * \remarks A TestApplication must be present.