Skip to content

Commit 4bf8b53

Browse files
committed
Align assertion statements; change some stderr to stdout and flush
1 parent 21b63e6 commit 4bf8b53

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

cpp/unittest/ArduinoUnitTests.h

+15-14
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,20 @@ class Test
4949
~ReporterTAP() {}
5050

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

5757
void onTestStart(TestData td) {
5858
mAssertCounter = 0;
5959
++mTestCounter;
60-
cerr << "# Subtest: " << td.name << endl;
60+
cout << "# Subtest: " << td.name << endl << flush;
6161
}
6262

6363
void onTestEnd(TestData td) {
64-
cerr << " 1.." << mAssertCounter << endl;
65-
if (td.result == RESULT_PASS) {
66-
cerr << "ok " << mTestCounter << " - " << td.name << endl;
67-
} else {
68-
cerr << "not ok " << mTestCounter << " - " << td.name << endl;
69-
}
64+
cout << " 1.." << mAssertCounter << endl << flush;
65+
cout << (td.result == RESULT_PASS ? "ok " : "not ok ") << mTestCounter << " - " << td.name << endl << flush;
7066
}
7167

7268
// non-comparative assert
@@ -76,8 +72,10 @@ class Test
7672
const char* description,
7773
bool pass
7874
) {
79-
cerr << " " << (pass ? "" : "not ") << "ok " << ++mAssertCounter << " - " << description << endl;
80-
if (!pass) {
75+
if (pass) {
76+
cout << " ok " << ++mAssertCounter << " - " << description << endl << flush;
77+
} else {
78+
cout << " not ok " << ++mAssertCounter << " - " << description << endl << flush;
8179
cerr << " ---" << endl;
8280
cerr << " at:" << endl;
8381
cerr << " file: " << file << endl;
@@ -99,9 +97,12 @@ class Test
9997
const char* rhsLabel,
10098
const B &rhs
10199
) {
102-
cerr << " " << (pass ? "" : "not ") << "ok " << ++mAssertCounter << " - ";
103-
cerr << description << " " << lhsLabel << " " << opLabel << " " << rhsLabel << endl;
104-
if (!pass) {
100+
if (pass) {
101+
cout << " ok " << ++mAssertCounter << " - ";
102+
cout << description << " " << lhsLabel << " " << opLabel << " " << rhsLabel << endl << flush;
103+
} else {
104+
cout << " not ok " << ++mAssertCounter << " - ";
105+
cout << description << " " << lhsLabel << " " << opLabel << " " << rhsLabel << endl << flush;
105106
cerr << " ---" << endl;
106107
cerr << " operator: " << opLabel << endl;
107108
cerr << " " << lhsRelevance << ": " << lhs << endl;

cpp/unittest/Assertion.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@
4444
#define assertFalse(arg) arduinoCITestBehaviorExp(false, "False " #arg, !(arg))
4545
#define assertNull(arg) arduinoCITestBehaviorExp(false, "Null " #arg, ((void*)NULL == (void*)(arg)))
4646
#define assertNotNull(arg) arduinoCITestBehaviorExp(false, "NotNull " #arg, ((void*)NULL != (void*)(arg)))
47-
#define assertEqual(arg1,arg2) arduinoCIAssertOp("Equal","expected",arg1,compareEqual,"==","actual",arg2)
48-
#define assertNotEqual(arg1,arg2) arduinoCIAssertOp("NotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
49-
#define assertComparativeEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>","actual",arg2)
50-
#define assertComparativeNotEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>","actual",arg2)
51-
#define assertLess(arg1,arg2) arduinoCIAssertOp("Less","lowerBound",arg1,compareLess,"<","actual",arg2)
52-
#define assertMore(arg1,arg2) arduinoCIAssertOp("More","upperBound",arg1,compareMore,">","actual",arg2)
53-
#define assertLessOrEqual(arg1,arg2) arduinoCIAssertOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","actual",arg2)
54-
#define assertMoreOrEqual(arg1,arg2) arduinoCIAssertOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","actual",arg2)
47+
#define assertEqual(arg1,arg2) arduinoCIAssertOp("Equal","expected",arg1,compareEqual,"=="," actual",arg2)
48+
#define assertNotEqual(arg1,arg2) arduinoCIAssertOp("NotEqual","unwanted",arg1,compareNotEqual,"!="," actual",arg2)
49+
#define assertComparativeEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>"," actual",arg2)
50+
#define assertComparativeNotEquivalent(arg1,arg2) arduinoCIAssertOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>"," actual",arg2)
51+
#define assertLess(arg1,arg2) arduinoCIAssertOp("Less","lowerBound",arg1,compareLess,"<"," actual",arg2)
52+
#define assertMore(arg1,arg2) arduinoCIAssertOp("More","upperBound",arg1,compareMore,">"," actual",arg2)
53+
#define assertLessOrEqual(arg1,arg2) arduinoCIAssertOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<="," actual",arg2)
54+
#define assertMoreOrEqual(arg1,arg2) arduinoCIAssertOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">="," actual",arg2)
5555

56-
#define assertEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("EqualFloat", "epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
57-
#define assertNotEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("NotEqualFloat", "epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
56+
#define assertEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("EqualFloat", " epsilon", arg3, compareMoreOrEqual, ">=", "actualDifference", fabs(arg1 - arg2))
57+
#define assertNotEqualFloat(arg1, arg2, arg3) arduinoCIAssertOp("NotEqualFloat", " epsilon", arg3, compareLessOrEqual, "<=", "insufficientDifference", fabs(arg1 - arg2))
5858
#define assertInfinity(arg) arduinoCITestBehaviorExp(false, "Infinity " #arg, isinf(arg))
5959
#define assertNotInfinity(arg) arduinoCITestBehaviorExp(false, "NotInfinity " #arg, !isinf(arg))
6060
#define assertNAN(arg) arduinoCITestBehaviorExp(false, "NAN " #arg, isnan(arg))
@@ -66,17 +66,17 @@
6666
#define assureFalse(arg) arduinoCITestBehaviorExp(true, "False " #arg, !(arg))
6767
#define assureNull(arg) arduinoCITestBehaviorExp(true, "Null " #arg, ((void*)NULL == (void*)(arg)))
6868
#define assureNotNull(arg) arduinoCITestBehaviorExp(true, "NotNull " #arg, ((void*)NULL != (void*)(arg)))
69-
#define assureEqual(arg1,arg2) arduinoCIAssureOp("Equal","expected",arg1,compareEqual,"==","actual",arg2)
70-
#define assureNotEqual(arg1,arg2) arduinoCIAssureOp("NotEqual","unwanted",arg1,compareNotEqual,"!=","actual",arg2)
71-
#define assureComparativeEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>","actual",arg2)
72-
#define assureComparativeNotEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>","actual",arg2)
73-
#define assureLess(arg1,arg2) arduinoCIAssureOp("Less","lowerBound",arg1,compareLess,"<","actual",arg2)
74-
#define assureMore(arg1,arg2) arduinoCIAssureOp("More","upperBound",arg1,compareMore,">","actual",arg2)
75-
#define assureLessOrEqual(arg1,arg2) arduinoCIAssureOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<=","actual",arg2)
76-
#define assureMoreOrEqual(arg1,arg2) arduinoCIAssureOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">=","actual",arg2)
69+
#define assureEqual(arg1,arg2) arduinoCIAssureOp("Equal","expected",arg1,compareEqual,"=="," actual",arg2)
70+
#define assureNotEqual(arg1,arg2) arduinoCIAssureOp("NotEqual","unwanted",arg1,compareNotEqual,"!="," actual",arg2)
71+
#define assureComparativeEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeEquivalent","expected",arg1,compareEquivalent,"!<>"," actual",arg2)
72+
#define assureComparativeNotEquivalent(arg1,arg2) arduinoCIAssureOp("ComparativeNotEquivalent","unwanted",arg1,compareNotEquivalent,"<>"," actual",arg2)
73+
#define assureLess(arg1,arg2) arduinoCIAssureOp("Less","lowerBound",arg1,compareLess,"<"," actual",arg2)
74+
#define assureMore(arg1,arg2) arduinoCIAssureOp("More","upperBound",arg1,compareMore,">"," actual",arg2)
75+
#define assureLessOrEqual(arg1,arg2) arduinoCIAssureOp("LessOrEqual","lowerBound",arg1,compareLessOrEqual,"<="," actual",arg2)
76+
#define assureMoreOrEqual(arg1,arg2) arduinoCIAssureOp("MoreOrEqual","upperBound",arg1,compareMoreOrEqual,">="," actual",arg2)
7777

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

0 commit comments

Comments
 (0)