Skip to content

Commit 838ea16

Browse files
authored
Merge pull request #2 from bxparks/develop
version v0.1.1
2 parents fd8c4a7 + 207d9e3 commit 838ea16

File tree

8 files changed

+53
-32
lines changed

8 files changed

+53
-32
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
22

3-
* 0.1.0 (2018-03-12)
3+
* v0.1.1 (2018-03-15)
4+
* Fix small bug with Test::setPassOrFail() which caused assertXxx()
5+
macros which returned true to terminate the testing() test cases.
6+
* v0.1.0 (2018-03-15)
7+
* First merge into 'master' branch and tagged.
8+
* (2018-03-12)
49
* Initial upload to GitHub.

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,16 @@ The following methods from ArduinoUnit are not yet implemented:
456456
* `assertTestSkip(name)`
457457
* `assertTestNotSkip(name)`
458458

459+
### Smaller Test Runner Loop Chunks
460+
461+
In ArduinoUnit, each call to `Test::run()` will process the entire list of
462+
currently active test cases. In AUnit, each call to `TestRunner::run()` will
463+
process just one test case and return. I chose to break up the
464+
`TestRunner::run()` method into smaller pieces to allow the `loop()` method to
465+
return to the system more frequently. This is especially important on the
466+
ESP8266 platform where system must get some periodic CPU cycles to perform its
467+
own tasks.
468+
459469
### Assertion Parameters Omitted in Messages
460470

461471
The various `assertXxx()` macros in AUnit print a slightly shorter
@@ -541,19 +551,19 @@ microcontrollers:
541551
```
542552
Platform (resource) | Max | ArduinoUnit | AUnit |
543553
---------------------------+---------+-------------+-------------|
544-
Arduino Nano (flash) | 30720 | 54038 | 18412 |
554+
Arduino Nano (flash) | 30720 | 54038 | 18418 |
545555
Arduino Nano (static) | 2048 | 1061 | 908 |
546556
---------------------------+---------+-------------+-------------|
547-
Teensy LC (flash) | 63488 | 36196 | 25104 |
557+
Teensy LC (flash) | 63488 | 36196 | 25096 |
548558
Teensy LC (static) | 8192 | 2980 | 2768 |
549559
---------------------------+---------+-------------+-------------|
550560
Teensy 3.2 (flash) | 262144 | 51236 | 36136 |
551561
Teensy 3.2 (static) | 65536 | 5328 | 5224 |
552562
---------------------------+---------+-------------+-------------|
553-
ESP8266 - ESP-12E (flash) | 1044464 | does not | 267375 |
563+
ESP8266 - ESP-12E (flash) | 1044464 | does not | 267359 |
554564
ESP8266 - ESP-12E (static) | 81920 | compile | 34564 |
555565
---------------------------+---------+-------------+-------------|
556-
ESP8266 - ESP-01 (flash) | 499696 | does not | 267375 |
566+
ESP8266 - ESP-01 (flash) | 499696 | does not | 267359 |
557567
ESP8266 - ESP-01 (static) | 47356 | compile | 34564 |
558568
---------------------------+---------+-------------+-------------|
559569
```

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AUnit
2-
version=0.1.0
2+
version=0.1.1
33
author=Brian T. Park
44
maintainer=Brian T. Park <[email protected]>
55
sentence=A unit testing framework for Arduino platforms inspired by ArduinoUnit.

src/AUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ SOFTWARE.
3333
#include "aunit/Assertion.h"
3434

3535
// Version format: 010203 == "1.2.3"
36-
#define AUNIT_VERSION 000100
36+
#define AUNIT_VERSION 000101
3737

3838
#endif

src/aunit/Compare.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,17 @@ int compareString(const __FlashStringHelper* a, const char* b) {
171171
return -strcmp_P(b, (const char*) a);
172172
}
173173

174+
// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
175+
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
176+
// optimizing for 4-byte alignment here.
174177
int compareString(const __FlashStringHelper* a, const __FlashStringHelper* b) {
175178
const char* aa = reinterpret_cast<const char*>(a);
176179
const char* bb = reinterpret_cast<const char*>(b);
177180

178-
// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
179-
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
180-
// optimizing for 4-byte alignment here.
181181
while (true) {
182-
char ca = pgm_read_byte(aa);
183-
char cb = pgm_read_byte(bb);
184-
if (ca < cb) return -1;
185-
if (ca > cb) return 1;
186-
// we hit this condition only if both strings are the same length,
187-
// so no need to check both strings for '\0'
182+
uint8_t ca = pgm_read_byte(aa);
183+
uint8_t cb = pgm_read_byte(bb);
184+
if (ca != cb) return (int) ca - (int) cb;
188185
if (ca == '\0') return 0;
189186
aa++;
190187
bb++;
@@ -225,21 +222,18 @@ int compareStringN(const __FlashStringHelper* a, const char* b, size_t n) {
225222
return -strncmp_P(b, (const char*)a, n);
226223
}
227224

225+
// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
226+
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
227+
// optimizing for 4-byte alignment here.
228228
int compareStringN(const __FlashStringHelper* a, const __FlashStringHelper* b,
229229
size_t n) {
230230
const char* aa = reinterpret_cast<const char*>(a);
231231
const char* bb = reinterpret_cast<const char*>(b);
232232

233-
// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
234-
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
235-
// optimizing for 4-byte alignment here.
236233
while (n > 0) {
237-
char ca = pgm_read_byte(aa);
238-
char cb = pgm_read_byte(bb);
239-
if (ca < cb) return -1;
240-
if (ca > cb) return 1;
241-
// we hit this condition only if both strings are the same length,
242-
// so no need to check both strings for '\0'
234+
uint8_t ca = pgm_read_byte(aa);
235+
uint8_t cb = pgm_read_byte(bb);
236+
if (ca != cb) return (int) ca - (int) cb;
243237
if (ca == '\0') return 0;
244238
aa++;
245239
bb++;

src/aunit/FCString.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ namespace aunit {
3838
* outside a function, it can only be used inside a function, so we are forced
3939
* to use normal c-strings instead of F() strings when manually creating Test or
4040
* TestOnce instances.
41+
*
42+
* I deliberately decided not to inherit from Printable. While it is convenient
43+
* to be able to call Print::print() with an instance of this class, the cost
44+
* is 2 (AVR) or 4 (Teensy-ARM or ESP8266) extra bytes of static memory for the
45+
* v-table pointer for each instance. But each instance is only 3 (AVR) or 5
46+
* (Teensy-ARM or ESP8266) bytes big, so the cost of 50-100 bytes of static
47+
* memory for a large suite of 25 unit tests does not seem worth the minor
48+
* convenience.
4149
*/
4250
class FCString {
4351
public:

src/aunit/Test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ Test::Test(const __FlashStringHelper* name):
4949
insert();
5050
}
5151

52+
// Resolve the status as kStatusFailed only if ok == false. Otherwise, keep the
53+
// status as kStatusSetup to allow testing() test cases to continue.
5254
void Test::setPassOrFail(bool ok) {
53-
mStatus = (ok) ? kStatusPassed : kStatusFailed;
55+
if (!ok) {
56+
mStatus = kStatusFailed;
57+
}
5458
}
5559

5660
// Insert the current test case into the singly linked list, sorted by

tests/AUnitTest/AUnitTest.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,29 +325,29 @@ test(flashString) {
325325

326326
testing(looping_skip) {
327327
static int count = 0;
328+
// a successful assetXxx() should not terminate a testing() early
329+
assertLess(count, 3);
328330
count++;
329-
Serial.print(F("looping_skip: iteration "));
330-
Serial.println(count);
331331
if (count >= 3) {
332332
skip();
333333
}
334334
}
335335

336336
testing(looping_fail) {
337337
static int count = 0;
338+
// a successful assetXxx() should not terminate a testing() early
339+
assertLess(count, 3);
338340
count++;
339-
Serial.print(F("looping_fail: iteration "));
340-
Serial.println(count);
341341
if (count >= 3) {
342342
fail();
343343
}
344344
}
345345

346346
testing(looping_pass) {
347347
static int count = 0;
348+
// a successful assetXxx() should not terminate a testing() early
349+
assertLess(count, 3);
348350
count++;
349-
Serial.print(F("looping_pass: iteration "));
350-
Serial.println(count);
351351
if (count >= 3) {
352352
pass();
353353
}

0 commit comments

Comments
 (0)