1#!perl -T
2# -*- mode: cperl ; compile-command: "cd .. ; ./Build ; prove -vb t/05-*.t" -*-
3use Test::More tests => 8;
4use strict;
5use warnings;
6
7BEGIN {
8  use_ok( 'Test::Trap' );
9}
10
11eval { Test::Trap->import(qw( trap1 trap2 )) };
12like( $@,
13      qr/^\QThe Test::Trap module does not export more than one function at ${\__FILE__} line/,
14      'Export of two functions',
15    );
16
17eval { Test::Trap->import(qw( $trap1 $trap2 )) };
18like( $@,
19      qr/^\QThe Test::Trap module does not export more than one scalar at ${\__FILE__} line/,
20      'Export of two globs',
21    );
22
23eval { Test::Trap->import(qw( @bad )) };
24like( $@,
25      qr/^"\@bad"\Q is not exported by the Test::Trap module at ${\__FILE__} line/,
26      'Export of an array',
27    );
28
29eval { Test::Trap->import(qw( :no_such_layer )) };
30like( $@,
31      qr/^\QUnknown trap layer "no_such_layer" at ${\__FILE__} line/,
32      'Export of an unknown layer',
33    );
34
35my %got;
36$got{perlio} = eval q{ use PerlIO 'scalar'; 1 };
37$got{tempfile} = eval q{ use File::Temp; 1 };
38
39eval { Test::Trap->import(qw( test1 $T1 :stdout(perlio) )) };
40like( $@,
41      $got{perlio} ?
42      qr/\A\z/ :
43      qr/^\QNo capture strategy found for "perlio" at ${\__FILE__} line/,
44      'Export of capture strategy :stdout(perlio)',
45    );
46
47eval { Test::Trap->import(qw( test2 $T2 :stdout(nosuch;tempfile) )) };
48like( $@,
49      $got{tempfile} ?
50      qr/\A\z/ :
51      qr/^\QNo capture strategy found for ("nosuch", "tempfile") at ${\__FILE__} line/,
52      'Export of capture strategy :stdout(nosuch;tempfile)',
53    );
54
55eval { Test::Trap->import(qw( test2 $T2 :stdout(nosuch1;nosuch2) )) };
56like( $@,
57      qr/^\QNo capture strategy found for ("nosuch1", "nosuch2") at ${\__FILE__} line/,
58      'Export of capture strategy:stdout(nosuch1;nosuch2)',
59    );
60
61