tests: move tests to a directory per utility
[coreutils.git] / tests / tac / tac.pl
blob1c188e41c2fb76c56d001102e169454e8d4c9e85
1 #!/usr/bin/perl
3 # Copyright (C) 2008-2023 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 use strict;
20 my $prog = 'tac';
22 # Turn off localization of executable's output.
23 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
25 my $bad_dir = 'no/such/dir';
27 # This must be longer than 16KiB to trigger the double free in coreutils-8.5.
28 my $long_line = 'o' x (16 * 1024 + 1);
30 my @Tests =
32 ['segfault', '-r', {IN=>"a\n"}, {IN=>"b\n"}, {OUT=>"a\nb\n"}],
33 ['segfault2','-r', {IN=>"a\nb\n"}, {IN=>"1\n2\n"}, {OUT=>"b\na\n2\n1\n"}],
35 ['basic-0', '', {IN=>""}, {OUT=>""}],
36 ['basic-a', '', {IN=>"a"}, {OUT=>"a"}],
37 ['basic-b', '', {IN=>"\n"}, {OUT=>"\n"}],
38 ['basic-c', '', {IN=>"a\n"}, {OUT=>"a\n"}],
39 ['basic-d', '', {IN=>"a\nb"}, {OUT=>"ba\n"}],
40 ['basic-e', '', {IN=>"a\nb\n"}, {OUT=>"b\na\n"}],
41 ['basic-f', '', {IN=>"1234567\n8\n"}, {OUT=>"8\n1234567\n"}],
42 ['basic-g', '', {IN=>"12345678\n9\n"}, {OUT=>"9\n12345678\n"}],
43 ['basic-h', '', {IN=>"123456\n8\n"}, {OUT=>"8\n123456\n"}],
44 ['basic-i', '', {IN=>"12345\n8\n"}, {OUT=>"8\n12345\n"}],
45 ['basic-j', '', {IN=>"1234\n8\n"}, {OUT=>"8\n1234\n"}],
46 ['basic-k', '', {IN=>"123\n8\n"}, {OUT=>"8\n123\n"}],
48 ['nul-0', '-s ""', {IN=>""}, {OUT=>""}],
49 ['nul-a', '-s ""', {IN=>"a"}, {OUT=>"a"}],
50 ['nul-b', '-s ""', {IN=>"\0"}, {OUT=>"\0"}],
51 ['nul-c', '-s ""', {IN=>"a\0"}, {OUT=>"a\0"}],
52 ['nul-d', '-s ""', {IN=>"a\0b"}, {OUT=>"ba\0"}],
53 ['nul-e', '-s ""', {IN=>"a\0b\0"}, {OUT=>"b\0a\0"}],
55 ['opt-b', '-b', {IN=>"\na\nb\nc"}, {OUT=>"\nc\nb\na"}],
56 ['opt-s', '-s:', {IN=>"a:b:c:"}, {OUT=>"c:b:a:"}],
57 ['opt-sb', qw(-s : -b), {IN=>":a:b:c"}, {OUT=>":c:b:a"}],
58 ['opt-r', qw(-r -s '\._+'),
59 {IN=>"1._2.__3.___4._"},
60 {OUT=>"4._3.___2.__1._"}],
62 ['opt-r2', qw(-r -s '\._+'),
63 {IN=>"a.___b.__1._2.__3.___4._"},
64 {OUT=>"4._3.___2.__1._b.__a.___"}],
66 # This gave incorrect output (.___4._2.__3._1) with tac-1.22.
67 ['opt-br', qw(-b -r -s '\._+'),
68 {IN=>"._1._2.__3.___4"}, {OUT=>".___4.__3._2._1"}],
70 ['opt-br2', qw(-b -r -s '\._+'),
71 {IN=>".__x.___y.____z._1._2.__3.___4"},
72 {OUT=>".___4.__3._2._1.____z.___y.__x"}],
74 ['pipe-bad-tmpdir',
75 {ENV => "TMPDIR=$bad_dir"},
76 {IN_PIPE => "a\n"},
77 {ERR_SUBST => "s,'$bad_dir': .*,...,"},
78 {ERR => "$prog: failed to create temporary file in ...\n"},
79 {EXIT => 1}],
81 # coreutils-8.5's tac would double-free its primary buffer.
82 ['double-free', {IN=>$long_line}, {OUT=>$long_line}],
85 @Tests = triple_test \@Tests;
87 my $save_temps = $ENV{DEBUG};
88 my $verbose = $ENV{VERBOSE};
90 my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose);
91 exit $fail;