]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/07-BAIL_OUT.t
Test BAIL_OUT()
[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 plan skip_all => 'perl 5.8 required to test BAIL_OUT()' unless $] >= 5.008;
9
10 my $buf = '';
11 open my $memory_stream, '>', \$buf
12                       or plan skip_all => 'could not create the in-memory file';
13
14 plan tests => 7;
15
16 our $status;
17 *CORE::GLOBAL::exit = *CORE::GLOBAL::exit = sub {
18  my $caller = caller;
19  if ($caller eq 'Test::Leaner') {
20   $status = $_[0] || 0;
21  } else {
22   CORE::exit $_[0];
23  }
24 };
25
26 require Test::Leaner;
27
28 {
29  local $@;
30  eval { Test::Leaner::tap_stream($memory_stream) };
31  is $@, '', 'tap_stream($fh) does not croak';
32 }
33
34 {
35  local ($@, $status);
36  $buf = '';
37  seek $memory_stream, 0, 0;
38  eval { Test::Leaner::BAIL_OUT() };
39  is $@,      '',            'BAIL_OUT() does not croak';
40  is $buf,    "Bail out!\n", 'BAIL_OUT() produces the correct TAP code';
41  is $status, 255,           'BAIL_OUT() exits with the correct status';
42 }
43
44 {
45  local ($@, $status);
46  $buf = '';
47  seek $memory_stream, 0, 0;
48  eval { Test::Leaner::BAIL_OUT('this is a comment') };
49  is $@,      '',  'BAIL_OUT("comment") does not croak';
50  is $buf,    "Bail out!  this is a comment\n",
51                   'BAIL_OUT("comment") produces the correct TAP code';
52  is $status, 255, 'BAIL_OUT("comment") exits with the correct status';
53 }