09 Nov 2019 04:12:40 UTC
- Distribution: Test-Expr
- Module version: 0.000011
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (242 / 42 / 2)
- KwaliteeBus factor: 1
- 62.68% Coverage
- License: artistic_2
- Perl: v5.10.0
- Download (6.75KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:1 non-PAUSE user
- Damian Conway
- CONFIGURATION AND ENVIRONMENT
- BUGS AND LIMITATIONS
- LICENCE AND COPYRIGHT
- DISCLAIMER OF WARRANTY
Test::Expr - Test an expression with better error messages
This document describes Test::Expr version 0.000011
use Test::Expr; plan tests => 5; ok $got == $expected; ok $got eq $expected; ok $got != $expected; ok $got le $expected; ok $got >= $expected;
This testing module installs a single keyword:
That keyword evaluates the expression and produces a test report entry in the usual way (i.e. just like
Test::More::ok). Except that, if you don't give it a description argument, it uses the test expression itself as the description.
In addition, the diagnostic message produced if the test fails is significantly more useful than that provided by either of those other two modules.
For example, the sample code in the Synopsis might produce the following report:
1..5 ok 1 - $got == $expected not ok 2 - $got eq $expected # Failed test '$got eq $expected' # at t/synopsis.t line 13. # because: # $got --> "1.0" # $expected --> 1 # not ok 3 - $got != $expected # Failed test '$got != $expected' # at t/synopsis.t line 14. # because: # $got --> "1.0" # $expected --> 1 # not ok 4 - $got le $expected # Failed test '$got le $expected' # at t/synopsis.t line 15. # because: # $got --> "1.0" # $expected --> 1 # ok 5 - $got >= $expected # Looks like you failed 3 tests of 5.
In other words, this version of
okreports both that the test that was done, and the values of the variables involved that caused the test to fail.
The idea is that you can just write every test as:
ok EXPR, but you now get useful error messages. This mostly eliminates the need for the following functions from Test::More:
# Can write... # Instead of... ok $got eq $expected; is $got, $expected; ok $got ne $unexpected; isnt $got, $unexpected; ok $got ~~ $expected; is_deeply $got, $expected; ok $got =~ $pattern; like $got, $pattern; ok $got !~ $pattern; unlike $got, $pattern; ok $obj->isa($classname); is_ok $got, $classname; ok $obj->can($methodname); can_ok $obj, $methodname;
okkeyword works exactly like the
okfunctions of Test::Simple and Test::More. The only difference in behaviour is in the detail of the diagnostics issued when the test fails.
None (apart from the diagnostics issued by failing tests).
Test::Expr requires no configuration files or environment variables.
Requires Perl v5.14 and the Keyword::Declare module.
Due to a problem with regex compilation under Perl v5.20, this module is absurdly and unusably slow under that release. This issue does not arise in any other supported release of Perl.
No bugs have been reported.
Please report any bugs or feature requests to
email@example.com, or through the web interface at http://rt.cpan.org.
Copyright (c) 2017, Damian Conway
<DCONWAY@CPAN.org>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|