Package: libtest-expect-perl
Version: 0.33-1
Severity: normal
Tags: patch
Forwarded: https://rt.cpan.org/Public/Bug/Display.html?id=110276

This package sometimes fails t/simple.t test 10 with

#   Failed test 'expect'
#   at lib/Test/Expect.pm line 86.
#          got: 'ping
# pong'
#     expected: 'pong'
# Looks like you failed 1 test of 18.

I can reproduce this locally by loading the host with other I/O and the
running the test in a loop. It looks like it's normally reading out the
'pong' response from the previous 'expect_send' test (rather than its
own) that never gets drained. However, sometimes stderr from careless
argument handling in the 'read' script intervenes:

 read: Can't open world: No such file or directory at ./read line 11.

The attached two patches should fix it, already forwarded upstream at
 https://rt.cpan.org/Public/Bug/Display.html?id=110276

-- 
Niko Tyni   nt...@debian.org
>From 7dd664d6b5be95ffbfc37b7c231ab1ba23d9914b Mon Sep 17 00:00:00 2001
From: Niko Tyni <nt...@debian.org>
Date: Thu, 10 Dec 2015 22:29:57 +0200
Subject: [PATCH 1/2] Fix testscripts not to treat their argument as a file

The argument is intended to be the name of the peer,
not a file to be read.

Bug: https://rt.cpan.org/Public/Bug/Display.html?id=110276
---
 read     | 2 +-
 readline | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/read b/read
index 56252cc..6eb6a34 100644
--- a/read
+++ b/read
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 $| = 1;
 
-my $what = $ARGV[0] || "there";
+my $what = (shift @ARGV) || "there";
 print "* Hi $what, to read\n";
 
 while (1) {
diff --git a/readline b/readline
index df5665c..4445981 100644
--- a/readline
+++ b/readline
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use Term::ReadLine;
 
-my $what = $ARGV[0] || "there";
+my $what = (shift @ARGV) || "there";
 print "* Hi $what, to readline\n";
 
 my $term = Term::ReadLine->new('readline');
-- 
2.6.2

>From 54f7b9e28c855d2bf5905aab6b510c9fd23322d0 Mon Sep 17 00:00:00 2001
From: Niko Tyni <nt...@debian.org>
Date: Thu, 10 Dec 2015 22:32:06 +0200
Subject: [PATCH 2/2] Read out the buffer after expect_send

This and the previous commit fix nondeterministic test failures
where output from the previous expect_send and stderr from
the argument handling can make the response vary.

Bug: https://rt.cpan.org/Public/Bug/Display.html?id=110276
---
 t/simple.t | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/simple.t b/t/simple.t
index 841dda4..4217207 100644
--- a/t/simple.t
+++ b/t/simple.t
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use lib 'lib';
 use Test::Expect;
-use Test::More tests => 18;
+use Test::More tests => 20;
 
 require_ok('Expect');
 
@@ -20,5 +20,6 @@ foreach my $filename ('read', 'readline') {
   expect_like(qr/Hi world, to $filename/, "expect_like");
   expect_is("* Hi world, to $filename", "expect_is");
   expect_send("ping", "expect_send");
+  expect_is("pong", "expect_is again");
   expect("ping", "pong", "expect");
 };
-- 
2.6.2

Reply via email to