Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nadako/sure
Assert like a boss
https://github.com/nadako/sure
Last synced: 29 days ago
JSON representation
Assert like a boss
- Host: GitHub
- URL: https://github.com/nadako/sure
- Owner: nadako
- Created: 2015-03-30T22:25:09.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-30T23:03:51.000Z (almost 10 years ago)
- Last Synced: 2024-10-25T09:49:56.012Z (3 months ago)
- Language: Haxe
- Size: 137 KB
- Stars: 14
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sure!
This is a very small assertion tool for writing tests for Haxe.
## Sure, but why?
I don't like existing assertion frameworks because they are either simply annoying to write (e.g. `assertGreaterThan`)
or trying to pretend they are your dumb friend (e.g. `expect(v).to.be(1)` and stuff).From my experience, in a unit test, I really just need to do some stuff and then check for results and I believe
that it's very natural for a programmer to write assertions like they would write an `if` expression.And thanks to Haxe macros, we could analyze given expressions and print a nice assertion failure for it.
## An example?
I want it to be short and straight to the point, so I intend to use it like this:
```haxe
import Sure.sure;class Main {
static function main() {
var a = 1, b = 2;
sure(a == 1, b == 1); // throws "FAIL: values are not equal (expected: 1, actual: 2)"
}
}
```It also supports assertion blocks:
```haxe
var a = 1, b = 2;
sure({
a == 1;
b == 2;
});
```And some sugar for checking for exception throw:
```haxe
sure(@throws sure(false));
```
The catched exception is available as `_` identifier and you can add additional checks as parameters for `@throws`:
```haxe
sure(@throws(_.indexOf("FAIL: ") == 0) sure(1 == 2));
```