Test-Unit-Lite
view release on metacpan or search on metacpan
lib/Test/Unit/Lite.pm view on Meta::CPAN
$self->assert_not_null($obj);
$self->assert_equals('expected result', $obj->foo);
$self->assert(qr/pattern/, $obj->foobar);
}
sub test_bar {
# test the bar feature
}
=head1 DESCRIPTION
This framework provides lighter version of L<Test::Unit> framework. It
implements some of the L<Test::Unit> classes and methods needed to run test
units. The L<Test::Unit::Lite> tries to be compatible with public API of
L<Test::Unit>. It doesn't implement all classes and methods at 100% and only
those necessary to run tests are available.
The L<Test::Unit::Lite> can be distributed as a part of package distribution,
so the package can be distributed without dependency on modules outside
standard Perl distribution. The L<Test::Unit::Lite> is provided as a single
file.
=head2 Bundling the L<Test::Unit::Lite> as a part of package distribution
The L<Test::Unit::Lite> framework can be bundled to the package distribution.
Then the L<Test::Unit::Lite> module is copied to the F<inc> directory of the
source directory for the package distribution.
=cut
use 5.006;
use strict;
use warnings;
our $VERSION = '0.1202';
use Carp ();
use File::Spec ();
use File::Basename ();
use File::Copy ();
use File::Path ();
use Symbol ();
# Can't use Exporter 'import'. Compatibility with Perl 5.6
use Exporter ();
BEGIN { *import = \&Exporter::import };
our @EXPORT = qw{ bundle all_tests };
# Copy this module to inc subdirectory of the source distribution
sub bundle {
-f 'Makefile.PL' or -f 'Build.PL'
or die "Cannot find Makefile.PL or Build.PL in current directory\n";
my $src = __FILE__;
my $dst = "inc/Test/Unit/Lite.pm";
my @src = split m{/}, $src;
my @dst = split m{/}, $dst;
my $srcfile = File::Spec->catfile(@src);
my $dstfile = File::Spec->catfile(@dst);
die "Cannot bundle to itself: $srcfile\n" if $srcfile eq $dstfile;
print "Copying $srcfile -> $dstfile\n";
my $dstdir = File::Basename::dirname($dstfile);
-d $dstdir or File::Path::mkpath([$dstdir], 0, oct(777) & ~umask);
File::Copy::cp($srcfile, $dstfile) or die "Cannot copy $srcfile to $dstfile: $!\n";
}
sub all_tests {
Test::Unit::TestRunner->new->start('Test::Unit::Lite::AllTests');
}
{
package Test::Unit::TestCase;
use Carp ();
our $VERSION = $Test::Unit::Lite::VERSION;
our %Seen_Refs = ();
our @Data_Stack;
my $DNE = bless [], 'Does::Not::Exist';
sub new {
my ($class) = @_;
$class = ref $class if ref $class;
my $self = {};
return bless $self => $class;
}
sub set_up { }
sub tear_down { }
sub list_tests {
my ($self) = @_;
my $class = ref $self || $self;
my @tests;
my %seen_isa;
my $list_base_tests;
$list_base_tests = sub {
my ($class) = @_;
foreach my $isa (@{ *{ Symbol::qualify_to_ref("${class}::ISA") } }) {
next unless $isa->isa(__PACKAGE__);
$list_base_tests->($isa) unless $seen_isa{$isa};
$seen_isa{$isa} = 1;
push @tests, grep { /^test_/ } keys %{ *{ Symbol::qualify_to_ref("${class}::") } };
};
};
$list_base_tests->($class);
my %uniq_tests = map { $_ => 1 } @tests;
@tests = sort keys %uniq_tests;
( run in 1.872 second using v1.01-cache-2.11-cpan-71847e10f99 )