randomconfig testsuite fixes
[oweals/busybox.git] / testsuite / tar.tests
1 #!/bin/sh
2 # Copyright 2009 by Denys Vlasenko
3 # Licensed under GPL v2, see file LICENSE for details.
4
5 . ./testing.sh
6
7 rm -rf tar.tempdir 2>/dev/null
8 mkdir tar.tempdir && cd tar.tempdir || exit 1
9
10 # testing "test name" "script" "expected result" "file input" "stdin"
11
12 optional FEATURE_TAR_CREATE
13 testing "tar hardlinks and repeated files" '\
14 rm -rf input_* test.tar 2>/dev/null
15 >input_hard1
16 ln input_hard1 input_hard2
17 mkdir input_dir
18 >input_dir/file
19 chmod -R 644 *
20 chmod    755 input_dir
21 tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
22 tar tvf test.tar | sed "s/.*[0-9] input/input/"
23 tar xf test.tar 2>&1
24 echo Ok: $?
25 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
26 ' "\
27 input
28 input_dir/
29 input_dir/file
30 input_hard1
31 input_hard2 -> input_hard1
32 input_hard1 -> input_hard1
33 input_dir/
34 input_dir/file
35 input
36 Ok: 0
37 -rw-r--r-- input_dir/file
38 drwxr-xr-x input_dir
39 -rw-r--r-- input_hard1
40 -rw-r--r-- input_hard2
41 " \
42 "" ""
43 SKIP=
44
45 optional FEATURE_TAR_CREATE
46 testing "tar hardlinks mode" '\
47 rm -rf input_* test.tar 2>/dev/null
48 >input_hard1
49 chmod 741 input_hard1
50 ln input_hard1 input_hard2
51 mkdir input_dir
52 chmod 550 input_dir
53 ln input_hard1 input_dir
54 ln input_hard2 input_dir
55 tar cf test.tar input_*
56 tar tvf test.tar | sed "s/.*[0-9] input/input/"
57 tar xf test.tar 2>&1
58 echo Ok: $?
59 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
60 ' "\
61 input_dir/
62 input_dir/input_hard1
63 input_dir/input_hard2 -> input_dir/input_hard1
64 input_hard1 -> input_dir/input_hard1
65 input_hard2 -> input_dir/input_hard1
66 Ok: 0
67 -rwxr----x input_dir/input_hard1
68 -rwxr----x input_dir/input_hard2
69 dr-xr-x--- input_dir
70 -rwxr----x input_hard1
71 -rwxr----x input_hard2
72 " \
73 "" ""
74 SKIP=
75
76 optional FEATURE_TAR_CREATE
77 testing "tar symlinks mode" '\
78 rm -rf input_* test.tar 2>/dev/null
79 >input_file
80 chmod 741 input_file
81 ln -s input_file input_soft
82 mkdir input_dir
83 chmod 550 input_dir
84 ln input_file input_dir
85 ln input_soft input_dir
86 tar cf test.tar input_*
87 tar tvf test.tar | sed "s/.*[0-9] input/input/"
88 tar xf test.tar 2>&1
89 echo Ok: $?
90 ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
91 ' "\
92 input_dir/
93 input_dir/input_file
94 input_dir/input_soft -> input_file
95 input_file -> input_dir/input_file
96 input_soft -> input_dir/input_soft
97 Ok: 0
98 -rwxr----x input_dir/input_file
99 lrwxrwxrwx input_file
100 dr-xr-x--- input_dir
101 -rwxr----x input_file
102 lrwxrwxrwx input_file
103 " \
104 "" ""
105 SKIP=
106
107 optional FEATURE_TAR_LONG_OPTIONS
108 testing "tar --overwrite" "\
109 rm -rf input_* test.tar 2>/dev/null
110 ln input input_hard
111 tar cf test.tar input_hard
112 echo WRONG >input
113 # --overwrite opens 'input_hard' without unlinking,
114 # thus 'input_hard' still linked to 'input' and we write 'Ok' into it
115 tar xf test.tar --overwrite 2>&1 && cat input
116 " "\
117 Ok
118 " \
119 "Ok\n" ""
120 SKIP=
121
122 cd .. && rm -rf tar.tempdir || exit 1
123
124 exit $FAILCOUNT