Skip to content

Commit b97138e

Browse files
committed
set up a unittest_main macro
1 parent fdbb065 commit b97138e

File tree

9 files changed

+15
-22
lines changed

9 files changed

+15
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
### Changed
1313
- `arduino_ci_remote.rb` doesn't attempt to set URLs if nothing needs to be downloaded
1414
- `arduino_ci_remote.rb` does unit tests first
15+
- `unittest_main()` is now the macro for the `int main()` of test files
1516

1617
### Deprecated
1718

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ unittest(your_test_name)
4343
assertEqual(4, doSomething());
4444
}
4545
46-
int main(int argc, char *argv[]) {
47-
return Test::run_and_report(argc, argv);
48-
}
46+
unittest_main()
4947
```
5048

51-
This test defines one `unittest` (a macro provided by `ArduionUnitTests.h`), called `your_test_name`, which makes some assertions on the target library. The `int main` section is boilerplate.
49+
This test defines one `unittest` (a macro provided by `ArduionUnitTests.h`), called `your_test_name`, which makes some assertions on the target library. The `unittest_main()` is a macro for the `int main()` boilerplate required for unit testing.
5250

5351

5452
## More Documentation

SampleProjects/DoSomething/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ unittest(your_test_name)
9898
assertEqual(4, doSomething());
9999
}
100100
101-
int main(int argc, char *argv[]) {
102-
return Test::run_and_report(argc, argv);
103-
}
101+
unittest_main()
104102
```
105103

106104
This test defines one `unittest` (a macro provided by `ArduionUnitTests.h`), called `your_test_name`, which makes some assertions on the target library. The `int main` section is boilerplate.

SampleProjects/DoSomething/test/good-library.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ unittest(library_does_something)
66
assertEqual(4, doSomething());
77
}
88

9-
int main(int argc, char *argv[]) {
10-
return Test::run_and_report(argc, argv);
11-
}
9+
unittest_main()

SampleProjects/DoSomething/test/good-null.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ unittest(nothing)
1919
{
2020
}
2121

22-
int main(int argc, char *argv[]) {
23-
return Test::run_and_report(argc, argv);
24-
}
22+
unittest_main()

SampleProjects/TestSomething/test/bad-null.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@ unittest(pretend_equal_things_arent)
77
assertNotEqual(x, y);
88
}
99

10-
int main(int argc, char *argv[]) {
11-
return Test::run_and_report(argc, argv);
12-
}
10+
unittest_main()

SampleProjects/TestSomething/test/good-library.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ unittest(library_tests_something)
66
assertEqual(4, testSomething());
77
}
88

9-
int main(int argc, char *argv[]) {
10-
return Test::run_and_report(argc, argv);
11-
}
9+
unittest_main()

SampleProjects/TestSomething/test/good-null.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@ unittest(nothing)
1919
{
2020
}
2121

22-
int main(int argc, char *argv[]) {
23-
return Test::run_and_report(argc, argv);
24-
}
22+
unittest_main()

cpp/unittest/ArduinoUnitTests.h

+6
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,9 @@ class Test
216216
void task(); \
217217
} test_##name##_instance; \
218218
void test_##name ::task()
219+
220+
221+
#define unittest_main() \
222+
int main(int argc, char *argv[]) { \
223+
return Test::run_and_report(argc, argv); \
224+
}

0 commit comments

Comments
 (0)