hhspecify/hhassert

Simple assertion library for Hack


Keywords
test, spec, Simple, assert, hack, hhvm
License
MIT

Documentation

hhassert

hhassert is simple assertion library for Hack.
You can use easily as assert module of nodejs.

Build Status HHVM Status Dependency Status

Basic Usage

It will specify the hhassert\Assert in the use keyword.

use hhassert\Assert;

Assert::ok(1 === 1);      //Passed
Assert::ok("a" === "b");  //Failed

Assert::equal("a", "a");  //Passed
Assert::equal(1, 1);      //Passed
Assert::equal(1.0, 2.0);  //Failed

Assert::notEqual("a", "b"); //Passed
Assert::notEqual("a", "a"); //Failed

Assert::throws(() ==> {
    throw new InvalidArgumentException("exception!!");
}, InvalidArgumentException::class);

Custom matcher

You can be the registration of the matcher in the configure method. Matcher specified in the lambda expression.

Assert::configure((ContextBuilder $builder) ==> {

    $builder->registerMatcher('custom_matcher', (...) ==> {
        list($a, $b) = func_get_args();

        if ($a !== $b) {
            throw new AssertionFailedException("custom matcher");
        }
    });

});

Assert::custom_matcher("a", "b");

Run the test

composer install
composer test