Skip to content

Commit

Permalink
use mkfifo, not bash
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Jun 12, 2012
1 parent 059e4ea commit 437f6c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -7,6 +7,9 @@ problems at http://github.com/petdance/file-next/issues.
[FIXES] [FIXES]
from_file() should return undef if the file can't be opened. from_file() should return undef if the file can't be opened.


Trying to make the named pipe test more portable by not requiring
bash.

1.09_01 Sat Jun 9 22:57:33 CDT 2012 1.09_01 Sat Jun 9 22:57:33 CDT 2012


No new features. This only fixes test failures on some platforms. No new features. This only fixes test failures on some platforms.
Expand Down
29 changes: 21 additions & 8 deletions t/process-substitution.t
Expand Up @@ -5,20 +5,33 @@ use warnings;


use Test::More; use Test::More;


system 'bash', '-c', 'exit'; plan skip_all => q{Windows doesn't have named pipes} if $^O =~ /MSWin32/;
plan tests => 4;


if ( $? ) { use POSIX ();
plan skip_all => 'You need bash to run this test';
}


my $perl = $^X; my $pipename = POSIX::tmpnam();
POSIX::mkfifo $pipename, 0666;


plan tests => 4; my $pid = fork();
if ( $pid == 0 ) {
open my $fifo, '>', $pipename or die "Couldn't create named pipe $pipename: $!";
open my $f, '<', 'Changes' or die "Couldn't open Changes: $!";
while (my $line = <$f>) {
print {$fifo} $line;
}
close $fifo;
close $f;
exit 0;
}

my @output = qx{$^X -Mblib t/first-and-last-lines-via-process-pipe.pl $pipename};
is( $?, 0, 'No errors in executing our little named pipe tester' );
unlink $pipename;


my @output = qx{bash -c "$perl -Mblib t/first-and-last-lines-via-process-pipe.pl <(cat Changes)"};
chomp @output; chomp @output;
is( scalar @output, 2, 'Get exactly 2 lines back' ); is( scalar @output, 2, 'Get exactly 2 lines back' );
is( $output[0], 'Revision history for File-Next' ); is( $output[0], 'Revision history for File-Next' );
is( $output[-1], ' First version, released on an unsuspecting world.' ); is( $output[-1], ' First version, released on an unsuspecting world.' );
is( $?, 0, 'passing a named pipe created by a bash process substitution should yield that filename' );
done_testing(); done_testing();

0 comments on commit 437f6c1

Please sign in to comment.