Test::S...:Compare(3)
okay bestie, buckle up π this is the manual page for Test::Stream::Compare, straight out of the User Contributed Perl Documentation set. She's a classic. She's also, uh, retired. More on that in a sec π
β¨ NAME β¨
Test::Stream::Compare β tools for comparing data structures. That's it, that's the whole vibe. π¦
π DEPRECATED π
ngl this one hurts. This whole distribution is deprecated, and it got replaced byTest2,Test2::Suite, andTest2::Workflow. She's not coming back, bestie.
If you need to migrate, there's a whole conversion guide: peep Test::Stream::Manual::ToTest2 π go forth and modernize.
π DESCRIPTION π
This library is literally the main character energy behind is(). It's the base class for a whole lil family of comparison classes, and those are the ones that make deep structure comparisons happen. π
π§ SYNOPSIS π§
π FOR COMPARISON CLASSES π
package Test::Stream::Compare::MyCheck;
use strict;
use warnings;
use base 'Test::Stream::Compare';
use Test::Stream::HashBase accessors => [qw/stuff/];
sub name { 'STUFF' }
sub operator {
my $self = shift;
my ($got) = @_;
return 'eq';
}
sub verify {
my $self = shift;
my $params = @_;
# Always check if $got even exists, this will be false if no value at
# all was received. (as opposed to a $got of 'undef' or '0' which are
# valid meaning this field will be true).
return 0 unless $params{exists};
my $got = $params{got};
return $got eq $self->stuff;
}
πΈ FOR PLUGINS πΈ
package Test::Stream::Plugin::MyCheck;
use Test::Stream::Compare::MyCheck;
use Test::Stream::Compare qw/compare get_build push_build pop_build build/;
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('Test::Stream::Compare::MyCheck');
return Test::Stream::Compare::MyCheck->new(stuff => $thing);
}
π EXPORTS π
these are the lil goodies this module hands you π«Ά
$delta = compare($got, $expect, \&convert)β compares the structures sitting in$gotagainst the ones in$expect. Thatconvertsub is your lil translator: it turns vanilla structures inside$expectinto checks. And if the structures don't match up? The differences come back at you as anTest::Stream::Deltatree. π³$build = get_build()β grab the current global build, if there even is one. πpush_build($build)β set the current global build. π$build = pop_build($build)β unset the current global build. β οΈ Real talk: this one throws an exception if the build you passed in isn't the same as the current global. So don't get sloppy.build($class, sub { ... })β runs that codeblock you handed over, with a fresh instance of$classas the current build. Returns the new build. β¨
π₯ METHODS π₯
Heads up bestie: some of these you must override, others you can if you're feeling fancy. π
$dclass = $check->delta_classβ returns the delta subclass that should be used. By default it'sTest::Stream::Delta.@deltas = $check->deltas(id => $id, exists => $bool, got => $got, convert => \&convert, seen => \%seen)β should return child deltas. πΌ@lines = $check->got_lines($got)β this is your moment β¨ your chance to provide line numbers for errors in the$gotstructure.$op = $check->operator()$op = $check->operator($got)β returns the operator that was used to compare the check against the received data in$got. π§ And here's the trick: if there was no value for got, then there'll be no arguments at all.undefonly shows up as an argument ifundefwas actually seen in$gotβ that's literally how you tell the difference between a missing value and an undefined one. iykyk π$bool = $check->verify(id => $id, exists => $bool, got => $got, convert => \&convert, seen => \%seen)β returns true if there's a shallow match. Like, both items are arrayrefs, both items are the same string, same number, etc. β οΈ Do not go looking deep here β deep checks live in"$check->deltas()". Stay in your lane, shallow queen. π$name = $check->nameβ gets the name of the check. π·οΈ$display = $check->renderβ what should be displayed in a table for this check, usually the name or the value. π$delta = $check->run(id => $id, exists => $bool, got => $got, convert => \&convert, seen => \%seen)β this is where the actual checking goes down: first a shallow check using"$check->verify", then checking"$check->deltas()". And"\%seen"is there to stop cycles from eating the whole thing. ππ
π¦ SOURCE π¦
The source code repo for Test::Stream lives at http://github.com/Test-More/Test-Stream/. Go star it or whatever, bestie. β
π 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/
and that's the whole page, babes π this was perl v5.42.0, dated 2025-07-25, manual page Test::Stream::Compare(3) β drink some water, hydrate, and go write some comparison classes πβ¨π¦
π¦ where this page comes from
- fedora 43: perl-Test-Stream 1.302027-35.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms