test/more

Standard Library documentation

Write unit tests and integration tests in ZuzuScript.

Module

Name
test/more
Area
Standard Library
Source
modules/test/more.zzm

NAME

test/more - Write unit tests and integration tests in ZuzuScript.

SYNOPSIS

  from test/more import *;
  from my/project import frobnicate;

  is(frobnicate(21), 42, "frobinated 21 correctly");
  is(frobnicate(null), null, "frobinate on null input");

  done_testing();

IMPLEMENTATION SUPPORT

This module is supported by all implementations of ZuzuScript.

DESCRIPTION

test/more is a module for test-driven development. It can be used for writing unit tests and integration tests. It generates output in TAP https://testanything.org/.

This module should feel familiar to anybody who has used Test::More for Perl, though there are some minor differences.

Functions

  • pass(String name?)

    Indicates the named test has passed.

  • fail(String name?)

    Indicates the named test has failed.

  • ok(expr, String name?)

    Passes the named test only if expr is truthy.

  • is(got, expected, String name?)

    Passes the named test only if got ≡ expected.

  • isnt(got, unexpected, String name?)

    Passes the named test only if got ≢ expected.

  • like(got, expected_re, String name?)

    Passes the named test only if got ~ expected.

  • unlike(got, unexpected_re, String name?)

    Fails the named test only if got ~ expected.

  • diag(diagnostic)

    Outputs the diagnostic.

  • explain(value)

    Combines diag with Dumper.dump();

  • bail_out(String message?)

    Bail out of running further tests.

  • skip_all(String reason)

    Skips the whole test file by emitting a TAP skip-all plan and exiting successfully when the runtime provides std/proc.

    This is intended for guards at the beginning of a test script, before any tests have run. Browser-like hosts without std/proc use a special exception fallback that the browser ztest runner treats as a skip.

  • requires_module(String module)

    Skips the whole test file if the named module cannot be loaded.

  • requires_capability(String capability)

    Skips the whole test file if the named runtime capability is not available.

  • author_testing()

    Skips the whole test file unless the AUTHOR_TESTING environment variable is set to a true value.

  • extended_testing()

    Skips the whole test file unless the EXTENDED_TESTING environment variable is set to a true value.

  • plan(Number n)

    Indicate the number of tests you intend on running, before running any tests.

    done_testing() can later check the number.

  • done_testing(Number n?)

    Indicates that testing is finished.

    You may optionally provide the expected total number of tests, and the function will throw an exception if that doesn't match the number of tests which were actually run.

    Will also throw an error if you called plan() earlier and the actual number of tests run differs from your plan.

  • subtest(String name, Function f)

    Calls f() as a subtest.

    Don't use done_testing() within the function.

  • todo(Boolean c, String reason, Function f)

    Runs the tests in the given function, but if condition c is true then first sets TODO to true.

    You can manually set and unset the TODO variable instead.

  • exception(Function f)

    Calls f() and returns any exception thrown.

    Returns null if no exception was thrown.

COPYRIGHT AND LICENCE

test/more is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.