1#!/usr/bin/perl
2# Test pr.
3
4# Copyright (C) 2008-2023 Free Software Foundation, Inc.
5
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 3 of the License, or
9# (at your option) any later version.
10
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.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19use strict;
20
21# Turn off localization of executable's output.
22@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
23
24my $prog = 'pr';
25my $normalize_strerror = "s/': .*/'/";
26
27my @tv = (
28
29# -b option is no longer an official option. But it's still working to
30# get a downward compatibility. Now (version 1.19m or newer) -COLUMN
31# only is equivalent to -b -COLUMN.
32#
33# test_name options input-file-name(s) expected-output-group-file-name
34#                                                         expected-return-code
35# -------------------------------------------------------------------------
36# Following tests with "FF set" don't contain a complete set of all
37# combinations of options and FF-arrangements
38#
39# One FF at start of file (one empty page)
40# ['1a', '', [\'0Ft'], [\'0F'], 0],
41['1b', '', [\'0Fnt'], [\'0F'], 0],
42['1c', '+3', [\'0Ft'], [\'3-0F'], 0],
43['1d', '+3 -f', [\'0Ft'], [\'3f-0F'], 0],
44['1e', '-a -3', [\'0Ft'], [\'a3-0F'], 0],
45['1f', '-a -3 -f', [\'0Ft'], [\'a3f-0F'], 0],
46['1g', '-a -3 -f', [\'0Fnt'], [\'a3f-0F'], 0],
47['1h', '+3 -a -3 -f', [\'0Ft'], [\'3a3f-0F'], 0],
48['1i', '-b -3', [\'0Ft'], [\'b3-0F'], 0],
49['1j', '-b -3 -f', [\'0Ft'], [\'b3f-0F'], 0],
50['1k', '-b -3 -f', [\'0Fnt'], [\'b3f-0F'], 0],
51['1l', '+3 -b -3 -f', [\'0Ft'], [\'3b3f-0F'], 0],
52# Two FF at start of file (two empty page)
53['2a', '', [\'0FFt'], [\'0FF'], 0],
54['2b', '', [\'0FnFnt'], [\'0FF'], 0],
55['2c', '-a -3 -f', [\'0FFt'], [\'a3f-0FF'], 0],
56['2d', '-a -3 -f', [\'0FFnt'], [\'a3f-0FF'], 0],
57['2e', '-b -3 -f', [\'0FFt'], [\'b3f-0FF'], 0],
58['2f', '-b -3 -f', [\'0FFnt'], [\'b3f-0FF'], 0],
59['2g', '-b -3 -f', [\'0FnFt'], [\'b3f-0FF'], 0],
60['2h', '-b -3 -f', [\'0FnFnt'], [\'b3f-0FF'], 0],
61['2i', '+3 -b -3 -f', [\'0FFt'], [\'3b3f-0FF'], 0],
62['2j', '+3 -b -3 -f', [\'0FFnt'], [\'3b3f-0FF'], 0],
63#
64# FFs in text (none / one / two empty page(s))
65['3a', '', [\'FFn'], [\'FF'], 0],
66['3b', '', [\'FnFn'], [\'FF'], 0],
67['3c', '+3', [\'FFn'], [\'3-FF'], 0],
68['3d', '+3 -f', [\'FFn'], [\'3f-FF'], 0],
69['3e', '-a -3 -f', [\'FFn'], [\'a3f-FF'], 0],
70['3f', '-a -3 -f', [\'FFtn'], [\'a3f-FF'], 0],
71['3g', '-b -3 -f', [\'FFn'], [\'b3f-FF'], 0],
72['3h', '-b -3 -f', [\'FFtn'], [\'b3f-FF'], 0],
73['3i', '-b -3 -f', [\'FnFn'], [\'b3f-FF'], 0],
74['3j', '-b -3 -f', [\'tFFn'], [\'b3f-FF'], 0],
75['3k', '-b -3 -f', [\'tFnFt'], [\'b3f-FF'], 0],
76['3l', '+3 -b -3 -f', [\'FFn'], [\'3b3f-FF'], 0],
77['3m', '+3 -b -3 -f', [\'FFtn'], [\'3b3f-FF'], 0],
78# A full page printed (lines_left_on_page = 0) without a FF found.
79# Avoid an extra empty page if a FF follows in the next input line.
80['3la', '-l 24', [\'FFn'], [\'l24-FF'], 0],
81['3lb', '-l 24', [\'FFtn'], [\'l24-FF'], 0],
82['3lc', '-l 24', [\'FnFn'], [\'l24-FF'], 0],
83['3ld', '-l 24', [\'tFFn'], [\'l24-FF'], 0],
84['3le', '-l 24', [\'tFnFt'], [\'l24-FF'], 0],
85['3lf', '-l 24', [\'tFFt'], [\'l24-FF'], 0],
86['3aa', '-a -2 -l 17', [\'FFn'], [\'a2l17-FF'], 0],
87['3ab', '-a -2 -l 17', [\'FFtn'], [\'a2l17-FF'], 0],
88['3ac', '-a -2 -l 17', [\'FnFn'], [\'a2l17-FF'], 0],
89['3ad', '-a -2 -l 17', [\'tFFn'], [\'a2l17-FF'], 0],
90['3ae', '-a -2 -l 17', [\'tFnFt'], [\'a2l17-FF'], 0],
91['3af', '-a -2 -l 17', [\'tFFt'], [\'a2l17-FF'], 0],
92['3ag', '-a -2 -l 15', [\'FFn'], [\'a2l15-FF'], 0],
93['3ah', '-a -2 -l 15', [\'FFtn'], [\'a2l15-FF'], 0],
94['3ai', '-a -2 -l 15', [\'FnFn'], [\'a2l15-FF'], 0],
95['3aj', '-a -2 -l 15', [\'tFFn'], [\'a2l15-FF'], 0],
96['3ak', '-a -2 -l 15', [\'tFnFt'], [\'a2l15-FF'], 0],
97['3ba', '-b -2 -l 17', [\'FFn'], [\'b2l17-FF'], 0],
98['3bb', '-b -2 -l 17', [\'FFtn'], [\'b2l17-FF'], 0],
99['3bc', '-b -2 -l 17', [\'FnFn'], [\'b2l17-FF'], 0],
100['3bd', '-b -2 -l 17', [\'tFFn'], [\'b2l17-FF'], 0],
101['3be', '-b -2 -l 17', [\'tFnFt'], [\'b2l17-FF'], 0],
102['3bf', '-b -2 -l 17', [\'tFFt'], [\'b2l17-FF'], 0],
103['3bg', '-b -2 -l 15', [\'FFn'], [\'b2l15-FF'], 0],
104['3bh', '-b -2 -l 15', [\'FFtn'], [\'b2l15-FF'], 0],
105['3bi', '-b -2 -l 15', [\'FnFn'], [\'b2l15-FF'], 0],
106['3bj', '-b -2 -l 15', [\'tFFn'], [\'b2l15-FF'], 0],
107['3bk', '-b -2 -l 15', [\'tFnFt'], [\'b2l15-FF'], 0],
108['3Pa', '+4 -l 24', [\'FFn'], [\'4l24-FF'], 0],
109['3Pb', '+4 -l 24', [\'FFtn'], [\'4l24-FF'], 0],
110['3Pc', '+4 -l 24', [\'FnFn'], [\'4l24-FF'], 0],
111['3Pd', '+4 -l 24', [\'tFFn'], [\'4l24-FF'], 0],
112['3Pe', '+4 -l 24', [\'tFnFt'], [\'4l24-FF'], 0],
113['3Pf', '+4 -l 24', [\'tFFt'], [\'4l24-FF'], 0],
114['3Pg', '+4:7 -l 24', [\'tFFt'], [\'4-7l24-FF'], 0],
115['3Paa', '+3 -a -2 -l 17', [\'FFn'], [\'3a2l17-FF'], 0],
116['3Pab', '+3 -a -2 -l 17', [\'FFtn'], [\'3a2l17-FF'], 0],
117['3Pac', '+3 -a -2 -l 17', [\'FnFn'], [\'3a2l17-FF'], 0],
118['3Pad', '+3 -a -2 -l 17', [\'tFFn'], [\'3a2l17-FF'], 0],
119['3Pae', '+3 -a -2 -l 17', [\'tFnFt'], [\'3a2l17-FF'], 0],
120['3Paf', '+3 -a -2 -l 17', [\'tFFt'], [\'3a2l17-FF'], 0],
121['3Pba', '+3 -b -2 -l 17', [\'FFn'], [\'3b2l17-FF'], 0],
122['3Pbb', '+3 -b -2 -l 17', [\'FFtn'], [\'3b2l17-FF'], 0],
123['3Pbc', '+3 -b -2 -l 17', [\'FnFn'], [\'3b2l17-FF'], 0],
124['3Pbd', '+3 -b -2 -l 17', [\'tFFn'], [\'3b2l17-FF'], 0],
125['3Pbe', '+3 -b -2 -l 17', [\'tFnFt'], [\'3b2l17-FF'], 0],
126['3Pbf', '+3 -b -2 -l 17', [\'tFFt'], [\'3b2l17-FF'], 0],
127#
128# Without "FF set by hand"
129['4a', '-l 24', [\'tn'], [\'l24-t'], 0],
130['4b', '-l 24 -f', [\'tn'], [\'l24f-t'], 0],
131['4c', '+3 -l 24', [\'tn'], [\'3l24-t'], 0],
132['4d', '+3 -l 24 -f', [\'tn'], [\'3l24f-t'], 0],
133['4e', '+3:5 -l 24 -f', [\'tn'], [\'3-5l24f-t'], 0],
134['4f', '-a -3 -l 15', [\'tn'], [\'a3l15-t'], 0],
135['4g', '-a -3 -l 15 -f', [\'tn'], [\'a3l15f-t'], 0],
136['4h', '+3 -a -3 -l 15', [\'tn'], [\'3a3l15-t'], 0],
137['4i', '+3 -a -3 -l 15 -f', [\'tn'], [\'3a3l15f-t'], 0],
138['4j', '-b -3 -l 15', [\'tn'], [\'b3l15-t'], 0],
139['4k', '-b -3 -l 15 -f', [\'tn'], [\'b3l15f-t'], 0],
140['4l', '+3 -b -3 -l 15', [\'tn'], [\'3b3l15-t'], 0],
141['4m', '+3 -b -3 -l 15 -f', [\'tn'], [\'3b3l15f-t'], 0],
142#
143# Merge input files (-m option)
144['5a', '-m -l 24', [\'tn', \'tn'], [\'ml24-t'], 0],
145['5b', '-m -l 24 -f', [\'tn', \'tn'], [\'ml24f-t'], 0],
146['5c', '+3 -m -l 24', [\'tn', \'tn'], [\'3ml24-t'], 0],
147['5d', '+3 -m -l 24 -f', [\'tn', \'tn'], [\'3ml24f-t'], 0],
148['5e', '-m -l 24 -f', [\'0Ft', \'0Ft'], [\'ml24f-0F'], 0],
149['5f', '-m -l 24 -f', [\'0Ft', \'0Fnt'], [\'ml24f-0F'], 0],
150['5g', '-m -l 24 -f', [\'tn', \'0Ft'], [\'ml24f-t-0F'], 0],
151# A full page printed (lines_left_on_page = 0) without a FF found.
152# Avoid an extra empty page if a FF follows in the next input line.
153['5ma', '-m -l 24', [\'tFFn', \'tFnFt'], [\'ml24-FF'], 0],
154['5mb', '-m -l 24', [\'tFFn', \'FFn'], [\'ml24-FF'], 0],
155['5mc', '-m -l 24', [\'tn', \'FFn'], [\'ml24-t-FF'], 0],
156['5md', '-m -l 20', [\'FFn', \'tn'], [\'ml20-FF-t'], 0],
157['5Pma', '+3 -m -l 24', [\'FFn', \'FnFn'], [\'3ml24-FF'], 0],
158['5Pmb', '+3 -m -l 24', [\'tFFn', \'FFn'], [\'3ml24-FF'], 0],
159['5Pmc', '+3 -m -l 24', [\'tn', \'FFn'], [\'3ml24-t-FF'], 0],
160#
161# Do not print header and footer but retain "FF set by Hand"
162# (-t option)
163['6a', '-t -l 24', [\'tn'], [\'t-t'], 0],
164['6b', '-t -l 24 -f', [\'tn'], [\'t-t'], 0],
165['6c', '-t -l 24 -f', [\'tFFt-bl'], [\'t-bl'], 0],
166['6d', '-t -l 24', [\'0FnFnt'], [\'t-0FF'], 0],
167['6e', '-t -l 24', [\'FFn'], [\'t-FF'], 0],
168['6f', '-t -l 24', [\'FnFn'], [\'t-FF'], 0],
169['6g', '-t -l 24 -f', [\'FFn'], [\'t-FF'], 0],
170['6aa', '-t -a -3', [\'0FnFnt'], [\'ta3-0FF'], 0],
171['6ab', '-t -a -3', [\'FFn'], [\'ta3-FF'], 0],
172['6ac', '-t -a -3 -l 24', [\'FnFn'], [\'ta3-FF'], 0],
173['6ba', '-t -b -3', [\'0FnFnt'], [\'tb3-0FF'], 0],
174['6bb', '-t -b -3', [\'FFn'], [\'tb3-FF'], 0],
175['6bc', '-t -b -3 -l 24', [\'FnFn'], [\'tb3-FF'], 0],
176#
177# Do not print header and footer nor "FF set by Hand" (-T option)
178['7a', '-T -l 24', [\'tn'], [\'tt-t'], 0],
179['7b', '-T -l 24 -f', [\'tn'], [\'tt-t'], 0],
180['7c', '-T -l 24 -f', [\'tFFt-bl'], [\'tt-bl'], 0],
181['7d', '-T -l 24', [\'0FnFnt'], [\'tt-0FF'], 0],
182['7e', '-T -l 24', [\'FFn'], [\'tt-FF'], 0],
183['7f', '-T -l 24', [\'FnFn'], [\'tt-FF'], 0],
184['7g', '-T -l 24 -f', [\'FFn'], [\'tt-FF'], 0],
185['7aa', '-T -a -3', [\'0FnFnt'], [\'tta3-0FF'], 0],
186['7ab', '-T -a -3', [\'FFn'], [\'tta3-FF'], 0],
187['7ac', '-T -a -3 -l 24', [\'FnFn'], [\'tta3-FF'], 0],
188['7ba', '-T -b -3', [\'0FnFnt'], [\'ttb3-0FF'], 0],
189['7bb', '-T -b -3', [\'FFn'], [\'ttb3-FF'], 0],
190['7bc', '-T -b -3 -l 24', [\'FnFn'], [\'ttb3-FF'], 0],
191#
192# lhs-truncation of header
193# pr-1.19m: Text line truncation only with column output
194#
195# numbering lines (-n  -N option)
196# skip pages (+FIRST_PAGE[:LAST_PAGE] option)
197['9a', '-n.3 -l 24 -f', [\'tFFt-bl'], [\'nl24f-bl'], 0],
198['9b', '-n.3 -N 15 -l 24 -f', [\'tFFt-bl'], [\'nN15l24f-bl'], 0],
199['9Pa', '-n.3 +2 -l 24 -f', [\'tFFt-bl'], [\'n+2l24f-bl'], 0],
200['9Pb', '-n.3 +3 -l 24 -f', [\'tFFt-bl'], [\'n+3l24f-bl'], 0],
201['9Pc', '-n.3 -N 1 +3 -l 24 -f', [\'tFFt-bl'], [\'nN1+3l24f-bl'], 0],
202['9Pe', '-n.3 +2 -l 24 -f', [\'0FFt'], [\'n+2l24f-0FF'], 0],
203['9Pf', '-n.3 +2 -l 24 -f', [\'0FFnt'], [\'n+2l24f-0FF'], 0],
204['9Pg', '-n.3 +2 -l 24 -f', [\'0FnFt'], [\'n+2l24f-0FF'], 0],
205['9Ph', '-n.3 +2 -l 24 -f', [\'0FnFnt'], [\'n+2l24f-0FF'], 0],
206['9Pi', '-n.3 +2:5 -l 24 -f', [\'0FFt'], [\'n+2-5l24f-0FF'], 0],
207['9Pj', '-n.3 +3 -l 24 -f', [\'0FFt'], [\'n+3l24f-0FF'], 0],
208['9Pk', '-n.3 +3 -l 24 -f', [\'0FFnt'], [\'n+3l24f-0FF'], 0],
209['9Pl', '-n.3 +3 -l 24 -f', [\'0FnFt'], [\'n+3l24f-0FF'], 0],
210['9Pm', '-n.3 +3 -l 24 -f', [\'0FnFnt'], [\'n+3l24f-0FF'], 0],
211['9Pn', '-n.3 +7 -l 24', [\'FFn'], [\'n+7l24-FF'], 0],
212['9Po', '-n.3 +7 -l 24', [\'FFtn'], [\'n+7l24-FF'], 0],
213['9Pp', '-n.3 +7 -l 24', [\'FnFn'], [\'n+7l24-FF'], 0],
214['9Pq', '-n.3 +3:7 -l 24', [\'FnFn'], [\'n+3-7l24-FF'], 0],
215['9Pr', '-n.3 +8 -l 20', [\'tFFn'], [\'n+8l20-FF'], 0],
216['9Ps', '-n.3 +8 -l 20', [\'tFnFt'], [\'n+8l20-FF'], 0],
217['9Pt', '-n.3 +8 -l 20', [\'tFFt'], [\'n+8l20-FF'], 0],
218['9Paa', '-n.3 +5 -a -3 -l 13 -f', [\'0FFt'], [\'n+5a3l13f-0FF'], 0],
219['9Pab', '-n.3 +5 -a -3 -l 13 -f', [\'0FFnt'], [\'n+5a3l13f-0FF'], 0],
220['9Pac', '-n.3 +5 -a -3 -l 13 -f', [\'0FnFt'], [\'n+5a3l13f-0FF'], 0],
221['9Pad', '-n.3 +5 -a -3 -l 13 -f', [\'0FnFnt'], [\'n+5a3l13f-0FF'], 0],
222['9Pae', '-n.3 +6 -a -2 -l 17', [\'FFn'], [\'n+6a2l17-FF'], 0],
223['9Paf', '-n.3 +6 -a -2 -l 17', [\'FFtn'], [\'n+6a2l17-FF'], 0],
224['9Pag', '-n.3 +6 -a -2 -l 17', [\'FnFn'], [\'n+6a2l17-FF'], 0],
225['9Pah', '-n.3 +6 -a -2 -l 17', [\'tFFn'], [\'n+6a2l17-FF'], 0],
226['9Pai', '-n.3 +6 -a -2 -l 17', [\'tFnFt'], [\'n+6a2l17-FF'], 0],
227['9Paj', '-n.3 +6 -a -2 -l 17', [\'tFFt'], [\'n+6a2l17-FF'], 0],
228['9Pak', '-n.3 +4:8 -a -2 -l 17', [\'tFFt'], [\'n+4-8a2l17-FF'], 0],
229['9Pba', '-n.3 +4 -b -2 -l 17 -f', [\'0FFt'], [\'n+4b2l17f-0FF'], 0],
230['9Pbb', '-n.3 +4 -b -2 -l 17 -f', [\'0FFnt'], [\'n+4b2l17f-0FF'], 0],
231['9Pbc', '-n.3 +4 -b -2 -l 17 -f', [\'0FnFt'], [\'n+4b2l17f-0FF'], 0],
232['9Pbd', '-n.3 +4 -b -2 -l 17 -f', [\'0FnFnt'], [\'n+4b2l17f-0FF'], 0],
233['9Pbe', '-n.3 +6 -b -3 -l 13 -f', [\'FFn'], [\'n+6b3l13f-FF'], 0],
234['9Pbf', '-n.3 +6 -b -3 -l 13 -f', [\'FFtn'], [\'n+6b3l13f-FF'], 0],
235['9Pbg', '-n.3 +6 -b -3 -l 13 -f', [\'FnFn'], [\'n+6b3l13f-FF'], 0],
236['9Pbh', '-n.3 +6 -b -3 -l 13 -f', [\'tFFn'], [\'n+6b3l13f-FF'], 0],
237['9Pbi', '-n.3 +6 -b -3 -l 13 -f', [\'tFnFt'], [\'n+6b3l13f-FF'], 0],
238['9Pbj', '-n.3 +6 -b -3 -l 13 -f', [\'tFFt'], [\'n+6b3l13f-FF'], 0],
239['9Pbk', '-n.3 +5:8 -b -3 -l 17 -f', [\'FnFn'], [\'n+5-8b3l17f-FF'], 0],
240['9Pma', '-n.3 +3 -m -l 20 -f', [\'tFFt-bl', \'FnFn'], [\'n+3ml20f-bl-FF'], 0],
241['9Pmb', '-n.3 +3 -m -l 24 -f', [\'tFFt-bl', \'tn'], [\'n+3ml24f-bl-tn'], 0],
242['9Pmc', '-n.3 +3 -m -l 24 -f', [\'tn', \'tFFt-bl'], [\'n+3ml24f-tn-bl'], 0],
243#
244# line truncation  column alignment; header line truncation
245# -w/W PAGE_WIDTH [-J] options
246['10wa', '-W 72 -J -l24 -f', [\'tFFt-ll'], [\'W72Jl24f-ll'], 0],
247['10wb', '-w 72 -J -l24 -f', [\'tFFt-ll'], [\'W72Jl24f-ll'], 0],
248['10wc', '-W 72 -l24 -f', [\'tFFt-ll'], [\'W-72l24f-ll'], 0],
249['10wd', '-w 72 -l24 -f', [\'tFFt-ll'], [\'w72l24f-ll'], 0],
250['10we', '-W 28 -l24 -f', [\'tFFt-ll'], [\'W28l24f-ll'], 0],
251['10wf', '-W 27 -l24 -f', [\'tFFt-ll'], [\'W27l24f-ll'], 0],
252['10wg', '-W 26 -l24 -f', [\'tFFt-ll'], [\'W26l24f-ll'], 0],
253['10wh', '-W 20 -l24 -f', [\'tFFt-ll'], [\'W20l24f-ll'], 0],
254['10ma', '-m -l 24 -f', [\'tFFt-lm', \'loli'], [\'ml24f-lm-lo'], 0],
255['10mb', '-W 35 -m -l 24 -f', [\'tFFt-lm', \'loli'], [\'W35ml24f-lm-lo'], 0],
256['10mc', '-w 35 -m -l 24 -f', [\'tFFt-lm', \'loli'], [\'W35ml24f-lm-lo'], 0],
257['10md', '-J -m -l 24 -f', [\'tFFt-lm', \'loli'], [\'Jml24f-lm-lo'], 0],
258['10me', '-W 35 -J -m -l 24 -f', [\'tFFt-lm', \'loli'], [\'W35Jml24f-lmlo'], 0],
259['10mf', '-w 35 -J -m -l 24 -f', [\'tFFt-lm', \'loli'], [\'W35Jml24f-lmlo'], 0],
260['10mg', '-n.3 -J -m -l 24 -f', [\'tFFt-lm', \'tFFt-lm', \'loli'],
261 [\'nJml24f-lmlmlo'], 0],
262['10mh', '-n.3 -J -m -l 24 -f', [\'tFFt-lm', \'loli', \'tFFt-lm'],
263 [\'nJml24f-lmlolm'], 0],
264['10aa', '-a -3 -l 24 -f', [\'tFFt-lm'], [\'a3l24f-lm'], 0],
265['10ab', '-W 35 -a -3 -l 24 -f', [\'tFFt-lm'], [\'W35a3l24f-lm'], 0],
266['10ac', '-J -a -3 -l 24 -f', [\'tFFt-lm'], [\'Ja3l24f-lm'], 0],
267['10ad', '-W 35 -J -a -3 -l 24 -f', [\'tFFt-lm'], [\'W35Ja3l24f-lm'], 0],
268['10ba', '-b -3 -l 24 -f', [\'tFFt-lm'], [\'b3l24f-lm'], 0],
269['10bb', '-W 35 -b -3 -l 24 -f', [\'tFFt-lm'], [\'W35b3l24f-lm'], 0],
270['10bc', '-J -b -3 -l 24 -f', [\'tFFt-lm'], [\'Jb3l24f-lm'], 0],
271['10bd', '-W 35 -J -b -3 -l 24 -f', [\'tFFt-lm'], [\'W35Jb3l24f-lm'], 0],
272#
273# merge files (-m option)  use separator string (-S option)
274['11sa', '-n.3 -S:--: -m -l 20 -f', [\'tFFt-bl', \'FnFn'],
275 [\'nSml20-bl-FF'], 0],
276['11sb', '-n.3 -S:--: -m -l 24 -f', [\'tFFt-bl', \'FnFn'],
277 [\'nSml24-bl-FF'], 0],
278['11se', '-n.3 -S:--: -m -l 20 -f', [\'tn', \'tn', \'FnFn'],
279 [\'nSml20-t-t-FF'], 0],
280['11sf', '-n.3 -S:--: -m -l 24 -f', [\'tn', \'tn', \'FnFn'],
281 [\'nSml24-t-t-FF'], 0],
282['11sg', '-n.3 -S:--: -m -l 20 -f', [\'tn', \'tn', \'FnFn', \'FnFn'],
283 [\'nSml20-t-tFFFF'], 0],
284['11sh', '-n.3 -S:--: -m -l 24 -f', [\'tn', \'tn', \'FnFn', \'FnFn'],
285 [\'nSml24-t-tFFFF'], 0],
286#
287# left margin (-o option) and separator string (-S option)
288['12aa', '-o3 -a -3 -l24 -f', [\'tn'], [\'o3a3l24f-tn'], 0],
289['12ab', '-o3 -a -3 -S:--: -l24 -f', [\'tn'], [\'o3a3Sl24f-tn'], 0],
290['12ac', '-o3 -a -3 -S:--: -n. -l24 -f', [\'tn'], [\'o3a3Snl24f-tn'], 0],
291['12ba', '-o3 -b -3 -l24 -f', [\'tn'], [\'o3b3l24f-tn'], 0],
292['12bb', '-o3 -b -3 -S:--: -l24 -f', [\'tn'], [\'o3b3Sl24f-tn'], 0],
293['12bc', '-o3 -b -3 -S:--: -n. -l24 -f', [\'tn'], [\'o3b3Snl24f-tn'], 0],
294['12ma', '-o3 -m -l24 -f', [\'tFFt-bl', \'tn'], [\'o3ml24f-bl-tn'], 0],
295['12mb', '-o3 -m -S:--: -l24 -f', [\'tFFt-bl', \'tn'], [\'o3mSl24f-bl-tn'], 0],
296['12mc', '-o3 -m -S:--: -n. -l24 -f', [\'tFFt-bl', \'tn'],
297 [\'o3mSnl24fbltn'], 0],
298['12md', '-o3 -J -m -l24 -f', [\'tFFt-lm', \'loli'], [\'o3Jml24f-lm-lo'], 0],
299#
300#
301# Single column output: POSIX compliant, adapt other UNIXes (SunOS.5.5.1 e.g.)
302# number-separator TAB always an output TAB --> varying number/text-spacing
303['13a', '-t -n -e8', [\'t_tab'], [\'tne8-t_tab'], 0],
304['13b', '-t -n -e8 -o3', [\'t_tab'], [\'tne8o3-t_tab'], 0],
305#
306# POSIX compliant: multi-columns of equal width (unlike SunOS.5.5.1 e.g.)
307# text-tab handling
308['13ba', '-t -n -2 -e8', [\'t_tab'], [\'tn2e8-t_tab'], 0],
309['13bb', '-t -n: -2 -e8', [\'t_tab'], [\'tn_2e8-t_tab'], 0],
310['13bc', '-t -n: -2 -e8 -S----', [\'t_tab'], [\'tn_2e8S-t_tab'], 0],
311['13bd', '-t -n -2 -e8 -o3', [\'t_tab'], [\'tn2e8o3-t_tab'], 0],
312# number-separator TAB not treated as input text-tab, no '-e' expansion
313['13be', '-t -n -2 -e5 -o3', [\'t_tab'], [\'tn2e5o3-t_tab'], 0],
314# input-tab-char ':' not equal default (text) TABs
315['13bf', '-t -n -2 -e:8', [\'t_tab_'], [\'tn2e8-t_tab'], 0],
316#
317# options -w/-s: POSIX-compliant, means adapting the interference of -w/-s
318# with multi-column output from other UNIXes (SunOS e.g.);
319# columns, truncated = 72   /  separator = space :
320['14a', '-2 -f', [\'t_notab'], [\'2f-t_notab'], 0],
321# full lines, no truncation /  separator = TAB :
322['14b', '-2 -s -f', [\'t_notab'], [\'2sf-t_notab'], 0],
323# full lines, no truncation /  separator = ':' :
324['14c', '-2 -s: -f', [\'t_notab'], [\'2s_f-t_notab'], 0],
325# columns, truncated = 60   /  separator = space :
326['14d', '-2 -w60 -f', [\'t_notab'], [\'2w60f-t_notab'], 0],
327# columns, truncated = 60   /  no separator   (SunOS-BUG: line width to small):
328['14e', '-2 -s -w60 -f', [\'t_notab'], [\'2sw60f-t_notab'], 0],
329# columns, truncated = 60   /  separator = ':'  (HP-UX.10.20-2-BUG:
330# ':' missing with -m option):
331['14f', '-2 -s: -w60 -f', [\'t_notab'], [\'2s_w60f-t_nota'], 0],
332#
333# new long-options -W/-S/-J disentangle those options (see also No.'10*')
334# columns, truncated = 72   /  no separator :
335['14g', '-2 -S -f', [\'t_notab'], [\'2-Sf-t_notab'], 0],
336# full lines, no truncation /  separator = TAB :  (Input: -S"<TAB>")
337['14h', '-2 -S"	" -J -f', [\'t_notab'], [\'2sf-t_notab'], 0],
338# columns, truncated = 72   /  separator ':' :
339['14i', '-2 -S: -f', [\'t_notab'], [\'2-S_f-t_notab'], 0],
340# full lines, no truncation /  separator = ':' :
341['14j', '-2 -S: -J -f', [\'t_notab'], [\'2s_f-t_notab'], 0],
342# columns, truncated = 60   /  separator = space:
343['14k', '-2 -W60 -f', [\'t_notab'], [\'2w60f-t_notab'], 0],
344# columns, truncated = 60   /  no separator :
345['14l', '-2 -S -W60 -f', [\'t_notab'], [\'2sw60f-t_notab'], 0],
346# columns, truncated = 60   /  separator = ':' :
347['14m', '-2 -S: -W60 -f', [\'t_notab'], [\'2s_w60f-t_nota'], 0],
348#
349# Tabify multiple spaces, -i option
350# number of input spaces between a and b must not change; be careful
351# comparing with other UNIXes (some other SunOS examples are OK !?)
352# SunOS.5.5.1-BUG: 8 input spaces --> 11 output spaces between a and b;
353['i-opt-a', '-tn -i5 -h ""', "a        b\n", "    1	a	    b\n", 0],
354# SunOS.5.5.1-BUG: 8 input spaces -->  9 output spaces between a and b;
355['i-opt-b', '-tn -i5 -o9 -h ""', "a        b\n",
356 "		   1	a	    b\n", 0],
357#
358# line number overflow not allowed: cut off leading digits;
359# don't adapt other UNIXes, no real standard to follow, a consequent
360# programming of column handling may change the GNU pr concept.
361['ncut-a', '-tn2 -N98', "y\ny\ny\ny\ny\n",
362 "98	y\n99	y\n00	y\n01	y\n02	y\n", 0],
363['ncut-b', '-tn:2 -N98', "y\ny\ny\ny\ny\n",
364 "98:y\n99:y\n00:y\n01:y\n02:y\n", 0],
365
366['margin-0', '-o 0', '', '', 0],
367
368# BUG fixed: that leading space on 3rd line of output should not be there
369['dbl-sp-a', '-d -l 14 -h ""', "1\n2\n",
370 "\n\n-- Date/Time --                                                   "
371 . "Page 1\n\n\n1\n\n2\n\n\n\n\n\n\n", 0],
372# This test failed with 1.22e and earlier.
373['dbl-sp-b', '-d -t', "1\n2\n", "1\n\n2\n\n", 0],
374
375# This test would segfault with 2.0f and earlier.
376['narrow-1', '-W1 -t', "12345\n", "1\n", 0],
377
378# This test would fail with textutils-2.1 and earlier.
379['col-last', '-W3 -t2', "a\nb\nc\n", "a c\nb\n", 0],
380
381# Make sure that -02 is treated just like -2.
382['col-02', '-W3 -t -02',                "a\nb\nc\n", "a c\nb\n", 0],
383# The -2 must override preceding column-count-specifying options.
384['col-2', '-W3 -t -4 --columns=1 -2', "a\nb\nc\n", "a c\nb\n", 0],
385# The --columns=2 must override preceding column-count-specifying options.
386['col-long', '-W3 -t -1 --columns=2',     "a\nb\nc\n", "a c\nb\n", 0],
387# Make sure these fail.
388['col-0', '-0', '', '', 1,
389 "$prog: invalid number of columns: '0'\n", $normalize_strerror],
390['col-inval', '-'.'9'x100, '', '', 1,
391 "$prog: invalid number of columns: '". ('9'x100) ."'\n", $normalize_strerror],
392
393# Before coreutils-5.3.1, --pages=1:-1 would be treated like
394# --pages=1:18446744073709551615.
395['neg-page', '--pages=1:-1', '', '', 1,
396 "$prog: invalid --pages argument '1:-1'\n"],
397
398# Up to coreutils-6.10, this would cause pr to decrement its
399# internal "input_position" below zero and sometimes segfault.
400['neg-inp-pos1', '-t -e', "\b\b\b\b\b\b\tx\n", "        x\n", 0],
401# NB: while there are 4 backspaces in the input, there are only 3 in the output
402['neg-inp-pos2', '-t -e', "abc\b\b\b\b\tx", "abc\b\b\b        x\n", 0],
403
404# This would clobber so much of the heap, it'd segfault or abort every time.
405['smash-heap', '-t -e300', "a".("\b"x50)."\t", "a\b".(" "x300)."\n", 0],
406['smash-heap8', '-t -e',   "a".("\b"x50)."\t", "a\b".(" "x  8)."\n", 0],
407
408# Before coreutils-8.13 page numbers were not handled correctly when
409# headers were not printed (when -l <= 10 or -t or -T specified)
410['page-range', '+1:1 -2 -l1 -s" "',  "a\nb\nc\n", "a b\n", 0],
411
412# This padded with zeros before coreutils-8.21
413['padding1', '-t -n,15', "1\n", (" "x 14)."1,1\n", 0],
414# This crashed with divide by zero before coreutils-8.21
415['padding2', '-t -n,64', "1\n", (" "x 63)."1,1\n", 0],
416# Ensure we handle buffer truncation correctly
417['padding3', '-t -N1000000 -n,1', "1\n", "0,1\n", 0],
418
419# This entered an infinite loop before coreutils-9.4
420['page-length1', '-dl1', "", "", 0],
421);
422
423# Convert the above old-style test vectors to the newer
424# format used by Coreutils.pm.
425
426my $pfx = "$ENV{abs_srcdir}/tests/pr";
427
428# Normalize otherwise-variable output page headers.
429my $common_option_prefix = '--date-format="-- Date/Time --" -h x';
430
431my @Tests;
432foreach my $t (@tv)
433  {
434    my ($test_name, $flags, $in, $exp, $ret, $err_msg, $err_sub) = @$t;
435    my $new_ent = [$test_name, $common_option_prefix, $flags];
436    if (!ref $in)
437      {
438        push @$new_ent, {IN=>$in};
439      }
440    else
441      {
442        foreach my $e (@$in)
443          {
444            my $file_name = $$e;
445            push @$new_ent, {IN=>{"$pfx/$file_name"=>undef}};
446          }
447      }
448    if (!ref $exp)
449      {
450        push @$new_ent, {OUT=>$exp};
451      }
452    else
453      {
454        foreach my $e (@$exp)
455          {
456            my $file_name = $$e;
457            push @$new_ent, {OUT=>{"$pfx/$file_name"=>undef}};
458          }
459      }
460    $ret
461      and push @$new_ent, {EXIT=>$ret}, {ERR=>$err_msg}, {ERR_SUBST=>$err_sub};
462    push @Tests, $new_ent;
463  }
464
465# Exercise a bug with pr -m -s (commit 553d347)
466push @Tests,
467   ['merge-w-tabs', '-m -s -t',
468    {IN=>{1=>"a\tb\tc\n"}},
469    {IN=>{2=>"m\tn\to\n"}},
470    {IN=>{3=>"x\ty\tz\n"}},
471     {OUT=>join("\t", qw(a b c m n o x y z)) . "\n"} ];
472# -s and -s$'\t' use different code paths
473push @Tests,
474   ['merge-w-tabs-sepstr', "-m -s'\t' -t",
475    {IN=>{1=>"a\tb\tc\n"}},
476    {IN=>{2=>"m\tn\to\n"}},
477    {IN=>{3=>"x\ty\tz\n"}},
478     {OUT=>join("\t", qw(a b c m n o x y z)) . "\n"} ];
479
480# Exercise a variant of the bug with pr -m -s (commit 553d347)
481# test 2 files, too (merging 3 files automatically aligns columns on TAB stops)
482push @Tests,
483   ['merge-2-w-tabs', '-m -s -t',
484    {IN=>{1=>"a\tb\tc\n"}},
485    {IN=>{2=>"m\tn\to\n"}},
486     {OUT=>join("\t", qw(a b c m n o)) . "\n"} ];
487# -s and -s$'\t' use different code paths
488push @Tests,
489   ['merge-2-w-tabs-sepstr', "-m -s'\t' -t",
490    {IN=>{1=>"a\tb\tc\n"}},
491    {IN=>{2=>"m\tn\to\n"}},
492     {OUT=>join("\t", qw(a b c m n o)) . "\n"} ];
493
494# This resulted in reading invalid memory before coreutils-8.26
495push @Tests,
496   ['asan1', "-m -S'\t\t\t' -t",
497    {IN=>{1=>"a\n"}},
498    {IN=>{2=>"a\n"}},
499     {OUT=>"a\t\t\t\t  \t\t\ta\n"} ];
500
501# Exercise a bug with pr -t -2 (bug #46422)
502push @Tests,
503   ['mcol-w-tabs', '-t -2',
504    {IN=>"x\tx\tx\tx\tx\nx\tx\tx\tx\tx\n"},
505     {OUT=>"x\tx\tx\tx\tx   x\t    x\t    x\t    x\t    x\n"} ];
506
507# generalize case from commit 553d347 (problem results from -s, not -m)
508push @Tests,
509   ['mcol-w-tabs-w-tabsep', '-t -2 -s',
510    {IN=>"x\tx\tx\tx\tx\nx\tx\tx\tx\tx\n"},
511     {OUT=>"x\tx\tx\tx\tx\tx\tx\tx\tx\tx\n"} ];
512# -s and -s$'\t' use different code paths
513push @Tests,
514   ['mcol-w-tabs-w-tabsep-sepstr', "-t -2 -s'\t'",
515    {IN=>"x\tx\tx\tx\tx\nx\tx\tx\tx\tx\n"},
516     {OUT=>"x\tx\tx\tx\tx\tx\tx\tx\tx\tx\n"} ];
517
518@Tests = triple_test \@Tests;
519
520my $save_temps = $ENV{DEBUG};
521my $verbose = $ENV{VERBOSE};
522
523my $fail = run_tests ($prog, $prog, \@Tests, $save_temps, $verbose);
524exit $fail;
525