Generalize, clean-up, and test for

cat, cksum, md5sum, and sha1sum all in the same loop.
This commit is contained in:
Jim Meyering 2003-02-18 07:59:58 +00:00
parent d3dbf68beb
commit 33c62fcef3

View File

@ -21,15 +21,26 @@ eval { require Expect };
$@ and (warn "$ME: this script requires Perl's Expect package\n"), exit 77; $@ and (warn "$ME: this script requires Perl's Expect package\n"), exit 77;
{ {
my $exp = new Expect; my $fail = 0;
# $exp->log_user(0); foreach my $cmd (qw(md5sum sha1sum cksum cat))
$exp->spawn('cat') {
or die "$ME: cannot run `cat': $!\n"; 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(''); exit $fail
!defined $exp->exitstatus || $exp->exitstatus
or die "$ME: cat didn't exit after ^D from standard input\n";
$exp->hard_close();
exit 0
} }
EOF EOF