tests: add test for locale decimal processing
[coreutils.git] / tests / misc / tty-eof.pl
blobf9ce86f206e2b04c73627119e790a2544367a098
1 #!/usr/bin/perl
2 # Test whether programs exit upon a single EOF from a tty.
3 # Ensure that e.g., cat exits upon a single EOF (^D) from a tty.
4 # Do the same for all programs that can read stdin,
5 # require no arguments and that write to standard output.
7 # Copyright (C) 2003-2019 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22 use strict;
23 (my $ME = $0) =~ s|.*/||;
25 # Some older versions of Expect.pm (e.g. 1.07) lack the log_user method,
26 # so check for that, too.
27 eval { require Expect; Expect->require_version('1.11') };
29 and CuSkip::skip "$ME: this script requires Perl's Expect package >=1.11\n";
32 my $fail = 0;
33 my @stdin_reading_commands = qw(
34 base32
35 base64
36 cat
37 cksum
39 expand
40 fmt
41 fold
42 head
43 md5sum
46 paste
48 ptx
49 sha1sum
50 sha224sum
51 sha256sum
52 sha384sum
53 sha512sum
54 shuf
55 sort
56 sum
57 tac
58 tail
59 tee
60 tsort
61 unexpand
62 uniq
65 my $stderr = 'tty-eof.err';
66 foreach my $cmd ((@stdin_reading_commands), 'cut -f2',
67 'numfmt --invalid=ignore')
69 my $exp = new Expect;
70 $exp->log_user(0);
71 $ENV{built_programs} =~ /\b$cmd\b/ || next;
72 $exp->spawn("$cmd 2> $stderr")
73 or (warn "$ME: cannot run '$cmd': $!\n"), $fail=1, next;
74 # No input for cut -f2.
75 $cmd =~ /^cut/
76 or $exp->send("a b\n");
77 $exp->send("\cD"); # This is Control-D. FIXME: what if that's not EOF?
78 $exp->expect (0, '-re', "^a b\\r?\$");
79 my $found = $exp->expect (1, '-re', "^.+\$");
80 $found and warn "F: $found: " . $exp->exp_match () . "\n";
81 $exp->expect(10, 'eof');
82 # Expect no output from cut, since we gave it no input.
83 defined $found || $cmd =~ /^cut/
84 or (warn "$ME: $cmd didn't produce expected output\n"),
85 $fail=1, next;
86 defined $exp->exitstatus
87 or (warn "$ME: $cmd didn't exit after ^D from standard input\n"),
88 $fail=1, next;
89 my $s = $exp->exitstatus;
90 $s == 0
91 or (warn "$ME: $cmd exited with status $s (expected 0)\n"),
92 $fail=1;
93 $exp->hard_close();
95 # dd normally writes to stderr. If it exits successfully, we're done.
96 $cmd eq 'dd' && $s == 0
97 and next;
99 if (-s $stderr)
101 warn "$ME: $cmd wrote to stderr:\n";
102 system "cat $stderr";
103 $fail = 1;
106 continue
108 unlink $stderr
109 or warn "$ME: failed to remove stderr file from $cmd, $stderr: $!\n";
112 exit $fail