GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  TEST2::COMPARE (3)

.ds Aq ’

NAME

Test2::Compare - Test2 Extention for writing deep comparison tools.

CONTENTS

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 detaisl 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 <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2015 Chad Granum <exodist7@gmail.com>.

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/

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 TEST2::COMPARE (3) 2016-03-20

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.