]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/21-ok-failing.t
Test ok() return value, with overloading, and failing
[perl/modules/Test-Leaner.git] / t / 21-ok-failing.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use Test::Leaner ();
9
10 use lib 't/lib';
11 use Test::Leaner::TestHelper;
12
13 my $buf;
14 capture_to_buffer $buf
15                   or plan skip_all =>'perl 5.8 required to test ok() failing';
16
17 plan tests => 3 * 5;
18
19 reset_buffer {
20  local $@;
21  my $ret = eval { Test::Leaner::ok(0) };
22  is $@,    '',           'ok(0) does not croak';
23  ok !$ret,               'ok(0) returns false';
24  is $buf,  "not ok 1\n", 'ok(0) produces the correct TAP code';
25 };
26
27 reset_buffer {
28  local $@;
29  my $ret = eval { Test::Leaner::ok(undef) };
30  is $@,    '',           'ok(undef) does not croak';
31  ok !$ret,               'ok(undef) returns false';
32  is $buf,  "not ok 2\n", 'ok(undef) produces the correct TAP code';
33 };
34
35 reset_buffer {
36  local $@;
37  my $ret = eval { Test::Leaner::ok(!1) };
38  is $@,    '',           'ok(false) does not croak';
39  ok !$ret,               'ok(false) returns false';
40  is $buf,  "not ok 3\n", 'ok(false) produces the correct TAP code';
41 };
42
43 reset_buffer {
44  local $@;
45  my $ret = eval { Test::Leaner::ok(0, 'this is a comment') };
46  is $@,    '', 'ok(0, "comment") does not croak';
47  ok !$ret,     'ok(0, "comment") returns false';
48  is $buf,  "not ok 4 - this is a comment\n",
49                'ok(0, "comment") produces the correct TAP code';
50 };
51
52 {
53  package Test::Leaner::TestOverload::AlwaysFalse;
54
55  use overload 'bool' => sub { !1 };
56
57  sub new { bless { }, shift }
58 }
59
60 my $z = Test::Leaner::TestOverload::AlwaysFalse->new;
61
62 reset_buffer {
63  local $@;
64  my $ret = eval { Test::Leaner::ok($z) };
65  is $@,    '',           'ok($overloaded_false) does not croak';
66  ok !$ret,               'ok($overloaded_false) returns false';
67  is $buf,  "not ok 5\n", 'ok($overloaded_false) produces the correct TAP code';
68 };
69