]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
c4f4a1a624d482e20d55208b0433d351fe4eac5f
[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 WVSTART "ls (short)"
38
39 WVPASSEQ "$(WVPASS bup ls /)" "src"
40
41 WVPASSEQ "$(WVPASS bup ls -A /)" ".commit
42 .tag
43 src"
44
45 WVPASSEQ "$(WVPASS bup ls -AF /)" ".commit/
46 .tag/
47 src/"
48
49 WVPASSEQ "$(WVPASS bup ls -a /)" ".
50 ..
51 .commit
52 .tag
53 src"
54
55 WVPASSEQ "$(WVPASS bup ls -aF /)" "./
56 ../
57 .commit/
58 .tag/
59 src/"
60
61 WVPASSEQ "$(WVPASS bup ls src/latest/"$tmpdir"/src)" "executable
62 fifo
63 file
64 socket
65 symlink"
66
67 WVPASSEQ "$(WVPASS bup ls -A src/latest/"$tmpdir"/src)" ".dotfile
68 executable
69 fifo
70 file
71 socket
72 symlink"
73
74 WVPASSEQ "$(WVPASS bup ls -a src/latest/"$tmpdir"/src)" ".
75 ..
76 .dotfile
77 executable
78 fifo
79 file
80 socket
81 symlink"
82
83 WVPASSEQ "$(WVPASS bup ls -F src/latest/"$tmpdir"/src)" "executable*
84 fifo|
85 file
86 socket=
87 symlink@"
88
89 WVPASSEQ "$(WVPASS bup ls --file-type src/latest/"$tmpdir"/src)" "executable
90 fifo|
91 file
92 socket=
93 symlink@"
94
95 WVSTART "ls (long)"
96
97 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
98 "d--------- ?/? 0 1970-01-01 00:00 src"
99
100 WVPASSEQ "$(WVPASS bup ls -lA / | tr -s ' ' ' ')" \
101 "d--------- ?/? 0 1970-01-01 00:00 .commit
102 d--------- ?/? 0 1970-01-01 00:00 .tag
103 d--------- ?/? 0 1970-01-01 00:00 src"
104
105 WVPASSEQ "$(WVPASS bup ls -lAF / | tr -s ' ' ' ')" \
106 "d--------- ?/? 0 1970-01-01 00:00 .commit/
107 d--------- ?/? 0 1970-01-01 00:00 .tag/
108 d--------- ?/? 0 1970-01-01 00:00 src/"
109
110 WVPASSEQ "$(WVPASS bup ls -la / | tr -s ' ' ' ')" \
111 "d--------- ?/? 0 1970-01-01 00:00 .
112 d--------- ?/? 0 1970-01-01 00:00 ..
113 d--------- ?/? 0 1970-01-01 00:00 .commit
114 d--------- ?/? 0 1970-01-01 00:00 .tag
115 d--------- ?/? 0 1970-01-01 00:00 src"
116
117 WVPASSEQ "$(WVPASS bup ls -laF / | tr -s ' ' ' ')" \
118 "d--------- ?/? 0 1970-01-01 00:00 ./
119 d--------- ?/? 0 1970-01-01 00:00 ../
120 d--------- ?/? 0 1970-01-01 00:00 .commit/
121 d--------- ?/? 0 1970-01-01 00:00 .tag/
122 d--------- ?/? 0 1970-01-01 00:00 src/"
123
124 symlink_mode="$(WVPASS ls -l src/symlink | cut -b -10)" || exit $?
125
126 symlink_size="$(WVPASS python -c "import os
127 print os.lstat('src/symlink').st_size")" || exit $?
128
129 symlink_date="$(WVPASS bup ls -l src/latest"$tmpdir"/src | grep symlink)" || exit $?
130 symlink_date="$(WVPASS echo "$symlink_date" \
131   | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')" \
132     || exit $?
133
134 uid="$(id -u)" || exit $?
135 gid="$(python -c 'import os; print os.stat("src").st_gid')" || exit $?
136 user="$(id -un)" || exit $?
137 group="$(python -c 'import grp, os;
138 print grp.getgrgid(os.stat("src").st_gid)[0]')" || exit $?
139
140 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
141 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
142 prw------- $user/$group 0 1969-07-20 20:18 fifo
143 -rw------- $user/$group 1024 1969-07-20 20:18 file
144 srwx------ $user/$group 0 1969-07-20 20:18 socket
145 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
146
147 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
148 "drwx------ $user/$group 0 1969-07-20 20:18 .
149 drwx------ $user/$group 0 1969-07-20 20:18 ..
150 -rw------- $user/$group 0 1969-07-20 20:18 .dotfile
151 -rwx------ $user/$group 0 1969-07-20 20:18 executable
152 prw------- $user/$group 0 1969-07-20 20:18 fifo
153 -rw------- $user/$group 1024 1969-07-20 20:18 file
154 srwx------ $user/$group 0 1969-07-20 20:18 socket
155 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
156
157 WVPASSEQ "$(bup ls -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
158 "-rw------- $user/$group 0 1969-07-20 20:18 .dotfile
159 -rwx------ $user/$group 0 1969-07-20 20:18 executable
160 prw------- $user/$group 0 1969-07-20 20:18 fifo
161 -rw------- $user/$group 1024 1969-07-20 20:18 file
162 srwx------ $user/$group 0 1969-07-20 20:18 socket
163 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
164
165 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
166 "-rwx------ $user/$group 0 1969-07-20 20:18 executable*
167 prw------- $user/$group 0 1969-07-20 20:18 fifo|
168 -rw------- $user/$group 1024 1969-07-20 20:18 file
169 srwx------ $user/$group 0 1969-07-20 20:18 socket=
170 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
171
172 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
173 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
174 prw------- $user/$group 0 1969-07-20 20:18 fifo|
175 -rw------- $user/$group 1024 1969-07-20 20:18 file
176 srwx------ $user/$group 0 1969-07-20 20:18 socket=
177 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
178
179 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
180 "-rwx------ $uid/$gid 0 1969-07-20 20:18 executable
181 prw------- $uid/$gid 0 1969-07-20 20:18 fifo
182 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
183 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
184 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
185
186 WVSTART "ls (backup set - long)"
187 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
188 "l--------- ?/?
189 l--------- ?/?"
190
191 WVSTART "ls (dates TZ != UTC)"
192 export TZ=US/Central
193 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
194 symlink_date_central="$(echo "$symlink_date_central" \
195   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
196 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
197 "-rwx------ $uid/$gid 0 1969-07-20 15:18 executable
198 prw------- $uid/$gid 0 1969-07-20 15:18 fifo
199 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
200 srwx------ $uid/$gid 0 1969-07-20 15:18 socket
201 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
202 unset TZ
203
204 WVPASS rm -rf "$tmpdir"