]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
test-ls.sh: don't check the symlink file size on NetBSD for now.
[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_bup_info="$(WVPASS bup ls -l src/latest"$tmpdir"/src | grep symlink)" \
127     || exit $?
128 symlink_date="$(WVPASS echo "$symlink_bup_info" \
129   | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')" \
130     || exit $?
131
132 if test "$(uname -s)" != NetBSD; then
133     symlink_size="$(WVPASS python -c "import os
134 print os.lstat('src/symlink').st_size")" || exit $?
135 else
136     # NetBSD appears to return varying sizes, so for now, just ignore it.
137     symlink_size="$(WVPASS echo "$symlink_bup_info" \
138       | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $1')" \
139         || exit $?
140 fi
141
142 uid="$(id -u)" || exit $?
143 gid="$(python -c 'import os; print os.stat("src").st_gid')" || exit $?
144 user="$(id -un)" || exit $?
145 group="$(python -c 'import grp, os;
146 print grp.getgrgid(os.stat("src").st_gid)[0]')" || exit $?
147
148 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
149 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
150 prw------- $user/$group 0 1969-07-20 20:18 fifo
151 -rw------- $user/$group 1024 1969-07-20 20:18 file
152 srwx------ $user/$group 0 1969-07-20 20:18 socket
153 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
154
155 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
156 "drwx------ $user/$group 0 1969-07-20 20:18 .
157 drwx------ $user/$group 0 1969-07-20 20:18 ..
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 -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
166 "-rw------- $user/$group 0 1969-07-20 20:18 .dotfile
167 -rwx------ $user/$group 0 1969-07-20 20:18 executable
168 prw------- $user/$group 0 1969-07-20 20:18 fifo
169 -rw------- $user/$group 1024 1969-07-20 20:18 file
170 srwx------ $user/$group 0 1969-07-20 20:18 socket
171 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
172
173 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
174 "-rwx------ $user/$group 0 1969-07-20 20:18 executable*
175 prw------- $user/$group 0 1969-07-20 20:18 fifo|
176 -rw------- $user/$group 1024 1969-07-20 20:18 file
177 srwx------ $user/$group 0 1969-07-20 20:18 socket=
178 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
179
180 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
181 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
182 prw------- $user/$group 0 1969-07-20 20:18 fifo|
183 -rw------- $user/$group 1024 1969-07-20 20:18 file
184 srwx------ $user/$group 0 1969-07-20 20:18 socket=
185 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
186
187 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
188 "-rwx------ $uid/$gid 0 1969-07-20 20:18 executable
189 prw------- $uid/$gid 0 1969-07-20 20:18 fifo
190 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
191 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
192 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
193
194 WVSTART "ls (backup set - long)"
195 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
196 "l--------- ?/?
197 l--------- ?/?"
198
199 WVSTART "ls (dates TZ != UTC)"
200 export TZ=US/Central
201 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
202 symlink_date_central="$(echo "$symlink_date_central" \
203   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
204 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
205 "-rwx------ $uid/$gid 0 1969-07-20 15:18 executable
206 prw------- $uid/$gid 0 1969-07-20 15:18 fifo
207 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
208 srwx------ $uid/$gid 0 1969-07-20 15:18 socket
209 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
210 unset TZ
211
212 WVPASS rm -rf "$tmpdir"