Testing
Mocking: Test::Mock (mocked(Class, returning => { ... }), check-mock). Use Test::When for author/network-only tests. Use Test::META to validate META6.json.
Output is TAP (Test Anything Protocol), compatible with Perl's tooling and CI systems.
# t/01-math.rakutest
use Test;
use lib 'lib';
use Math::Utils;
plan 9; # or omit and call done-testing at the end
ok square(2) == 4, 'square works';
nok square(2) == 5, 'square is not wrong';
is square(3), 9, 'is compares with eq (string comparison)';
isnt cube(2), 9, 'isnt';
is-approx GOLDEN, 1.618, 'approximately golden', :abs-tol(0.001);
is-deeply [1, 2, 3].map(&square).list, (1, 4, 9), 'deep structural comparison';
cmp-ok 10, '>', 5, 'cmp-ok with an operator';
isa-ok Vector.new(x => 1, y => 2), Vector, 'isa-ok';
subtest 'edge cases' => {
plan 3;
is square(0), 0, 'zero';
dies-ok { square('abc') }, 'dies on a non-numeric argument';
throws-like { die X::AdHoc.new(payload => 'boom') }, X::AdHoc, message => /boom/, 'throws-like';
};
# Other functions: lives-ok, can-ok, does-ok, like/unlike (regex), use-ok, eval-dies-ok,
# skip, skip-rest, todo, bail-out, diag, pass, flunk
# done-testing; # when not using planprove6 -l t/ # run all tests (zef install App::Prove6), -l adds lib
prove -e 'raku -Ilib' t/ # using Perl's prove
zef test . # run tests as zef would
raku -Ilib t/01-math.rakutest # run one test file