Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align assertion statements; change some stderr to stdout and flush #322

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Update .gitattributes so we have consistent line endings
- Change 266 files from CRLF to LF.
- Run tests on push as well as on a pull request so developers can see impact
- Align value indicators in assertion statements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am being picky, but it would be great if you could split up the current commit (4bf8b53) into two separate commits, one for each entry here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you post a screenshot of the before/after alignment? I'm not sure what this change is addressing

- Change some stderr messages in unittest to stdout and add flushes to prevent loss from SEGFAULT

### Deprecated

Expand Down
29 changes: 15 additions & 14 deletions cpp/unittest/ArduinoUnitTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,20 @@ class Test
~ReporterTAP() {}

void onTestRunInit(int numTests) {
cerr << "TAP version 13" << endl;
cerr << 1 << ".." << numTests << endl; // we know how many tests, in advance
cout << "TAP version 13" << endl << flush;
cout << 1 << ".." << numTests << endl << flush; // we know how many tests, in advance
mTestCounter = 0;
}

void onTestStart(TestData td) {
mAssertCounter = 0;
++mTestCounter;
cerr << "# Subtest: " << td.name << endl;
cout << "# Subtest: " << td.name << endl << flush;
}

void onTestEnd(TestData td) {
cerr << " 1.." << mAssertCounter << endl;
if (td.result == RESULT_PASS) {
cerr << "ok " << mTestCounter << " - " << td.name << endl;
} else {
cerr << "not ok " << mTestCounter << " - " << td.name << endl;
}
cout << " 1.." << mAssertCounter << endl << flush;
cout << (td.result == RESULT_PASS ? "ok " : "not ok ") << mTestCounter << " - " << td.name << endl << flush;
}

// non-comparative assert
Expand All @@ -76,8 +72,10 @@ class Test
const char* description,
bool pass
) {
cerr << " " << (pass ? "" : "not ") << "ok " << ++mAssertCounter << " - " << description << endl;
if (!pass) {
if (pass) {
cout << " ok " << ++mAssertCounter << " - " << description << endl << flush;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here.

} else {
cout << " not ok " << ++mAssertCounter << " - " << description << endl << flush;
cerr << " ---" << endl;
cerr << " at:" << endl;
cerr << " file: " << file << endl;
Expand All @@ -99,9 +97,12 @@ class Test
const char* rhsLabel,
const B &rhs
) {
cerr << " " << (pass ? "" : "not ") << "ok " << ++mAssertCounter << " - ";
cerr << description << " " << lhsLabel << " " << opLabel << " " << rhsLabel << endl;
if (!pass) {
if (pass) {
cout << " ok " << ++mAssertCounter << " - ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here.

cout << description << " " << lhsLabel << " " << opLabel << " " << rhsLabel << endl << flush;
} else {
cout << " not ok " << ++mAssertCounter << " - ";
cout << description << " " << lhsLabel << " " << opLabel << " " << rhsLabel << endl << flush;
cerr << " ---" << endl;
cerr << " operator: " << opLabel << endl;
cerr << " " << lhsRelevance << ": " << lhs << endl;
Expand Down
40 changes: 20 additions & 20 deletions cpp/unittest/Assertion.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@
#define assertFalse(arg) arduinoCITestBehaviorExp(false, "False " #arg, !(arg))
#define assertNull(arg) arduinoCITestBehaviorExp(false, "Null " #arg, ((void*)NULL == (void*)(arg)))
#define assertNotNull(arg) arduinoCITestBehaviorExp(false, "NotNull " #arg, ((void*)NULL != (void*)(arg)))
#define assertEqual(arg1,arg2) arduinoCIAssertOp("Equal","expected",arg1,compareEqual,"==","actual",arg2)
#define assertNotEqual(arg1,arg2) arduinoCIAssertOp("NotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
#define assertComparativeEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>","actual",arg2)
#define assertComparativeNotEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>","actual",arg2)
#define assertLess(arg1,arg2) arduinoCIAssertOp("Less","lowerBound",arg1,compareLess,"<","actual",arg2)
#define assertMore(arg1,arg2) arduinoCIAssertOp("More","upperBound",arg1,compareMore,">","actual",arg2)
#define assertLessOrEqual(arg1,arg2) arduinoCIAssertOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","actual",arg2)
#define assertMoreOrEqual(arg1,arg2) arduinoCIAssertOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","actual",arg2)
#define assertEqual(arg1,arg2) arduinoCIAssertOp("Equal","expected",arg1,compareEqual,"=="," actual",arg2)
#define assertNotEqual(arg1,arg2) arduinoCIAssertOp("NotEqual","unwanted",arg1,compareNotEqual,"!="," actual",arg2)
#define assertComparativeEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>"," actual",arg2)
#define assertComparativeNotEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>"," actual",arg2)
#define assertLess(arg1,arg2) arduinoCIAssertOp("Less","lowerBound",arg1,compareLess,"<"," actual",arg2)
#define assertMore(arg1,arg2) arduinoCIAssertOp("More","upperBound",arg1,compareMore,">"," actual",arg2)
#define assertLessOrEqual(arg1,arg2) arduinoCIAssertOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<="," actual",arg2)
#define assertMoreOrEqual(arg1,arg2) arduinoCIAssertOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">="," actual",arg2)

#define assertEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("EqualFloat", "epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
#define assertNotEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("NotEqualFloat", "epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
#define assertEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("EqualFloat", " epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either add some comments explaining how the extra spaces work, or possibly work around it entirely by making it part of the macro.

#define assertNotEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("NotEqualFloat", " epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
#define assertInfinity(arg) arduinoCITestBehaviorExp(false, "Infinity " #arg, isinf(arg))
#define assertNotInfinity(arg) arduinoCITestBehaviorExp(false, "NotInfinity " #arg, !isinf(arg))
#define assertNAN(arg) arduinoCITestBehaviorExp(false, "NAN " #arg, isnan(arg))
Expand All @@ -66,17 +66,17 @@
#define assureFalse(arg) arduinoCITestBehaviorExp(true, "False " #arg, !(arg))
#define assureNull(arg) arduinoCITestBehaviorExp(true, "Null " #arg, ((void*)NULL == (void*)(arg)))
#define assureNotNull(arg) arduinoCITestBehaviorExp(true, "NotNull " #arg, ((void*)NULL != (void*)(arg)))
#define assureEqual(arg1,arg2) arduinoCIAssureOp("Equal","expected",arg1,compareEqual,"==","actual",arg2)
#define assureNotEqual(arg1,arg2) arduinoCIAssureOp("NotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
#define assureComparativeEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>","actual",arg2)
#define assureComparativeNotEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>","actual",arg2)
#define assureLess(arg1,arg2) arduinoCIAssureOp("Less","lowerBound",arg1,compareLess,"<","actual",arg2)
#define assureMore(arg1,arg2) arduinoCIAssureOp("More","upperBound",arg1,compareMore,">","actual",arg2)
#define assureLessOrEqual(arg1,arg2) arduinoCIAssureOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","actual",arg2)
#define assureMoreOrEqual(arg1,arg2) arduinoCIAssureOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","actual",arg2)
#define assureEqual(arg1,arg2) arduinoCIAssureOp("Equal","expected",arg1,compareEqual,"=="," actual",arg2)
#define assureNotEqual(arg1,arg2) arduinoCIAssureOp("NotEqual","unwanted",arg1,compareNotEqual,"!="," actual",arg2)
#define assureComparativeEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>"," actual",arg2)
#define assureComparativeNotEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>"," actual",arg2)
#define assureLess(arg1,arg2) arduinoCIAssureOp("Less","lowerBound",arg1,compareLess,"<"," actual",arg2)
#define assureMore(arg1,arg2) arduinoCIAssureOp("More","upperBound",arg1,compareMore,">"," actual",arg2)
#define assureLessOrEqual(arg1,arg2) arduinoCIAssureOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<="," actual",arg2)
#define assureMoreOrEqual(arg1,arg2) arduinoCIAssureOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">="," actual",arg2)

#define assureEqualFloat(arg1, arg2, arg3) arduinoCIAssureOp("EqualFloat", "epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
#define assureNotEqualFloat(arg1, arg2, arg3) arduinoCIAssureOp("NotEqualFloat", "epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
#define assureEqualFloat(arg1, arg2, arg3) arduinoCIAssureOp("EqualFloat", " epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
#define assureNotEqualFloat(arg1, arg2, arg3) arduinoCIAssureOp("NotEqualFloat", " epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
#define assureInfinity(arg) arduinoCITestBehaviorExp(true, "Infinity " #arg, isinf(arg))
#define assureNotInfinity(arg) arduinoCITestBehaviorExp(true, "NotInfinity " #arg, !isinf(arg))
#define assureNAN(arg) arduinoCITestBehaviorExp(true, "NAN " #arg, isnan(arg))
Expand Down