#!/usr/bin/perl -w
use strict;

use Test::More tests => 1;

use IO::Pty;
my $pty = IO::Pty->new;
my $slave = $pty->slave;
my ($rp, $wp);
pipe($rp, $wp);

my $pid = fork;
if (!$pid) { # kid
	$wp->close;
	close $slave;
    exit 0;
}
$wp->close;
$pty->close_slave;
<$rp>; # synchronize with kid
$pty->write("\n");
my $found=0;
while (1) {
	my $buf;
	$pty->read($buf, 4096);
	last if !defined $buf or !length $buf;;
	$found++ if $buf eq "\r\n";
}
ok($found, "got it");

# avoid cleanup warnings from perl
END { local $@; local $?; $pty->close }
