From 34f3ebb45d7648898564ec092408ae741f117ab5 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 30 Oct 2017 23:03:43 +0100 Subject: [PATCH] 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. --- tests/testutils.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/testutils.cpp b/tests/testutils.cpp index 68c4c68..c1653b6 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -359,10 +359,22 @@ 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) { - throw runtime_error("Unable to execute application to be tested: no application path specified"); + // 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)