1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) International Business Machines Corp., 2001 4# Copyright (c) Cyril Hrubis <chrubis@suse.cz> 5# Author: Manoj Iyer <manjo@mail.utexas.edu> 6# 7# Tests basic functionality of unzip command. 8 9TST_SETUP=setup 10TST_TESTFUNC=do_test 11TST_NEEDS_TMPDIR=1 12TST_NEEDS_CMDS="unzip" 13. tst_test.sh 14 15EXTRACT_MATCH="extracting" 16 17if unzip 2>&1 | grep -q 'BusyBox'; then 18 EXTRACT_MATCH="inflating" 19fi 20 21setup() 22{ 23 cat > unzip_exp.out <<EOF 24Archive: $TST_DATAROOT/test.zip 25 creating: dir/ 26 creating: dir/d1/ 27 creating: dir/d2/ 28 creating: dir/d3/ 29 creating: dir/d4/ 30 $EXTRACT_MATCH: dir/d1/f1 31 $EXTRACT_MATCH: dir/d1/f2 32 $EXTRACT_MATCH: dir/d1/f3 33 creating: dir/d2/d1/ 34 creating: dir/d2/d2/ 35 creating: dir/d2/d3/ 36 $EXTRACT_MATCH: dir/d2/f1 37 $EXTRACT_MATCH: dir/d2/f2 38 $EXTRACT_MATCH: dir/d2/f3 39 creating: dir/d3/d1/ 40 creating: dir/d3/d2/ 41 creating: dir/d3/d3/ 42EOF 43} 44 45stable_ls() 46{ 47 local i 48 49 for i in $(echo "$1/*" | sort); do 50 51 if ! [ -e "$i" ]; then 52 return 53 fi 54 55 echo "$i" 56 57 if [ -d "$i" ]; then 58 stable_ls "$i" 59 fi 60 done 61} 62 63do_test() 64{ 65 EXPECT_PASS unzip "$TST_DATAROOT/test.zip" \> unzip.out 66 67 if diff -w unzip_exp.out unzip.out; then 68 tst_res TPASS "Unzip output is correct" 69 else 70 tst_res TFAIL "Unzip output is incorrect" 71 cat unzip.out 72 fi 73 74 stable_ls "dir" > dir.out 75 76 if diff "$TST_DATAROOT/dir.out" dir.out; then 77 tst_res TPASS "Files unzipped correctly" 78 else 79 tst_res TFAIL "Files unzipped incorrectly" 80 cat dir.out 81 fi 82 83 ROD rm -rf "dir/" 84} 85 86tst_run 87