Built-in routines
Testing — use Test
FullThe built-in Test module — plan, ok, is, isnt, is-deeply — emitting TAP.
use Test brings in Raku's standard testing routines. Each assertion prints a TAP line (ok N - description or not ok N …), and plan declares how many you expect. This is the same module Raku's own test suite uses, and it runs unchanged in the playground.
A small test suite #
plan states the count; ok asserts a truthy value; is checks a value against an expected one; isnt checks inequality.
use Test; plan 3; ok 2 > 1, "two is greater than one"; is "ab".uc, "AB", "uppercasing"; isnt "cat", "dog", "different words";
Output
1..3
ok 1 - two is greater than one
ok 2 - uppercasing
ok 3 - different wordsEach passing assertion is numbered in order, and the 1..3 plan line lets a test harness confirm the whole suite ran.
Comparing structures — is-deeply #
is compares stringified values; is-deeply compares structure and type exactly, so it's the right check for lists, hashes, and nested data.
use Test;
plan 2;
is-deeply (1, 2, 3).grep(* > 1).List, (2, 3), "grep keeps the tail";
is-deeply { a => 1, b => 2 }, { b => 2, a => 1 }, "hash order-independent";
Output
1..2
ok 1 - grep keeps the tail
ok 2 - hash order-independentNotes #
- Core assertions:
ok/nok(truthy/falsy),is/isnt(string-equal or not),is-deeply(structural),like/unlike(regex match),cmp-ok(compare with a named op), anddies-ok/lives-ok/throws-likefor exceptions. - A failing assertion prints
not ok Nfollowed by diagnostic lines showing the expected and received values, so a red test tells you what went wrong. plan Nup front fixes the expected count; alternatively calldone-testingat the end to let the count be inferred.subtest "name", { … }groups related assertions and reports them as one.- The output format is TAP (Test Anything Protocol), consumable by
proveand other standard harnesses.