Add test helper execHelperAppInSearchPath()

This commit is contained in:
Martchus 2020-06-10 18:42:50 +02:00
parent 2ecc0adceb
commit 52722be407
3 changed files with 28 additions and 5 deletions

View File

@ -112,8 +112,8 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities") set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local) set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local)
set(META_VERSION_MAJOR 5) set(META_VERSION_MAJOR 5)
set(META_VERSION_MINOR 4) set(META_VERSION_MINOR 5)
set(META_VERSION_PATCH 1) set(META_VERSION_PATCH 0)
# find required 3rd party libraries # find required 3rd party libraries
include(3rdParty) include(3rdParty)

View File

@ -361,8 +361,8 @@ string TestApplication::workingCopyPathAs(
* \brief Executes an application with the specified \a args. * \brief Executes an application with the specified \a args.
* \remarks Provides internal implementation of execApp() and execHelperApp(). * \remarks Provides internal implementation of execApp() and execHelperApp().
*/ */
int execAppInternal(const char *appPath, const char *const *args, std::string &output, std::string &errors, bool suppressLogging, int timeout, static int execAppInternal(const char *appPath, const char *const *args, std::string &output, std::string &errors, bool suppressLogging, int timeout,
const std::string &newProfilingPath) const std::string &newProfilingPath, bool enableSearchPath = false)
{ {
// print log message // print log message
if (!suppressLogging) { if (!suppressLogging) {
@ -460,7 +460,12 @@ int execAppInternal(const char *appPath, const char *const *args, std::string &o
} }
// -> execute application // -> execute application
execv(appPath, const_cast<char *const *>(args)); if (enableSearchPath) {
execvp(appPath, const_cast<char *const *>(args));
} else {
execv(appPath, const_cast<char *const *>(args));
}
cerr << Phrases::Error << "Unable to execute \"" << appPath << "\": execv() failed" << Phrases::EndFlush; cerr << Phrases::Error << "Unable to execute \"" << appPath << "\": execv() failed" << Phrases::EndFlush;
exit(-101); exit(-101);
} }
@ -538,6 +543,22 @@ int execHelperApp(const char *appPath, const char *const *args, std::string &out
{ {
return execAppInternal(appPath, args, output, errors, suppressLogging, timeout, string()); return execAppInternal(appPath, args, output, errors, suppressLogging, timeout, string());
} }
/*!
* \brief Executes an application with the specified \a args.
*
* Searches for the location of \a appName among the directories specified by the PATH environment variable.
*
* \remarks
* - Intended to invoke helper applications (eg. to setup test files). Use execApp() and TestApplication::execApp() to
* invoke the application to be tested itself.
* - Currently only supported under UNIX.
*/
int execHelperAppInSearchPath(
const char *appName, const char *const *args, std::string &output, std::string &errors, bool suppressLogging, int timeout)
{
return execAppInternal(appName, args, output, errors, suppressLogging, timeout, string(), true);
}
#endif // PLATFORM_UNIX #endif // PLATFORM_UNIX
/*! /*!

View File

@ -181,6 +181,8 @@ inline CPP_UTILITIES_EXPORT int execApp(const char *const *args, std::string &ou
CPP_UTILITIES_EXPORT int execHelperApp( CPP_UTILITIES_EXPORT int execHelperApp(
const char *appPath, const char *const *args, std::string &output, std::string &errors, bool suppressLogging = false, int timeout = -1); const char *appPath, const char *const *args, std::string &output, std::string &errors, bool suppressLogging = false, int timeout = -1);
CPP_UTILITIES_EXPORT int execHelperAppInSearchPath(
const char *appName, const char *const *args, std::string &output, std::string &errors, bool suppressLogging = false, int timeout = -1);
#endif // PLATFORM_UNIX #endif // PLATFORM_UNIX
/*! /*!