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

Add support for the ESP8266 env. Fix headers in readme. #57

Closed
wants to merge 3 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
24 changes: 12 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ArduinoUnit

Unit test framework for arduino projects.

##Current Version 2.2.0
## Current Version 2.2.0
[Download ArduinoUnit 2.2.0](https://github.com/mmurdoch/arduinounit/releases/tag/v2.2.0).

ArduinoUnit 2.0 is a complete rewrite of ArduinoUnit based on the experience
Expand All @@ -18,7 +18,7 @@ If you don't want to take advantage of the great new features in 2.0 then the
latest release of the 1.x code line is still
[available for download](https://github.com/mmurdoch/arduinounit/tree/v1.7).

##Why Version 2?
## Why Version 2?

ArduinoUnit 2 follows the spirit of ArduinoUnit 1.x with the following
less-is-more features:
Expand All @@ -40,7 +40,7 @@ And the following more-is-more features:
- Test names can optionally be stored in either RAM or flash.
1. assertions about other tests.

##Getting Started
## Getting Started

Create a directory called ArduinoUnit in your [Arduino Libraries Directory](http://arduino.cc/en/Guide/Libraries) e.g. `<arduino installation directory>\libraries`.

Expand Down Expand Up @@ -91,7 +91,7 @@ Test bad failed.
Test ok passed.
Test summary: 1 passed, 1 failed, and 0 skipped, out of 2 test(s).
```
#Verbosity
# Verbosity

Just how much information is generated on each test is fairly flexible, and designed to address these rules:

Expand Down Expand Up @@ -138,7 +138,7 @@ TEST_VERBOSITY_ALL (0x3F)
TEST_VERBOSITY_NONE (0x00)
```

#Output
# Output

The `Test::out` value is the *shared* value for all tests describing where output for all tests goes. The default is

Expand All @@ -154,7 +154,7 @@ Test::out = &Serial3;

in your `setup()`. Note the library does not set the baud rate - you have to do that in your `setup()`.

##Built-in Assertions
## Built-in Assertions

The following assertions are supported

Expand Down Expand Up @@ -215,7 +215,7 @@ assertions.

All the assert macros expand to a test that creates an optional message, and, if false, calls fail() on the current test and returns.

##Meta Assertions
## Meta Assertions

You can make assertions on the outcome of tests as well. The following meta-assertions are supported:
```
Expand Down Expand Up @@ -267,7 +267,7 @@ testing(too_slow)
Since the ordering tests cannot be controlled, only use test-asserts
in a testing() environment.

#`Test` and `TestOnce`
# `Test` and `TestOnce`
You can create your own modular tests by deriving from these classes.

```
Expand Down Expand Up @@ -319,7 +319,7 @@ MyTestOnce myTestOnce2("myTestOnce2");

Note that `Test::run()` only calls the active unresolved tests.

##Selecting tests
## Selecting tests

In your setup() function, you can select which tests are going to be setup and looped. The default is that all tests are included.

Expand All @@ -329,7 +329,7 @@ In your setup() function, you can select which tests are going to be setup and l

Here are some examples:

##Select examples:
## Select examples:

A single test `my_test`

Expand Down Expand Up @@ -357,7 +357,7 @@ void setup()
}
```

##FAQ
## FAQ

Q. The line number of the asserts do not match the source file.

Expand Down Expand Up @@ -405,7 +405,7 @@ A. Here is a troubleshooting guideline:
* Setting Test::min_verbosity = TEST_VERBOSITY_ALL (the default is TEST_VERSOBITY_TESTS_ALL | TEST_VERBOSITY_ASSERTIONS_FAILED, generating output only for failed assertions, completions of tests, and an overall summary).
* With these settings, the per-test verbosity has no effect.

##License
## License

Copyright (c) 2013 Warren MacEvoy, Matthew Murdoch, freenerd, John Macdonald,
nicolaspanel, Matt Paine
Expand Down
24 changes: 15 additions & 9 deletions src/ArduinoUnitUtility/ArduinoUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int8_t Test::TestString::compare(const Test::TestString &to) const
{
uint8_t a_buf[4],b_buf[4];
uint16_t i=0;

for (;;) {
uint8_t j=(i%4);
if (j == 0) {
Expand Down Expand Up @@ -89,7 +89,7 @@ bool Test::TestString::matches(const char *pattern) const {
k=j+1;
state1[k/8] |= (1 << (k%8));
while (pattern[k] == '*') {
++k;
++k;
state1[k/8] |= (1 << (k%8));
}
}
Expand Down Expand Up @@ -117,20 +117,20 @@ uint8_t Test::min_verbosity = TEST_VERBOSITY_TESTS_SUMMARY;

Print* Test::out = &Serial;

void Test::resolve()
void Test::resolve()
{
bool pass = current->state==DONE_PASS;
bool fail = current->state==DONE_FAIL;
bool skip = current->state==DONE_SKIP;
bool done = (pass || fail || skip);

if (done) {
if (pass) ++Test::passed;
if (fail) ++Test::failed;
if (skip) ++Test::skipped;

#if TEST_VERBOSITY_EXISTS(TESTS_SKIPPED) || TEST_VERBOSITY_EXISTS(TESTS_PASSED) || TEST_VERBOSITY_EXISTS(TESTS_FAILED)

bool output = false;

output = output || (skip && TEST_VERBOSITY(TESTS_SKIPPED));
Expand All @@ -143,11 +143,11 @@ void Test::resolve()
#if TEST_VERBOSITY_EXISTS(TESTS_SKIPPED)
if (skip) out->println(F(" skipped."));
#endif

#if TEST_VERBOSITY_EXISTS(TESTS_PASSED)
if (pass) out->println(F(" passed."));
#endif

#if TEST_VERBOSITY_EXISTS(TESTS_FAILED)
if (fail) out->println(F(" failed."));
#endif
Expand All @@ -167,6 +167,9 @@ void Test::resolve()
out->println(F(" test(s)."));
}
#endif
#ifdef ESP8266
yield();
#endif
}

void Test::remove()
Expand Down Expand Up @@ -232,6 +235,9 @@ void Test::run()
} else {
p=&((*p)->next);
}
#ifdef ESP8266
yield();
#endif
}
}

Expand Down Expand Up @@ -261,7 +267,7 @@ void Test::exclude(const char *pattern)
TestOnce::TestOnce(const __FlashStringHelper *name) : Test(name) {}
TestOnce::TestOnce(const char *name) : Test(name) {}

void TestOnce::loop()
void TestOnce::loop()
{
once();
if (state == LOOPING) state = DONE_PASS;
Expand Down
34 changes: 34 additions & 0 deletions src/ArduinoUnitUtility/Compare.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,73 @@
#pragma once
#if defined(F)
#ifndef ESP8266
#include <avr/pgmspace.h>
#endif
#ifdef ESP8266
#undef PROGMEM
#define PROGMEM
#undef PSTR
#define PSTR(s) (s)
#undef pgm_read_byte
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))
#undef pgm_read_word
#define pgm_read_word(addr) (*reinterpret_cast<const uint16_t*>(addr))
#define typeof(x) __typeof__(x)
#endif
#endif
#include <WString.h>

template < typename A, typename B > struct Compare
{
inline static int between(const A &a,const B &b)
{
#ifdef ESP8266
yield();
#endif
if (a<b) return -1;
if (b<a) return 1;
return 0;
} // between
inline static bool equal(const A &a,const B &b)
{
#ifdef ESP8266
yield();
#endif
return (!(a<b)) && (!(b<a));
} // equal
inline static bool notEqual(const A &a,const B &b)
{
#ifdef ESP8266
yield();
#endif
return (a<b) || (b<a);
} // notEqual
inline static bool less(const A &a,const B &b)
{
#ifdef ESP8266
yield();
#endif
return a<b;
} // less
inline static bool more(const A &a,const B &b)
{
#ifdef ESP8266
yield();
#endif
return b<a;
} // more
inline static bool lessOrEqual(const A &a,const B &b)
{
#ifdef ESP8266
yield();
#endif
return !(b<a);
} // lessOrEqual
inline static bool moreOrEqual(const A &a,const B &b)
{
#ifdef ESP8266
yield();
#endif
return !(a<b);
} // moreOrEqual
};
Expand Down