1Test::Stream::Compare(3U)ser Contributed Perl DocumentatiToenst::Stream::Compare(3)
2
3
4

NAME

6       Test::Stream::Compare - Tools for comparing data structures.
7

DEPRECATED

9       This distribution is deprecated in favor of Test2, Test2::Suite, and
10       Test2::Workflow.
11
12       See Test::Stream::Manual::ToTest2 for a conversion guide.
13

DESCRIPTION

15       This library is the driving force behind is(). The library is the base
16       class for several comparison classes that allow for deep structure
17       comparisons.
18

SYNOPSIS

20   FOR COMPARISON CLASSES
21           package Test::Stream::Compare::MyCheck;
22           use strict;
23           use warnings;
24
25           use base 'Test::Stream::Compare';
26           use Test::Stream::HashBase accessors => [qw/stuff/];
27
28           sub name { 'STUFF' }
29
30           sub operator {
31               my $self = shift;
32               my ($got) = @_;
33               return 'eq';
34           }
35
36           sub verify {
37               my $self = shift;
38               my $params = @_;
39
40               # Always check if $got even exists, this will be false if no value at
41               # all was received. (as opposed to a $got of 'undef' or '0' which are
42               # valid meaning this field will be true).
43               return 0 unless $params{exists};
44
45               my $got = $params{got};
46
47               return $got eq $self->stuff;
48           }
49
50   FOR PLUGINS
51           package Test::Stream::Plugin::MyCheck;
52
53           use Test::Stream::Compare::MyCheck;
54
55           use Test::Stream::Compare qw/compare get_build push_build pop_build build/;
56
57           sub MyCheck {
58               my ($got, $exp, $name, @diag) = @_;
59               my $ctx = context();
60
61               my $delta = compare($got, $exp, \&convert);
62
63               if ($delta) {
64                   $ctx->ok(0, $name, [$delta->table, @diag]);
65               }
66               else {
67                   $ctx->ok(1, $name);
68               }
69
70               $ctx->release;
71               return !$delta;
72           }
73
74           sub convert {
75               my $thing = shift;
76               return $thing if blessed($thing) && $thing->isa('Test::Stream::Compare::MyCheck');
77
78               return Test::Stream::Compare::MyCheck->new(stuff => $thing);
79           }
80

EXPORTS

82       $delta = compare($got, $expect, \&convert)
83           This will compare the structures in $got with those in $expect, The
84           convert sub should convert vanilla structures inside $expect into
85           checks.  If there are differences in the structures they will be
86           reported back as an Test::Stream::Delta tree.
87
88       $build = get_build()
89           Get the current global build, if any.
90
91       push_build($build)
92           Set the current global build.
93
94       $build = pop_build($build)
95           Unset the current global build. This will throw an exception if the
96           build passed in is different from the current global.
97
98       build($class, sub { ... })
99           Run the provided codeblock with a new instance of $class as the
100           current build. Returns the new build.
101

METHODS

103       Some of these must be overriden, others can be.
104
105       $dclass = $check->delta_class
106           Returns the delta subclass that should be used. By default
107           Test::Stream::Delta is used.
108
109       @deltas = $check->deltas(id => $id, exists => $bool, got => $got,
110       convert => \&convert, seen => \%seen)
111           Should return child deltas.
112
113       @lines = $check->got_lines($got)
114           This is your chance to provide line numbers for errors in the $got
115           structure.
116
117       $op = $check->operator()
118       $op = $check->operator($got)
119           Returns the operator that was used to compare the check with the
120           received data in $got. If there was no value for got then there
121           will be no arguments, undef will only be an argument if undef was
122           seen in $got, this is how you can tell the difference between a
123           missing value and an undefined one.
124
125       $bool = $check->verify(id => $id, exists => $bool, got => $got, convert
126       => \&convert, seen => \%seen)
127           Return true if there is a shallow match, that is both items are
128           arrayrefs, both items are the same string or same number, etc. This
129           should not look deep, deep checks are done in "$check->deltas()".
130
131       $name = $check->name
132           Get the name of the check.
133
134       $display = $check->render
135           What should be displayed in a table for this check, usually the
136           name or value.
137
138       $delta = $check->run(id => $id, exists => $bool, got => $got, convert
139       => \&convert, seen => \%seen)
140           This is where the checking is done, first a shallow check using
141           "$check->verify", then checking "$check->deltas()". "\%seen" is
142           used to prevent cycles.
143

SOURCE

145       The source code repository for Test::Stream can be found at
146       http://github.com/Test-More/Test-Stream/.
147

MAINTAINERS

149       Chad Granum <exodist@cpan.org>
150

AUTHORS

152       Chad Granum <exodist@cpan.org>
153
155       Copyright 2015 Chad Granum <exodist7@gmail.com>.
156
157       This program is free software; you can redistribute it and/or modify it
158       under the same terms as Perl itself.
159
160       See http://dev.perl.org/licenses/
161
162
163
164perl v5.38.0                      2023-07-21          Test::Stream::Compare(3)
Impressum