t/92-pod-coverage.t
t/95-portability-files.t
t/99-kwalitee.t
+t/lib/Test/Leaner/TestHelper.pm
use Test::More;
-plan skip_all => 'perl 5.8 required to test pass()' unless $] >= 5.008;
+use Test::Leaner ();
-my $buf = '';
-open my $memory_stream, '>', \$buf
- or plan skip_all => 'could not create the in-memory file';
-
-plan tests => 5;
+use lib 't/lib';
+use Test::Leaner::TestHelper;
-require Test::Leaner;
+my $buf = '';
+capture_to_buffer $buf or plan skip_all => 'perl 5.8 required to test pass()';
-{
- local $@;
- eval { Test::Leaner::tap_stream($memory_stream) };
- is $@, '', 'tap_stream($fh) does not croak';
-}
+plan tests => 4;
-{
+reset_buffer {
local $@;
- $buf = '';
- seek $memory_stream, 0, 0;
eval { Test::Leaner::pass() };
is $@, '', 'pass() does not croak';
is $buf, "ok 1\n", 'pass() produces the correct TAP code';
-}
+};
-{
+reset_buffer {
local $@;
- $buf = '';
- seek $memory_stream, 0, 0;
eval { Test::Leaner::pass('this is a comment') };
is $@, '', 'pass("comment") does not croak';
is $buf, "ok 2 - this is a comment\n",
'pass("comment") produces the correct TAP code';
-}
+};
use Test::More;
-plan skip_all => 'perl 5.8 required to test fail()' unless $] >= 5.008;
+use Test::Leaner ();
-my $buf = '';
-open my $memory_stream, '>', \$buf
- or plan skip_all => 'could not create the in-memory file';
+use lib 't/lib';
+use Test::Leaner::TestHelper;
-plan tests => 5;
+my $buf = '';
+capture_to_buffer $buf or plan skip_all => 'perl 5.8 required to test fail()';
-require Test::Leaner;
-{
- local $@;
- eval { Test::Leaner::tap_stream($memory_stream) };
- is $@, '', 'tap_stream($fh) does not croak';
-}
+plan tests => 4;
-{
+reset_buffer {
local $@;
- $buf = '';
- seek $memory_stream, 0, 0;
eval { Test::Leaner::fail() };
is $@, '', 'fail() does not croak';
is $buf, "not ok 1\n", 'fail() produces the correct TAP code';
-}
+};
-{
+reset_buffer {
local $@;
- $buf = '';
- seek $memory_stream, 0, 0;
eval { Test::Leaner::fail('this is a comment') };
is $@, '', 'fail("comment") does not croak';
is $buf, "not ok 2 - this is a comment\n",
'fail("comment") produces the correct TAP code';
-}
+};
use Test::More;
-plan skip_all => 'perl 5.8 required to test BAIL_OUT()' unless $] >= 5.008;
+our $status;
+BEGIN {
+ *CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub {
+ my $caller = caller;
+ if ($caller eq 'Test::Leaner') {
+ $status = $_[0] || 0;
+ } else {
+ CORE::exit $_[0];
+ }
+ };
+}
-my $buf = '';
-open my $memory_stream, '>', \$buf
- or plan skip_all => 'could not create the in-memory file';
+use Test::Leaner ();
-plan tests => 7;
+use lib 't/lib';
+use Test::Leaner::TestHelper;
-our $status;
-*CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub {
- my $caller = caller;
- if ($caller eq 'Test::Leaner') {
- $status = $_[0] || 0;
- } else {
- CORE::exit $_[0];
- }
-};
+my $buf = '';
+capture_to_buffer $buf
+ or plan skip_all => 'perl 5.8 required to test BAIL_OUT()';
-require Test::Leaner;
-{
- local $@;
- eval { Test::Leaner::tap_stream($memory_stream) };
- is $@, '', 'tap_stream($fh) does not croak';
-}
+plan tests => 6;
-{
+reset_buffer {
local ($@, $status);
- $buf = '';
- seek $memory_stream, 0, 0;
eval { Test::Leaner::BAIL_OUT() };
is $@, '', 'BAIL_OUT() does not croak';
is $buf, "Bail out!\n", 'BAIL_OUT() produces the correct TAP code';
is $status, 255, 'BAIL_OUT() exits with the correct status';
-}
+};
-{
+reset_buffer {
local ($@, $status);
- $buf = '';
- seek $memory_stream, 0, 0;
eval { Test::Leaner::BAIL_OUT('this is a comment') };
is $@, '', 'BAIL_OUT("comment") does not croak';
is $buf, "Bail out! this is a comment\n",
'BAIL_OUT("comment") produces the correct TAP code';
is $status, 255, 'BAIL_OUT("comment") exits with the correct status';
-}
+};
--- /dev/null
+package Test::Leaner::TestHelper;
+
+use strict;
+use warnings;
+
+my $memory_stream;
+my $buf_ref;
+
+sub capture_to_buffer {
+ return unless $] >= 5.008;
+
+ die "Can't call capture_to_buffer twice" if $memory_stream;
+
+ $buf_ref = \$_[0];
+ open $memory_stream, '>', $buf_ref
+ or die 'could not create the in-memory file';
+
+ Test::Leaner::tap_stream($memory_stream);
+
+ return 1;
+}
+
+# The ";&" prototype does not work well with perl 5.6
+sub reset_buffer (&) {
+ my $code = shift;
+
+ die "The memory stream has not been initialized" unless $memory_stream;
+
+ $$buf_ref = '';
+ seek $memory_stream, 0, 0;
+
+ goto $code if $code;
+}
+
+our @EXPORT = qw<
+ capture_to_buffer
+ reset_buffer
+>;
+
+use Exporter ();
+
+sub import { goto &Exporter::import }
+
+1;