Skip to content

Commit

Permalink
Adding can_ok(). Bringing VERSION in sync with Test::Simple
Browse files Browse the repository at this point in the history
  • Loading branch information
schwern committed Aug 29, 2001
1 parent db87196 commit 1c41c86
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
38 changes: 37 additions & 1 deletion lib/Test/More.pm
Expand Up @@ -14,7 +14,7 @@ BEGIN {

require Exporter;
use vars qw($VERSION @ISA @EXPORT);
$VERSION = '0.13';
$VERSION = '0.16';
@ISA = qw(Exporter);
@EXPORT = qw(ok use_ok require_ok
is isnt like
Expand All @@ -24,6 +24,7 @@ $VERSION = '0.13';
skip
$TODO
plan
can_ok
);


Expand Down Expand Up @@ -98,6 +99,8 @@ Test::More - yet another framework for writing test scripts
is( foo(42), 23, $test_name );
};
can_ok($module, @methods);
pass($test_name);
fail($test_name);
Expand Down Expand Up @@ -398,6 +401,39 @@ DIAGNOSTIC
return $ok;
}

=item B<can_ok>
can_ok($module, @methods);
Checks to make sure the $module can do these @methods.
can_ok('Foo', qw(this that whatever));
is almost exactly like saying:
ok( Foo->can('this') );
ok( Foo->can('that') );
ok( Foo->can('whatever') );
only without all the typing. Handy for quickly enforcing an
interface.
Each method counts as a seperate test.
=cut

sub can_ok {
my($module, @methods) = @_;

my $all_ok = 1;
foreach my $method (@methods) {
my $test = "$module->can('$method')";
ok( eval $test, $test ) or $all_ok = 0;
}

return $all_ok;
}

=item B<pass>
=item B<fail>
Expand Down
5 changes: 4 additions & 1 deletion t/More.t
@@ -1,4 +1,4 @@
use Test::More tests => 18;
use Test::More tests => 31;

use_ok('Text::Soundex');
require_ok('Test::More');
Expand All @@ -13,6 +13,9 @@ isn't("foo", "bar", 'foo isn\'t bar');
like("fooble", '/^foo/', 'foo is like fooble');
like("FooBle", '/foo/i', 'foo is like FooBle');

can_ok('Test::More', qw(require_ok use_ok ok is isnt like skip can_ok
pass fail eq_array eq_hash eq_set));

pass('pass() passed');

ok( eq_array([qw(this that whatever)], [qw(this that whatever)]),
Expand Down
20 changes: 13 additions & 7 deletions t/fail-more.t
Expand Up @@ -29,7 +29,7 @@ push @INC, 't', '.';
require Catch::More;
my($out, $err) = Catch::More::caught();

Test::More->import(tests => 8);
Test::More->import(tests => 10);

# Preserve the line numbers.
#line 31
Expand All @@ -42,20 +42,24 @@ like( "foo", '/that/', 'is foo like that' );

fail('fail()');

can_ok('Mooble::Hooble::Yooble', qw(this that));

use_ok('Hooble::mooble::yooble');
require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');

END {
My::Test::ok($$out eq <<OUT, 'failing output');
1..8
1..10
not ok 1 - failing
not ok 2 - foo is bar?
not ok 3 - foo isnt foo?
not ok 4 - foo isn't foo?
not ok 5 - is foo like that
not ok 6 - fail()
not ok 7 - use Hooble::mooble::yooble;
not ok 8 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
not ok 7 - Mooble::Hooble::Yooble->can('this')
not ok 8 - Mooble::Hooble::Yooble->can('that')
not ok 9 - use Hooble::mooble::yooble;
not ok 10 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
OUT

my $err_re = <<ERR;
Expand All @@ -73,19 +77,21 @@ OUT
# 'foo'
# doesn't match '/that/'
# Failed test ($0 at line 38)
# Failed test ($0 at line 40)
# Failed test ($0 at line 40)
ERR

my $filename = quotemeta $0;
my $more_err_re = <<ERR;
# Failed test \\($filename at line 40\\)
# Failed test \\($filename at line 42\\)
# Tried to use 'Hooble::mooble::yooble'.
# Error: Can't locate Hooble.* in \\\@INC .*
# Failed test \\($filename at line 41\\)
# Failed test \\($filename at line 43\\)
# Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
# Error: Can't locate ALL.* in \\\@INC .*
# Looks like you failed 8 tests of 8.
# Looks like you failed 10 tests of 10.
ERR

unless( My::Test::ok($$err =~ /^\Q$err_re\E$more_err_re$/,
Expand Down

0 comments on commit 1c41c86

Please sign in to comment.