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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
# !perl
#$Id: 06_io.t 1213 2008-02-09 23:40:34Z jimk $
# 06_io.t - test say() when printing to FileHandle and IO::File objects
use strict;
use warnings;
use Test::More tests => 22;
use lib ( qq{./t/lib} );
BEGIN {
use_ok('Perl6::Say');
use_ok('File::Temp');
use_ok('Carp');
use_ok('FileHandle');
use_ok('IO::File');
use_ok('Perl6::Say::Auxiliary', qw| _validate capture_say_file |);
};
my ($say_sub, $msg, @list);
##### FileHandle: Comma #####
$say_sub = sub {
my ($tmpfile, $arg) = @_;
my $fh = FileHandle->new($tmpfile, q{w});
if (defined $fh) {
ref($arg eq q{ARRAY}) ? say $fh, @{$arg} : say $fh, $arg;
$fh->close;
} else {
croak "Could not get FileHandle object";
}
};
$msg= q{correctly printed to file via FileHandle object, comma syntax};
@list = ( 'Hello', ' ', 'World' );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n" );
capture_say_file( {
data => \@list, pred => 2, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n", 'Again!', "\n" );
capture_say_file( {
data => \@list, pred => 3, eval => $say_sub, msg => $msg,
} );
@list = ( );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
##### FileHandle: Arrow #####
$say_sub = sub {
my ($tmpfile, $arg) = @_;
my $fh = FileHandle->new($tmpfile, q{w});
if (defined $fh) {
ref($arg eq q{ARRAY}) ? $fh->say(@{$arg}) : $fh->say($arg);
$fh->close;
} else {
croak "Could not get FileHandle object";
}
};
$msg= q{correctly printed to file via FileHandle object, arrow syntax};
@list = ( 'Hello', ' ', 'World' );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n" );
capture_say_file( {
data => \@list, pred => 2, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n", 'Again!', "\n" );
capture_say_file( {
data => \@list, pred => 3, eval => $say_sub, msg => $msg,
} );
@list = ( );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
##### IO::File: Comma #####
$say_sub = sub {
my ($tmpfile, $arg) = @_;
my $fh = IO::File->new($tmpfile, q{w});
if (defined $fh) {
ref($arg eq q{ARRAY}) ? say $fh, @{$arg} : say $fh, $arg;
$fh->close;
} else {
croak "Could not get IO::File object";
}
};
$msg= q{correctly printed to file via IO::File object, comma syntax};
@list = ( 'Hello', ' ', 'World' );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n" );
capture_say_file( {
data => \@list, pred => 2, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n", 'Again!', "\n" );
capture_say_file( {
data => \@list, pred => 3, eval => $say_sub, msg => $msg,
} );
@list = ( );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
##### IO::File: Arrow #####
$say_sub = sub {
my ($tmpfile, $arg) = @_;
my $fh = IO::File->new($tmpfile, q{w});
if (defined $fh) {
ref($arg eq q{ARRAY}) ? $fh->say(@{$arg}) : $fh->say($arg);
$fh->close;
} else {
croak "Could not get IO::File object";
}
};
$msg= q{correctly printed to file via IO::File object, arrow syntax};
@list = ( 'Hello', ' ', 'World' );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n" );
capture_say_file( {
data => \@list, pred => 2, eval => $say_sub, msg => $msg,
} );
@list = ( 'Hello', ' ', 'World', "\n", 'Again!', "\n" );
capture_say_file( {
data => \@list, pred => 3, eval => $say_sub, msg => $msg,
} );
@list = ( );
capture_say_file( {
data => \@list, pred => 1, eval => $say_sub, msg => $msg,
} );
|