2 # Test whether programs exit upon a single EOF from a tty.
4 # Copyright (C) 2003, 2006 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 $PERL -e 1 > /dev/null 2>&1 || {
24 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
25 "so can't run this test"
32 exec $PERL -w -- - <<\EOF
34 # Ensure that cat exits upon a single EOF (^D) from a tty.
35 # Do the same for all programs that can read stdin,
36 # require no arguments and that write to standard output.
39 (my $ME = $ENV{ARGV_0}) =~ s|.*/||;
41 # Some older versions of Expect.pm (e.g. 1.07) lack the log_user method,
42 # so check for that, too.
43 eval { require Expect; Expect->require_version('1.11') };
44 $@ and (warn "$ME: this script requires Perl's Expect package >=1.11\n"),
49 my @stdin_reading_commands = qw(
79 foreach my $cmd ((@stdin_reading_commands), 'cut -f2')
84 or (warn "$ME: cannot run `$cmd': $!\n"), $fail=1, next;
85 # No input for cut -f2.
87 or $exp->send("a b\n");
88 $exp->send("\cD"); # This is Control-D. FIXME: what if that's not EOF?
89 $exp->expect (0, '-re', "^a b\\r?\$");
90 my $found = $exp->expect (1, '-re', "^.+\$");
91 # $found and warn "F: $found: " . $exp->exp_match () . "\n";
92 $exp->expect(1, 'eof');
93 # Expect no output from cut, since we gave it no input.
94 defined $found || $cmd =~ /^cut/
95 or (warn "$ME: $cmd didn't produce expected output\n"),
97 defined defined $exp->exitstatus
98 or (warn "$ME: $cmd didn't exit after ^D from standard input\n"),
100 my $s = $exp->exitstatus;
102 or (warn "$ME: $cmd exited with status $s (expected 0)\n"),