fix issue with blead (require 5.010 != use 5.010)
[p5sagit/Try-Tiny.git] / t / finally.t
CommitLineData
7195fc08 1#!/usr/bin/perl
2
3use strict;
4#use warnings;
5
68094f9e 6use Test::More tests => 12;
7195fc08 7
8BEGIN { use_ok 'Try::Tiny' };
9
10try {
11 my $a = 1+1;
12} catch {
13 fail('Cannot go into catch block because we did not throw an exception')
14} finally {
15 pass('Moved into finally from try');
16};
17
18try {
19 die('Die');
20} catch {
21 ok($_ =~ /Die/, 'Error text as expected');
22 pass('Into catch block as we died in try');
23} finally {
24 pass('Moved into finally from catch');
25};
26
27try {
28 die('Die');
29} finally {
30 pass('Moved into finally from catch');
31} catch {
32 ok($_ =~ /Die/, 'Error text as expected');
33};
34
35try {
36 die('Die');
37} finally {
38 pass('Moved into finally block when try throws an exception and we have no catch block');
39};
40
b611f396 41try {
42 die('Die');
43} finally {
44 pass('First finally clause run');
45} finally {
46 pass('Second finally clause run');
47};
48
49try {
50 # do not die
51} finally {
52 if (@_) {
53 fail("errors reported: @_");
54 } else {
55 pass("no error reported") ;
56 }
57};
58
68094f9e 59try {
60 die("Die\n");
61} finally {
62 is_deeply(\@_, [ "Die\n" ], "finally got passed the exception");
63};
7195fc08 64
651;