From 6bba99fce1a25725182f22701ac3d74b965d7454 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 17 Mar 2020 14:33:30 -0700 Subject: [PATCH] add testStrEq() --- src/pvxs/unittest.h | 9 ++++++++ src/unittest.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/pvxs/unittest.h b/src/pvxs/unittest.h index daf331f..c6a3b82 100644 --- a/src/pvxs/unittest.h +++ b/src/pvxs/unittest.h @@ -122,6 +122,9 @@ testCase testNotEq(const char *sLHS, const LHS& lhs, const char *sRHS, const RHS return ret; } +PVXS_API +testCase _testStrEq(const char *sLHS, const std::string& lhs, const char *sRHS, const std::string& rhs); + } // namespace detail /** Assert that an exception is thrown. @@ -175,6 +178,12 @@ testCase testThrows(FN fn) //! Roughly equivalent to @code testOk((LHS)!=(RHS), "..."); @endcode #define testNotEq(LHS, RHS) ::pvxs::detail::testNotEq(#LHS, LHS, #RHS, RHS) +//! Macro which asserts equality between LHS and RHS. +//! Evaluates to a pvxs::testCase +//! Functionally equivalent to testEq() with two std::string instances. +//! Prints diff-like output which is friendlier to multi-line strings. +#define testStrEq(LHS, RHS) ::pvxs::detail::_testStrEq(#LHS, LHS, #RHS, RHS) + //! Macro which prints diagnostic (non-test) lines. //! Evaluates to a pvxs::testCase //! Roughly equivalent to @code testDiag("..."); @endcode diff --git a/src/unittest.cpp b/src/unittest.cpp index d7a3465..909fe89 100644 --- a/src/unittest.cpp +++ b/src/unittest.cpp @@ -7,6 +7,7 @@ #include #include "pvxs/unittest.h" +#include "utilpvt.h" namespace pvxs { @@ -63,4 +64,59 @@ testCase::~testCase() } } +namespace detail { + +size_t findNextLine(const std::string& s, size_t pos=0u) +{ + size_t next = s.find_first_of('\n', pos); + if(next!=std::string::npos) + next++; + return next; +} + +testCase _testStrEq(const char *sLHS, const std::string& lhs, const char *sRHS, const std::string& rhs) +{ + testCase ret(lhs==rhs); + ret<