NAME
Test2::Compare - 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;
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: - $compare = relaxed_convert($thing)
-
Convert
$thing
to an Test2::Compare::* object. This will be relaxed which means:
SOURCE
The source code repository for Test2-Suite can be found at http://github.com/Test-More/Test2-Suite/.
MAINTAINERS
AUTHORS
COPYRIGHT
Copyright 2016 Chad Granum <exodist@cpan.org>.
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/