@@ -4,7 +4,7 @@ use warnings;
44use File::Spec;
55use Test::More;
66
7- $| ++; # autoflush both processes (superfluous?)
7+ $| ++;
88
99subtest ' test yes' => sub {
1010 # set default path to yes as seen from PPT root directory
@@ -32,30 +32,30 @@ subtest 'test yes' => sub {
3232sub fork_yes {
3333 my ($yes_path , $yes_str ) = @_ ;
3434 my ($pid , $child );
35- $yes_str ||= ' y ' ;
36- if ( $pid = open ( $child , ' -| ' , " $yes_path $yes_str " )) {
37- # PARENT PROCESS
38- # read ten lines from child
39- my @lines ;
40- for (1..10) {
41- # NOTE <> must be called in scalar context to prevent blocking.
42- my $line = < $child >;
43- push @lines , $line ;
44- }
45-
46- is $lines [0], " $yes_str \n " , " First line is ' $yes_str '. \n " ; # superfluous?
47- is scalar ( @ lines), 10, ' Expected no. of output lines (10). ' ;
48- my $count_of_ys = grep { / ^ $yes_str $ / } @ lines ;
49- note $count_of_ys ;
50- is $count_of_ys , 10, " All 10 lines contain ' $yes_str ' only. \n " ;
51-
52- close ( $child ); # apparently superfluous
53- }
54- else {
55- die " cannot fork: $! \n " unless defined $pid ;
56- # CHILD PROCESS
57- exit ; # apparently superfluous
58- }
35+ my $line_count = 10 ;
36+ $yes_str //= ' y ' ;
37+
38+ subtest " yes string = < $yes_str > " => sub {
39+ if ( $pid = open ( $child , ' -| ' , " $yes_path $yes_str " )) { # PARENT PROCESS
40+ my @lines ;
41+ for (1.. $line_count ) {
42+ # NOTE <> must be called in scalar context to prevent blocking.
43+ my $line = < $child > ;
44+ push @lines , $line ;
45+ }
46+
47+ is $ lines[0], " $yes_str \n " , " First line is ' $yes_str '. " ;
48+ is scalar ( @lines ), $line_count , " Expected no. of output lines ( $line_count ). " ;
49+
50+ my $count_of_ys = grep { / ^ $yes_str $ / } @lines ;
51+ is $count_of_ys , $line_count , " All $line_count lines contain ' $yes_str ' only. " ;
52+
53+ close $child ;
54+ }
55+ else { # CHILD PROCESS
56+ die " cannot fork: $! \n " unless defined $pid ;
57+ }
58+ }
5959 }
6060
6161done_testing();
0 commit comments