Skip to content

Commit

Permalink
Merge branch 'inherit_assert' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bxparks committed Mar 22, 2018
2 parents 44041e4 + e76c207 commit 708d681
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 178 deletions.
4 changes: 2 additions & 2 deletions src/AUnit.h
Expand Up @@ -35,10 +35,10 @@ SOFTWARE.
#include "aunit/Verbosity.h"
#include "aunit/Compare.h"
#include "aunit/Printer.h"
#include "aunit/Test.h"
#include "aunit/TestRunner.h"
#include "aunit/Assertion.h"
#include "aunit/MetaAssertion.h"
#include "aunit/Test.h"
#include "aunit/TestRunner.h"

// Version format: 010203 == "1.2.3"
#define AUNIT_VERSION 000303
Expand Down
112 changes: 74 additions & 38 deletions src/aunit/Assertion.cpp
Expand Up @@ -22,10 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include "TestRunner.h" // seems like a circular reference but ok from cpp file
#include "Assertion.h"

namespace aunit {


// This can be a template function because it is accessed only through the
// various assertXxx() methods. Those assertXxx() methods are explicitly
// overloaded for the various types that we want to support.
Expand All @@ -37,11 +39,6 @@ template <typename A, typename B>
void printAssertionMessage(bool ok, const char* file, uint16_t line,
const A& lhs, const char *opName, const B& rhs) {

bool isOutput =
(ok && TestRunner::isVerbosity(Verbosity::kAssertionPassed)) ||
(!ok && TestRunner::isVerbosity(Verbosity::kAssertionFailed));
if (!isOutput) return;

// Don't use F() strings here because flash memory strings are not deduped by
// the compiler, so each template instantiation of this method causes a
// duplication of all the strings below. See
Expand All @@ -56,158 +53,197 @@ void printAssertionMessage(bool ok, const char* file, uint16_t line,
printer->print(opName);
printer->print(" (");
printer->print(rhs);
printer->print("), file ");
printer->print(')');
// reuse string in MataAssertion::printAssertionTestStatusMessage()
printer->print(", file ");
printer->print(file);
printer->print(", line ");
printer->print(line);
printer->println('.');
}

bool assertion(const char* file, uint16_t line, bool lhs,
bool Assertion::isOutputEnabled(bool ok) {
return (ok && TestRunner::isVerbosity(Verbosity::kAssertionPassed)) ||
(!ok && TestRunner::isVerbosity(Verbosity::kAssertionFailed));
}

bool Assertion::assertion(const char* file, uint16_t line, bool lhs,
const char* opName, bool (*op)(bool lhs, bool rhs),
bool rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, char lhs,
bool Assertion::assertion(const char* file, uint16_t line, char lhs,
const char* opName, bool (*op)(char lhs, char rhs),
char rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, int lhs,
bool Assertion::assertion(const char* file, uint16_t line, int lhs,
const char* opName, bool (*op)(int lhs, int rhs),
int rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, unsigned int lhs,
bool Assertion::assertion(const char* file, uint16_t line, unsigned int lhs,
const char* opName, bool (*op)(unsigned int lhs, unsigned int rhs),
unsigned int rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, long lhs,
bool Assertion::assertion(const char* file, uint16_t line, long lhs,
const char* opName, bool (*op)(long lhs, long rhs),
long rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, unsigned long lhs,
bool Assertion::assertion(const char* file, uint16_t line, unsigned long lhs,
const char* opName, bool (*op)(unsigned long lhs, unsigned long rhs),
unsigned long rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, double lhs,
bool Assertion::assertion(const char* file, uint16_t line, double lhs,
const char* opName, bool (*op)(double lhs, double rhs),
double rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, const char* lhs,
bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
const char* opName, bool (*op)(const char* lhs, const char* rhs),
const char* rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, const char* lhs,
bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
const char *opName, bool (*op)(const char* lhs, const String& rhs),
const String& rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, const char* lhs,
bool Assertion::assertion(const char* file, uint16_t line, const char* lhs,
const char *opName,
bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
const __FlashStringHelper* rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, const String& lhs,
bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
const char *opName, bool (*op)(const String& lhs, const char* rhs),
const char* rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, const String& lhs,
bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
const char *opName, bool (*op)(const String& lhs, const String& rhs),
const String& rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line, const String& lhs,
bool Assertion::assertion(const char* file, uint16_t line, const String& lhs,
const char *opName,
bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
const __FlashStringHelper* rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line,
bool Assertion::assertion(const char* file, uint16_t line,
const __FlashStringHelper* lhs, const char *opName,
bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
const char* rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line,
bool Assertion::assertion(const char* file, uint16_t line,
const __FlashStringHelper* lhs, const char *opName,
bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
const String& rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}

bool assertion(const char* file, uint16_t line,
bool Assertion::assertion(const char* file, uint16_t line,
const __FlashStringHelper* lhs, const char *opName,
bool (*op)(const __FlashStringHelper* lhs, const __FlashStringHelper* rhs),
const __FlashStringHelper* rhs) {
bool ok = op(lhs, rhs);
printAssertionMessage(ok, file, line, lhs, opName, rhs);
if (isOutputEnabled(ok)) {
printAssertionMessage(ok, file, line, lhs, opName, rhs);
}
TestRunner::setPassOrFail(ok);
return ok;
}
Expand Down

0 comments on commit 708d681

Please sign in to comment.