Documentation for sub cmp-ok assembled from the following pages:

Module: Test §

From Test

(Test) sub cmp-ok §

multi sub cmp-ok(Mu $got is raw$opMu $expected is raw$desc = '')

Compares $got and $expected with the given $op comparator and passes the test if the comparison yields a True value. The description of the test is optional.

The $op comparator can be either a Callable or a Str containing an infix operator, such as '==', a '~~', or a user-defined infix.

cmp-ok 'my spelling is apperling''~~', /perl/"bad speller";

Metaoperators cannot be given as a string; pass them as a Callable instead:

cmp-ok <a b c>, &[!eqv], <b d e>'not equal';

A Callable $op lets you use custom comparisons:

sub my-comp { $^a / $^b  < rand };
cmp-ok 1&my-comp2'the dice giveth and the dice taketh away'
cmp-ok 2-> $a$b { $a.is-prime and $b.is-prime and $a < $b }7,
    'we got primes, one larger than the other!';