xref: /freebsd/usr.bin/gzip/tests/zdiff_test.sh (revision 02e9120893770924227138ba49df1edb3896112a)
1#
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright (c) 2022 Kyle Evans <kevans@FreeBSD.org>
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27
28specials="foo'bar foo\"bar foo\$bar"
29
30prepare_files()
31{
32	compressfunc="$1"
33	compresssuffix="$2"
34
35	echo "foo" > foo
36
37	for f in $specials foo; do
38		[ "$f" == "foo" ] || cp foo "$f"
39		atf_check "$compressfunc" -k "$f"
40		atf_check tar -ckf "$f.tar" "$f"
41		atf_check -o save:"$f.$compresssuffix" \
42		    "$compressfunc" -c "$f.tar"
43
44		# Regenerate $f.tar to create a diff from the .$compresssuffix
45		# file, too.
46		echo "bar" >> "$f"
47		atf_check tar -ckf "$f.tar" "$f"
48	done
49}
50
51atf_test_case gzip
52gzip_body()
53{
54	prepare_files gzip tgz
55	cp foo.gz foo.Z
56
57	for f in foo $specials; do
58		atf_check -s exit:1 -o file:"$(atf_get_srcdir)"/foo.diff \
59		    zdiff "$f.gz"
60	done
61
62	atf_check -s exit:1 -o file:"$(atf_get_srcdir)"/foo.diff zdiff foo.Z
63
64	for f in foo $specials; do
65		rm "$f"
66		atf_check -s exit:1 -o match:"Binary files" zdiff "$f.tgz"
67	done
68}
69
70atf_test_case bzip
71bzip_body()
72{
73	prepare_files bzip2 tbz2
74	cp foo.bz2 foo.bz
75
76	for f in foo $specials; do
77		atf_check -s exit:1 -o file:"$(atf_get_srcdir)"/foo.diff \
78		    zdiff "$f.bz2"
79	done
80
81	atf_check -s exit:1 -o file:"$(atf_get_srcdir)"/foo.diff zdiff foo.bz
82
83	for f in foo $specials; do
84		rm "$f"
85		atf_check -s exit:1 -o match:"Binary files" zdiff "$f.tbz2"
86	done
87}
88
89atf_test_case xzip
90xzip_body()
91{
92	prepare_files xz txz
93	cp foo.xz foo.lzma
94
95	for f in foo $specials; do
96		atf_check -s exit:1 -o file:"$(atf_get_srcdir)"/foo.diff \
97		    zdiff "$f.xz"
98	done
99
100	atf_check -s exit:1 -o file:"$(atf_get_srcdir)"/foo.diff zdiff foo.lzma
101
102	for f in foo $specials; do
103		rm "$f"
104		atf_check -s exit:1 -o match:"Binary files" zdiff "$f.txz"
105	done
106}
107
108atf_test_case unknown
109unknown_body()
110{
111	prepare_files xz fxz
112
113	for f in foo $specials; do
114		atf_check -s exit:1 -e match:"unknown suffix$" zdiff "$f.fxz"
115	done
116}
117
118atf_init_test_cases()
119{
120
121	atf_add_test_case gzip
122	atf_add_test_case bzip
123	atf_add_test_case xzip
124	atf_add_test_case unknown
125}
126