summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Test/More.pm
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-03-08 00:16:42 +0000
committerKarl Berry <karl@freefriends.org>2018-03-08 00:16:42 +0000
commit34a8597760ab5740abd49b6d8be10e1876f5ce98 (patch)
tree099a794912a28b3ebbc857961643ba29b28e674a /Master/tlpkg/tlperl/lib/Test/More.pm
parent2ca3610031316a7312d046d3ae4c783452831216 (diff)
(tl)perl 5.26.1 from siep
git-svn-id: svn://tug.org/texlive/trunk@46882 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Test/More.pm')
-rw-r--r--Master/tlpkg/tlperl/lib/Test/More.pm88
1 files changed, 71 insertions, 17 deletions
diff --git a/Master/tlpkg/tlperl/lib/Test/More.pm b/Master/tlpkg/tlperl/lib/Test/More.pm
index 4bab267fcf6..2863c1bba5b 100644
--- a/Master/tlpkg/tlperl/lib/Test/More.pm
+++ b/Master/tlpkg/tlperl/lib/Test/More.pm
@@ -17,10 +17,9 @@ sub _carp {
return warn @_, " at $file line $line\n";
}
-our $VERSION = '1.001014';
-$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
+our $VERSION = '1.302073';
-use Test::Builder::Module 0.99;
+use Test::Builder::Module;
our @ISA = qw(Test::Builder::Module);
our @EXPORT = qw(ok use_ok require_ok
is isnt like unlike is_deeply
@@ -126,6 +125,8 @@ the end.
done_testing( $number_of_tests_run );
+B<NOTE> C<done_testing()> should never be called in an C<END { ... }> block.
+
Sometimes you really don't know how many tests were run, or it's too
difficult to calculate. In which case you can leave off
$number_of_tests_run.
@@ -176,12 +177,22 @@ sub import_extra {
my @other = ();
my $idx = 0;
+ my $import;
while( $idx <= $#{$list} ) {
my $item = $list->[$idx];
if( defined $item and $item eq 'no_diag' ) {
$class->builder->no_diag(1);
}
+ elsif( defined $item and $item eq 'import' ) {
+ if ($import) {
+ push @$import, @{$list->[ ++$idx ]};
+ }
+ else {
+ $import = $list->[ ++$idx ];
+ push @other, $item, $import;
+ }
+ }
else {
push @other, $item;
}
@@ -191,6 +202,18 @@ sub import_extra {
@$list = @other;
+ if ($class eq __PACKAGE__ && (!$import || grep $_ eq '$TODO', @$import)) {
+ my $to = $class->builder->exported_to;
+ no strict 'refs';
+ *{"$to\::TODO"} = \our $TODO;
+ if ($import) {
+ @$import = grep $_ ne '$TODO', @$import;
+ }
+ else {
+ push @$list, import => [grep $_ ne '$TODO', @EXPORT];
+ }
+ }
+
return;
}
@@ -211,6 +234,10 @@ conclusion.
This is safer than and replaces the "no_plan" plan.
+B<Note:> You must never put C<done_testing()> inside an C<END { ... }> block.
+The plan is there to ensure your test does not exit before testing has
+completed. If you use an END block you completely bypass this protection.
+
=back
=cut
@@ -703,7 +730,7 @@ sub new_ok {
=item B<subtest>
- subtest $name => \&code;
+ subtest $name => \&code, @args;
C<subtest()> runs the &code as its own little test with its own plan and
its own result. The main test counts this as a single test using the
@@ -762,11 +789,20 @@ subtests are equivalent:
done_testing();
};
+Extra arguments given to C<subtest> are passed to the callback. For example:
+
+ sub my_subtest {
+ my $range = shift;
+ ...
+ }
+
+ for my $range (1, 10, 100, 1000) {
+ subtest "testing range $range", \&my_subtest, $range;
+ }
+
=cut
sub subtest {
- my ($name, $subtests) = @_;
-
my $tb = Test::More->builder;
return $tb->subtest(@_);
}
@@ -940,7 +976,10 @@ sub use_ok ($;@) {
@imports = () unless @imports;
my $tb = Test::More->builder;
- my( $pack, $filename, $line ) = caller;
+ my %caller;
+ @caller{qw/pack file line sub args want eval req strict warn/} = caller(0);
+
+ my ($pack, $filename, $line, $warn) = @caller{qw/pack file line warn/};
$filename =~ y/\n\r/_/; # so it doesn't run off the "#line $line $f" line
my $code;
@@ -949,7 +988,7 @@ sub use_ok ($;@) {
# for it to work with non-Exporter based modules.
$code = <<USE;
package $pack;
-
+BEGIN { \${^WARNING_BITS} = \$args[-1] if defined \$args[-1] }
#line $line $filename
use $module $imports[0];
1;
@@ -958,14 +997,14 @@ USE
else {
$code = <<USE;
package $pack;
-
+BEGIN { \${^WARNING_BITS} = \$args[-1] if defined \$args[-1] }
#line $line $filename
use $module \@{\$args[0]};
1;
USE
}
- my( $eval_result, $eval_error ) = _eval( $code, \@imports );
+ my ($eval_result, $eval_error) = _eval($code, \@imports, $warn);
my $ok = $tb->ok( $eval_result, "use $module;" );
unless($ok) {
@@ -1034,6 +1073,20 @@ improve in the future.
L<Test::Differences> and L<Test::Deep> provide more in-depth functionality
along these lines.
+B<NOTE> is_deeply() has limitations when it comes to comparing strings and
+refs:
+
+ my $path = path('.');
+ my $hash = {};
+ is_deeply( $path, "$path" ); # ok
+ is_deeply( $hash, "$hash" ); # fail
+
+This happens because is_deeply will unoverload all arguments unconditionally.
+It is probably best not to use is_deeply with overloading. For legacy reasons
+this is not likely to ever be fixed. If you would like a much better tool for
+this you should see L<Test2::Suite> Specifically L<Test2::Tools::Compare> has
+an C<is()> function that works like C<is_deeply> with many improvements.
+
=cut
our( @Data_Stack, %Refs_Seen );
@@ -1134,7 +1187,7 @@ sub _type {
return '' if !ref $thing;
- for my $type (qw(Regexp ARRAY HASH REF SCALAR GLOB CODE)) {
+ for my $type (qw(Regexp ARRAY HASH REF SCALAR GLOB CODE VSTRING)) {
return $type if UNIVERSAL::isa( $thing, $type );
}
@@ -1293,10 +1346,13 @@ sub skip {
my( $why, $how_many ) = @_;
my $tb = Test::More->builder;
- unless( defined $how_many ) {
- # $how_many can only be avoided when no_plan is in use.
+ # If the plan is set, and is static, then skip needs a count. If the plan
+ # is 'no_plan' we are fine. As well if plan is undefined then we are
+ # waiting for done_testing.
+ unless (defined $how_many) {
+ my $plan = $tb->has_plan;
_carp "skip() needs to know \$how_many tests are in the block"
- unless $tb->has_plan eq 'no_plan';
+ if $plan && $plan =~ m/^\d+$/;
$how_many = 1;
}
@@ -1903,8 +1959,6 @@ comes from.
=head2 BUNDLES
-L<Bundle::Test> installs a whole bunch of useful test modules.
-
L<Test::Most> Most commonly needed test functions and features.
=head1 AUTHORS
@@ -1925,7 +1979,7 @@ the perl-qa gang.
=head1 BUGS
-See F<http://rt.cpan.org> to report and view bugs.
+See F<https://github.com/Test-More/test-more/issues> to report and view bugs.
=head1 SOURCE