Let tests find the application path without extra args

Currently the path of the application to be tested always had to
be specified either manually using the -a argument or by running
the tests via the build system targets. The first option is annoying
and the second option not so nice when using Qt Creator and the
debugger.

This commit makes tests assume the application to be tested is
called like the test executable itself, just without "_tests"-suffix.
This commit is contained in:
Martchus 2017-10-30 23:03:43 +01:00
parent 2bb4aa36a4
commit 34f3ebb45d
1 changed files with 15 additions and 3 deletions

View File

@ -359,11 +359,23 @@ int TestApplication::execApp(const char *const *args, string &output, string &er
static unsigned int invocationCount = 0;
++invocationCount;
// determine application path
const char *const appPath = m_applicationPathArg.firstValue();
// determine the path of the application to be tested
const char *appPath = m_applicationPathArg.firstValue();
string fallbackAppPath;
if (!appPath || !*appPath) {
// try to find the path by removing "_tests"-suffix from own executable path
// (the own executable path is the path of the test application and its name is usually the name of the application
// to be tested with "_tests"-suffix)
const char *const testAppPath = m_parser.executable();
const size_t testAppPathLength = strlen(testAppPath);
if (testAppPathLength > 6 && !strcmp(testAppPath + testAppPathLength - 6, "_tests")) {
fallbackAppPath.assign(testAppPath, testAppPathLength - 6);
appPath = fallbackAppPath.data();
// TODO: it would not hurt to verify whether "fallbackAppPath" actually exists and is executalbe
} else {
throw runtime_error("Unable to execute application to be tested: no application path specified");
}
}
// determine new path for profiling output (to not override profiling output of parent and previous invocations)
string newProfilingPath;