Test-Most-0.37/000755 000766 000024 00000000000 13642144022 013405 5ustar00ovidstaff000000 000000 Test-Most-0.37/PaxHeader/Changes000644 000766 000024 00000000035 13642143763 016662 xustar00ovidstaff000000 000000 29 mtime=1586022387.59783724 Test-Most-0.37/Changes000644 000766 000024 00000011776 13642143763 014727 0ustar00ovidstaff000000 000000 Revision history for Test::Most 0.37 2020-04-04 - Don't call parent DESTROY method if it does not exist (thanks, Karen) 0.36 2020-04-04 - Ensure Test::Builder's original DESTROY is called. Thanks to Karen Etheridge. https://github.com/Ovid/test--most/pull/10 0.35 2016-08-11 - Bump module deps due to Test2. Test2 is tested well enough that you're probably OK, but you'll want to retest your code with this release. 0.34 2014-08-03 - Make compatible with the new Test::Builder (exodist - Chad Granum) - Backwards-incompatible change: reftype no longer exported by default. See https://github.com/Ovid/test--most/issues/6 (reported by rjattril). This should not be noticed by most users (crosses-fingers). - defer_plan() has long been deprecated and will be removed in a future release. This release carp()s if you try to call it. 0.33 2013-01-12 - Oops. Uploaded a bad .tar.gz 0.32 2013-01-12 - Fixed "(in cleanup) Can't use an undefined value as a subroutine reference" error. - Remove Build.PL. 0.31 2012-09-06 - Fix "You tried to plan twice" bug (reported on #78564) 0.30 2012-09-05 - Bugfix: Moose can now be used safely as we exclude Test::Deep::blessed by default (multiple reports) - Bugfix from Randy Stauner. Time::HiRes eval test uses $@, not @_ - carp instead of warn (Olivier Mengué) - Remove autogenerated files (Olivier Mengué) 0.25 2011-08-17 - Add timeit() function to time individual behaviours. 0.24 2011-06-18 - Update dependencies to pick up multiple bug fixes, new behaviours, in various Test:: libraries. 0.23 2010-09-08 - added "Excluding Test Symbols" feature (RT#61146, Karen Etheridge). 0.22 2010-08-07 - Added always_explain() and always_show(). - Apply doc fixes from ranguard. Thanks :) 0.21_04 2010-02-06 - Give people the ability to exclude test modules in case of conflicts. This is to resolve: "Prototype mismatch: sub main::blessed ($) vs none" error with Moose and Test::Deep. See https://rt.cpan.org/Ticket/Display.html?id=54362&results=e73ff63c5bf9ba0f796efdba5773cf3f 0.21_03 2010-02-06 - Bump up dependency on Test::Builder. Need that for done_testing() and to deprecate all_done(). - Remove strict and warnings from tests since they no longer need them :) - Decided to bump up the minimum version number for all test modules. This module should be "one stop shopping" for most people. - Moderately significant POD update. 0.21_02 2010-02-06 - Import strict an warnings. - Increase version requirement for https://rt.cpan.org/Ticket/Display.html?id=44790 Thanks to Gerda Shank for that. 0.21_01 2009-02-18 - Have explain() depend on Test::More::note() (patch from Schwern) - Depend on Test::More directly (patch from Scwhern) 0.21 2009-02-18 - No changes. Update version for release. 0.20_02 2008-11-26 - Make sure tests don't fail if optional Data::Dumper::Names dependency is not met. 0.20_01 2008-11-25 - Added &show. Like &explain, but tries to show variable names. 0.20 2008-11-06 - If a test dies because die_on_fail() or 'Test::Most qw(die)' is triggered, we now throw a 'Test::Most::Exception' rather than simply dieing. This makes it easier for software to understand what's happening if this is trapped in an eval. - Have t/00-load.t report dependency versions since CPAN testers does not reliably do this. - Move some tests to xt/author to ensure that spurious failures don't cause CPAN install issues. 0.12 2008-10-15 - Make sure we don't get redef warnings with Test::Builder 0.82. - Expose &set_failure_handler to people can customize it more. 0.11 2008-07-29 - explain() now automatically uses Data::Dumper on references. 0.10 2008-07-22 - Rename internal keys to begin with TEST_MOST_ instead of XXX_. - Rework tests to be slightly less comprehensive but more likely to pass (removed the otherwise lovely Test::Command until we can figure out what's up with it). 0.04 2008-06-19 - Forget to add Test::Warn to Build.pl :) 0.03 2008-06-18 - Remembered to add t/defer_plan.t to the manifest. D'oh! 0.02 2008-06-18 - Fixed Perl version in Build.PL to avoid problems with smoke testers skipping this test. - Added Test::Warn support (suggestion from benh). - Fixed bug whereby Test::Deep tests were not exported. Whoops! :) - Add deferred plans. Thanks to barefootcoder++ (Buddy Burden) for this. - Added build dependency on Test::Command (nice module!) 0.01 2008-01-13 - Use the most common test features. Test-Most-0.37/MANIFEST000644 000766 000024 00000000760 12367357570 014562 0ustar00ovidstaff000000 000000 Changes lib/Test/Most.pm lib/Test/Most/Exception.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.json META.yml README t/00-load.t t/bug_duplicate_plan.t t/common.t t/defer_plan.t t/env_bail.t t/env_die.t t/exception.t t/exclude_test_modules.t t/exclude_test_symbols.t t/explain.t t/function_bail.t t/function_die.t t/import_bail.t t/import_die.t t/import_strict_and_warnings.t t/lib/DuplicatePlanRegression.pm t/lib/OurTester.pm t/timex.t xt/author/pod-coverage.t xt/author/pod.t Test-Most-0.37/t/000755 000766 000024 00000000000 13642144022 013650 5ustar00ovidstaff000000 000000 Test-Most-0.37/xt/000755 000766 000024 00000000000 13642144022 014040 5ustar00ovidstaff000000 000000 Test-Most-0.37/README000644 000766 000024 00000001404 12264471052 014271 0ustar00ovidstaff000000 000000 INSTALLATION To install this module, run the following commands: perl Build.PL ./Build ./Build test ./Build install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Test::Most You can also look for information at: RT, CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Most AnnoCPAN, Annotated CPAN documentation http://annocpan.org/dist/Test-Most CPAN Ratings http://cpanratings.perl.org/d/Test-Most Search CPAN http://search.cpan.org/dist/Test-Most COPYRIGHT AND LICENCE Copyright (C) 2008 Curtis Poe This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Test-Most-0.37/MANIFEST.SKIP000644 000766 000024 00000001770 12367357570 015331 0ustar00ovidstaff000000 000000 #!start included /usr/share/perl/5.14/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild\.bat$ \bBuild\.COM$ \bBUILD\.COM$ \bbuild\.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ \.sw.$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /usr/share/perl/5.14/ExtUtils/MANIFEST.SKIP # Avoid archives of this distribution \bTest-Most-[\d\.\_]+ Test-Most-0.37/META.yml000644 000766 000024 00000001321 13642144022 014653 0ustar00ovidstaff000000 000000 --- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Most no_index: directory: - t - inc requires: Exception::Class: '1.14' Test::Deep: '0.119' Test::Differences: '0.64' Test::Exception: '0.43' Test::Harness: '3.35' Test::More: '1.302047' Test::Warn: '0.30' resources: repository: https://github.com/Ovid/test--most version: '0.37' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Test-Most-0.37/lib/000755 000766 000024 00000000000 13642144022 014153 5ustar00ovidstaff000000 000000 Test-Most-0.37/PaxHeader/Makefile.PL000644 000766 000024 00000000036 13642066713 017341 xustar00ovidstaff000000 000000 30 mtime=1585999307.721297519 Test-Most-0.37/Makefile.PL000644 000766 000024 00000001477 13642066713 015402 0ustar00ovidstaff000000 000000 require 5.006; use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Test::Most', 'VERSION_FROM' => 'lib/Test/Most.pm', 'PREREQ_PM' => { 'Exception::Class' => '1.14', 'Test::Deep' => '0.119', 'Test::Differences' => '0.64', 'Test::Exception' => '0.43', 'Test::Harness' => '3.35', 'Test::More' => '1.302047', 'Test::Warn' => '0.30' }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {}, META_MERGE => { "meta-spec" => { version => 2 }, resources => { repository => { type => 'git', url => 'git@github.com:Ovid/test--most.github', web => 'https://github.com/Ovid/test--most', }, }, }, ); Test-Most-0.37/META.json000644 000766 000024 00000002350 13642144022 015026 0ustar00ovidstaff000000 000000 { "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-Most", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Exception::Class" : "1.14", "Test::Deep" : "0.119", "Test::Differences" : "0.64", "Test::Exception" : "0.43", "Test::Harness" : "3.35", "Test::More" : "1.302047", "Test::Warn" : "0.30" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "web" : "https://github.com/Ovid/test--most" } }, "version" : "0.37", "x_serialization_backend" : "JSON::PP version 4.04" } Test-Most-0.37/lib/Test/000755 000766 000024 00000000000 13642144022 015072 5ustar00ovidstaff000000 000000 Test-Most-0.37/lib/Test/Most/000755 000766 000024 00000000000 13642144022 016014 5ustar00ovidstaff000000 000000 Test-Most-0.37/lib/Test/PaxHeader/Most.pm000644 000766 000024 00000000036 13642143714 020331 xustar00ovidstaff000000 000000 30 mtime=1586022348.455897404 Test-Most-0.37/lib/Test/Most.pm000644 000766 000024 00000057152 13642143714 016373 0ustar00ovidstaff000000 000000 package Test::Most; use warnings; use strict; use Test::Most::Exception 'throw_failure'; # XXX don't use 'base' as it can override signal handlers use Test::Builder::Module; our ( @ISA, @EXPORT, $DATA_DUMPER_NAMES_INSTALLED ); my $HAVE_TIME_HIRES; BEGIN { require Test::More; if (Test::More->can('TB_PROVIDER_META')) { Test::More->import(import => [ '!explain' ]); } else { # There's some strange fiddling around with import(), so this allows us to # be nicely backwards compatible to earlier versions of Test::More. @Test::More::EXPORT = grep { $_ ne 'explain' } @Test::More::EXPORT; Test::More->import; } eval "use Time::HiRes"; $HAVE_TIME_HIRES = 1 unless $@; } use Test::Builder; my $OK_FUNC; BEGIN { $OK_FUNC = \&Test::Builder::ok; } our $VERSION = '0.37'; $VERSION = eval $VERSION; BEGIN { @ISA = qw(Test::Builder::Module); @EXPORT = ( Test::More->can('TB_PROVIDER_META') ? grep { $_ ne 'TODO' } keys( %{Test::More->TB_PROVIDER_META->{attrs}}) : @Test::More::EXPORT, qw< $TODO all_done bail_on_fail die_on_fail explain always_explain last_test_failed restore_fail set_failure_handler show always_show > ); } sub import { my $bail_set = 0; my %modules_to_load = map { $_ => 1 } qw/ Test::Differences Test::Exception Test::Deep Test::Warn /; warnings->import; strict->import; eval "use Data::Dumper::Names 0.03"; $DATA_DUMPER_NAMES_INSTALLED = !$@; if ( $ENV{BAIL_ON_FAIL} ) { $bail_set = 1; bail_on_fail(); } if ( !$bail_set and $ENV{DIE_ON_FAIL} ) { die_on_fail(); } for my $i ( 0 .. $#_ ) { if ( 'bail' eq $_[$i] ) { splice @_, $i, 1; bail_on_fail(); $bail_set = 1; last; } } my $caller = caller; for my $i ( 0 .. $#_ ) { if ( 'timeit' eq $_[$i] ) { splice @_, $i, 1; no strict; *{"${caller}::timeit"} = \&timeit; last; } } my %exclude_symbol; my $i = 0; foreach my $do_not_import_by_default (qw/blessed reftype/) { if ( grep { $_ eq $do_not_import_by_default } @_ ) { @_ = grep { $_ ne $do_not_import_by_default } @_; } else { $exclude_symbol{$do_not_import_by_default} = 1; } } while ($i < @_) { if ( !$bail_set and ( 'die' eq $_[$i] ) ) { splice @_, $i, 1; die_on_fail(); $i = 0; next; } if ( $_[$i] =~ /^-(.*)/ ) { my $module = $1; splice @_, $i, 1; unless (exists $modules_to_load{$module}) { require Carp; Carp::croak("Cannot remove non-existent Test::Module ($module)"); } delete $modules_to_load{$module}; $i = 0; next; } if ( $_[$i] =~ /^!(.*)/ ) { splice @_, $i, 1; $exclude_symbol{$1} = 1; $i = 0; next; } if ( 'defer_plan' eq $_[$i] ) { require Carp; Carp::carp(<<'END') unless $ENV{DO_NOT_WARN_ON_DEFER_PLAN}; defer_plan() is deprecated and will be removed in a future release of Test::Most. It's functionality is provided by Test::More's done_testing(), first added in 2009 (0.88). END splice @_, $i, 1; my $builder = Test::Builder->new; # XXX I don't like setting this directly, but # Test::Builder::has_plan isn't public $builder->{Have_Plan} = 1; $builder->{TEST_MOST_deferred_plan} = 1; $builder->{TEST_MOST_all_done} = 0; $i = 0; next; } $i++; } foreach my $module (keys %modules_to_load) { eval "use $module"; if ( my $error = $@) { require Carp; Carp::croak($error); } no strict 'refs'; # Note: export_to_level would be better here. push @EXPORT => grep { !$exclude_symbol{$_} } @{"${module}::EXPORT"}; } # 'magic' goto to avoid updating the callstack goto &Test::Builder::Module::import; } sub explain { _explain(\&Test::More::note, @_); } sub timeit(&;$) { my ( $code, $message ) = @_; unless($HAVE_TIME_HIRES) { Test::Most::diag("timeit: Time::HiRes not installed"); $code->(); } if ( !$message ) { my ( $package, $filename, $line ) = caller; $message = "$filename line $line"; } my $start = [Time::HiRes::gettimeofday()]; $code->(); explain( sprintf "$message: took %s seconds" => Time::HiRes::tv_interval($start) ); } sub always_explain { _explain(\&Test::More::diag, @_); } sub _explain { my $diag = shift; no warnings 'once'; $diag->( map { ref $_ ? do { require Data::Dumper; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Terse = 1; Data::Dumper::Dumper($_); } : $_ } @_ ); } sub show { _show(\&Test::More::note, @_); } sub always_show { _show(\&Test::More::diag, @_); } sub _show { unless ( $DATA_DUMPER_NAMES_INSTALLED ) { require Carp; Carp::carp("Data::Dumper::Names 0.03 not found. Use explain() instead of show()"); goto &_explain; } my $diag = shift; no warnings 'once'; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Names::UpLevel = $Data::Dumper::Names::UpLevel + 2; $diag->(Data::Dumper::Names::Dumper(@_)); } sub die_on_fail { set_failure_handler( sub { throw_failure } ); } sub bail_on_fail { set_failure_handler( sub { Test::More::BAIL_OUT("Test failed. BAIL OUT!.\n") } ); } sub restore_fail { no warnings 'redefine'; *Test::Builder::ok = $OK_FUNC; } sub all_done { my $builder = Test::Builder->new; if ($builder->{TEST_MOST_deferred_plan}) { $builder->{TEST_MOST_all_done} = 1; $builder->expected_tests(@_ ? $_[0] : $builder->current_test); } } sub set_failure_handler { my $action = shift; no warnings 'redefine'; Test::Builder->new->{TEST_MOST_failure_action} = $action; # for DESTROY *Test::Builder::ok = sub { local $Test::Builder::Level = $Test::Builder::Level + 1; my $builder = $_[0]; if ( $builder->{TEST_MOST_test_failed} ) { $builder->{TEST_MOST_test_failed} = 0; $action->($builder); } $builder->{TEST_MOST_test_failed} = 0; my $result = $OK_FUNC->(@_); $builder->{TEST_MOST_test_failed} = !( $builder->summary )[-1]; return $result; }; } { no warnings 'redefine'; my $orig_destroy = Test::Builder->can('DESTROY'); # we need this because if the failure is on the final test, we won't have # a subsequent test triggering the behavior. *Test::Builder::DESTROY = sub { my $builder = $_[0]; if ( $builder->{TEST_MOST_test_failed} ) { ( $builder->{TEST_MOST_failure_action} || sub {} )->(); } $orig_destroy->(@_) if $orig_destroy; }; } sub _deferred_plan_handler { my $builder = Test::Builder->new; if ($builder->{TEST_MOST_deferred_plan} and !$builder->{TEST_MOST_all_done}) { $builder->expected_tests($builder->current_test + 1); } } # This should work because the END block defined by Test::Builder should be # guaranteed to be run before t one, since we use'd Test::Builder way up top. # The other two alternatives would be either to replace Test::Builder::_ending # similar to how we did Test::Builder::ok, or to call Test::Builder::no_ending # and basically rewrite _ending in our own image. Neither is very palatable, # considering _ending's initial underscore. END { _deferred_plan_handler(); } 1; __END__ =head1 NAME Test::Most - Most commonly needed test functions and features. =head1 VERSION Version 0.34 =head1 SYNOPSIS Instead of this: use strict; use warnings; use Test::Exception 0.88; use Test::Differences 0.500; use Test::Deep 0.106; use Test::Warn 0.11; use Test::More tests => 42; You type this: use Test::Most tests => 42; =head1 DESCRIPTION L exists to reduce boilerplate and to make your testing life easier. We provide "one stop shopping" for most commonly used testing modules. In fact, we often require the latest versions so that you get bug fixes through L and don't have to keep upgrading these modules separately. This module provides you with the most commonly used testing functions, along with automatically turning on strict and warning and gives you a bit more fine-grained control over your test suite. use Test::Most tests => 4, 'die'; ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; eq_or_diff [3], [4], '... but failing tests should die'; ok 4, '... will never get to here'; As you can see, the C test will fail. Because 'die' is in the import list, the test program will halt at that point. If you do not want strict and warnings enabled, you must explicitly disable them. Thus, you must be explicit about what you want and no longer need to worry about accidentally forgetting them. use Test::Most tests => 4; no strict; no warnings; =head1 EXPORT All functions from the following modules will automatically be exported into your namespace: =over 4 =item * L =item * L =item * L =item * L =item * L =back Functions which are I exported from any of those modules must be referred to by their fully-qualified name: Test::Deep::render_stack( $var, $stack ); =head1 FUNCTIONS Several other functions are also automatically exported: =head2 C die_on_fail; is_deeply $foo, bar, '... we throw an exception if this fails'; This function, if called, will cause the test program to throw a L, effectively halting the test. =head2 C bail_on_fail; is_deeply $foo, bar, '... we bail out if this fails'; This function, if called, will cause the test suite to BAIL_OUT() if any tests fail after it. =head2 C die_on_fail; is_deeply $foo, bar, '... we throw an exception if this fails'; restore_fail; cmp_bag(\@got, \@bag, '... we will not throw an exception if this fails'; This restores the original test failure behavior, so subsequent tests will no longer throw an exception or BAIL_OUT(). =head2 C If you prefer other behavior to 'die_on_fail' or 'bail_on_fail', you can set your own failure handler: set_failure_handler( sub { my $builder = shift; if ( $builder && $builder->{Test_Results}[-1] =~ /critical/ ) { send_admin_email("critical failure in tests"); } } ); It receives the C<< Test::Builder >> instance as its only argument. B: Note that if the failing test is the very last test run, then the C<$builder> will likely be undefined. This is an unfortunate side effect of how C has been designed. =head2 C Similar to C, the output will only be seen by the user by using the C<-v> switch with C or reading the raw TAP. Unlike C, any reference in the argument list is automatically expanded using C. Thus, instead of this: my $self = Some::Object->new($id); use Data::Dumper; explain 'I was just created', Dumper($self); You can now just do this: my $self = Some::Object->new($id); explain 'I was just created: ', $self; That output will look similar to: I was just created: bless( { 'id' => 2, 'stack' => [] }, 'Some::Object' ) Note that the "dumpered" output has the C variables C<$Indent>, C and C all set to the value of C<1> (one). This allows for a much cleaner diagnostic output and at the present time cannot be overridden. Note that Test::More's C acts differently. This C is equivalent to C in Test::More. =head2 C Experimental. Just like C, but also tries to show you the lexical variable names: my $var = 3; my @array = qw/ foo bar /; show $var, \@array; __END__ $var = 3; @array = [ 'foo', 'bar' ]; It will show C<$VAR1>, C<$VAR2> ... C<$VAR_N> for every variable it cannot figure out the variable name to: my @array = qw/ foo bar /; show @array; __END__ $VAR1 = 'foo'; $VAR2 = 'bar'; Note that this relies on L version 0.03 or greater. If this is not present, it will warn and call L instead. Also, it can only show the names for lexical variables. Globals such as C<%ENV> or C<%@> are not accessed via PadWalker and thus cannot be shown. It would be nice to find a workaround for this. =head2 C and C These are identical to C and C, but like L's C function, these will always emit output, regardless of whether or not you're in verbose mode. =head2 C B. Use the new C (added in L since 0.87_01). Instead. We're leaving this in here for a long deprecation cycle. After a while, we might even start warning. If the plan is specified as C, you may call C<&all_done> at the end of the test with an optional test number. This lets you set the plan without knowing the plan before you run the tests. If you call it without a test number, the tests will still fail if you don't get to the end of the test. This is useful if you don't want to specify a plan but the tests exit unexpectedly. For example, the following would I with C but fails with C. use Test::More 'defer_plan'; ok 1; exit; ok 2; all_done; See L for more information. =head1 EXPORT ON DEMAND The following will be exported only if requested: =head2 C Prototype: C This function will warn if C is not installed. The test will still be run, but no timing information will be displayed. use Test::Most 'timeit'; timeit { is expensive_function(), $some_value, $message } "expensive_function()"; timeit { is expensive_function(), $some_value, $message }; C accepts a code reference and an optional message. After the test is run, will C the time of the function using C. If a message is supplied, it will be formatted as: sprintf "$message: took %s seconds" => $time; Otherwise, it will be formatted as: sprintf "$filename line $line: took %s seconds" => $time; =head1 DIE OR BAIL ON FAIL Sometimes you want your test suite to throw an exception or BAIL_OUT() if a test fails. In order to provide maximum flexibility, there are three ways to accomplish each of these. =head2 Import list use Test::Most 'die', tests => 7; use Test::Most qw< no_plan bail >; If C or C is anywhere in the import list, the test program/suite will throw a C or C as appropriate the first time a test fails. Calling C anywhere in the test program will restore the original behavior (not throwing an exception or bailing out). =head2 Functions use Test::Most 'no_plan'; ok $bar, 'The test suite will continue if this passes'; die_on_fail; is_deeply $foo, bar, '... we throw an exception if this fails'; restore_fail; ok $baz, 'The test suite will continue if this passes'; The C and C functions will automatically set the desired behavior at runtime. =head2 Environment variables DIE_ON_FAIL=1 prove t/ BAIL_ON_FAIL=1 prove t/ If the C or C environment variables are true, any tests which use C will throw an exception or call BAIL_OUT on test failure. =head1 MISCELLANEOUS =head2 Moose It used to be that this module would produce a warning when used with Moose: Prototype mismatch: sub main::blessed ($) vs none This was because L exported a C function by default, but its prototype did not match the L version's prototype. We now exclude the L version by default. If you need it, you can call the fully-qualified version or request it on the command line: use Test::Most 'blessed'; Note that as of version C<0.34>, C is also excluded from C's import list. This was causing issues with people trying to use C's C function. =head2 Excluding Test Modules Sometimes you want a exclude a particular test module. For example, L, when used with L, produces the following warning: Prototype mismatch: sub main::blessed ($) vs none You can exclude this with by adding the module to the import list with a '-' symbol in front: use Test::Most tests => 42, '-Test::Deep'; See L for more information. =head2 Excluding Test Symbols Sometimes you don't want to exclude an entire test module, but just a particular symbol that is causing issues You can exclude the symbol(s) in the standard way, by specifying the symbol in the import list with a '!' in front: use Test::Most tests => 42, '!throws_ok'; =head2 Deferred plans B and will be removed in some future release of this module. Using C will C. Use C from L instead. use Test::Most qw; use My::Tests; my $test_count = My::Tests->run; all_done($test_count); Sometimes it's difficult to know the plan up front, but you can calculate the plan as your tests run. As a result, you want to defer the plan until the end of the test. Typically, the best you can do is this: use Test::More 'no_plan'; use My::Tests; My::Tests->run; But when you do that, C merely asserts that the number of tests you I is the number of tests. Until now, there was no way of asserting that the number of tests you I is the number of tests unless you do so before any tests have run. This fixes that problem. =head2 One-stop shopping We generally require the latest stable versions of various test modules. Why? Because they have bug fixes and new features. You don't want to have to keep remembering them, so periodically we'll release new versions of L just for bug fixes. =head2 C We do not bundle L, though it's been requested. That's because C is broken, but L is also subtly broken (and a touch harder to fix). See L for more information. If you want to test if you can use a module, just use it. If it fails, the test will still fail and that's the desired result. =head1 RATIONALE People want more control over their test suites. Sometimes when you see hundreds of tests failing and whizzing by, you want the test suite to simply halt on the first failure. This module gives you that control. As for the reasons for the four test modules chosen, I ran code over a local copy of the CPAN to find the most commonly used testing modules. Here's the top twenty as of January 2010 (the numbers are different because we're now counting distributions which use a given module rather than simply the number of times a module is used). 1 Test::More 14111 2 Test 1736 3 Test::Exception 744 4 Test::Simple 331 5 Test::Pod 328 6 Test::Pod::Coverage 274 7 Test::Perl::Critic 248 8 Test::Base 228 9 Test::NoWarnings 155 10 Test::Distribution 142 11 Test::Kwalitee 138 12 Test::Deep 128 13 Test::Warn 127 14 Test::Differences 102 15 Test::Spelling 101 16 Test::MockObject 87 17 Test::Builder::Tester 84 18 Test::WWW::Mechanize::Catalyst 79 19 Test::UseAllModules 63 20 Test::YAML::Meta 61 L is number 24 on that list, if you're curious. See L. The modules chosen seemed the best fit for what C is trying to do. As of 0.02, we've added L by request. It's not in the top ten, but it's a great and useful module. =cut =head1 AUTHOR Curtis Poe, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Test::Most You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 TODO =head2 Deferred plans Sometimes you don't know the number of tests you will run when you use C. The C function allows you to delay specifying the plan, but you must still call it before the tests are run. This is an error: use Test::More; my $tests = 0; foreach my $test ( my $count = run($test); # assumes tests are being run $tests += $count; } plan($tests); The way around this is typically to use 'no_plan' and when the tests are done, C merely sets the plan to the number of tests run. We'd like for the programmer to specify this number instead of letting C do it. However, C internals are a bit difficult to work with, so we're delaying this feature. =head2 Cleaner skip() if ( $some_condition ) { skip $message, $num_tests; } else { # run those tests } That would be cleaner and I might add it if enough people want it. =head1 CAVEATS Because of how Perl handles arguments, and because diagnostics are not really part of the Test Anything Protocol, what actually happens internally is that we note that a test has failed and we throw an exception or bail out as soon as the I test is called (but before it runs). This means that its arguments are automatically evaluated before we can take action: use Test::Most qw; ok $foo, 'Die if this fails'; ok factorial(123456), '... but wait a loooong time before you throw an exception'; =head1 ACKNOWLEDGEMENTS Many thanks to C for arguing about this so much that I just went ahead and did it :) Thanks to Aristotle for suggesting a better way to die or bailout. Thanks to 'swillert' (L) for suggesting a better implementation of my "dumper explain" idea (L). =head1 COPYRIGHT & LICENSE Copyright 2008 Curtis Poe, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Test-Most-0.37/lib/Test/Most/PaxHeader/Exception.pm000644 000766 000024 00000000036 13642143724 022270 xustar00ovidstaff000000 000000 30 mtime=1586022356.672121384 Test-Most-0.37/lib/Test/Most/Exception.pm000644 000766 000024 00000004073 13642143724 020324 0ustar00ovidstaff000000 000000 package Test::Most::Exception; use warnings; use strict; use base 'Exporter'; our @EXPORT_OK = ('throw_failure'); our $VERSION = '0.37'; $VERSION = eval $VERSION; use Exception::Class 'Test::Most::Exception' => { alias => 'throw_failure', description => 'Test failed. Stopping test.', }; 1; __END__ =head1 NAME Test::Most::Exception - Internal exception class =head1 VERSION Version 0.34 =head1 SYNOPSIS This is the exception thrown by C by C. =head1 EXPORT We export only one function: =head2 C This is the exception for C. =cut =head1 AUTHOR Curtis Poe, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Test::Most You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 CAVEATS The stack trace is likely useless due to how C internals work. Sorry 'bout that. =head1 ACKNOWLEDGEMENTS Many thanks to C for arguing about this so much that I just went ahead and did it :) Thanks to Aristotle for suggesting a better way to die or bailout. Thanks to 'swillert' (L) for suggesting a better implementation of my "dumper explain" idea (L). =head1 COPYRIGHT & LICENSE Copyright 2008 Curtis Poe, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Test-Most-0.37/xt/author/000755 000766 000024 00000000000 13642144022 015342 5ustar00ovidstaff000000 000000 Test-Most-0.37/xt/author/pod.t000644 000766 000024 00000000350 12264471052 016314 0ustar00ovidstaff000000 000000 #!perl -T use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok(); Test-Most-0.37/xt/author/pod-coverage.t000644 000766 000024 00000001047 12264471052 020111 0ustar00ovidstaff000000 000000 use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod::Coverage my $min_tpc = 1.08; eval "use Test::Pod::Coverage $min_tpc"; plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" if $@; # Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, # but older versions don't recognize some common documentation styles my $min_pc = 0.18; eval "use Pod::Coverage $min_pc"; plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; all_pod_coverage_ok(); Test-Most-0.37/t/exclude_test_modules.t000644 000766 000024 00000000552 12264471052 020264 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most tests => 4, '-Test::Exception'; use OurTester qw($DIED dies); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; eq_or_diff [ 3, 4 ], [ 3, 4 ], '... and Test::Differences tests'; ok !defined &lives_ok, '... but excluding a test module excludes its test functions'; Test-Most-0.37/t/explain.t000644 000766 000024 00000004173 12264471052 015507 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most tests => 8; use Data::Dumper; no warnings 'redefine'; my @NOTE; local *Test::More::note = sub { @NOTE = @_ }; my @DIAG; local *Test::More::diag = sub { @DIAG = @_ }; explain 'foo'; eq_or_diff \@NOTE, ['foo'], 'Basic explain() should work just fine'; my $aref = [qw/this that/]; { local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Terse = 1; explain 'hi', $aref, 'bye'; eq_or_diff \@NOTE, [ 'hi', Dumper($aref), 'bye' ], '... and also allow you to dump references'; } { my $expected; local $Data::Dumper::Indent = 1; $expected = Dumper($aref); $expected =~ s/VAR1/aref/; show $aref; SKIP: { eval "use Data::Dumper::Names ()"; skip 'show() requires Data::Dumper::Names version 0.03 or better', 2 if $@ or $Data::Dumper::Names::VERSION < .03; eq_or_diff \@NOTE, [$expected], '... and show() should try to show the variable name'; show 3; chomp @NOTE; eq_or_diff \@NOTE, ['$VAR1 = 3;'], '... but will default to $VARX names if it can\'t'; } } always_explain 'foo'; eq_or_diff \@DIAG, ['foo'], 'Basic always_explain() should work just fine'; { local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Terse = 1; always_explain 'hi', $aref, 'bye'; eq_or_diff \@DIAG, [ 'hi', Dumper($aref), 'bye' ], '... and also allow you to dump references'; } { my $expected; local $Data::Dumper::Indent = 1; $expected = Dumper($aref); $expected =~ s/VAR1/aref/; always_show $aref; SKIP: { eval "use Data::Dumper::Names ()"; skip 'always_show() requires Data::Dumper::Names version 0.03 or better', 2 if $@ or $Data::Dumper::Names::VERSION < .03; eq_or_diff \@DIAG, [$expected], '... and always_show() should try to show the variable name'; always_show 3; chomp @DIAG; eq_or_diff \@DIAG, ['$VAR1 = 3;'], '... but will default to $VARX names if it can\'t'; } } Test-Most-0.37/t/bug_duplicate_plan.t000644 000766 000024 00000000151 12367357570 017674 0ustar00ovidstaff000000 000000 use lib 'lib', 't/lib'; use Test::Most; use DuplicatePlanRegression; # adds 1 test ok 1; done_testing; Test-Most-0.37/t/import_strict_and_warnings.t000644 000766 000024 00000000362 12264471052 021477 0ustar00ovidstaff000000 000000 use lib 'lib'; use Test::Most tests => 2; eval '$foo = 1'; ok my $error = $@, 'evaling an undeclared variable should fail'; like $error, qr/Global symbol.*requires explicit package name/, '... and give us an appropriate error message'; Test-Most-0.37/t/env_die.t000644 000766 000024 00000000557 12264471052 015462 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; BEGIN { $ENV{DIE_ON_FAIL} = 1 } use Test::Most tests => 7; use OurTester qw($DIED dies); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; dies { eq_or_diff( [3], [4] ) } '... but failing tests should die'; ok 4, 'Subsequent calls to ok() should be fine'; ok !$DIED, '... and not die'; Test-Most-0.37/t/timex.t000644 000766 000024 00000000210 12367357520 015170 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most qw; ok 1; timeit { ok 1 }; timeit { ok 1 } 'message'; done_testing(); Test-Most-0.37/t/exclude_test_symbols.t000644 000766 000024 00000001211 12367357520 020304 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; BEGIN { package t::Fake; use Exporter 'import'; our @EXPORT = 'any'; our @EXPORT_OK = 'any'; $INC{'t/Fake.pm'} => 1; # Test::Deep's any() returns a Test::Deep::Any object sub any { 1; } } use Test::Most tests => 5, '!any'; use OurTester qw($DIED dies); t::Fake->import; ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; cmp_deeply [ 3, 4 ], [ 3, 4 ], '... and Test::Deep tests'; ok !ref(any('foo')), "... but any() calls our version, not Test::Deep's"; ok !(grep { $_ eq 'any' } @Test::Most::EXPORT), 'and "any" is not in our @EXPORT'; Test-Most-0.37/t/import_bail.t000644 000766 000024 00000000551 12264471052 016344 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most 'bail', tests => 7; use OurTester qw($BAILED bails); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; bails { is_deeply( [3], [4] ) } '... but failing tests should bail'; ok 4, 'Subsequent calls to ok() should be fine'; ok !$BAILED, '... and not bail'; Test-Most-0.37/t/00-load.t000644 000766 000024 00000001227 12264471052 015200 0ustar00ovidstaff000000 000000 #!perl -T use Test::More tests => 9; BEGIN { local $^W; use_ok('Test::Most') or BAIL_OUT("Cannot load Test::Most"); use_ok('Test::Most::Exception') or BAIL_OUT("Cannot load Test::Most::Exception"); diag("Testing Test::Most $Test::Most::VERSION, Perl $], $^X"); my @dependencies = qw( Exception::Class Test::Deep Test::Differences Test::Exception Test::Harness Test::More Test::Warn ); foreach my $module (@dependencies) { use_ok $module or BAIL_OUT("Cannot load $module"); my $version = $module->VERSION; diag(" $module version is $version"); } } Test-Most-0.37/t/common.t000644 000766 000024 00000000704 12264471052 015333 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most tests => 6; use OurTester qw($DIED dies); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; eq_or_diff [ 3, 4 ], [ 3, 4 ], '... and Test::Differences tests'; dies_ok {die} '... and Test::Exception tests'; cmp_deeply [ 3, 4 ], [ 3, 4 ], '... and Test::Deep tests'; warnings_are { warn 'Hi!' } 'Hi!', '... and Test::Warn tests'; explain +Test::Builder->new; Test-Most-0.37/t/function_bail.t000644 000766 000024 00000000632 12264471052 016657 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most 'no_plan';#tests => 7; use OurTester qw($BAILED bails); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; bail_on_fail; bails { eq_or_diff( [3], [4] ) } '... but failing tests should bail'; ok 4, 'Subsequent calls to ok() should be fine'; ok !$BAILED, '... and not bail'; explain("this is a comment"); Test-Most-0.37/t/lib/000755 000766 000024 00000000000 13642144022 014416 5ustar00ovidstaff000000 000000 Test-Most-0.37/t/function_die.t000644 000766 000024 00000000535 12264471052 016513 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most tests => 7; use OurTester qw($DIED dies); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; die_on_fail; dies { eq_or_diff( [3], [4] ) } '... but failing tests should die'; ok 4, 'Subsequent calls to ok() should be fine'; ok !$DIED, '... and not die'; Test-Most-0.37/t/env_bail.t000644 000766 000024 00000000566 12264471052 015630 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; BEGIN { $ENV{BAIL_ON_FAIL} = 1 } use Test::Most tests => 7; use OurTester qw($BAILED bails); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; bails { eq_or_diff( [3], [4] ) } '... but failing tests should die'; ok 4, 'Subsequent calls to ok() should be fine'; ok !$BAILED, '... and not die'; Test-Most-0.37/t/import_die.t000644 000766 000024 00000000541 12264471052 016175 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most 'die', tests => 7; use OurTester qw($DIED dies); ok 1, 'Normal calls to ok() should succeed'; is 2, 2, '... as should all passing tests'; dies { eq_or_diff( [3], [4] ) } '... but failing tests should die'; ok 4, 'Subsequent calls to ok() should be fine'; ok !$DIED, '... and not die'; Test-Most-0.37/t/exception.t000644 000766 000024 00000001001 12264471052 016030 0ustar00ovidstaff000000 000000 #!/usr/bin/perl use lib 'lib', 't/lib'; use Test::Most tests => 4; use Test::Most::Exception 'throw_failure'; ok defined &throw_failure, '&throw_failure should be exported to our namespace'; throws_ok { throw_failure error => 'some message' } 'Test::Most::Exception', '... and it should throw an exception'; my $error = $@; is $error->message, 'some message', '... and it should have the proper error message'; is $error->description, 'Test failed. Stopping test.', '... and the proper description'; Test-Most-0.37/t/PaxHeader/defer_plan.t000644 000766 000024 00000000036 13642066713 020116 xustar00ovidstaff000000 000000 30 mtime=1585999307.728701886 Test-Most-0.37/t/defer_plan.t000644 000766 000024 00000001446 13642066713 016153 0ustar00ovidstaff000000 000000 #!/usr/bin/perl BEGIN { $ENV{DO_NOT_WARN_ON_DEFER_PLAN} = 1 } use lib 'lib', 't/lib'; use Test::Most qw; ok 1; ok 1; ok 1; all_done(3); __END__ # :( use Test::Command; my $prog = q{ use strict; use warnings; use lib 'lib', 't/lib'; use Test::Most qw; ok(1); die("premature termination"); ok(1); ok(1); all_done(); }; stdout_like(['perl', '-e', $prog], qr/1\.\.2\n\Z/); $prog = q{ use strict; use warnings; use lib 'lib', 't/lib'; use Test::Most qw; ok(1); ok(1); ok(1); all_done(); }; stdout_like(['perl', '-e', $prog], qr/1\.\.3\n\Z/); $prog = q{ use strict; use warnings; use lib 'lib', 't/lib'; use Test::Most qw; ok(1); ok(1); ok(1); all_done(4); }; stdout_like(['perl', '-e', $prog], qr/1\.\.4\n\Z/); all_done(3); Test-Most-0.37/t/lib/DuplicatePlanRegression.pm000644 000766 000024 00000000075 12367357570 021565 0ustar00ovidstaff000000 000000 package DuplicatePlanRegression; use Test::Most; ok 1; 1; Test-Most-0.37/t/lib/OurTester.pm000644 000766 000024 00000003612 12264471052 016717 0ustar00ovidstaff000000 000000 package OurTester; use strict; use warnings; use Carp 'croak'; BEGIN { unless ( $INC{'Test/Most.pm'} ) { croak ("Test::Most must be loaded before ".__PACKAGE__); } } use Exporter; our @ISA = 'Exporter'; our ( $DIED, $BAILED ); our @EXPORT_OK = qw($DIED $BAILED dies bails); use Test::Builder; my $BUILDER = Test::Builder->new; sub _set_die { _set_test_failure_handler( sub { $DIED = 1 } ); } sub _set_bail { _set_test_failure_handler( sub { $BAILED = 1 } ); } # # This is like the normal override for Test::More::ok, but we need to check # the actual value of of the test status, regardless of whether or not it's a # TODO test. # sub _set_test_failure_handler { my $action = shift; my $ok = \&Test::Builder::ok; no warnings 'redefine'; *Test::Builder::ok = sub { local $Test::Builder::Level = $Test::Builder::Level + 1; my $builder = $_[0]; if ( $builder->{TEST_MOST_test_failed} ) { $builder->{TEST_MOST_test_failed} = 0; $action->($builder); } $builder->{TEST_MOST_test_failed} = 0; my $result = $ok->(@_); # Not a fun interface $builder->{TEST_MOST_test_failed} = !( $builder->details )[-1]->{actual_ok}; return $result; }; } sub dies(&;$) { my ( $sub, $message ) = @_; _die_or_bail($sub, \&_set_die, $message, \$DIED); } sub bails(&;$) { my ( $sub, $message ) = @_; _die_or_bail($sub, \&_set_bail, $message, \$BAILED); } sub _die_or_bail { my ($sub, $internal_sub, $message, $die_or_bail) = @_; $internal_sub->(); $BUILDER->todo_start('Planned failure'); # ignore the error messages as they will be confusing. $BUILDER->no_diag(1); $sub->(); $BUILDER->no_diag(0); $BUILDER->todo_end; Test::More::ok 1, 'arguments are evaluated *before* ok()'; Test::More::ok $$die_or_bail, $message; $$die_or_bail = 0; } 1;