From: Vincent Pit Date: Sat, 25 Dec 2010 18:28:36 +0000 (+0100) Subject: Add author tests and minimal documentation X-Git-Tag: v0.01~17 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Leaner.git;a=commitdiff_plain;h=982694f9f93cdad187a51077b5e6c48a17792870 Add author tests and minimal documentation --- diff --git a/MANIFEST b/MANIFEST index d0c4d96..c5fd1f3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,3 +19,7 @@ t/80-threads.t t/20-ok.t t/21-is.t t/22-cmp_ok.t +t/91-pod.t +t/92-pod-coverage.t +t/95-portability-files.t +t/99-kwalitee.t diff --git a/lib/Test/Leaner.pm b/lib/Test/Leaner.pm index 1efe7a2..6ae6e2b 100644 --- a/lib/Test/Leaner.pm +++ b/lib/Test/Leaner.pm @@ -4,8 +4,35 @@ use 5.006; use strict; use warnings; +=head1 NAME + +Test::Leaner - A slimmer Test::More for when you favor performance over completeness. + +=head1 VERSION + +Version 0.01 + +=cut + our $VERSION = '0.01'; +=head1 SYNOPSIS + + use Test::Leaner tests => 10_000; + for (1 .. 10_000) { + ... + is $one, 1, "checking situation $_"; + } + + +=head1 DESCRIPTION + +When profiling some L-based test script that contained about 10 000 unit tests, I realized that 60% of the time was spent in L itself, even though every single test actually involved a costly C. + +This module aims to be a partial replacement to L in those situations where you want to run a large number of simple tests. + +=cut + use Exporter (); BEGIN { @@ -69,6 +96,14 @@ sub sanitize_comment { $_[0] =~ s/\n/\n# /g; } +=head1 FUNCTIONS + +The following functions from L are implemented and exported by default. + +=head2 C<< plan [ tests => $count | 'no_plan' | skip_all => $reason ] >> + +=cut + sub plan { my ($key, $value) = @_; @@ -164,11 +199,19 @@ sub import { goto &Exporter::import; } +=head2 C + +=cut + sub skip_all { @_ = (skip_all => $_[0]); goto &plan; } +=head2 C<< skip $reason => $count >> + +=cut + sub skip { my ($reason, $count) = @_; @@ -200,6 +243,10 @@ sub skip { last SKIP; } +=head2 C + +=cut + sub done_testing { my ($count) = @_; @@ -227,6 +274,10 @@ sub done_testing { return 1; } +=head2 C + +=cut + sub ok ($;$) { my ($ok, $desc) = @_; @@ -250,16 +301,28 @@ sub ok ($;$) { return $ok; } +=head2 C + +=cut + sub pass (;$) { unshift @_, 1; goto &ok; } +=head2 C + +=cut + sub fail (;$) { unshift @_, 0; goto &ok; } +=head2 C + +=cut + sub is ($$;$) { my ($got, $expected, $desc) = @_; no warnings 'uninitialized'; @@ -270,6 +333,10 @@ sub is ($$;$) { goto &ok; } +=head2 C + +=cut + sub isnt ($$;$) { my ($got, $expected, $desc) = @_; no warnings 'uninitialized'; @@ -332,12 +399,22 @@ IS_BINOP } } +=head2 C + +=head2 C + +=cut + { no warnings 'once'; *like = _create_binop_handler('=~'); *unlike = _create_binop_handler('!~'); } +=head2 C + +=cut + sub cmp_ok ($$$;$) { my ($got, $op, $expected, $desc) = @_; my $handler = $binop_handlers{$op}; @@ -367,16 +444,28 @@ sub _diag_fh { return 0; }; +=head2 C + +=cut + sub diag { unshift @_, $DIAG_STREAM; goto &_diag_fh; } +=head2 C + +=cut + sub note { unshift @_, $TAP_STREAM; goto &_diag_fh; } +=head2 C + +=cut + sub BAIL_OUT { my ($desc) = @_; @@ -411,4 +500,35 @@ END { } } +=head1 DEPENDENCIES + +L 5.6. + +L, L + +=head1 AUTHOR + +Vincent Pit, C<< >>, L. + +You can contact me by mail or on C (vincent). + +=head1 BUGS + +Please report any bugs or feature requests to C, or through the web interface at L. +I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc Test::Leaner + +=head1 COPYRIGHT & LICENSE + +Copyright 2010 Vincent Pit, all rights reserved. + +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=cut + 1; # End of Test::Leaner diff --git a/t/91-pod.t b/t/91-pod.t new file mode 100644 index 0000000..ee8b18a --- /dev/null +++ b/t/91-pod.t @@ -0,0 +1,12 @@ +#!perl -T + +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod +my $min_tp = 1.22; +eval "use Test::Pod $min_tp"; +plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; + +all_pod_files_ok(); diff --git a/t/92-pod-coverage.t b/t/92-pod-coverage.t new file mode 100644 index 0000000..f9c77a5 --- /dev/null +++ b/t/92-pod-coverage.t @@ -0,0 +1,27 @@ +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod::Coverage +my $min_tpc = 1.08; +eval "use Test::Pod::Coverage $min_tpc"; +plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" if $@; + +# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, +# but older versions don't recognize some common documentation styles +my $min_pc = 0.18; +eval "use Pod::Coverage $min_pc"; +plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; + +all_pod_coverage_ok({ + also_private => [ qw< + NO_PLAN + SKIP_ALL + THREADSAFE + carp + croak + is_like + is_unlike + sanitize_comment + > ], +}); diff --git a/t/95-portability-files.t b/t/95-portability-files.t new file mode 100644 index 0000000..ab541f3 --- /dev/null +++ b/t/95-portability-files.t @@ -0,0 +1,10 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More; + +eval "use Test::Portability::Files"; +plan skip_all => "Test::Portability::Files required for testing filenames portability" if $@; +run_tests(); diff --git a/t/99-kwalitee.t b/t/99-kwalitee.t new file mode 100644 index 0000000..185d4ce --- /dev/null +++ b/t/99-kwalitee.t @@ -0,0 +1,21 @@ +#!perl + +use strict; +use warnings; + +use Test::More; + +eval { require Test::Kwalitee; }; +plan(skip_all => 'Test::Kwalitee not installed') if $@; + +SKIP: { + eval { Test::Kwalitee->import(); }; + if (my $err = $@) { + 1 while chomp $err; + require Test::Builder; + my $Test = Test::Builder->new; + my $plan = $Test->has_plan; + $Test->skip_all($err) if not defined $plan or $plan eq 'no_plan'; + skip $err => $plan - $Test->current_test; + } +}