Test2::Tools::ClassicCompare(3) | Perl Programmers Reference Guide | Test2::Tools::ClassicCompare(3) |
Test2::Tools::ClassicCompare - Classic (Test::More style) comparison tools.
This provides comparison functions that behave like they did in Test::More, unlike the Test2::Tools::Compare plugin which has modified them.
use Test2::Tools::ClassicCompare qw/is is_deeply isnt like unlike cmp_ok/; is($got, $expect, "These are the same when stringified"); isnt($got, $unexpected, "These are not the same when stringified"); like($got, qr/.../, "'got' matches the pattern"); unlike($got, qr/.../, "'got' does not match the pattern"); is_deeply($got, $expect, "These structures are same when checked deeply"); cmp_ok($GOT, $OP, $WANT, 'Compare these items using the specified operatr');
The test $name is optional.
The test @diag is optional, it is extra diagnostics messages that will be displayed if the test fails. The diagnostics are ignored if the test passes.
It is important to note that this tool considers "1" and "1.0" to not be equal as it uses a string comparison.
See Test2::Tools::Compare if you want an is() function that tries to be smarter for you.
The test $name is optional.
The test @diag is optional. It contains extra diagnostics messages that will be displayed if the test fails. The diagnostics are ignored if the test passes.
This is the same as Test2::Tools::Compare::is().
Overloading Note: Your input is passed as-is to the comparison. If the comparison fails between two overloaded objects, the diagnostics will try to show you the overload form that was used in comparisons. It is possible that the diagnostics will be wrong, though attempts have been made to improve them since Test::More.
Exceptions: If the comparison results in an exception then the test will fail and the exception will be shown.
cmp_ok() has an internal list of operators it supports. If you provide an unsupported operator it will issue a warning. You can add operators to the %Test2::Tools::ClassicCompare::OPS hash, the key should be the operator, and the value should either be 'str' for string comparison operators, 'num' for numeric operators, or any other true value for other operators.
Supported operators:
The source code repository for Test2-Suite can be found at https://github.com/Test-More/Test2-Suite/.
Copyright 2018 Chad Granum <exodist@cpan.org>.
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/
2024-04-28 | perl v5.40.0 |