From: Vincent Pit Date: Mon, 27 Dec 2010 22:25:23 +0000 (+0100) Subject: Test pass() and fail() X-Git-Tag: v0.01~14 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FTest-Leaner.git;a=commitdiff_plain;h=c80a21dbcb4445fe4aebe276d439d2a2d8b310b1 Test pass() and fail() --- diff --git a/MANIFEST b/MANIFEST index c5fd1f3..c89c5a8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5,6 +5,8 @@ README lib/Test/Leaner.pm t/00-load.t t/01-import.t +t/05-pass.t +t/06-fail.t t/10-plan-tests.t t/11-plan-no_plan.t t/12-plan-skip_all.t diff --git a/t/05-pass.t b/t/05-pass.t new file mode 100644 index 0000000..f999747 --- /dev/null +++ b/t/05-pass.t @@ -0,0 +1,41 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More; + +plan skip_all => 'perl 5.8 required to test pass()' unless $] >= 5.008; + +my $buf = ''; +open my $memory_stream, '>', \$buf + or plan skip_all => 'could not create the in-memory file'; + +plan tests => 5; + +require Test::Leaner; + +{ + local $@; + eval { Test::Leaner::tap_stream($memory_stream) }; + is $@, '', 'tap_stream($fh) does not croak'; +} + +{ + 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'; +} + +{ + 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'; +} diff --git a/t/06-fail.t b/t/06-fail.t new file mode 100644 index 0000000..a3ed9e0 --- /dev/null +++ b/t/06-fail.t @@ -0,0 +1,41 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More; + +plan skip_all => 'perl 5.8 required to test fail()' unless $] >= 5.008; + +my $buf = ''; +open my $memory_stream, '>', \$buf + or plan skip_all => 'could not create the in-memory file'; + +plan tests => 5; + +require Test::Leaner; + +{ + local $@; + eval { Test::Leaner::tap_stream($memory_stream) }; + is $@, '', 'tap_stream($fh) does not croak'; +} + +{ + 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'; +} + +{ + 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'; +}