Debian lenny version packages
[pkg-perl] / deb-src / libtest-simple-perl / libtest-simple-perl-0.80 / t / is_fh.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ('../lib', 'lib');
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12
13 use strict;
14 use Test::More tests => 11;
15 use TieOut;
16
17 ok( !Test::Builder->is_fh("foo"), 'string is not a filehandle' );
18 ok( !Test::Builder->is_fh(''),    'empty string' );
19 ok( !Test::Builder->is_fh(undef), 'undef' );
20
21 ok( open(FILE, '>foo') );
22 END { close FILE; 1 while unlink 'foo' }
23
24 ok( Test::Builder->is_fh(*FILE) );
25 ok( Test::Builder->is_fh(\*FILE) );
26 ok( Test::Builder->is_fh(*FILE{IO}) );
27
28 tie *OUT, 'TieOut';
29 ok( Test::Builder->is_fh(*OUT) );
30 ok( Test::Builder->is_fh(\*OUT) );
31
32 SKIP: {
33     skip "*TIED_HANDLE{IO} doesn't work in this perl", 1
34         unless defined *OUT{IO};
35     ok( Test::Builder->is_fh(*OUT{IO}) );
36 }
37
38
39 package Lying::isa;
40
41 sub isa {
42     my $self = shift;
43     my $parent = shift;
44     
45     return 1 if $parent eq 'IO::Handle';
46 }
47
48 ::ok( Test::Builder->is_fh(bless {}, "Lying::isa"));