xref: /aosp_15_r20/external/zstd/tests/gzip/keep.sh (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui#!/bin/sh
2*01826a49SYabin Cui# Exercise the --keep option.
3*01826a49SYabin Cui
4*01826a49SYabin Cui# Copyright (C) 2013-2016 Free Software Foundation, Inc.
5*01826a49SYabin Cui
6*01826a49SYabin Cui# This program is free software: you can redistribute it and/or modify
7*01826a49SYabin Cui# it under the terms of the GNU General Public License as published by
8*01826a49SYabin Cui# the Free Software Foundation, either version 3 of the License, or
9*01826a49SYabin Cui# (at your option) any later version.
10*01826a49SYabin Cui
11*01826a49SYabin Cui# This program is distributed in the hope that it will be useful,
12*01826a49SYabin Cui# but WITHOUT ANY WARRANTY; without even the implied warranty of
13*01826a49SYabin Cui# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*01826a49SYabin Cui# GNU General Public License for more details.
15*01826a49SYabin Cui
16*01826a49SYabin Cui# You should have received a copy of the GNU General Public License
17*01826a49SYabin Cui# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18*01826a49SYabin Cui# limit so don't run it by default.
19*01826a49SYabin Cui
20*01826a49SYabin Cui. "${srcdir=.}/init.sh"; path_prepend_ .
21*01826a49SYabin Cui
22*01826a49SYabin Cuiecho fooooooooo > in || framework_failure_
23*01826a49SYabin Cuicp in orig || framework_failure_
24*01826a49SYabin Cui
25*01826a49SYabin Cuifail=0
26*01826a49SYabin Cui
27*01826a49SYabin Cui# Compress and decompress both with and without --keep.
28*01826a49SYabin Cuifor k in --keep ''; do
29*01826a49SYabin Cui  # With --keep, the source must be retained, otherwise, it must be removed.
30*01826a49SYabin Cui  case $k in --keep) op='||' ;; *) op='&&' ;; esac
31*01826a49SYabin Cui
32*01826a49SYabin Cui  gzip $k in || fail=1
33*01826a49SYabin Cui  eval "test -f in $op fail=1"
34*01826a49SYabin Cui  test -f in.gz || fail=1
35*01826a49SYabin Cui  rm -f in || fail=1
36*01826a49SYabin Cui
37*01826a49SYabin Cui  gzip -d $k in.gz || fail=1
38*01826a49SYabin Cui  eval "test -f in.gz $op fail=1"
39*01826a49SYabin Cui  test -f in || fail=1
40*01826a49SYabin Cui  compare in orig || fail=1
41*01826a49SYabin Cui  rm -f in.gz || fail=1
42*01826a49SYabin Cuidone
43*01826a49SYabin Cui
44*01826a49SYabin Cuicp orig in || framework_failure_
45*01826a49SYabin Cuilog=$(gzip -kv in 2>&1) || fail=1
46*01826a49SYabin Cuicase $log in
47*01826a49SYabin Cui  *'created in.gz'*) ;;
48*01826a49SYabin Cui  *) fail=1;;
49*01826a49SYabin Cuiesac
50*01826a49SYabin Cui
51*01826a49SYabin CuiExit $fail
52