1package Test::Most; 2 3use warnings; 4use strict; 5 6use Test::Most::Exception 'throw_failure'; 7 8# XXX don't use 'base' as it can override signal handlers 9use Test::Builder::Module; 10our ( @ISA, @EXPORT, $DATA_DUMPER_NAMES_INSTALLED ); 11my $HAVE_TIME_HIRES; 12 13BEGIN { 14 15 require Test::More; 16 if (Test::More->can('TB_PROVIDER_META')) { 17 Test::More->import(import => [ '!explain' ]); 18 } 19 else { 20 # There's some strange fiddling around with import(), so this allows us to 21 # be nicely backwards compatible to earlier versions of Test::More. 22 @Test::More::EXPORT = grep { $_ ne 'explain' } @Test::More::EXPORT; 23 Test::More->import; 24 } 25 26 eval "use Time::HiRes"; 27 $HAVE_TIME_HIRES = 1 unless $@; 28} 29 30use Test::Builder; 31my $OK_FUNC; 32BEGIN { 33 $OK_FUNC = \&Test::Builder::ok; 34} 35 36our $VERSION = '0.37'; 37$VERSION = eval $VERSION; 38 39BEGIN { 40 @ISA = qw(Test::Builder::Module); 41 @EXPORT = ( 42 Test::More->can('TB_PROVIDER_META') 43 ? grep { $_ ne 'TODO' } keys( %{Test::More->TB_PROVIDER_META->{attrs}}) 44 : @Test::More::EXPORT, 45 qw< 46 $TODO 47 all_done 48 bail_on_fail 49 die_on_fail 50 explain 51 always_explain 52 last_test_failed 53 restore_fail 54 set_failure_handler 55 show 56 always_show 57 > 58 ); 59} 60 61sub import { 62 my $bail_set = 0; 63 64 my %modules_to_load = map { $_ => 1 } qw/ 65 Test::Differences 66 Test::Exception 67 Test::Deep 68 Test::Warn 69 /; 70 warnings->import; 71 strict->import; 72 eval "use Data::Dumper::Names 0.03"; 73 $DATA_DUMPER_NAMES_INSTALLED = !$@; 74 75 if ( $ENV{BAIL_ON_FAIL} ) { 76 $bail_set = 1; 77 bail_on_fail(); 78 } 79 if ( !$bail_set and $ENV{DIE_ON_FAIL} ) { 80 die_on_fail(); 81 } 82 for my $i ( 0 .. $#_ ) { 83 if ( 'bail' eq $_[$i] ) { 84 splice @_, $i, 1; 85 bail_on_fail(); 86 $bail_set = 1; 87 last; 88 } 89 } 90 my $caller = caller; 91 for my $i ( 0 .. $#_ ) { 92 if ( 'timeit' eq $_[$i] ) { 93 splice @_, $i, 1; 94 no strict; 95 *{"${caller}::timeit"} = \&timeit; 96 last; 97 } 98 } 99 100 my %exclude_symbol; 101 my $i = 0; 102 103 foreach my $do_not_import_by_default (qw/blessed reftype/) { 104 if ( grep { $_ eq $do_not_import_by_default } @_ ) { 105 @_ = grep { $_ ne $do_not_import_by_default } @_; 106 } 107 else { 108 $exclude_symbol{$do_not_import_by_default} = 1; 109 } 110 } 111 112 while ($i < @_) { 113 if ( !$bail_set and ( 'die' eq $_[$i] ) ) { 114 splice @_, $i, 1; 115 die_on_fail(); 116 $i = 0; 117 next; 118 } 119 if ( $_[$i] =~ /^-(.*)/ ) { 120 my $module = $1; 121 splice @_, $i, 1; 122 unless (exists $modules_to_load{$module}) { 123 require Carp; 124 Carp::croak("Cannot remove non-existent Test::Module ($module)"); 125 } 126 delete $modules_to_load{$module}; 127 $i = 0; 128 next; 129 } 130 if ( $_[$i] =~ /^!(.*)/ ) { 131 splice @_, $i, 1; 132 $exclude_symbol{$1} = 1; 133 $i = 0; 134 next; 135 } 136 if ( 'defer_plan' eq $_[$i] ) { 137 require Carp; 138 Carp::carp(<<'END') unless $ENV{DO_NOT_WARN_ON_DEFER_PLAN}; 139defer_plan() is deprecated and will be removed in a future release of 140Test::Most. It's functionality is provided by Test::More's done_testing(), 141first added in 2009 (0.88). 142END 143 splice @_, $i, 1; 144 145 my $builder = Test::Builder->new; 146 147 # XXX I don't like setting this directly, but 148 # Test::Builder::has_plan isn't public 149 $builder->{Have_Plan} = 1; 150 $builder->{TEST_MOST_deferred_plan} = 1; 151 $builder->{TEST_MOST_all_done} = 0; 152 $i = 0; 153 next; 154 } 155 $i++; 156 } 157 foreach my $module (keys %modules_to_load) { 158 eval "use $module"; 159 160 if ( my $error = $@) { 161 require Carp; 162 Carp::croak($error); 163 } 164 no strict 'refs'; 165 # Note: export_to_level would be better here. 166 push @EXPORT => grep { !$exclude_symbol{$_} } @{"${module}::EXPORT"}; 167 } 168 169 # 'magic' goto to avoid updating the callstack 170 goto &Test::Builder::Module::import; 171} 172 173sub explain { 174 _explain(\&Test::More::note, @_); 175} 176 177 178sub timeit(&;$) { 179 my ( $code, $message ) = @_; 180 unless($HAVE_TIME_HIRES) { 181 Test::Most::diag("timeit: Time::HiRes not installed"); 182 $code->(); 183 } 184 if ( !$message ) { 185 my ( $package, $filename, $line ) = caller; 186 $message = "$filename line $line"; 187 } 188 my $start = [Time::HiRes::gettimeofday()]; 189 $code->(); 190 explain( 191 sprintf "$message: took %s seconds" => Time::HiRes::tv_interval($start) ); 192} 193 194sub always_explain { 195 _explain(\&Test::More::diag, @_); 196} 197 198sub _explain { 199 my $diag = shift; 200 no warnings 'once'; 201 $diag->( 202 map { 203 ref $_ 204 ? do { 205 require Data::Dumper; 206 local $Data::Dumper::Indent = 1; 207 local $Data::Dumper::Sortkeys = 1; 208 local $Data::Dumper::Terse = 1; 209 Data::Dumper::Dumper($_); 210 } 211 : $_ 212 } @_ 213 ); 214} 215 216sub show { 217 _show(\&Test::More::note, @_); 218} 219 220sub always_show { 221 _show(\&Test::More::diag, @_); 222} 223 224sub _show { 225 unless ( $DATA_DUMPER_NAMES_INSTALLED ) { 226 require Carp; 227 Carp::carp("Data::Dumper::Names 0.03 not found. Use explain() instead of show()"); 228 goto &_explain; 229 } 230 my $diag = shift; 231 no warnings 'once'; 232 local $Data::Dumper::Indent = 1; 233 local $Data::Dumper::Sortkeys = 1; 234 local $Data::Dumper::Names::UpLevel = $Data::Dumper::Names::UpLevel + 2; 235 $diag->(Data::Dumper::Names::Dumper(@_)); 236} 237 238sub die_on_fail { 239 set_failure_handler( sub { throw_failure } ); 240} 241 242sub bail_on_fail { 243 set_failure_handler( 244 sub { Test::More::BAIL_OUT("Test failed. BAIL OUT!.\n") } ); 245} 246 247sub restore_fail { 248 no warnings 'redefine'; 249 *Test::Builder::ok = $OK_FUNC; 250} 251 252sub all_done { 253 my $builder = Test::Builder->new; 254 if ($builder->{TEST_MOST_deferred_plan}) { 255 $builder->{TEST_MOST_all_done} = 1; 256 $builder->expected_tests(@_ ? $_[0] : $builder->current_test); 257 } 258} 259 260 261sub set_failure_handler { 262 my $action = shift; 263 no warnings 'redefine'; 264 Test::Builder->new->{TEST_MOST_failure_action} = $action; # for DESTROY 265 *Test::Builder::ok = sub { 266 local $Test::Builder::Level = $Test::Builder::Level + 1; 267 my $builder = $_[0]; 268 if ( $builder->{TEST_MOST_test_failed} ) { 269 $builder->{TEST_MOST_test_failed} = 0; 270 $action->($builder); 271 } 272 $builder->{TEST_MOST_test_failed} = 0; 273 my $result = $OK_FUNC->(@_); 274 $builder->{TEST_MOST_test_failed} = !( $builder->summary )[-1]; 275 return $result; 276 }; 277} 278 279{ 280 no warnings 'redefine'; 281 my $orig_destroy = Test::Builder->can('DESTROY'); 282 283 # we need this because if the failure is on the final test, we won't have 284 # a subsequent test triggering the behavior. 285 *Test::Builder::DESTROY = sub { 286 my $builder = $_[0]; 287 if ( $builder->{TEST_MOST_test_failed} ) { 288 ( $builder->{TEST_MOST_failure_action} || sub {} )->(); 289 } 290 $orig_destroy->(@_) if $orig_destroy; 291 }; 292} 293 294sub _deferred_plan_handler { 295 my $builder = Test::Builder->new; 296 if ($builder->{TEST_MOST_deferred_plan} and !$builder->{TEST_MOST_all_done}) 297 { 298 $builder->expected_tests($builder->current_test + 1); 299 } 300} 301 302# This should work because the END block defined by Test::Builder should be 303# guaranteed to be run before t one, since we use'd Test::Builder way up top. 304# The other two alternatives would be either to replace Test::Builder::_ending 305# similar to how we did Test::Builder::ok, or to call Test::Builder::no_ending 306# and basically rewrite _ending in our own image. Neither is very palatable, 307# considering _ending's initial underscore. 308 309END { 310 _deferred_plan_handler(); 311} 312 3131; 314__END__ 315 316=head1 NAME 317 318Test::Most - Most commonly needed test functions and features. 319 320=head1 VERSION 321 322Version 0.34 323 324=head1 SYNOPSIS 325 326Instead of this: 327 328 use strict; 329 use warnings; 330 use Test::Exception 0.88; 331 use Test::Differences 0.500; 332 use Test::Deep 0.106; 333 use Test::Warn 0.11; 334 use Test::More tests => 42; 335 336You type this: 337 338 use Test::Most tests => 42; 339 340=head1 DESCRIPTION 341 342L<Test::Most> exists to reduce boilerplate and to make your testing life 343easier. We provide "one stop shopping" for most commonly used testing 344modules. In fact, we often require the latest versions so that you get bug 345fixes through L<Test::Most> and don't have to keep upgrading these modules 346separately. 347 348This module provides you with the most commonly used testing functions, along 349with automatically turning on strict and warning and gives you a bit more 350fine-grained control over your test suite. 351 352 use Test::Most tests => 4, 'die'; 353 354 ok 1, 'Normal calls to ok() should succeed'; 355 is 2, 2, '... as should all passing tests'; 356 eq_or_diff [3], [4], '... but failing tests should die'; 357 ok 4, '... will never get to here'; 358 359As you can see, the C<eq_or_diff> test will fail. Because 'die' is in the 360import list, the test program will halt at that point. 361 362If you do not want strict and warnings enabled, you must explicitly disable 363them. Thus, you must be explicit about what you want and no longer need to 364worry about accidentally forgetting them. 365 366 use Test::Most tests => 4; 367 no strict; 368 no warnings; 369 370=head1 EXPORT 371 372All functions from the following modules will automatically be exported into 373your namespace: 374 375=over 4 376 377=item * L<Test::More> 378 379=item * L<Test::Exception> 380 381=item * L<Test::Differences> 382 383=item * L<Test::Deep> 384 385=item * L<Test::Warn> 386 387=back 388 389Functions which are I<optionally> exported from any of those modules must be 390referred to by their fully-qualified name: 391 392 Test::Deep::render_stack( $var, $stack ); 393 394=head1 FUNCTIONS 395 396Several other functions are also automatically exported: 397 398=head2 C<die_on_fail> 399 400 die_on_fail; 401 is_deeply $foo, bar, '... we throw an exception if this fails'; 402 403This function, if called, will cause the test program to throw a 404L<Test::Most::Exception>, effectively halting the test. 405 406=head2 C<bail_on_fail> 407 408 bail_on_fail; 409 is_deeply $foo, bar, '... we bail out if this fails'; 410 411This function, if called, will cause the test suite to BAIL_OUT() if any 412tests fail after it. 413 414=head2 C<restore_fail> 415 416 die_on_fail; 417 is_deeply $foo, bar, '... we throw an exception if this fails'; 418 419 restore_fail; 420 cmp_bag(\@got, \@bag, '... we will not throw an exception if this fails'; 421 422This restores the original test failure behavior, so subsequent tests will no 423longer throw an exception or BAIL_OUT(). 424 425=head2 C<set_failure_handler> 426 427If you prefer other behavior to 'die_on_fail' or 'bail_on_fail', you can 428set your own failure handler: 429 430 set_failure_handler( sub { 431 my $builder = shift; 432 if ( $builder && $builder->{Test_Results}[-1] =~ /critical/ ) { 433 send_admin_email("critical failure in tests"); 434 } 435 } ); 436 437It receives the C<< Test::Builder >> instance as its only argument. 438 439B<Important>: Note that if the failing test is the very last test run, then 440the C<$builder> will likely be undefined. This is an unfortunate side effect 441of how C<Test::Builder> has been designed. 442 443=head2 C<explain> 444 445Similar to C<note()>, the output will only be seen by the user by 446using the C<-v> switch with C<prove> or reading the raw TAP. 447 448Unlike C<note()>, any reference in the argument list is automatically expanded 449using C<Data::Dumper>. Thus, instead of this: 450 451 my $self = Some::Object->new($id); 452 use Data::Dumper; 453 explain 'I was just created', Dumper($self); 454 455You can now just do this: 456 457 my $self = Some::Object->new($id); 458 explain 'I was just created: ', $self; 459 460That output will look similar to: 461 462 I was just created: bless( { 463 'id' => 2, 464 'stack' => [] 465 }, 'Some::Object' ) 466 467Note that the "dumpered" output has the C<Data::Dumper> variables 468C<$Indent>, C<Sortkeys> and C<Terse> all set to the value of C<1> (one). This 469allows for a much cleaner diagnostic output and at the present time cannot be 470overridden. 471 472Note that Test::More's C<explain> acts differently. This C<explain> 473is equivalent to C<note explain> in Test::More. 474 475=head2 C<show> 476 477Experimental. Just like C<explain>, but also tries to show you the lexical 478variable names: 479 480 my $var = 3; 481 my @array = qw/ foo bar /; 482 show $var, \@array; 483 __END__ 484 $var = 3; 485 @array = [ 486 'foo', 487 'bar' 488 ]; 489 490It will show C<$VAR1>, C<$VAR2> ... C<$VAR_N> for every variable it cannot 491figure out the variable name to: 492 493 my @array = qw/ foo bar /; 494 show @array; 495 __END__ 496 $VAR1 = 'foo'; 497 $VAR2 = 'bar'; 498 499Note that this relies on L<Data::Dumper::Names> version 0.03 or greater. If 500this is not present, it will warn and call L<explain> instead. Also, it can 501only show the names for lexical variables. Globals such as C<%ENV> or C<%@> 502are not accessed via PadWalker and thus cannot be shown. It would be nice to 503find a workaround for this. 504 505=head2 C<always_explain> and C<always_show> 506 507These are identical to C<explain> and C<show>, but like L<Test::More>'s 508C<diag> function, these will always emit output, regardless of whether or not 509you're in verbose mode. 510 511=head2 C<all_done> 512 513B<DEPRECATED>. Use the new C<done_testing()> (added in 514L<Test::More|Test::More> since 0.87_01). Instead. We're leaving this in here 515for a long deprecation cycle. After a while, we might even start warning. 516 517If the plan is specified as C<defer_plan>, you may call C<&all_done> at the 518end of the test with an optional test number. This lets you set the plan 519without knowing the plan before you run the tests. 520 521If you call it without a test number, the tests will still fail if you don't 522get to the end of the test. This is useful if you don't want to specify a 523plan but the tests exit unexpectedly. For example, the following would 524I<pass> with C<no_plan> but fails with C<all_done>. 525 526 use Test::More 'defer_plan'; 527 ok 1; 528 exit; 529 ok 2; 530 all_done; 531 532See L<Deferred plans> for more information. 533 534=head1 EXPORT ON DEMAND 535 536The following will be exported only if requested: 537 538=head2 C<timeit> 539 540Prototype: C<timeit(&;$)> 541 542This function will warn if C<Time::HiRes> is not installed. The test will 543still be run, but no timing information will be displayed. 544 545 use Test::Most 'timeit'; 546 timeit { is expensive_function(), $some_value, $message } 547 "expensive_function()"; 548 timeit { is expensive_function(), $some_value, $message }; 549 550C<timeit> accepts a code reference and an optional message. After the test is 551run, will C<explain> the time of the function using C<Time::HiRes>. If a 552message is supplied, it will be formatted as: 553 554 sprintf "$message: took %s seconds" => $time; 555 556Otherwise, it will be formatted as: 557 558 sprintf "$filename line $line: took %s seconds" => $time; 559 560=head1 DIE OR BAIL ON FAIL 561 562Sometimes you want your test suite to throw an exception or BAIL_OUT() if a 563test fails. In order to provide maximum flexibility, there are three ways to 564accomplish each of these. 565 566=head2 Import list 567 568 use Test::Most 'die', tests => 7; 569 use Test::Most qw< no_plan bail >; 570 571If C<die> or C<bail> is anywhere in the import list, the test program/suite 572will throw a C<Test::Most::Exception> or C<BAIL_OUT()> as appropriate the 573first time a test fails. Calling C<restore_fail> anywhere in the test program 574will restore the original behavior (not throwing an exception or bailing out). 575 576=head2 Functions 577 578 use Test::Most 'no_plan'; 579 ok $bar, 'The test suite will continue if this passes'; 580 581 die_on_fail; 582 is_deeply $foo, bar, '... we throw an exception if this fails'; 583 584 restore_fail; 585 ok $baz, 'The test suite will continue if this passes'; 586 587The C<die_on_fail> and C<bail_on_fail> functions will automatically set the 588desired behavior at runtime. 589 590=head2 Environment variables 591 592 DIE_ON_FAIL=1 prove t/ 593 BAIL_ON_FAIL=1 prove t/ 594 595If the C<DIE_ON_FAIL> or C<BAIL_ON_FAIL> environment variables are true, any 596tests which use C<Test::Most> will throw an exception or call BAIL_OUT on test 597failure. 598 599=head1 MISCELLANEOUS 600 601=head2 Moose 602 603It used to be that this module would produce a warning when used with Moose: 604 605 Prototype mismatch: sub main::blessed ($) vs none 606 607This was because L<Test::Deep> exported a C<blessed()> function by default, 608but its prototype did not match the L<Moose> version's prototype. We now 609exclude the L<Test::Deep> version by default. If you need it, you can call the 610fully-qualified version or request it on the command line: 611 612 use Test::Most 'blessed'; 613 614Note that as of version C<0.34>, C<reftype> is also excluded from 615C<Test::Deep>'s import list. This was causing issues with people trying to use 616C<Scalar::Util>'s C<reftype> function. 617 618=head2 Excluding Test Modules 619 620Sometimes you want a exclude a particular test module. For example, 621L<Test::Deep>, when used with L<Moose>, produces the following warning: 622 623 Prototype mismatch: sub main::blessed ($) vs none 624 625You can exclude this with by adding the module to the import list with a '-' 626symbol in front: 627 628 use Test::Most tests => 42, '-Test::Deep'; 629 630See 631L<https://rt.cpan.org/Ticket/Display.html?id=54362&results=e73ff63c5bf9ba0f796efdba5773cf3f> 632for more information. 633 634=head2 Excluding Test Symbols 635 636Sometimes you don't want to exclude an entire test module, but just a 637particular symbol that is causing issues You can exclude the symbol(s) in the 638standard way, by specifying the symbol in the import list with a '!' in front: 639 640 use Test::Most tests => 42, '!throws_ok'; 641 642=head2 Deferred plans 643 644B<DEPRECATED> and will be removed in some future release of this module. 645Using C<defer_plan> will C<carp()>. Use C<done_testing()> from L<Test::More> 646instead. 647 648 use Test::Most qw<defer_plan>; 649 use My::Tests; 650 my $test_count = My::Tests->run; 651 all_done($test_count); 652 653Sometimes it's difficult to know the plan up front, but you can calculate the 654plan as your tests run. As a result, you want to defer the plan until the end 655of the test. Typically, the best you can do is this: 656 657 use Test::More 'no_plan'; 658 use My::Tests; 659 My::Tests->run; 660 661But when you do that, C<Test::Builder> merely asserts that the number of tests 662you I<ran> is the number of tests. Until now, there was no way of asserting 663that the number of tests you I<expected> is the number of tests unless you do 664so before any tests have run. This fixes that problem. 665 666=head2 One-stop shopping 667 668We generally require the latest stable versions of various test modules. Why? 669Because they have bug fixes and new features. You don't want to have to keep 670remembering them, so periodically we'll release new versions of L<Test::Most> 671just for bug fixes. 672 673=head2 C<use ok> 674 675We do not bundle L<Test::use::ok>, though it's been requested. That's because 676C<use_ok> is broken, but L<Test::use::ok> is also subtly broken (and a touch 677harder to fix). See L<http://use.perl.org/~Ovid/journal/39859> for more 678information. 679 680If you want to test if you can use a module, just use it. If it fails, the 681test will still fail and that's the desired result. 682 683=head1 RATIONALE 684 685People want more control over their test suites. Sometimes when you see 686hundreds of tests failing and whizzing by, you want the test suite to simply 687halt on the first failure. This module gives you that control. 688 689As for the reasons for the four test modules chosen, I ran code over a local 690copy of the CPAN to find the most commonly used testing modules. Here's the 691top twenty as of January 2010 (the numbers are different because we're now 692counting distributions which use a given module rather than simply the number 693of times a module is used). 694 695 1 Test::More 14111 696 2 Test 1736 697 3 Test::Exception 744 698 4 Test::Simple 331 699 5 Test::Pod 328 700 6 Test::Pod::Coverage 274 701 7 Test::Perl::Critic 248 702 8 Test::Base 228 703 9 Test::NoWarnings 155 704 10 Test::Distribution 142 705 11 Test::Kwalitee 138 706 12 Test::Deep 128 707 13 Test::Warn 127 708 14 Test::Differences 102 709 15 Test::Spelling 101 710 16 Test::MockObject 87 711 17 Test::Builder::Tester 84 712 18 Test::WWW::Mechanize::Catalyst 79 713 19 Test::UseAllModules 63 714 20 Test::YAML::Meta 61 715 716L<Test::Most> is number 24 on that list, if you're curious. See 717L<http://blogs.perl.org/users/ovid/2010/01/most-popular-testing-modules---january-2010.html>. 718 719The modules chosen seemed the best fit for what C<Test::Most> is trying to do. 720As of 0.02, we've added L<Test::Warn> by request. It's not in the top ten, but 721it's a great and useful module. 722 723=cut 724 725 726=head1 AUTHOR 727 728Curtis Poe, C<< <ovid at cpan.org> >> 729 730=head1 BUGS 731 732Please report any bugs or feature requests to C<bug-test-extended at 733rt.cpan.org>, or through the web interface at 734L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Most>. I will be 735notified, and then you'll automatically be notified of progress on your bug as 736I make changes. 737 738=head1 SUPPORT 739 740You can find documentation for this module with the perldoc command. 741 742 perldoc Test::Most 743 744You can also look for information at: 745 746=over 4 747 748=item * RT: CPAN's request tracker 749 750L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Most> 751 752=item * AnnoCPAN: Annotated CPAN documentation 753 754L<http://annocpan.org/dist/Test-Most> 755 756=item * CPAN Ratings 757 758L<http://cpanratings.perl.org/d/Test-Most> 759 760=item * Search CPAN 761 762L<http://search.cpan.org/dist/Test-Most> 763 764=back 765 766=head1 TODO 767 768=head2 Deferred plans 769 770Sometimes you don't know the number of tests you will run when you use 771C<Test::More>. The C<plan()> function allows you to delay specifying the 772plan, but you must still call it before the tests are run. This is an error: 773 774 use Test::More; 775 776 my $tests = 0; 777 foreach my $test ( 778 my $count = run($test); # assumes tests are being run 779 $tests += $count; 780 } 781 plan($tests); 782 783The way around this is typically to use 'no_plan' and when the tests are done, 784C<Test::Builder> merely sets the plan to the number of tests run. We'd like 785for the programmer to specify this number instead of letting C<Test::Builder> 786do it. However, C<Test::Builder> internals are a bit difficult to work with, 787so we're delaying this feature. 788 789=head2 Cleaner skip() 790 791 if ( $some_condition ) { 792 skip $message, $num_tests; 793 } 794 else { 795 # run those tests 796 } 797 798That would be cleaner and I might add it if enough people want it. 799 800=head1 CAVEATS 801 802Because of how Perl handles arguments, and because diagnostics are not really 803part of the Test Anything Protocol, what actually happens internally is that 804we note that a test has failed and we throw an exception or bail out as soon 805as the I<next> test is called (but before it runs). This means that its 806arguments are automatically evaluated before we can take action: 807 808 use Test::Most qw<no_plan die>; 809 810 ok $foo, 'Die if this fails'; 811 ok factorial(123456), 812 '... but wait a loooong time before you throw an exception'; 813 814=head1 ACKNOWLEDGEMENTS 815 816Many thanks to C<perl-qa> for arguing about this so much that I just went 817ahead and did it :) 818 819Thanks to Aristotle for suggesting a better way to die or bailout. 820 821Thanks to 'swillert' (L<http://use.perl.org/~swillert/>) for suggesting a 822better implementation of my "dumper explain" idea 823(L<http://use.perl.org/~Ovid/journal/37004>). 824 825=head1 COPYRIGHT & LICENSE 826 827Copyright 2008 Curtis Poe, all rights reserved. 828 829This program is free software; you can redistribute it and/or modify it 830under the same terms as Perl itself. 831 832 833=cut 834 8351; 836