Test2::Compare(3) Test2 extension for writing deep comparison tools.

DESCRIPTION

This library is the driving force behind deep comparison tools such as "Test2::Tools::Compare::is()" and "Test2::Tools::ClassicCompare::is_deeply()".

SYNOPSIS


package Test2::Tools::MyCheck;
use Test2::Compare::MyCheck;
use Test2::Compare qw/compare/;
sub MyCheck {
my ($got, $exp, $name, @diag) = @_;
my $ctx = context();
my $delta = compare($got, $exp, \&convert);
if ($delta) {
$ctx->ok(0, $name, [$delta->table, @diag]);
}
else {
$ctx->ok(1, $name);
}
$ctx->release;
return !$delta;
}
sub convert {
my $thing = shift;
return $thing if blessed($thing) && $thing->isa('Test2::Compare::MyCheck');
return Test2::Compare::MyCheck->new(stuff => $thing);
}

See Test2::Compare::Base for details about writing a custom check.

EXPORTS

$delta = compare($got, $expect, \&convert)
This will compare the structures in $got with those in $expect, The convert sub should convert vanilla structures inside $expect into checks. If there are differences in the structures they will be reported back as an Test2::Compare::Delta tree.
$build = get_build()
Get the current global build, if any.
push_build($build)
Set the current global build.
$build = pop_build($build)
Unset the current global build. This will throw an exception if the build passed in is different from the current global.
build($class, sub { ... })
Run the provided codeblock with a new instance of $class as the current build. Returns the new build.
$check = strict_convert($thing)
Convert $thing to an Test2::Compare::* object. This will behave strictly which means:
Array bounds will be checked when this object is used in a comparison
No unexpected hash keys can be present.
Sub references will be compared as refs (IE are these sub refs the same ref?)
Regexes will be compared directly (IE are the regexes the same?)
$compare = relaxed_convert($thing)
Convert $thing to an Test2::Compare::* object. This will be relaxed which means:
Array bounds will not be checked when this object is used in a comparison
Unexpected hash keys can be present.
Sub references will be run to verify a value.
Values will be checked against any regexes provided.

SOURCE

The source code repository for Test2-Suite can be found at http://github.com/Test-More/Test2-Suite/.

MAINTAINERS

Chad Granum <[email protected]>

AUTHORS

Chad Granum <[email protected]>

COPYRIGHT

Copyright 2016 Chad Granum <[email protected]>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/