File: 05-import.t

package info (click to toggle)
libtest-trap-perl 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 256 kB
  • sloc: perl: 2,258; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,826 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!perl -T
# -*- mode: cperl ; compile-command: "cd .. ; ./Build ; prove -vb t/05-*.t" -*-
use Test::More tests => 8;
use strict;
use warnings;

BEGIN {
  use_ok( 'Test::Trap' );
}

eval { Test::Trap->import(qw( trap1 trap2 )) };
like( $@,
      qr/^\QThe Test::Trap module does not export more than one function at ${\__FILE__} line/,
      'Export of two functions',
    );

eval { Test::Trap->import(qw( $trap1 $trap2 )) };
like( $@,
      qr/^\QThe Test::Trap module does not export more than one scalar at ${\__FILE__} line/,
      'Export of two globs',
    );

eval { Test::Trap->import(qw( @bad )) };
like( $@,
      qr/^"\@bad"\Q is not exported by the Test::Trap module at ${\__FILE__} line/,
      'Export of an array',
    );

eval { Test::Trap->import(qw( :no_such_layer )) };
like( $@,
      qr/^\QUnknown trap layer "no_such_layer" at ${\__FILE__} line/,
      'Export of an unknown layer',
    );

my %got;
$got{perlio} = eval q{ use PerlIO 'scalar'; 1 };
$got{tempfile} = eval q{ use File::Temp; 1 };

eval { Test::Trap->import(qw( test1 $T1 :stdout(perlio) )) };
like( $@,
      $got{perlio} ?
      qr/\A\z/ :
      qr/^\QNo output layer implementation found for "perlio" at ${\__FILE__} line/,
      'Export of PerlIO implementation :stdout(perlio)',
    );

eval { Test::Trap->import(qw( test2 $T2 :stdout(nosuch;tempfile) )) };
like( $@,
      $got{tempfile} ?
      qr/\A\z/ :
      qr/^\QNo output layer implementation found for ("nosuch", "tempfile") at ${\__FILE__} line/,
      'Export of PerlIO implementation :stdout(nosuch;tempfile)',
    );

eval { Test::Trap->import(qw( test2 $T2 :stdout(nosuch1;nosuch2) )) };
like( $@,
      qr/^\QNo output layer implementation found for ("nosuch1", "nosuch2") at ${\__FILE__} line/,
      'Export of PerlIO implementation :stdout(nosuch1;nosuch2)',
    );