1Test2::Tools::ClassicCoUmspearreC(o3n)tributed Perl DocuTmeesntt2a:t:iToonols::ClassicCompare(3)
2
3
4
6 Test2::Tools::ClassicCompare - Classic (Test::More style) comparison
7 tools.
8
10 This provides comparison functions that behave like they did in
11 Test::More, unlike the Test2::Tools::Compare plugin which has modified
12 them.
13
15 use Test2::Tools::ClassicCompare qw/is is_deeply isnt like unlike cmp_ok/;
16
17 is($got, $expect, "These are the same when stringified");
18 isnt($got, $unexpect, "These are not the same when stringified");
19
20 like($got, qr/.../, "'got' matches the pattern");
21 unlike($got, qr/.../, "'got' does not match the pattern");
22
23 is_deeply($got, $expect, "These structures are same when checked deeply");
24
25 cmp_ok($GOT, $OP, $WANT, 'Compare these items using the specified operatr');
26
28 $bool = is($got, $expect)
29 $bool = is($got, $expect, $name)
30 $bool = is($got, $expect, $name, @diag)
31 This does a string comparison of the two arguments. If the two
32 arguments are the same after stringification the test passes. The
33 test will also pass if both arguments are undef.
34
35 The test $name is optional.
36
37 The test @diag is optional, it is extra diagnostics messages that
38 will be displayed if the test fails. The diagnostics are ignored if
39 the test passes.
40
41 It is important to note that this tool considers "1" and "1.0" to
42 not be equal as it uses a string comparison.
43
44 See Test2::Tools::Compare if you want an "is()" function that tries
45 to be smarter for you.
46
47 $bool = isnt($got, $dont_expect)
48 $bool = isnt($got, $dont_expect, $name)
49 $bool = isnt($got, $dont_expect, $name, @diag)
50 This is the inverse of "is()", it passes when the strings are not
51 the same.
52
53 $bool = like($got, $pattern)
54 $bool = like($got, $pattern, $name)
55 $bool = like($got, $pattern, $name, @diag)
56 Check if $got matches the specified pattern. Will fail if it does
57 not match.
58
59 The test $name is optional.
60
61 The test @diag is optional. It contains extra diagnostics messages
62 that will be displayed if the test fails. The diagnostics are
63 ignored if the test passes.
64
65 $bool = unlike($got, $pattern)
66 $bool = unlike($got, $pattern, $name)
67 $bool = unlike($got, $pattern, $name, @diag)
68 This is the inverse of "like()". This will fail if $got matches
69 $pattern.
70
71 $bool = is_deeply($got, $expect)
72 $bool = is_deeply($got, $expect, $name)
73 $bool = is_deeply($got, $expect, $name, @diag)
74 This does a deep check, comparing the structures in $got with those
75 in $expect. It will recurse into hashrefs, arrayrefs, and scalar
76 refs. All other values will be stringified and compared as strings.
77 It is important to note that this tool considers "1" and "1.0" to
78 not be equal as it uses a string comparison.
79
80 This is the same as "Test2::Tools::Compare::is()".
81
82 cmp_ok($got, $op, $expect)
83 cmp_ok($got, $op, $expect, $name)
84 cmp_ok($got, $op, $expect, $name, @diag)
85 Compare $got to $expect using the operator specified in $op. This
86 is effectively an "eval "\$got $op \$expect"" with some other stuff
87 to make it more sane. This is useful for comparing numbers,
88 overloaded objects, etc.
89
90 Overloading Note: Your input is passed as-is to the comparison. If
91 the comparison fails between two overloaded objects, the
92 diagnostics will try to show you the overload form that was used in
93 comparisons. It is possible that the diagnostics will be wrong,
94 though attempts have been made to improve them since Test::More.
95
96 Exceptions: If the comparison results in an exception then the test
97 will fail and the exception will be shown.
98
99 "cmp_ok()" has an internal list of operators it supports. If you
100 provide an unsupported operator it will issue a warning. You can
101 add operators to the %Test2::Tools::ClassicCompare::OPS hash, the
102 key should be the operator, and the value should either be 'str'
103 for string comparison operators, 'num' for numeric operators, or
104 any other true value for other operators.
105
106 Supported operators:
107
108 == (num)
109 != (num)
110 >= (num)
111 <= (num)
112 > (num)
113 < (num)
114 <=> (num)
115 eq (str)
116 ne (str)
117 gt (str)
118 lt (str)
119 ge (str)
120 le (str)
121 cmp (str)
122 !~ (str)
123 =~ (str)
124 &&
125 ||
126 xor
127 or
128 and
129 //
130 &
131 |
132 ~~
133
135 The source code repository for Test2-Suite can be found at
136 https://github.com/Test-More/Test2-Suite/.
137
139 Chad Granum <exodist@cpan.org>
140
142 Chad Granum <exodist@cpan.org>
143
145 Copyright 2018 Chad Granum <exodist@cpan.org>.
146
147 This program is free software; you can redistribute it and/or modify it
148 under the same terms as Perl itself.
149
150 See http://dev.perl.org/licenses/
151
152
153
154perl v5.28.2 2019-05-18 Test2::Tools::ClassicCompare(3)