1#!/bin/sh
2# Test use of compression by sort
3
4# Copyright (C) 2007-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
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ sort
21require_trap_signame_
22
23seq -w 2000 > exp || framework_failure_
24tac exp > in || framework_failure_
25
26# This should force the use of temp files
27sort -S 1k in > out || fail=1
28compare exp out || fail=1
29
30# Create our own gzip program that will be used as the default
31cat <<EOF > gzip || framework_failure_
32#!$SHELL
33tr 41 14
34touch ok
35EOF
36
37chmod +x gzip
38
39# Ensure 'sort' is immune to parent's SIGCHLD handler
40# Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh.
41(
42  trap '' CHLD
43
44  # This should force the use of child processes for "compression"
45  PATH=.:$PATH exec sort -S 1k --compress-program=gzip in > /dev/null
46) || fail=1
47
48# This will find our new gzip in PATH
49PATH=.:$PATH sort -S 1k --compress-program=gzip in > out || fail=1
50compare exp out || fail=1
51test -f ok || fail=1
52rm -f ok
53
54# This is to make sure it works with no compression.
55PATH=.:$PATH sort -S 1k in > out || fail=1
56compare exp out || fail=1
57test -f ok && fail=1
58
59# This is to make sure we can use something other than gzip
60mv gzip dzip || fail=1
61sort --compress-program=./dzip -S 1k in > out || fail=1
62compare exp out || fail=1
63test -f ok || fail=1
64rm -f ok
65
66# Make sure it can find other programs in PATH correctly
67PATH=.:$PATH sort --compress-program=dzip -S 1k in > out || fail=1
68compare exp out || fail=1
69test -f ok || fail=1
70rm -f dzip ok
71
72Exit $fail
73