Created
October 17, 2016 20:08
-
-
Save petdance/f482792afd7bb9fe4f9eafe392dd0148 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package TW::Test2::Bundle; ## no critic ( Subroutines::ProhibitExportingUndeclaredSubs ) | |
# Stolen mostly from Test2::Bundle::More; | |
use strict; | |
use warnings; | |
=head1 DESCRIPTION | |
TW::Test2::Bundle is designed to be everything you need in testing all | |
in one place. This saves you from having to decide which Test2::Tools:: | |
modules to include, or which Test2::Bundle:: you want. | |
=head1 DIFFERENCES FROM Test::More | |
=head2 Test counts are no longer specified in your C<use> of a module. | |
You can no longer do something like: | |
use TW::Test2::Bundle tests => 14; | |
In Test2, you do this as: | |
use TW::Test2::Bundle; | |
plan 14; | |
You can still do C<skip_all> like before: | |
plan 'skip_all'; | |
You're not required to have a plan if you don't want one, and | |
C<done_testing()> still exists. | |
=head2 isa_ok()'s arguments are different | |
The old Test::More C<isa_ok()> had arguments like this: | |
isa_ok( $user, 'TW::User', '<USER>' ); | |
The third argument to the old C<isa_ok()> is not a test name like the | |
second argument to C<ok()> is. Instead, it is an alternate display name | |
for C<$user> when diagnostics are printed. It's not wrong to have used it | |
as a name, but it didn't match the semantics of how the function used it. | |
The new C<isa_ok()> takes multiple classes, so you can do this: | |
isa_ok( $user, 'TW::User', 'TW::DBI' ); | |
But that means if you want to pass a name for the test, it has to be like this: | |
isa_ok( $user, [ 'TW::User' ], 'Got a user' ); | |
The new C<isa_ok()> also actually uses the test name as the test name, | |
instead of using it as the basis of building its own test name. | |
=head2 Use C<ref_ok()> on unblessed references, not C<isa_ok()>. | |
Don't use C<isa_ok()> to check if something is a non-object reference. | |
Use C<ref_ok()>. | |
my $stats = get_list_of_stats(); | |
ref_ok( $stats, 'HASH' ); | |
=cut | |
use Test2::Tools::Basic qw( | |
ok pass fail skip todo diag note | |
plan skip_all done_testing bail_out | |
); | |
# These are the new compare tools, not the compatability-with-Test::More tools. | |
use Test2::Tools::Compare qw( | |
is isnt like unlike | |
); | |
use Test2::Tools::Explain qw( | |
explain | |
); | |
use Test2::Tools::Expressive qw( | |
is_undef | |
is_blank | |
is_nonblank | |
is_empty_array | |
is_nonempty_array | |
is_empty_hash | |
is_nonempty_hash | |
); | |
# But we use the old-style cmp_ok. | |
use Test2::Tools::ClassicCompare qw( cmp_ok ); | |
use Test2::Tools::Exception qw( lives dies ); | |
use Test2::Tools::Class qw( can_ok isa_ok ); | |
use Test2::Tools::Compare qw( | |
is like isnt unlike | |
match mismatch validator | |
hash array bag object meta number string subset | |
in_set not_in_set check_set | |
item field call call_list call_hash prop check all_items all_keys all_vals all_values | |
end filter_items | |
T F D DNE FDNE E | |
event fail_events | |
exact_ref | |
); | |
use Test2::Tools::Ref qw( ref_ok ); | |
use Test2::Tools::Subtest qw( subtest_streamed ); | |
use Test2::Plugin::NoWarnings echo => 1; | |
BEGIN { | |
*BAIL_OUT = \&bail_out; | |
*subtest = \&subtest_streamed; | |
} | |
our @EXPORT = ## no critic ( Modules::ProhibitAutomaticExportation ) | |
qw( | |
ok pass fail skip todo diag note | |
plan skip_all done_testing BAIL_OUT | |
is isnt like unlike cmp_ok | |
isa_ok can_ok ref_ok | |
subtest | |
lives dies | |
explain | |
is like isnt unlike | |
match mismatch validator | |
hash array bag object meta number string subset | |
in_set not_in_set check_set | |
item field call call_list call_hash prop check all_items all_keys all_vals all_values | |
end filter_items | |
T F D DNE FDNE E | |
event fail_events | |
exact_ref | |
is_undef | |
is_blank | |
is_nonblank | |
is_empty_array | |
is_nonempty_array | |
is_empty_hash | |
is_nonempty_hash | |
); | |
use parent 'Exporter'; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment