Skip to content

Commit

Permalink
r3633@windhund: schwern | 2005-09-23 22:40:11 -0700
Browse files Browse the repository at this point in the history
 Make Test::Simple and Test::More eat their own dog food.
 
 Set versions to alpha versions.
  • Loading branch information
schwern committed Sep 26, 2005
1 parent 9a7f268 commit 60d8e99
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 42 deletions.
8 changes: 6 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
0.61
0.60_02 Tue Aug 9 00:27:41 PDT 2005
* Added Test::Builder::Module.
- Changed Test::More and Test::Simple to use Test::Builder::Module
- Minor Win32 testing nit in fail-more.t
- Added no_diag() method to Test::Builder and changed Test::More's
- create.t was trying to read from a file before it had been closed
(and thus the changes may not have yet been written).
* Added no_diag() method to Test::Builder and changed Test::More's
no_diag internals to use that. [rt.cpan.org 8655]
* Deprecated no_diag() as an option to "use Test::More". Call the
Test::Builder method instead.
Expand Down
2 changes: 1 addition & 1 deletion lib/Test/Builder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $^C ||= 0;

use strict;
use vars qw($VERSION);
$VERSION = '0.30_01';
$VERSION = '0.30_02';
$VERSION = eval $VERSION; # make the alpha version come out as a number

# Make Test::Builder thread-safe for ithreads.
Expand Down
2 changes: 2 additions & 0 deletions lib/Test/Builder/Module.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use Test::Builder;
require Exporter;
@ISA = qw(Exporter);

$VERSION = '0.01_01';

use strict;

# 5.004's Exporter doesn't have export_to_level.
Expand Down
103 changes: 65 additions & 38 deletions lib/Test/More.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sub _carp {


use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS $TODO);
$VERSION = '0.60_01';
$VERSION = '0.60_02';
$VERSION = eval $VERSION; # make the alpha version come out as a number

use Test::Builder::Module;
Expand All @@ -34,8 +34,6 @@ use Test::Builder::Module;
BAIL_OUT
);

my $Test = Test::More->builder;


=head1 NAME
Expand Down Expand Up @@ -159,7 +157,9 @@ or for deciding between running the tests at all:
=cut

sub plan {
$Test->plan(@_);
my $tb = Test::More->builder;

$tb->plan(@_);
}


Expand Down Expand Up @@ -258,7 +258,9 @@ This is actually Test::Simple's ok() routine.

sub ok ($;$) {
my($test, $name) = @_;
$Test->ok($test, $name);
my $tb = Test::More->builder;

$tb->ok($test, $name);
}

=item B<is>
Expand Down Expand Up @@ -322,11 +324,15 @@ function which is an alias of isnt().
=cut

sub is ($$;$) {
$Test->is_eq(@_);
my $tb = Test::More->builder;

$tb->is_eq(@_);
}

sub isnt ($$;$) {
$Test->isnt_eq(@_);
my $tb = Test::More->builder;

$tb->isnt_eq(@_);
}

*isn't = \&isnt;
Expand Down Expand Up @@ -363,7 +369,9 @@ diagnostics on failure.
=cut
sub like ($$;$) {
$Test->like(@_);
my $tb = Test::More->builder;
$tb->like(@_);
}
Expand All @@ -377,7 +385,9 @@ given pattern.
=cut
sub unlike ($$;$) {
$Test->unlike(@_);
my $tb = Test::More->builder;
$tb->unlike(@_);
}
Expand Down Expand Up @@ -415,7 +425,9 @@ is()'s use of C<eq> will interfere:
=cut

sub cmp_ok($$$;$) {
$Test->cmp_ok(@_);
my $tb = Test::More->builder;

$tb->cmp_ok(@_);
}


Expand Down Expand Up @@ -451,10 +463,11 @@ as one test. If you desire otherwise, use:
sub can_ok ($@) {
my($proto, @methods) = @_;
my $class = ref $proto || $proto;
my $tb = Test::More->builder;

unless( @methods ) {
my $ok = $Test->ok( 0, "$class->can(...)" );
$Test->diag(' can_ok() called with no methods');
my $ok = $tb->ok( 0, "$class->can(...)" );
$tb->diag(' can_ok() called with no methods');
return $ok;
}

Expand All @@ -469,9 +482,9 @@ sub can_ok ($@) {
$name = @methods == 1 ? "$class->can('$methods[0]')"
: "$class->can(...)";

my $ok = $Test->ok( !@nok, $name );
my $ok = $tb->ok( !@nok, $name );

$Test->diag(map " $class->can('$_') failed\n", @nok);
$tb->diag(map " $class->can('$_') failed\n", @nok);

return $ok;
}
Expand Down Expand Up @@ -507,6 +520,7 @@ you'd like them to be more specific, you can supply an $object_name

sub isa_ok ($$;$) {
my($object, $class, $obj_name) = @_;
my $tb = Test::More->builder;

my $diag;
$obj_name = 'The object' unless defined $obj_name;
Expand Down Expand Up @@ -546,11 +560,11 @@ WHOA

my $ok;
if( $diag ) {
$ok = $Test->ok( 0, $name );
$Test->diag(" $diag\n");
$ok = $tb->ok( 0, $name );
$tb->diag(" $diag\n");
}
else {
$ok = $Test->ok( 1, $name );
$ok = $tb->ok( 1, $name );
}

return $ok;
Expand All @@ -575,11 +589,13 @@ Use these very, very, very sparingly.
=cut

sub pass (;$) {
$Test->ok(1, @_);
my $tb = Test::More->builder;
$tb->ok(1, @_);
}

sub fail (;$) {
$Test->ok(0, @_);
my $tb = Test::More->builder;
$tb->ok(0, @_);
}

=back
Expand Down Expand Up @@ -636,6 +652,7 @@ because the notion of "compile-time" is relative. Instead, you want:
sub use_ok ($;@) {
my($module, @imports) = @_;
@imports = () unless @imports;
my $tb = Test::More->builder;

my($pack,$filename,$line) = caller;

Expand All @@ -656,13 +673,13 @@ use $module \@imports;
USE
}

my $ok = $Test->ok( !$@, "use $module;" );
my $ok = $tb->ok( !$@, "use $module;" );

unless( $ok ) {
chomp $@;
$@ =~ s{^BEGIN failed--compilation aborted at .*$}
{BEGIN failed--compilation aborted at $filename line $line.}m;
$Test->diag(<<DIAGNOSTIC);
$tb->diag(<<DIAGNOSTIC);
Tried to use '$module'.
Error: $@
DIAGNOSTIC
Expand All @@ -683,6 +700,7 @@ Like use_ok(), except it requires the $module or $file.

sub require_ok ($) {
my($module) = shift;
my $tb = Test::More->builder;

my $pack = caller;

Expand All @@ -696,11 +714,11 @@ package $pack;
require $module;
REQUIRE

my $ok = $Test->ok( !$@, "require $module;" );
my $ok = $tb->ok( !$@, "require $module;" );

unless( $ok ) {
chomp $@;
$Test->diag(<<DIAGNOSTIC);
$tb->diag(<<DIAGNOSTIC);
Tried to require '$module'.
Error: $@
DIAGNOSTIC
Expand Down Expand Up @@ -755,6 +773,8 @@ along these lines.
use vars qw(@Data_Stack %Refs_Seen);
my $DNE = bless [], 'Does::Not::Exist';
sub is_deeply {
my $tb = Test::More->builder;

unless( @_ == 2 or @_ == 3 ) {
my $msg = <<WARNING;
is_deeply() takes two or three args, you gave %d.
Expand All @@ -765,29 +785,29 @@ WARNING

_carp sprintf $msg, scalar @_;

return $Test->ok(0);
return $tb->ok(0);
}

my($this, $that, $name) = @_;

$Test->_unoverload_str(\$that, \$this);
$tb->_unoverload_str(\$that, \$this);

my $ok;
if( !ref $this and !ref $that ) { # neither is a reference
$ok = $Test->is_eq($this, $that, $name);
$ok = $tb->is_eq($this, $that, $name);
}
elsif( !ref $this xor !ref $that ) { # one's a reference, one isn't
$ok = $Test->ok(0, $name);
$Test->diag( _format_stack({ vals => [ $this, $that ] }) );
$ok = $tb->ok(0, $name);
$tb->diag( _format_stack({ vals => [ $this, $that ] }) );
}
else { # both references
local @Data_Stack = ();
if( _deep_check($this, $that) ) {
$ok = $Test->ok(1, $name);
$ok = $tb->ok(1, $name);
}
else {
$ok = $Test->ok(0, $name);
$Test->diag(_format_stack(@Data_Stack));
$ok = $tb->ok(0, $name);
$tb->diag(_format_stack(@Data_Stack));
}
}

Expand Down Expand Up @@ -891,7 +911,9 @@ interfere with the test.
=cut

sub diag {
$Test->diag(@_);
my $tb = Test::More->builder;

$tb->diag(@_);
}


Expand Down Expand Up @@ -960,16 +982,17 @@ use TODO. Read on.
#'#
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.
_carp "skip() needs to know \$how_many tests are in the block"
unless $Test->has_plan eq 'no_plan';
unless $tb->has_plan eq 'no_plan';
$how_many = 1;
}

for( 1..$how_many ) {
$Test->skip($why);
$tb->skip($why);
}

local $^W = 0;
Expand Down Expand Up @@ -1040,16 +1063,17 @@ interpret them as passing.

sub todo_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.
_carp "todo_skip() needs to know \$how_many tests are in the block"
unless $Test->has_plan eq 'no_plan';
unless $tb->has_plan eq 'no_plan';
$how_many = 1;
}

for( 1..$how_many ) {
$Test->todo_skip($why);
$tb->todo_skip($why);
}

local $^W = 0;
Expand Down Expand Up @@ -1092,8 +1116,9 @@ The test will exit with 255.

sub BAIL_OUT {
my $reason = shift;
my $tb = Test::More->builder;

$Test->BAIL_OUT($reason);
$tb->BAIL_OUT($reason);
}

=back
Expand Down Expand Up @@ -1162,6 +1187,8 @@ sub _eq_array {

sub _deep_check {
my($e1, $e2) = @_;
my $tb = Test::More->builder;

my $ok = 0;

# Effectively turn %Refs_Seen into a stack. This avoids picking up
Expand All @@ -1173,7 +1200,7 @@ sub _deep_check {
# Quiet uninitialized value warnings when comparing undefs.
local $^W = 0;

$Test->_unoverload_str(\$e1, \$e2);
$tb->_unoverload_str(\$e1, \$e2);

# Either they're both references or both not.
my $same_ref = !(!ref $e1 xor !ref $e2);
Expand Down
2 changes: 1 addition & 1 deletion lib/Test/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use 5.004;

use strict 'vars';
use vars qw($VERSION @ISA @EXPORT);
$VERSION = '0.60_01';
$VERSION = '0.60_02';
$VERSION = eval $VERSION; # make the alpha version come out as a number

use Test::Builder::Module;
Expand Down

0 comments on commit 60d8e99

Please sign in to comment.