Imported Upstream version 1.23.0
[platform/upstream/groff.git] / src / preproc / preconv / tests / do-not-seek-the-unseekable.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2022 Free Software Foundation, Inc.
4 #
5 # This file is part of groff.
6 #
7 # groff is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or (at your
10 # option) any later version.
11 #
12 # groff is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 # for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 set -e
22
23 preconv="${abs_top_builddir:-.}/preconv"
24
25 fail=
26
27 wail () {
28     echo FAILED >&2
29     fail=YES
30 }
31
32 # Scrape debugging output to see if we're skipping unseekable streams.
33 # This is fragile, but we don't want to lock the language of diagnostic
34 # messages (especially debugging ones).  If this test fails, check the
35 # text of the command's debugging output for a mismatch before
36 # investigating deeper problems.
37
38 echo "testing seekability of file operand '-'" >&2
39 output=$(printf '' | "$preconv" -d - 2>&1)
40 echo "$output" | grep -q "stream is not seekable" || wail
41
42 # /dev/stdin might not exist in a chroot.  Or, if it's not (a symbolic
43 # link to) a character special device, the next test will not be valid,
44 # as when using GNU Make's `-j` option.
45 #
46 # Similarly, we must have a controlling terminal.
47 test -z "$fail"
48 echo "skipping if /dev/stdin is not a character device" >&2
49 test -c /dev/stdin || exit 77 # skip
50 echo "skipping if there is no controlling terminal" >&2
51 test "$(tty)" != "not a tty" || exit 77 # skip
52
53 echo "testing seekability of standard input stream" >&2
54 output=$(printf '' | "$preconv" -d /dev/stdin 2>&1)
55 echo "$output" | grep -q "stream is not seekable" || wail
56
57 test -z "$fail"
58
59 # vim:set ai et sw=4 ts=4 tw=72: