]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
Add initial support for ls(1) style "-d" argument to "bup ls".
[bup.git] / t / test-ls.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh
3
4 set -o pipefail
5
6 top="$(WVPASS pwd)" || exit $?
7 tmpdir="$(WVPASS wvmktempdir)" || exit $?
8
9 export BUP_DIR="$tmpdir/bup"
10 export GIT_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 export TZ=UTC
15
16 WVPASS bup init
17 WVPASS cd "$tmpdir"
18
19 WVPASS mkdir src
20 WVPASS touch -t 196907202018 src/.dotfile
21 WVPASS bup random 1k > src/file
22 WVPASS touch -t 196907202018 src/file
23 (WVPASS cd src; WVPASS ln -s file symlink) || exit $?
24 WVPASS mkfifo src/fifo
25 WVPASS touch -t 196907202018 src/fifo
26 WVPASS "$top"/t/mksock src/socket
27 WVPASS touch -t 196907202018 src/socket
28 WVPASS touch -t 196907202018 src/executable
29 WVPASS chmod u+x src/executable
30 WVPASS touch -t 196907202018 src/executable
31 WVPASS touch -t 196907202018 src
32 WVPASS touch -t 196907202018 .
33 WVPASS chmod -R u=rwX,g-rwx,o-rwx .
34 WVPASS bup index src
35 WVPASS bup save -n src src
36
37
38 WVSTART "ls (short)"
39
40 WVPASSEQ "$(WVPASS bup ls /)" "src"
41
42 WVPASSEQ "$(WVPASS bup ls -A /)" ".commit
43 .tag
44 src"
45
46 WVPASSEQ "$(WVPASS bup ls -AF /)" ".commit/
47 .tag/
48 src/"
49
50 WVPASSEQ "$(WVPASS bup ls -a /)" ".
51 ..
52 .commit
53 .tag
54 src"
55
56 WVPASSEQ "$(WVPASS bup ls -aF /)" "./
57 ../
58 .commit/
59 .tag/
60 src/"
61
62 WVPASSEQ "$(WVPASS bup ls src/latest/"$tmpdir"/src)" "executable
63 fifo
64 file
65 socket
66 symlink"
67
68 WVPASSEQ "$(WVPASS bup ls -A src/latest/"$tmpdir"/src)" ".dotfile
69 executable
70 fifo
71 file
72 socket
73 symlink"
74
75 WVPASSEQ "$(WVPASS bup ls -a src/latest/"$tmpdir"/src)" ".
76 ..
77 .dotfile
78 executable
79 fifo
80 file
81 socket
82 symlink"
83
84 WVPASSEQ "$(WVPASS bup ls -F src/latest/"$tmpdir"/src)" "executable*
85 fifo|
86 file
87 socket=
88 symlink@"
89
90 WVPASSEQ "$(WVPASS bup ls --file-type src/latest/"$tmpdir"/src)" "executable
91 fifo|
92 file
93 socket=
94 symlink@"
95
96 WVPASSEQ "$(WVPASS bup ls -d src/latest/"$tmpdir"/src)" "src/latest$tmpdir/src"
97
98
99 WVSTART "ls (long)"
100
101 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
102 "d--------- ?/? 0 1970-01-01 00:00 src"
103
104 WVPASSEQ "$(WVPASS bup ls -lA / | tr -s ' ' ' ')" \
105 "d--------- ?/? 0 1970-01-01 00:00 .commit
106 d--------- ?/? 0 1970-01-01 00:00 .tag
107 d--------- ?/? 0 1970-01-01 00:00 src"
108
109 WVPASSEQ "$(WVPASS bup ls -lAF / | tr -s ' ' ' ')" \
110 "d--------- ?/? 0 1970-01-01 00:00 .commit/
111 d--------- ?/? 0 1970-01-01 00:00 .tag/
112 d--------- ?/? 0 1970-01-01 00:00 src/"
113
114 WVPASSEQ "$(WVPASS bup ls -la / | tr -s ' ' ' ')" \
115 "d--------- ?/? 0 1970-01-01 00:00 .
116 d--------- ?/? 0 1970-01-01 00:00 ..
117 d--------- ?/? 0 1970-01-01 00:00 .commit
118 d--------- ?/? 0 1970-01-01 00:00 .tag
119 d--------- ?/? 0 1970-01-01 00:00 src"
120
121 WVPASSEQ "$(WVPASS bup ls -laF / | tr -s ' ' ' ')" \
122 "d--------- ?/? 0 1970-01-01 00:00 ./
123 d--------- ?/? 0 1970-01-01 00:00 ../
124 d--------- ?/? 0 1970-01-01 00:00 .commit/
125 d--------- ?/? 0 1970-01-01 00:00 .tag/
126 d--------- ?/? 0 1970-01-01 00:00 src/"
127
128 symlink_mode="$(WVPASS ls -l src/symlink | cut -b -10)" || exit $?
129
130 symlink_bup_info="$(WVPASS bup ls -l src/latest"$tmpdir"/src | grep symlink)" \
131     || exit $?
132 symlink_date="$(WVPASS echo "$symlink_bup_info" \
133   | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')" \
134     || exit $?
135
136 if test "$(uname -s)" != NetBSD; then
137     symlink_size="$(WVPASS python -c "import os
138 print os.lstat('src/symlink').st_size")" || exit $?
139 else
140     # NetBSD appears to return varying sizes, so for now, just ignore it.
141     symlink_size="$(WVPASS echo "$symlink_bup_info" \
142       | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $1')" \
143         || exit $?
144 fi
145
146 uid="$(id -u)" || exit $?
147 gid="$(python -c 'import os; print os.stat("src").st_gid')" || exit $?
148 user="$(id -un)" || exit $?
149 group="$(python -c 'import grp, os;
150 print grp.getgrgid(os.stat("src").st_gid)[0]')" || exit $?
151
152 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
153 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
154 prw------- $user/$group 0 1969-07-20 20:18 fifo
155 -rw------- $user/$group 1024 1969-07-20 20:18 file
156 srwx------ $user/$group 0 1969-07-20 20:18 socket
157 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
158
159 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
160 "drwx------ $user/$group 0 1969-07-20 20:18 .
161 drwx------ $user/$group 0 1969-07-20 20:18 ..
162 -rw------- $user/$group 0 1969-07-20 20:18 .dotfile
163 -rwx------ $user/$group 0 1969-07-20 20:18 executable
164 prw------- $user/$group 0 1969-07-20 20:18 fifo
165 -rw------- $user/$group 1024 1969-07-20 20:18 file
166 srwx------ $user/$group 0 1969-07-20 20:18 socket
167 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
168
169 WVPASSEQ "$(bup ls -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
170 "-rw------- $user/$group 0 1969-07-20 20:18 .dotfile
171 -rwx------ $user/$group 0 1969-07-20 20:18 executable
172 prw------- $user/$group 0 1969-07-20 20:18 fifo
173 -rw------- $user/$group 1024 1969-07-20 20:18 file
174 srwx------ $user/$group 0 1969-07-20 20:18 socket
175 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
176
177 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
178 "-rwx------ $user/$group 0 1969-07-20 20:18 executable*
179 prw------- $user/$group 0 1969-07-20 20:18 fifo|
180 -rw------- $user/$group 1024 1969-07-20 20:18 file
181 srwx------ $user/$group 0 1969-07-20 20:18 socket=
182 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
183
184 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
185 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
186 prw------- $user/$group 0 1969-07-20 20:18 fifo|
187 -rw------- $user/$group 1024 1969-07-20 20:18 file
188 srwx------ $user/$group 0 1969-07-20 20:18 socket=
189 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
190
191 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
192 "-rwx------ $uid/$gid 0 1969-07-20 20:18 executable
193 prw------- $uid/$gid 0 1969-07-20 20:18 fifo
194 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
195 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
196 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
197
198 WVPASSEQ "$(bup ls -ld "src/latest$tmpdir/src" | tr -s ' ' ' ')" \
199 "drwx------ $user/$group 0 1969-07-20 20:18 src/latest$tmpdir/src"
200
201
202 WVSTART "ls (backup set - long)"
203 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
204 "l--------- ?/?
205 l--------- ?/?"
206
207
208 WVSTART "ls (dates TZ != UTC)"
209 export TZ=US/Central
210 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
211 symlink_date_central="$(echo "$symlink_date_central" \
212   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
213 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
214 "-rwx------ $uid/$gid 0 1969-07-20 15:18 executable
215 prw------- $uid/$gid 0 1969-07-20 15:18 fifo
216 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
217 srwx------ $uid/$gid 0 1969-07-20 15:18 socket
218 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
219 unset TZ
220
221
222 WVPASS rm -rf "$tmpdir"