12#if defined(PLATFORM_UNIX) || defined(CPP_UTILITIES_BOOST_PROCESS)
13#define CPP_UTILITIES_HAS_EXEC_APP
33 operator bool()
const;
36 std::string
testFilePath(
const std::string &relativeTestFilePath)
const;
37 std::string
testDirPath(
const std::string &relativeTestDirPath)
const;
39 std::string
workingCopyPathAs(
const std::string &relativeTestFilePath,
const std::string &relativeWorkingCopyPath,
41#ifdef CPP_UTILITIES_HAS_EXEC_APP
42 int execApp(
const char *
const *args, std::string &output, std::string &errors,
bool suppressLogging =
false,
int timeout = -1)
const;
46 const std::vector<std::string> &testFilePaths()
const;
47 const std::string &workingDirectory()
const;
48 const char *applicationPath();
49 bool unitsSpecified()
const;
50 const std::vector<const char *> &units()
const;
51 bool onlyListUnits()
const;
55 static const char *appPath();
58 static std::string readTestfilePathFromEnv();
59 static std::vector<std::string> readTestfilePathFromSrcRef();
68 std::vector<std::string> m_testFilesPaths;
69 std::string m_workingDir;
80inline TestApplication::operator
bool()
const
90 return TestApplication::s_instance;
106 return m_testFilesPaths;
139 return m_unitsArg.
values();
187#ifdef CPP_UTILITIES_HAS_EXEC_APP
207template <
typename Optional, Traits::EnableIf<Traits::IsSpecializationOf<Optional, std::optional>> * =
nullptr>
213 return out <<
"[no value]";
236 return lhs.value ==
rhs.value;
244 return out <<
'0' <<
'x' << std::hex << std::setfill(
'0') << std::setw(2) <<
unsigned(value.
value) << std::dec;
271template <
typename T, Traits::DisableIf<std::is_
integral<T>> * =
nullptr>
const T &
integralsAsHexNumber(
const T &value)
284#define TESTUTILS_ASSERT_EXEC(args) TESTUTILS_ASSERT_EXEC_EXIT_STATUS(args, 0)
294#ifdef CPP_UTILITIES_BOOST_PROCESS
295#define TESTUTILS_ASSERT_EXEC_EXIT_STATUS(args, expectedExitStatus) \
297 const auto status = execApp(args, stdout, stderr); \
298 if (status != expectedExitStatus) { \
299 CPPUNIT_FAIL(::CppUtilities::argsToString( \
300 "app exited with status ", status, " (expected ", expectedExitStatus, ")\nstdout: ", stdout, "\nstderr: ", stderr)); \
304#define TESTUTILS_ASSERT_EXEC_EXIT_STATUS(args, expectedExitStatus) \
306 const auto status = execApp(args, stdout, stderr); \
307 if (!WIFEXITED(status)) { \
308 CPPUNIT_FAIL(::CppUtilities::argsToString("app did not terminate normally\nstdout: ", stdout, "\nstderr: ", stderr)); \
310 if (const auto exitStatus = WEXITSTATUS(status); exitStatus != expectedExitStatus) { \
311 CPPUNIT_FAIL(::CppUtilities::argsToString( \
312 "app exited with status ", exitStatus, " (expected ", expectedExitStatus, ")\nstdout: ", stdout, "\nstderr: ", stderr)); \
321#define TESTUTILS_ASSERT_LIKE_FLAGS(message, expectedRegex, regexFlags, actualString) \
322 (CPPUNIT_NS::Asserter::failIf(!(std::regex_match(actualString, std::regex(expectedRegex, regexFlags))), \
323 CPPUNIT_NS::Message( \
324 CppUtilities::argsToString('\"', actualString, "\"\n not like\n\"", expectedRegex, '\"'), "Expression: " #actualString, message), \
325 CPPUNIT_SOURCELINE()))
331#define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString) \
332 TESTUTILS_ASSERT_LIKE_FLAGS(message, expectedRegex, std::regex::ECMAScript, actualString)
337template <typename Pair, CppUtilities::Traits::EnableIf<CppUtilities::Traits::IsSpecializationOf<Pair, std::pair>> * = nullptr>
338inline std::ostream &operator<<(std::ostream &out, const Pair &pair)
340 return out << "key: " << pair.first << "; value: " << pair.second << '\n';
346template <typename Iteratable, Traits::EnableIf<Traits::IsIteratable<Iteratable>, Traits::Not<Traits::IsString<Iteratable>>> * = nullptr>
347inline std::ostream &operator<<(std::ostream &out, const Iteratable &iteratable)
350 std::size_t index = 0;
351 for (const auto &item : iteratable) {
352 out << std::setw(2) << index << ':' << ' ' << integralsAsHexNumber(item) << '\n';
366constexpr std::size_t operator"" _st(unsigned long long size)
368 return static_cast<std::size_t>(size);
375constexpr std::uint64_t operator"" _uint64(unsigned long long size)
377 return static_cast<std::uint64_t>(size);
384constexpr std::int64_t operator"" _int64(unsigned long long size)
386 return static_cast<std::int64_t>(size);
388} // namespace Literals
389} // namespace CppUtilities
The ArgumentParser class provides a means for handling command line arguments.
const char * firstValue() const
Returns the first parameter value of the first occurrence of the argument.
const std::vector< const char * > & values(std::size_t occurrence=0) const
Returns the parameter values for the specified occurrence of argument.
bool isPresent() const
Returns an indication whether the argument could be detected when parsing.
The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using ...
AsHexNumber(const T &value)
Constructs a new instance; use asHexNumber() for convenience instead.
The ConfigValueArgument class is an Argument where setCombinable() is true by default.
The OperationArgument class is an Argument where denotesOperation() is true by default.
The TestApplication class simplifies writing test applications that require opening test files.
bool onlyListUnits() const
Returns whether the test application should only list available units and not actually run any tests.
const std::vector< const char * > & units() const
Returns the specified test units.
std::string testFilePath(const std::string &relativeTestFilePath) const
Returns the full path of the test file with the specified relativeTestFilePath.
static const char * appPath()
Returns the application path or an empty string if no application path has been set.
const std::vector< std::string > & testFilePaths() const
Returns the list of directories to look for test files.
bool unitsSpecified() const
Returns whether particular units have been specified.
const char * applicationPath()
Returns the application path or an empty string if no application path has been set.
const std::string & workingDirectory() const
Returns the directory which is supposed to used for storing files created by tests.
static const TestApplication * instance()
Returns the current TestApplication instance.
std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy) const
Returns the full path to a working copy of the test file with the specified relativeTestFilePath.
std::string testDirPath(const std::string &relativeTestDirPath) const
Returns the full path of the test directory with the specified relativeTestDirPath.
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Contains all utilities provides by the c++utilities library.
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &relativeTestFilePath)
Convenience function to invoke TestApplication::testFilePath().
CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &relativeTestFilePath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPath().
WorkingCopyMode
The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::worki...
CPP_UTILITIES_EXPORT std::string testDirPath(const std::string &relativeTestDirPath)
Convenience function to invoke TestApplication::testDirPath().
CPP_UTILITIES_EXPORT std::ostream & operator<<(std::ostream &out, Indentation indentation)
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
bool operator==(const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
Provides operator == required by CPPUNIT_ASSERT_EQUAL.
AsHexNumber< T > asHexNumber(const T &value)
Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or sim...
CPP_UTILITIES_EXPORT std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPathAs().
AsHexNumber< T > integralsAsHexNumber(const T &value)
Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or sim...