Module devel.ensure

Functions for writing tests.

These functions write messages to stdout, so it’s natural to run tests using mcscript.

Example:

local ensure = devel.ensure

ensure(4 > 3, "Basic math")
ensure.equal(utils.text.parse_size("4KB"), 4000, "parse_size()")

For more examples, see the test scripts in the folder lua/tests/auto.

Functions

does_not_throw(f, msg) Tests that some code does not throw exception.
equal(a, b, msg) Tests for equality.
not_equal(a, b, msg) Tests for inequality.
ok(cond, msg) Tests a condition.
throws(f, needle, msg) Tests that some code throws exception.


Functions

does_not_throw(f, msg)
Tests that some code does not throw exception.
equal(a, b, msg)
Tests for equality.
not_equal(a, b, msg)
Tests for inequality.
ok(cond, msg)
Tests a condition.

local ensure = devel.ensure
ensure.ok(4 > 3, "Basic math")

Since this test is so elementary, it’s possible to use a shorter syntax:

local ensure = devel.ensure
ensure(4 > 3, "Basic math")
throws(f, needle, msg)
Tests that some code throws exception.

local ensure = devel.ensure

ensure.throws(function()
  -- A pattern cannot start with a star!
  regex.compile "*"
end, nil, "Invalid regex pattern throws error")

The needle argument, if provided, is a sub-string to ensure appears in the exception message.

generated by LDoc 1.4.3 Last updated 2016-08-23 17:29:40