]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/07-BAIL_OUT.t
Fall back to Test::More when PERL_TEST_LEANER_USES_TEST_MORE is set
[perl/modules/Test-Leaner.git] / t / 07-BAIL_OUT.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 our $status;
9 BEGIN {
10  *CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub {
11   my $caller = caller;
12   if ($caller eq 'Test::Leaner') {
13    $status = $_[0] || 0;
14   } else {
15    CORE::exit $_[0];
16   }
17  };
18
19  delete $ENV{PERL_TEST_LEANER_USES_TEST_MORE};
20 }
21
22 use Test::Leaner ();
23
24 use lib 't/lib';
25 use Test::Leaner::TestHelper;
26
27 my $buf = '';
28 capture_to_buffer $buf
29                   or plan skip_all => 'perl 5.8 required to test BAIL_OUT()';
30
31
32 plan tests => 6;
33
34 reset_buffer {
35  local ($@, $status);
36  eval { Test::Leaner::BAIL_OUT() };
37  is $@,      '',            'BAIL_OUT() does not croak';
38  is $buf,    "Bail out!\n", 'BAIL_OUT() produces the correct TAP code';
39  is $status, 255,           'BAIL_OUT() exits with the correct status';
40 };
41
42 reset_buffer {
43  local ($@, $status);
44  eval { Test::Leaner::BAIL_OUT('this is a comment') };
45  is $@,      '',  'BAIL_OUT("comment") does not croak';
46  is $buf,    "Bail out!  this is a comment\n",
47                   'BAIL_OUT("comment") produces the correct TAP code';
48  is $status, 255, 'BAIL_OUT("comment") exits with the correct status';
49 };