Permalink
Browse files

add tests

  • Loading branch information...
tsucchi committed Dec 29, 2010
1 parent b461923 commit 8bee2676ee870275d77a1151b570a5d2c9e0a187
Showing with 169 additions and 20 deletions.
  1. +6 −3 Changes
  2. +4 −0 MANIFEST
  3. +1 −0 Makefile.PL
  4. +35 −17 lib/Test/Module/Used.pm
  5. +31 −0 t/014_requires_ok_fail.t
  6. +28 −0 t/015_used_ok_fail.t
  7. +34 −0 t/016_ok_fail1.t
  8. +30 −0 t/017_ok_fail2.t
View
@@ -1,3 +1,6 @@
+0.2.1_04
+ - add tests
+ - refactorings
0.2.1_03
- implement used_ok() and requires_ok()
@@ -14,14 +17,14 @@
- fix: modules used in test_lib_dir are ignored.(RT#54187)
- ChangeLog format change(Because ShipIt doesn't support previous format)
-0.1.8
+0.1.8
- remove executable permission in Makefile.PL
0.1.7
- add repository in Makefile.PL
(merge from git://github.com/cpanservice/Test-Module-Used.git)
-
+
0.1.6
- fix: add copyright information(for RT#53290)
@@ -73,7 +76,7 @@
0.0.4
- found bug in ok(module_requires exclude)
add build_requires and requires exclusion in constructor
-
+
0.0.3
- add ChangeLog and README
- describe about perl_version
View
@@ -27,6 +27,10 @@ t/010_test_myself2.t
t/011_read_meta_json.t
t/012_used_ok.t
t/013_requires_ok.t
+t/014_requires_ok_fail.t
+t/015_used_ok_fail.t
+t/016_ok_fail1.t
+t/017_ok_fail2.t
testdata/lib/SampleModule.pm
testdata/lib2/My/Test.pm
testdata/META.json
View
@@ -10,6 +10,7 @@ requires 'Module::CoreList';
requires 'PPI::Document';
requires 'version' => 0.77;
test_requires 'Test::More';
+test_requires 'Test::Builder::Tester';
author_tests 'xt';
View
@@ -13,7 +13,7 @@ use version;
use CPAN::Meta;
use Carp;
use 5.008;
-our $VERSION = '0.2.1_03';
+our $VERSION = '0.2.1_04';
=head1 NAME
@@ -82,7 +82,7 @@ all parameters are as follows.(specified values are default, except I<exclude_in
exclude_in_requires => [], # ignored module(s) even if it is written in requires of META.yml.
);
-if perl_version is not passed in constructor, this modules reads I<meta_file> and get perl version.
+if perl_version is not passed in constructor, this modules reads I<meta_file> and get perl version.
I<exclude_in_testdir> is automatically set by default. This module reads I<lib_dir> and parse "pacakge" statement, then found "package" statements and myself(Test::Module::Used) is set.
I<exclude_in_libdir> is also automatically set by default. This module reads I<lib_dir> and parse "package" statement, found "package" statement are set.(Test::Module::Used isnt included)
@@ -198,29 +198,47 @@ sub requires_ok {
sub _ok {
my $self = shift;
my ($num_tests_subref, @ok_subrefs) = @_;
- my $test = Test::Builder->new();
croak('Already tested. Calling ok(), used_ok() and requires_ok() in same test file is not allowed') if ( !!$self->{tested} );
my $num_tests = $num_tests_subref->($self);
- my $test_status;
- if ( $num_tests > 0 ) {
- $test->plan(tests => $num_tests);
- my @status;
- for my $ok_subref ( @ok_subrefs ) {
- push(@status, $ok_subref->($self, $test));
- }
- $test_status = all { $_ } @status;
- }
- else {
- $test->plan(tests => 1);
- $test->ok(1, "no tests run");
- $test_status = 1;
- }
+ return $self->_do_test($num_tests, @ok_subrefs);
+}
+
+sub _do_test {
+ my $self = shift;
+ my ($num_tests, @ok_subrefs) = @_;
+
+ my $test = Test::Builder->new();
+ my $test_status = $num_tests > 0 ? $self->_do_test_normal($num_tests, @ok_subrefs) :
+ $self->_do_test_no_tests();
$self->{tested} = 1;
return !!$test_status;
}
+sub _do_test_normal {
+ my $self = shift;
+ my ($num_tests, @ok_subrefs) = @_;
+
+ my $test = Test::Builder->new();
+ $test->plan(tests => $num_tests);
+ my @status;
+ for my $ok_subref ( @ok_subrefs ) {
+ push(@status, $ok_subref->($self, $test));
+ }
+ my $test_status = all { $_ } @status;
+ return !!$test_status;
+}
+
+sub _do_test_no_tests {
+ my $self = shift;
+
+ my $test = Test::Builder->new();
+ $test->plan(tests => 1);
+ $test->ok(1, "no tests run");
+ return 1;
+}
+
sub _used_ok {
my $self = shift;
my ($test) = @_;
View
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+
+use Test::Builder::Tester;
+use Test::Module::Used;
+use File::Spec::Functions qw(catdir catfile);
+use Test::Builder;
+use Test::More;
+my $used = Test::Module::Used->new(
+ test_dir => [catdir('testdata', 't')],
+ lib_dir => [catdir('testdata', 'lib')],
+ meta_file => catfile('testdata', 'META.yml4'),
+);
+
+
+test_out("1..4");
+test_out("ok 1 - check required module: Module::Used");
+test_out("not ok 2 - check required module: Plack");
+test_out("ok 3 - check required module: Test::Module::Used");
+test_out("ok 4 - check required module: Test::Class");
+$used->requires_ok();
+
+
+my $builder = Test::Builder->new();
+$builder->reset;# reset because plan is automatically set in Test::Module::Used.
+plan tests=>1;
+test_test(skip_err=>1);
+
+
View
@@ -0,0 +1,28 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+use Test::Module::Used;
+use File::Spec::Functions qw(catdir catfile);
+use Test::Builder::Tester;
+use Test::Builder;
+use Test::More;
+
+my $used = Test::Module::Used->new(
+ test_dir => [catdir('testdata', 't')],
+ lib_dir => [catdir('testdata', 'lib')],
+ meta_file => catfile('testdata', 'META.yml5'),
+);
+
+
+test_out("1..3");
+test_out("not ok 1 - check used module: Module::Used");
+test_out("ok 2 - check used module: Test::Module::Used");
+test_out("ok 3 - check used module: Test::Class");
+$used->used_ok();
+
+my $builder = Test::Builder->new();
+$builder->reset;# reset because plan is automatically set in Test::Module::Used.
+plan tests=>1;
+test_test(skip_err=>1);
+
View
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+
+use Test::Builder::Tester;
+use Test::Module::Used;
+use File::Spec::Functions qw(catdir catfile);
+use Test::Builder;
+use Test::More;
+my $used = Test::Module::Used->new(
+ test_dir => [catdir('testdata', 't')],
+ lib_dir => [catdir('testdata', 'lib')],
+ meta_file => catfile('testdata', 'META.yml4'),
+);
+
+
+test_out("1..7");
+test_out("ok 1 - check used module: Module::Used");
+test_out("ok 2 - check used module: Test::Module::Used");
+test_out("ok 3 - check used module: Test::Class");
+test_out("ok 4 - check required module: Module::Used");
+test_out("not ok 5 - check required module: Plack");
+test_out("ok 6 - check required module: Test::Module::Used");
+test_out("ok 7 - check required module: Test::Class");
+$used->ok();
+
+
+my $builder = Test::Builder->new();
+$builder->reset;# reset because plan is automatically set in Test::Module::Used.
+plan tests=>1;
+test_test(skip_err=>1);
+
+
View
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+use Test::Module::Used;
+use File::Spec::Functions qw(catdir catfile);
+use Test::Builder::Tester;
+use Test::Builder;
+use Test::More;
+
+my $used = Test::Module::Used->new(
+ test_dir => [catdir('testdata', 't')],
+ lib_dir => [catdir('testdata', 'lib')],
+ meta_file => catfile('testdata', 'META.yml5'),
+);
+
+
+test_out("1..5");
+test_out("not ok 1 - check used module: Module::Used");
+test_out("ok 2 - check used module: Test::Module::Used");
+test_out("ok 3 - check used module: Test::Class");
+test_out("ok 4 - check required module: Test::Module::Used");
+test_out("ok 5 - check required module: Test::Class");
+$used->ok();
+
+my $builder = Test::Builder->new();
+$builder->reset;# reset because plan is automatically set in Test::Module::Used.
+plan tests=>1;
+test_test(skip_err=>1);
+

0 comments on commit 8bee267

Please sign in to comment.