Improve test helper for launching an app
* Add helper that allows to specify the exit code (in case a non-zero exit code is actually expected) * Use the proper macros to inspect the status returned by `waitpid()` to print/check the exit status correctly
This commit is contained in:
parent
93a632e831
commit
cb5ca77658
|
@ -277,11 +277,25 @@ template <typename T, Traits::DisableIf<std::is_integral<T>> * = nullptr> const
|
||||||
*
|
*
|
||||||
* \remarks Requires cppunit.
|
* \remarks Requires cppunit.
|
||||||
*/
|
*/
|
||||||
#define TESTUTILS_ASSERT_EXEC(args) \
|
#define TESTUTILS_ASSERT_EXEC(args) TESTUTILS_ASSERT_EXEC_EXIT_STATUS(args, 0)
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Asserts the execution of the application with the specified CLI \a args and the specified \a expectedExitStatus.
|
||||||
|
*
|
||||||
|
* The application is executed via TestApplication::execApp(). Output is stored in the std::string variables stdout
|
||||||
|
* and stderr.
|
||||||
|
*
|
||||||
|
* \remarks Requires cppunit.
|
||||||
|
*/
|
||||||
|
#define TESTUTILS_ASSERT_EXEC_EXIT_STATUS(args, expectedExitStatus) \
|
||||||
{ \
|
{ \
|
||||||
const auto returnCode = execApp(args, stdout, stderr); \
|
const auto status = execApp(args, stdout, stderr); \
|
||||||
if (returnCode != 0) { \
|
if (!WIFEXITED(status)) { \
|
||||||
CPPUNIT_FAIL(::CppUtilities::argsToString("app failed with return code ", returnCode, "\nstdout: ", stdout, "\nstderr: ", stderr)); \
|
CPPUNIT_FAIL(::CppUtilities::argsToString("app did not terminate normally\nstdout: ", stdout, "\nstderr: ", stderr)); \
|
||||||
|
} \
|
||||||
|
if (const auto exitStatus = WEXITSTATUS(status); exitStatus != expectedExitStatus) { \
|
||||||
|
CPPUNIT_FAIL(::CppUtilities::argsToString( \
|
||||||
|
"app exited with status ", exitStatus, " (expected ", expectedExitStatus, ")\nstdout: ", stdout, "\nstderr: ", stderr)); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue