Test-Lite

 view release on metacpan or  search on metacpan

lib/Test/Lite.pm  view on Meta::CPAN

package Test::Lite;

$Test::Lite::VERSION = '0.009';
$Test::Lite::DieOnSyntaxError = 0;

=head1 NAME

Test::Lite - A small Perl Test Library

=head1 DESCRIPTION

Test::Lite is just that. A minimal test library based on the brilliant L<Test::Builder>. The main focus of this project 
was to learn more about testing while building this module. A pretty overlooked subject amongst some Perl developers is testing (myself included). 
I've tried to offer some different features in this module, but you're probably still better off with L<Test::More>, L<Test::Most> or one of the many other 
testing libraries out there.

=head1 SYNOPSIS

Using Test::Lite is pretty similar to other test modules (Why break tradition, eh?)

    use Test::Lite;

    my $a = { name => 'World' };
    my $b = { name => 'Worlds' };
    
    diff ($a, $b, "Difference between hash 'a' and hash 'b'");

    my @non_ref qw(not a ref);
    my $true_ref = [1, 2, 3];
    is_ref(@non_ref, 'Name of test');
    is_ref($true_ref => 'HASH', 'Name of test'); # Checks to see if $true_ref returns a HASH

    use_ok [qw( A::Module Another::Module )];

=cut

use strict;
use warnings;

use 5.010;
use Scalar::Util 'looks_like_number';
use Sub::Mage ':Class';
extends 'Test::Builder::Module';

my $CLASS = __PACKAGE__;

sub import {
    my ($class, @args) = @_;
    my $pkg = caller(1);
    for (@args) {
        if ($_ eq ':strict') {
            warnings->import;
            strict->import;
        }
    }
    $CLASS->_export_defs(qw/
        is
        ok
        has_key
        cmp_ok
        diff
        diag
        plan 
        use_ok
        can_ok
        isa_ok
        is_ref
        like
        explain
        extended
        methods
        subtest
        todo_start
        todo_end
        is_passing
        count
        note
        level
        finfo
        done_testing
    /);
}

sub _export_defs {
    my ($self, @defs) = @_;
    my $pkg = caller(1);
    for (@defs) {
        exports $_ => ( into => $pkg );
    }
}

sub dieonsyntax { return $Test::Lite::DieOnSyntaxError; }

sub ok {
    my ($val, $name) = @_;
    my $tb = $CLASS->builder;
    $tb->ok(@_);
}

sub cmp_ok {
    my ($a, $type, $b, $name) = @_;
    my $tb = $CLASS->builder;
    $tb->cmp_ok(@_);
}

sub is {
    my ($a, $b, $args, $name) = @_;
    my $tb = $CLASS->builder;
    if (scalar keys %$args < 1) {
        if (looks_like_number($b)) { $tb->is_num($a, $b, $name); }
        else { $tb->is_eq($a, $b, $name); }
    }
    else {



( run in 1.454 second using v1.01-cache-2.11-cpan-fe3c2283af0 )