blob: cef16b65e55efe33707ef043319aa69f271a6f1b [file] [log] [blame]
Denys Vlasenkobf224752009-11-29 19:09:29 +01001#!/bin/sh
2# Copyright 2009 by Denys Vlasenko
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003# Licensed under GPLv2, see file LICENSE in this source tree.
Denys Vlasenkobf224752009-11-29 19:09:29 +01004
5. ./testing.sh
6
Dan Fandrich775965d2010-08-10 23:33:57 -07007unset LANG
8unset LANGUAGE
9unset LC_COLLATE
10unset LC_ALL
11umask 022
12
Denys Vlasenko02365a62010-04-09 10:52:52 +020013rm -rf tar.tempdir 2>/dev/null
14mkdir tar.tempdir && cd tar.tempdir || exit 1
Denys Vlasenkobf224752009-11-29 19:09:29 +010015
16# testing "test name" "script" "expected result" "file input" "stdin"
17
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020018optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenko02365a62010-04-09 10:52:52 +020019testing "tar hardlinks and repeated files" '\
Denys Vlasenko425ad9c2009-12-16 22:46:01 +010020rm -rf input_* test.tar 2>/dev/null
21>input_hard1
Denys Vlasenkobf224752009-11-29 19:09:29 +010022ln input_hard1 input_hard2
23mkdir input_dir
24>input_dir/file
Denys Vlasenko02365a62010-04-09 10:52:52 +020025chmod -R 644 *
26chmod 755 input_dir
Denys Vlasenkobf224752009-11-29 19:09:29 +010027tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
Denys Vlasenko02365a62010-04-09 10:52:52 +020028tar tvf test.tar | sed "s/.*[0-9] input/input/"
29tar xf test.tar 2>&1
30echo Ok: $?
31ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
32' "\
Denys Vlasenko425ad9c2009-12-16 22:46:01 +010033input
Denys Vlasenkobf224752009-11-29 19:09:29 +010034input_dir/
35input_dir/file
36input_hard1
37input_hard2 -> input_hard1
38input_hard1 -> input_hard1
39input_dir/
40input_dir/file
41input
Denys Vlasenko02365a62010-04-09 10:52:52 +020042Ok: 0
43-rw-r--r-- input_dir/file
44drwxr-xr-x input_dir
45-rw-r--r-- input_hard1
46-rw-r--r-- input_hard2
47" \
48"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +020049SKIP=
Denys Vlasenko02365a62010-04-09 10:52:52 +020050
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020051optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenko02365a62010-04-09 10:52:52 +020052testing "tar hardlinks mode" '\
53rm -rf input_* test.tar 2>/dev/null
54>input_hard1
55chmod 741 input_hard1
56ln input_hard1 input_hard2
57mkdir input_dir
58chmod 550 input_dir
59ln input_hard1 input_dir
60ln input_hard2 input_dir
61tar cf test.tar input_*
62tar tvf test.tar | sed "s/.*[0-9] input/input/"
63tar xf test.tar 2>&1
64echo Ok: $?
65ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
66' "\
67input_dir/
68input_dir/input_hard1
69input_dir/input_hard2 -> input_dir/input_hard1
70input_hard1 -> input_dir/input_hard1
71input_hard2 -> input_dir/input_hard1
72Ok: 0
73-rwxr----x input_dir/input_hard1
74-rwxr----x input_dir/input_hard2
75dr-xr-x--- input_dir
76-rwxr----x input_hard1
77-rwxr----x input_hard2
Denys Vlasenkobf224752009-11-29 19:09:29 +010078" \
79"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +020080SKIP=
Denys Vlasenkobf224752009-11-29 19:09:29 +010081
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020082optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020083testing "tar symlinks mode" '\
84rm -rf input_* test.tar 2>/dev/null
85>input_file
86chmod 741 input_file
87ln -s input_file input_soft
88mkdir input_dir
89chmod 550 input_dir
90ln input_file input_dir
91ln input_soft input_dir
92tar cf test.tar input_*
Denys Vlasenkoe82cf332010-05-12 15:59:32 +020093tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
Denys Vlasenkoe69ad872010-04-09 14:11:45 +020094tar xf test.tar 2>&1
95echo Ok: $?
96ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
97' "\
98input_dir/
99input_dir/input_file
100input_dir/input_soft -> input_file
101input_file -> input_dir/input_file
102input_soft -> input_dir/input_soft
103Ok: 0
104-rwxr----x input_dir/input_file
105lrwxrwxrwx input_file
106dr-xr-x--- input_dir
107-rwxr----x input_file
108lrwxrwxrwx input_file
109" \
110"" ""
Denys Vlasenkoe3d90a92010-05-10 05:53:16 +0200111SKIP=
Denys Vlasenkoe69ad872010-04-09 14:11:45 +0200112
Denys Vlasenkoda138242010-05-11 12:02:48 +0200113optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100114testing "tar --overwrite" "\
115rm -rf input_* test.tar 2>/dev/null
116ln input input_hard
117tar cf test.tar input_hard
118echo WRONG >input
119# --overwrite opens 'input_hard' without unlinking,
120# thus 'input_hard' still linked to 'input' and we write 'Ok' into it
121tar xf test.tar --overwrite 2>&1 && cat input
122" "\
123Ok
124" \
125"Ok\n" ""
Chris Metcalf208d35d2010-04-02 09:57:27 +0200126SKIP=
Denys Vlasenko8a936cf2009-12-16 23:18:59 +0100127
Denys Vlasenko02365a62010-04-09 10:52:52 +0200128cd .. && rm -rf tar.tempdir || exit 1
Denys Vlasenkobf224752009-11-29 19:09:29 +0100129
130exit $FAILCOUNT