sure 0.1.1

Assert like a boss

Released 2015-03-31.

To install, run:

haxelib install sure 0.1.1

See using Haxelib in Haxelib documentation for more information.

Current version0.1.1
StatisticsInstalled 566 times
Tags assert, cross, test


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) 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:

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:

var a = 1, b = 2;
    a == 1;
    b == 2;

And some sugar for checking for exception throw:

sure(@throws sure(false));

The catched exception is available as _ identifier and you can add additional checks as parameters for @throws:

sure(@throws(_.indexOf("FAIL: ") == 0) sure(1 == 2));