Skip to content

Commit 318bc1b

Browse files
committed
Merge branch 'develop'
2 parents d4d846b + 5dbc72d commit 318bc1b

File tree

6 files changed

+169
-51
lines changed

6 files changed

+169
-51
lines changed

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# AUnit - Unit Testing Framework for Arduino Platforms
1+
# AUnit
2+
3+
A unit testing framework for Arduino platforms inspired by ArduinoUnit and
4+
Google Test.
25

36
Version: 0.4.0 (2018-03-30)
47

@@ -87,6 +90,8 @@ Here are the features in AUnit which are not available in ArduinoUnit:
8790
* `externTestF()`
8891
* `externTestingF()`
8992
* AUnit works on the ESP8266 platform.
93+
* Test filters (`TestRunner::include()` and `TestRunner::exclude()`) support the
94+
same 2 arguments versions corresponding to `testF()` and `testingF()`
9095

9196
### Beta Status
9297

@@ -130,6 +135,7 @@ The `examples/` directory has a number of examples:
130135
In the `tests/` directory:
131136

132137
* `AUnitTest` - the unit test for `AUnit` itself has a large number of examples
138+
* `FilterTest` - manual tests for `include()` and `exclude()` filters
133139

134140
### Header and Namespace
135141

@@ -237,7 +243,7 @@ class CustomTestAgain: public TestAgain {
237243
}
238244
};
239245
240-
testingF(CustomTestAgain, examle_test) {
246+
testingF(CustomTestAgain, example_test) {
241247
...
242248
assertBigStuff();
243249
...
@@ -249,6 +255,7 @@ void setup() {
249255
250256
TestRunner::exclude("*");
251257
TestRunner::include("looping*");
258+
TestRunner::include("CustomTestAgain", "example*");
252259
}
253260
254261
void loop() {
@@ -628,36 +635,45 @@ ArduinoUnit, each call to `Test::run()` will process the entire list of
628635
currently active test cases. In AUnit, each call to `TestRunner::run()` performs
629636
only a single test case, then returns._
630637

631-
### Excluding and Including Test Cases
638+
### Filtering Test Cases
632639

633-
We can `exclude()` or `include()` test cases using a pattern match,
634-
just like ArduinoUnit. The names are slightly different:
640+
We can `exclude()` or `include()` test cases using a pattern match:
641+
642+
* `TestRunner::exclude(pattern)`
643+
* `TestRunner::exclude(testClass, pattern)`
644+
* `TestRunner::include(pattern)`
645+
* `TestRunner::include(testClass, pattern)`
635646

636-
* `TestRunner::exclude()`
637-
* `TestRunner::include()`
638647

639648
These methods are called from the global `setup()` method:
640649

641650
```
642651
void setup() {
643652
TestRunner::exclude("*");
644653
TestRunner::include("looping*");
654+
TestRunner::exclude("CustomTestAgain", "*");
655+
TestRunner::include("CustomTestAgain", "test*");
645656
...
646657
}
647658
```
648659

660+
The 2-argument versions of `include()` and `exclude()` correspond to the
661+
2 arguments of `testF()` and `testingF()`.
662+
649663
***ArduinoUnit Compatibility***:
650664
_The equivalent versions in ArduinoUnit are `Test::exclude()` and
651-
`Test::include()` The matching algorithm in AUnit is not as powerful as one in
652-
ArduinoUnit. AUnit supports only a single wildcard character `*` and that
665+
`Test::include()` The matching algorithm in AUnit is not as powerful as the one
666+
in ArduinoUnit. AUnit supports only a single wildcard character `*` and that
653667
character can appear only at the end if it is present. For example, the
654668
following are accepted:_
655669

656670
* `TestRunner::exclude("*");`
657671
* `TestRunner::include("f*");`
658672
* `TestRunner::exclude("flash_*");`
659673
* `TestRunner::include("looping*");`
660-
* `TestRunner::include("flashTest");`
674+
* `TestRunner::include("CustomTestOnce", "flashTest*");`
675+
676+
_AUnit provides 2-argument versions of `include()` and `exclude()`_
661677

662678
### Output Printer
663679

keywords.txt

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
Test KEYWORD1
1010
TestOnce KEYWORD1
11+
TestAgain KEYWORD1
12+
Assertion KEYWORD1
13+
MetaAssertion KEYWORD1
1114
test KEYWORD1
1215
testing KEYWORD1
16+
testF KEYWORD1
17+
testingF KEYWORD1
1318

1419
#######################################
1520
# Methods and Functions (KEYWORD2)
@@ -23,11 +28,13 @@ include KEYWORD2
2328
setVerbosity KEYWORD2
2429
isVerbosity KEYWORD2
2530
setPrinter KEYWORD2
31+
setTimeout KEYWORD2
2632

2733
# Public methods from Test.h
2834
getRoot KEYWORD2
2935
setup KEYWORD2
3036
loop KEYWORD2
37+
resolve KEYWORD2
3138
getName KEYWORD2
3239
getStatus KEYWORD2
3340
setStatus KEYWORD2
@@ -44,12 +51,21 @@ isSkipped KEYWORD2
4451
isNotSkipped KEYWORD2
4552
isExpired KEYWORD2
4653
isNotExpired KEYWORD2
47-
#
48-
# Protected methods from Test.h
4954
skip KEYWORD2
55+
expire KEYWORD2
56+
enableVerbosity KEYWORD2
57+
disableVerbosity KEYWORD2
58+
# Protected methods from Test.h
5059
pass KEYWORD2
5160
fail KEYWORD2
52-
# TestOnce
61+
init KEYWORD2
62+
isVerbosity KEYWORD2
63+
getVerbosity KEYWORD2
64+
65+
# TestOnce.h
66+
once KEYWORD2
67+
68+
# TestAgain.h
5369
once KEYWORD2
5470

5571
# Public macros from Assertion.h
@@ -82,7 +98,28 @@ assertTestNotFail KEYWORD2
8298
assertTestSkip KEYWORD2
8399
assertTestNotSkip KEYWORD2
84100
assertTestExpire KEYWORD2
85-
assertTestNotExpireDone KEYWORD2
101+
assertTestNotExpire KEYWORD2
102+
# F versions
103+
checkTestDoneF KEYWORD2
104+
checkTestNotDoneF KEYWORD2
105+
checkTestPassF KEYWORD2
106+
checkTestNotPassF KEYWORD2
107+
checkTestFailF KEYWORD2
108+
checkTestNotFailF KEYWORD2
109+
checkTestSkipF KEYWORD2
110+
checkTestNotSkipF KEYWORD2
111+
checkTestExpireF KEYWORD2
112+
checkTestNotExpireDoneF KEYWORD2
113+
assertTestDoneF KEYWORD2
114+
assertTestNotDoneF KEYWORD2
115+
assertTestPassF KEYWORD2
116+
assertTestNotPassF KEYWORD2
117+
assertTestFailF KEYWORD2
118+
assertTestNotFailF KEYWORD2
119+
assertTestSkipF KEYWORD2
120+
assertTestNotSkipF KEYWORD2
121+
assertTestExpireF KEYWORD2
122+
assertTestNotExpireF KEYWORD2
86123

87124
# Overloaded functions from Compare.h
88125
compareString KEYWORD2

src/aunit/TestRunner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ void TestRunner::setStatusMatchingPattern(const char* pattern, uint8_t status) {
6464
}
6565
}
6666

67+
void TestRunner::setStatusMatchingPattern(const char* testClass,
68+
const char* pattern, uint8_t status) {
69+
String fullPattern(testClass);
70+
fullPattern.concat('_');
71+
fullPattern.concat(pattern);
72+
73+
setStatusMatchingPattern(fullPattern.c_str(), status);
74+
}
75+
6776
TestRunner::TestRunner():
6877
mCurrent(nullptr),
6978
mIsResolved(false),

src/aunit/TestRunner.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ class TestRunner {
5757
getRunner()->setStatusMatchingPattern(pattern, Test::kStatusSkipped);
5858
}
5959

60+
/**
61+
* Exclude the tests which match the pattern given by (testClass + "_" +
62+
* pattern), the same concatenation rule used by the testF() macro.
63+
* Currently supports only a trailing '*'. For example,
64+
* exclude("CustomTest", "flash*").
65+
*/
66+
static void exclude(const char* testClass, const char* pattern) {
67+
getRunner()->setStatusMatchingPattern(testClass, pattern,
68+
Test::kStatusSkipped);
69+
}
70+
6071
/**
6172
* Include the tests which match the pattern.
6273
* Currently supports only a trailing '*'. For example, include("flash*").
@@ -65,6 +76,17 @@ class TestRunner {
6576
getRunner()->setStatusMatchingPattern(pattern, Test::kStatusNew);
6677
}
6778

79+
/**
80+
* Include the tests which match the pattern given by (testClass + "_" +
81+
* pattern), the same concatenation rule used by the testF() macro.
82+
* Currently supports only a trailing '*'. For example,
83+
* include("CustomTest", "flash*").
84+
*/
85+
static void include(const char* testClass, const char* pattern) {
86+
getRunner()->setStatusMatchingPattern(testClass, pattern,
87+
Test::kStatusNew);
88+
}
89+
6890
/** Set the verbosity flag. */
6991
static void setVerbosity(uint8_t verbosity) {
7092
getRunner()->setVerbosityFlag(verbosity);
@@ -129,6 +151,13 @@ class TestRunner {
129151
/** Set the status of the tests which match the pattern. */
130152
void setStatusMatchingPattern(const char* pattern, uint8_t status);
131153

154+
/**
155+
* Set the status of the tests which match the pattern formed by (testClass
156+
* + "_" + pattern), the same rule used by testF() and testingF()
157+
*/
158+
void setStatusMatchingPattern(const char* testClass, const char* pattern,
159+
uint8_t status);
160+
132161
/** Set the test runner timeout. */
133162
void setRunnerTimeout(TimeoutType seconds);
134163

tests/AUnitTest/AUnitTest.ino

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,51 +88,59 @@ test(type_mismatch) {
8888

8989
#if USE_AUNIT == 1
9090

91+
// We use if-statements instead of assertXxx() because compareXxx() is used by
92+
// the assertXxx() methods. Strictly speaking, it's not necessary because one
93+
// is a string compare and the other is an integer compare, but this feels
94+
// conceptually cleaner.
9195
test(compareString) {
92-
assertEqual(compareString(a, a), 0);
93-
assertEqual(compareString(a, f), 0);
94-
assertEqual(compareString(a, s), 0);
96+
if (!(compareString(a, a) == 0)) { fail(); }
97+
if (!(compareString(a, f) == 0)) { fail(); }
98+
if (!(compareString(a, s) == 0)) { fail(); }
9599

96-
assertEqual(compareString(f, a), 0);
97-
assertEqual(compareString(f, f), 0);
98-
assertEqual(compareString(f, s), 0);
100+
if (!(compareString(f, a) == 0)) { fail(); }
101+
if (!(compareString(f, f) == 0)) { fail(); }
102+
if (!(compareString(f, s) == 0)) { fail(); }
99103

100-
assertEqual(compareString(s, a), 0);
101-
assertEqual(compareString(s, f), 0);
102-
assertEqual(compareString(s, s), 0);
104+
if (!(compareString(s, a) == 0)) { fail(); }
105+
if (!(compareString(s, f) == 0)) { fail(); }
106+
if (!(compareString(s, s) == 0)) { fail(); }
103107

104-
assertLess(compareString(a, b), 0);
105-
assertLess(compareString(a, g), 0);
106-
assertLess(compareString(a, t), 0);
108+
if (!(compareString(a, b) < 0)) { fail(); }
109+
if (!(compareString(a, g) < 0)) { fail(); }
110+
if (!(compareString(a, t) < 0)) { fail(); }
107111

108-
assertLess(compareString(f, b), 0);
109-
assertLess(compareString(f, g), 0);
110-
assertLess(compareString(f, t), 0);
112+
if (!(compareString(f, b) < 0)) { fail(); }
113+
if (!(compareString(f, g) < 0)) { fail(); }
114+
if (!(compareString(f, t) < 0)) { fail(); }
111115

112-
assertLess(compareString(s, b), 0);
113-
assertLess(compareString(s, g), 0);
114-
assertLess(compareString(s, t), 0);
116+
if (!(compareString(s, b) < 0)) { fail(); }
117+
if (!(compareString(s, g) < 0)) { fail(); }
118+
if (!(compareString(s, t) < 0)) { fail(); }
115119
}
116120

121+
// We use if-statements instead of assertXxx() because compareXxx() is used by
122+
// the assertXxx() methods. Strictly speaking, it's not necessary because one
123+
// is a string compare and the other is an integer compare, but this feels
124+
// conceptually cleaner.
117125
test(compareStringN) {
118-
assertEqual(compareStringN(ff, "abcde", 5), 0);
119-
assertEqual(compareStringN("abcde", ff, 5), 0);
126+
if (!(compareStringN(ff, "abcde", 5) == 0)) { fail(); }
127+
if (!(compareStringN("abcde", ff, 5) == 0)) { fail(); }
120128

121-
assertMore(compareStringN(ff, "abcd", 5), 0);
129+
if (!(compareStringN(ff, "abcd", 5) > 0)) { fail(); }
122130
assertLess(compareStringN("abcd", ff, 5), 0);
123131

124-
assertEqual(compareStringN(ff, "abcd", 4), 0);
125-
assertEqual(compareStringN("abcd", ff, 4), 0);
132+
if (!(compareStringN(ff, "abcd", 4) == 0)) { fail(); }
133+
if (!(compareStringN("abcd", ff, 4) == 0)) { fail(); }
126134

127-
assertMore(compareStringN(ff, "", 1), 0);
128-
assertLess(compareStringN("", ff, 1), 0);
135+
if (!(compareStringN(ff, "", 1) > 0)) { fail(); }
136+
if (!(compareStringN("", ff, 1) < 0)) { fail(); }
129137

130-
assertEqual(compareStringN(ff, "", 0), 0);
131-
assertEqual(compareStringN("", ff, 0), 0);
138+
if (!(compareStringN(ff, "", 0) == 0)) { fail(); }
139+
if (!(compareStringN("", ff, 0) == 0)) { fail(); }
132140

133-
assertEqual(compareStringN(gg, ff, 5), 0);
141+
if (!(compareStringN(gg, ff, 5) == 0)) { fail(); }
134142

135-
assertMore(compareStringN(gg, ff, 6), 0);
143+
if (!(compareStringN(gg, ff, 6) > 0)) { fail(); }
136144
}
137145

138146
#endif
@@ -728,9 +736,9 @@ testing(fixture_slow_expire_monitor) {
728736
// ------------------------------------------------------
729737

730738
void setup() {
731-
Serial.begin(74880); // 74880 is the default for some ESP8266 boards
732-
while (! Serial); // Wait until Serial is ready - Leonardo
733739
delay(1000); // Wait for stability on some boards, otherwise garage on Serial
740+
Serial.begin(115200); // ESP8266 default of 74880 not supported on Linux
741+
while (! Serial); // Wait until Serial is ready - Leonardo/Micro
734742

735743
#if USE_AUNIT == 1
736744
// These are useful for debugging.

tests/FilterTest/FilterTest.ino

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,44 @@ testingF(CustomAgain, display) { pass(); }
4949

5050
void setup() {
5151
delay(1000); // Wait for stability on some boards, otherwise garage on Serial
52-
Serial.begin(74880); // 74880 is the default for some ESP8266 boards
52+
Serial.begin(115200); // ESP8266 default of 74880 not supported on Linux
5353
while (! Serial); // Wait until Serial is ready - Leonardo
5454

5555
// Verify that the names of these tests don't collide and can be
56-
// independently selected. Name of test = "{test_class}_{name}".
56+
// independently selected. Name of test is "{test_class}_{name}", but we can
57+
// use the new 2-argument versions of include(testClass, pattern) and
58+
// exclude(testClass, pattern) instead.
59+
5760
TestRunner::list();
61+
62+
Serial.println("exclude(\"*\")");
5863
TestRunner::exclude("*");
5964
TestRunner::list();
65+
66+
Serial.println("include(\"configure*\")");
67+
TestRunner::include("configure");
68+
TestRunner::list();
69+
70+
Serial.println("include(\"CustomAgain*\")");
6071
TestRunner::include("CustomAgain*");
6172
TestRunner::list();
62-
TestRunner::include("CustomOnce_dis*");
73+
74+
Serial.println("exclude(\"CustomAgain\", \"*\")");
75+
TestRunner::exclude("CustomAgain", "*");
6376
TestRunner::list();
64-
TestRunner::include("configure");
77+
78+
Serial.println("include(\"CustomAgain\", \"display\")");
79+
TestRunner::include("CustomAgain", "display");
80+
TestRunner::list();
81+
82+
Serial.println("include(\"CustomOnce_dis*\")");
83+
TestRunner::include("CustomOnce_dis*");
6584
TestRunner::list();
6685
}
6786

6887
void loop() {
69-
// Should get:
88+
// Should get something like:
7089
// TestRunner summary:
71-
// 4 passed, 0 failed, 2 skipped, 0 timed out, out of 6 test(s).
90+
// 3 passed, 0 failed, 3 skipped, 0 timed out, out of 6 test(s).
7291
TestRunner::run();
7392
}

0 commit comments

Comments
 (0)