hxassert 0.1.0

General assert utility for Haxe

Released 2016-10-23.

To install, run:

haxelib install hxassert 0.1.0

See using Haxelib in Haxelib documentation for more information.

Current version0.1.0
StatisticsInstalled 11 times
Tags assert, contract, debug, utility



Build Status Build status

Lang Version License

Assert utility for Haxe. Lightweight library deliveries flexible base functionality on assertions. It could be used as standard assert library. It could provide base API for more high-level tools as "matching extensions", "contract-by-design", "assert-that notation".


API is not final yet. Development is in progress. Feel free to suggest better naming, API hacks, and compatibility features!

Assertion level

  • Top level: Assert.require - generates always.
  • Medium level: Assert.expect - could be disabled for release builds by defining -D hxassert_no_expect.
  • Debug level: Assert.assert - generates only for -debug builds.

Look at method documentation for usage suggestions.

Failure messages

var x = -1;
var y = 1;

// assert: x > 0
Assert.require(x > 0);

// assert: x > 0
// x: -1
// y: 1
// x + y: 0
Assert.require(x > 0, x, y, x + y);

// (x == y) failed: -1 != 1
// Validation: x + y = 0
Assert.require(x == y, "(${}) failed: $x != $y\nValidation: x + y = ${x + y}");

// Expression: x == y
// x: -1
// y: 1
Assert.require(x == y, "ASSERTION FAILED\nExpression: ${}", x, y);

Failure handling

Errors could be recovered from throwing by handlers by calling error.recovery() method Throwing could be disabled totally in release builds by defining -D hxassert_mute. In case of muting errors throwing, they are dispatched and handled anyway. That allows to recover, report and log critical failures in release builds without throwing assertion failure error.

// whatever
var disposeAssertLogging = Assert.on(
	function(err) {
		haxe.Log.trace(err.toString(), err.position);

		// in case if you want to recover from throwing assert error immediately

// if need to remove listeners