Assert like a boss

To install, run:

haxelib install sure 0.1.1 

See using Haxelib in Haxelib documentation for more information.


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));
3 years ago

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser!

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github