Skip to content

Commit

Permalink
Fix macos eof (#349)
Browse files Browse the repository at this point in the history
* Test .eof on TTY handles works right

RT#132349: https://rt.perl.org/Ticket/Display.html?id=132349

* Fix test's failure mode

On failure, it diag()s the received output, but diag returns True,
causing the failed test to succeed

* Reword proc launch

We can't .Bool a Proc as that'll cause its `await`ion before
we sent stuff to STDIN
  • Loading branch information
zoffixznet committed Oct 24, 2017
1 parent bcf0f93 commit cb7ec60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 16 additions & 2 deletions S16-io/eof.t
@@ -1,10 +1,15 @@
use v6;
use lib <t/spec/packages/>;
use Test;
plan 2;
use Test::Util;

plan 3;

sub nonce () { return (".{$*PID}." ~ 1000.rand.Int) }

my $tmpfile = "eof-test-" ~ nonce();
END unlink $tmpfile;

{
my $fh = open($tmpfile, :w) or die qq/Failed to open "$tmpfile": $!/;
$fh.print: "EOF_TESTING\n\n";
Expand Down Expand Up @@ -39,6 +44,15 @@ my $tmpfile = "eof-test-" ~ nonce();
}
}

END { unlink $tmpfile }
# RT # 132349
run-with-tty with $*IN { .eof.say; .slurp.say; .eof.say }, :in<meow>,
# Here we use .ends-width because (currently) there's some sort of
# bug with Proc or something where sent STDIN ends up on our STDOUT.
# Extra "\n" after `meow` is 'cause run-as-tty sends extra new line,
# 'cause MacOS's `script` really wants it or something
:out{ .ends-with: "False\nmeow\n\nTrue\n" or do {
diag "Got STDOUT: {.perl}";
False;
}}, '.eof on TTY STDIN works right';

# vim: ft=perl6
6 changes: 1 addition & 5 deletions packages/Test/Util.pm
Expand Up @@ -307,18 +307,14 @@ sub run-with-tty (

subtest $desc => {
$path.IO.spurt: $code;
if shell :in, :out, :err, $script -> $_ {
given shell :in, :out, :err, $script {
plan 3;
# on MacOS, `script` really wants the ending newline...
.in.spurt: "$in\n", :close;
cmp-ok .out.slurp(:close), '~~', $out, 'STDOUT';
cmp-ok .err.slurp(:close), '~~', $err, 'STDERR';
cmp-ok .exitcode, '~~', $status, 'exit code';
}
else {
plan 1;
flunk "Failed to run command; exitcode: $^proc.exitcode()";
}
}
}

Expand Down

0 comments on commit cb7ec60

Please sign in to comment.