summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/dist/IO/t/io_file.t
blob: 1cf60f54414dfe37e80522eaf1bd4e0f2bb6fc8e (plain)
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
#!./perl -w

use strict;
require($ENV{PERL_CORE} ? "../../t/test.pl" : "./t/test.pl");
plan(tests => ($^O =~ /MSWin32/ ? 9 : 6));

my $Class       = 'IO::File';
my $All_Chars   = join '', "\r\n", map( chr, 1..255 ), "zzz\n\r";
my $File        = 'bin.'.$$;
my $Expect      = quotemeta $All_Chars;

use_ok( $Class );
can_ok( $Class,                 "binmode" );

### file the file with binary data;
### use standard open to make sure we can compare binmodes
### on both.
{   my $tmp;
    open $tmp, ">$File" or die "Could not open '$File': $!";
    binmode $tmp;
    print $tmp $All_Chars; 
    close $tmp;
}

### now read in the file, once without binmode, once with.
### without binmode should fail at least on win32...
if( $^O =~ /MSWin32/ ) {
    my $fh = $Class->new;

    isa_ok( $fh,                $Class );
    ok( $fh->open($File),       "   Opened '$File'" );
    
    my $cont = do { local $/; <$fh> };
    unlike( $cont, qr/$Expect/, "   Content match fails without binmode" );
}    

### now with binmode, it must pass 
{   my $fh = $Class->new;

    isa_ok( $fh,                $Class );
    ok( $fh->open($File),       "   Opened '$File' $!" );
    ok( $fh->binmode,           "   binmode enabled" );
    
    my $cont = do { local $/; <$fh> };
    like( $cont, qr/$Expect/,   "   Content match passes with binmode" );
}
    
unlink $File;