Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Tools::ClassicCompare.3pm

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