From 33c62fcef39b82c46ee94c3194dbf4650a11de55 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 18 Feb 2003 07:59:58 +0000 Subject: [PATCH] Generalize, clean-up, and test for cat, cksum, md5sum, and sha1sum all in the same loop. --- tests/misc/cat-tty-eof | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/misc/cat-tty-eof b/tests/misc/cat-tty-eof index c8acdd54b..1d7a3edbb 100755 --- a/tests/misc/cat-tty-eof +++ b/tests/misc/cat-tty-eof @@ -21,15 +21,26 @@ eval { require Expect }; $@ and (warn "$ME: this script requires Perl's Expect package\n"), exit 77; { - my $exp = new Expect; - # $exp->log_user(0); - $exp->spawn('cat') - or die "$ME: cannot run `cat': $!\n"; + my $fail = 0; + foreach my $cmd (qw(md5sum sha1sum cksum cat)) + { + my $exp = new Expect; + $exp->log_user(0); + $exp->spawn($cmd) + or (warn "$ME: cannot run `$cmd': $!\n"), $fail=1, next; + $exp->send("foo\n"); + $exp->send(''); # FIXME: it'd be better not to hard-code ^D here + $exp->expect (0, '-re', "^foo\\r?\$"); + my $found = $exp->expect (1, '-re', "^.+\$"); + $found and warn "F: $found: " . $exp->exp_match () . "\n"; + $exp->expect(0, 'eof'); + # defined $exp->exitstatus and warn "E: " . $exp->exitstatus . "\n"; + defined $found && defined $exp->exitstatus && $exp->exitstatus == 0 + or (warn "$ME: $cmd didn't exit after ^D from standard input\n"), + $fail=1; + $exp->hard_close(); + } - $exp->send(''); - !defined $exp->exitstatus || $exp->exitstatus - or die "$ME: cat didn't exit after ^D from standard input\n"; - $exp->hard_close(); - exit 0 + exit $fail } EOF