Debian Codegraph @

upstream/debian-unstable/man3/Test2::Tools::ClassicCompare.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Test2::Tools::ClassicCompare 3perl"
58 .TH Test2::Tools::ClassicCompare 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Test2::Tools::ClassicCompare \- Classic (Test::More style) comparison tools.
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 This provides comparison functions that behave like they did in Test::More,
68 unlike the Test2::Tools::Compare plugin which has modified them.
69 .SH SYNOPSIS
70 .IX Header "SYNOPSIS"
71 .Vb 1
72 \& use Test2::Tools::ClassicCompare qw/is is_deeply isnt like unlike cmp_ok/;
73 \&
74 \& is($got, $expect, "These are the same when stringified");
75 \& isnt($got, $unexpected, "These are not the same when stringified");
76 \&
77 \& like($got, qr/.../, "\*(Aqgot\*(Aq matches the pattern");
78 \& unlike($got, qr/.../, "\*(Aqgot\*(Aq does not match the pattern");
79 \&
80 \& is_deeply($got, $expect, "These structures are same when checked deeply");
81 \&
82 \& cmp_ok($GOT, $OP, $WANT, \*(AqCompare these items using the specified operatr\*(Aq);
83 .Ve
84 .SH EXPORTS
85 .IX Header "EXPORTS"
86 .ie n .IP "$bool = is($got, $expect)" 4
87 .el .IP "\f(CW$bool\fR = is($got, \f(CW$expect\fR)" 4
88 .IX Item "$bool = is($got, $expect)"
89 .PD 0
90 .ie n .IP "$bool = is($got, $expect, $name)" 4
91 .el .IP "\f(CW$bool\fR = is($got, \f(CW$expect\fR, \f(CW$name\fR)" 4
92 .IX Item "$bool = is($got, $expect, $name)"
93 .ie n .IP "$bool = is($got, $expect, $name, @diag)" 4
94 .el .IP "\f(CW$bool\fR = is($got, \f(CW$expect\fR, \f(CW$name\fR, \f(CW@diag\fR)" 4
95 .IX Item "$bool = is($got, $expect, $name, @diag)"
96 .PD
97 This does a string comparison of the two arguments. If the two arguments are the
98 same after stringification the test passes. The test will also pass if both
99 arguments are undef.
100 .Sp
101 The test \f(CW$name\fR is optional.
102 .Sp
103 The test \f(CW@diag\fR is optional, it is extra diagnostics messages that will be
104 displayed if the test fails. The diagnostics are ignored if the test passes.
105 .Sp
106 It is important to note that this tool considers \f(CW"1"\fR and \f(CW"1.0"\fR to not be
107 equal as it uses a string comparison.
108 .Sp
109 See Test2::Tools::Compare if you want an \f(CWis()\fR function that tries
110 to be smarter for you.
111 .ie n .IP "$bool = isnt($got, $dont_expect)" 4
112 .el .IP "\f(CW$bool\fR = isnt($got, \f(CW$dont_expect\fR)" 4
113 .IX Item "$bool = isnt($got, $dont_expect)"
114 .PD 0
115 .ie n .IP "$bool = isnt($got, $dont_expect, $name)" 4
116 .el .IP "\f(CW$bool\fR = isnt($got, \f(CW$dont_expect\fR, \f(CW$name\fR)" 4
117 .IX Item "$bool = isnt($got, $dont_expect, $name)"
118 .ie n .IP "$bool = isnt($got, $dont_expect, $name, @diag)" 4
119 .el .IP "\f(CW$bool\fR = isnt($got, \f(CW$dont_expect\fR, \f(CW$name\fR, \f(CW@diag\fR)" 4
120 .IX Item "$bool = isnt($got, $dont_expect, $name, @diag)"
121 .PD
122 This is the inverse of \f(CWis()\fR, it passes when the strings are not the same.
123 .ie n .IP "$bool = like($got, $pattern)" 4
124 .el .IP "\f(CW$bool\fR = like($got, \f(CW$pattern\fR)" 4
125 .IX Item "$bool = like($got, $pattern)"
126 .PD 0
127 .ie n .IP "$bool = like($got, $pattern, $name)" 4
128 .el .IP "\f(CW$bool\fR = like($got, \f(CW$pattern\fR, \f(CW$name\fR)" 4
129 .IX Item "$bool = like($got, $pattern, $name)"
130 .ie n .IP "$bool = like($got, $pattern, $name, @diag)" 4
131 .el .IP "\f(CW$bool\fR = like($got, \f(CW$pattern\fR, \f(CW$name\fR, \f(CW@diag\fR)" 4
132 .IX Item "$bool = like($got, $pattern, $name, @diag)"
133 .PD
134 Check if \f(CW$got\fR matches the specified pattern. Will fail if it does not match.
135 .Sp
136 The test \f(CW$name\fR is optional.
137 .Sp
138 The test \f(CW@diag\fR is optional. It contains extra diagnostics messages that will
139 be displayed if the test fails. The diagnostics are ignored if the test passes.
140 .ie n .IP "$bool = unlike($got, $pattern)" 4
141 .el .IP "\f(CW$bool\fR = unlike($got, \f(CW$pattern\fR)" 4
142 .IX Item "$bool = unlike($got, $pattern)"
143 .PD 0
144 .ie n .IP "$bool = unlike($got, $pattern, $name)" 4
145 .el .IP "\f(CW$bool\fR = unlike($got, \f(CW$pattern\fR, \f(CW$name\fR)" 4
146 .IX Item "$bool = unlike($got, $pattern, $name)"
147 .ie n .IP "$bool = unlike($got, $pattern, $name, @diag)" 4
148 .el .IP "\f(CW$bool\fR = unlike($got, \f(CW$pattern\fR, \f(CW$name\fR, \f(CW@diag\fR)" 4
149 .IX Item "$bool = unlike($got, $pattern, $name, @diag)"
150 .PD
151 This is the inverse of \f(CWlike()\fR. This will fail if \f(CW$got\fR matches
152 \&\f(CW$pattern\fR.
153 .ie n .IP "$bool = is_deeply($got, $expect)" 4
154 .el .IP "\f(CW$bool\fR = is_deeply($got, \f(CW$expect\fR)" 4
155 .IX Item "$bool = is_deeply($got, $expect)"
156 .PD 0
157 .ie n .IP "$bool = is_deeply($got, $expect, $name)" 4
158 .el .IP "\f(CW$bool\fR = is_deeply($got, \f(CW$expect\fR, \f(CW$name\fR)" 4
159 .IX Item "$bool = is_deeply($got, $expect, $name)"
160 .ie n .IP "$bool = is_deeply($got, $expect, $name, @diag)" 4
161 .el .IP "\f(CW$bool\fR = is_deeply($got, \f(CW$expect\fR, \f(CW$name\fR, \f(CW@diag\fR)" 4
162 .IX Item "$bool = is_deeply($got, $expect, $name, @diag)"
163 .PD
164 This does a deep check, comparing the structures in \f(CW$got\fR with those in
165 \&\f(CW$expect\fR. It will recurse into hashrefs, arrayrefs, and scalar refs. All
166 other values will be stringified and compared as strings. It is important to
167 note that this tool considers \f(CW"1"\fR and \f(CW"1.0"\fR to not be equal as it uses a
168 string comparison.
169 .Sp
170 This is the same as \f(CWTest2::Tools::Compare::is()\fR.
171 .ie n .IP "cmp_ok($got, $op, $expect)" 4
172 .el .IP "cmp_ok($got, \f(CW$op\fR, \f(CW$expect\fR)" 4
173 .IX Item "cmp_ok($got, $op, $expect)"
174 .PD 0
175 .ie n .IP "cmp_ok($got, $op, $expect, $name)" 4
176 .el .IP "cmp_ok($got, \f(CW$op\fR, \f(CW$expect\fR, \f(CW$name\fR)" 4
177 .IX Item "cmp_ok($got, $op, $expect, $name)"
178 .ie n .IP "cmp_ok($got, $op, $expect, $name, @diag)" 4
179 .el .IP "cmp_ok($got, \f(CW$op\fR, \f(CW$expect\fR, \f(CW$name\fR, \f(CW@diag\fR)" 4
180 .IX Item "cmp_ok($got, $op, $expect, $name, @diag)"
181 .PD
182 Compare \f(CW$got\fR to \f(CW$expect\fR using the operator specified in \f(CW$op\fR. This is
183 effectively an \f(CW\*(C`eval "\e$got $op \e$expect"\*(C'\fR with some other stuff to make it
184 more sane. This is useful for comparing numbers, overloaded objects, etc.
185 .Sp
186 \&\fBOverloading Note:\fR Your input is passed as-is to the comparison.
187 If the comparison fails between two overloaded objects, the diagnostics will
188 try to show you the overload form that was used in comparisons. It is possible
189 that the diagnostics will be wrong, though attempts have been made to improve
190 them since Test::More.
191 .Sp
192 \&\fBExceptions:\fR If the comparison results in an exception then the test will
193 fail and the exception will be shown.
194 .Sp
195 \&\f(CWcmp_ok()\fR has an internal list of operators it supports. If you provide an
196 unsupported operator it will issue a warning. You can add operators to the
197 \&\f(CW%Test2::Tools::ClassicCompare::OPS\fR hash, the key should be the operator, and
198 the value should either be 'str' for string comparison operators, 'num' for
199 numeric operators, or any other true value for other operators.
200 .Sp
201 Supported operators:
202 .RS 4
203 .IP "== (num)" 4
204 .IX Item "== (num)"
205 .PD 0
206 .IP "!= (num)" 4
207 .IX Item "!= (num)"
208 .IP ">= (num)" 4
209 .IX Item ">= (num)"
210 .IP "<= (num)" 4
211 .IX Item "<= (num)"
212 .IP "> (num)" 4
213 .IX Item "> (num)"
214 .IP "< (num)" 4
215 .IX Item "< (num)"
216 .IP "<=> (num)" 4
217 .IX Item "<=> (num)"
218 .IP "eq (str)" 4
219 .IX Item "eq (str)"
220 .IP "ne (str)" 4
221 .IX Item "ne (str)"
222 .IP "gt (str)" 4
223 .IX Item "gt (str)"
224 .IP "lt (str)" 4
225 .IX Item "lt (str)"
226 .IP "ge (str)" 4
227 .IX Item "ge (str)"
228 .IP "le (str)" 4
229 .IX Item "le (str)"
230 .IP "cmp (str)" 4
231 .IX Item "cmp (str)"
232 .IP "!~ (str)" 4
233 .IX Item "!~ (str)"
234 .IP "=~ (str)" 4
235 .IX Item "=~ (str)"
236 .IP && 4
237 .IP || 4
238 .IP xor 4
239 .IX Item "xor"
240 .IP or 4
241 .IX Item "or"
242 .IP and 4
243 .IX Item "and"
244 .IP // 4
245 .IP & 4
246 .IP | 4
247 .IP ~~ 4
248 .RE
249 .RS 4
250 .RE
251 .PD
252 .SH SOURCE
253 .IX Header "SOURCE"
254 The source code repository for Test2\-Suite can be found at
255 \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
256 .SH MAINTAINERS
257 .IX Header "MAINTAINERS"
258 .IP "Chad Granum <[email protected]>" 4
259 .IX Item "Chad Granum <[email protected]>"
260 .SH AUTHORS
261 .IX Header "AUTHORS"
262 .PD 0
263 .IP "Chad Granum <[email protected]>" 4
264 .IX Item "Chad Granum <[email protected]>"
265 .PD
266 .SH COPYRIGHT
267 .IX Header "COPYRIGHT"
268 Copyright 2018 Chad Granum <[email protected]>.
269 .PP
270 This program is free software; you can redistribute it and/or
271 modify it under the same terms as Perl itself.
272 .PP
273 See \fIhttp://dev.perl.org/licenses/\fR