]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
test-ls.sh: eliminate timezone dependencies; test dates in two timezones.
[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 date > src/file
22 WVPASS bup random 1k > src/file
23 WVPASS touch -t 196907202018 src/file
24 (WVPASS cd src; WVPASS ln -s file symlink) || exit $?
25 WVPASS mkfifo src/fifo
26 WVPASS touch -t 196907202018 src/fifo
27 WVPASS "$top"/t/mksock src/socket
28 WVPASS touch -t 196907202018 src/socket
29 WVPASS touch -t 196907202018 src/executable
30 WVPASS chmod u+x src/executable
31 WVPASS touch -t 196907202018 src/executable
32 WVPASS touch -t 196907202018 src
33 WVPASS touch -t 196907202018 .
34 WVPASS chmod -R u=rwX,g-rwx,o-rwx .
35 WVPASS bup index src
36 WVPASS bup save -n src src
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 WVSTART "ls (long)"
97
98 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
99 "d--------- ?/? - 1970-01-01 00:00 src"
100
101 WVPASSEQ "$(WVPASS bup ls -lA / | tr -s ' ' ' ')" \
102 "d--------- ?/? - 1970-01-01 00:00 .commit
103 d--------- ?/? - 1970-01-01 00:00 .tag
104 d--------- ?/? - 1970-01-01 00:00 src"
105
106 WVPASSEQ "$(WVPASS bup ls -lAF / | tr -s ' ' ' ')" \
107 "d--------- ?/? - 1970-01-01 00:00 .commit/
108 d--------- ?/? - 1970-01-01 00:00 .tag/
109 d--------- ?/? - 1970-01-01 00:00 src/"
110
111 WVPASSEQ "$(WVPASS bup ls -la / | tr -s ' ' ' ')" \
112 "d--------- ?/? - 1970-01-01 00:00 .
113 d--------- ?/? - 1970-01-01 00:00 ..
114 d--------- ?/? - 1970-01-01 00:00 .commit
115 d--------- ?/? - 1970-01-01 00:00 .tag
116 d--------- ?/? - 1970-01-01 00:00 src"
117
118 WVPASSEQ "$(WVPASS bup ls -laF / | tr -s ' ' ' ')" \
119 "d--------- ?/? - 1970-01-01 00:00 ./
120 d--------- ?/? - 1970-01-01 00:00 ../
121 d--------- ?/? - 1970-01-01 00:00 .commit/
122 d--------- ?/? - 1970-01-01 00:00 .tag/
123 d--------- ?/? - 1970-01-01 00:00 src/"
124
125 symlink_size="$(python -c "import os; print os.lstat('src/symlink').st_size")"
126 symlink_date="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
127 symlink_date="$(echo "$symlink_date" \
128   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
129 uid="$(id -u)" || exit $?
130 gid="$(id -g)" || exit $?
131 user="$(id -un)" || exit $?
132 group="$(id -gn)" || exit $?
133
134 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
135 "-rwx------ $user/$group - 1969-07-20 20:18 executable
136 prw------- $user/$group - 1969-07-20 20:18 fifo
137 -rw------- $user/$group 1024 1969-07-20 20:18 file
138 srwx------ $user/$group - 1969-07-20 20:18 socket
139 lrwxrwxrwx $user/$group $symlink_size $symlink_date symlink -> file"
140
141 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
142 "drwx------ $user/$group - 1969-07-20 20:18 .
143 drwx------ $user/$group - 1969-07-20 20:18 ..
144 -rw------- $user/$group - 1969-07-20 20:18 .dotfile
145 -rwx------ $user/$group - 1969-07-20 20:18 executable
146 prw------- $user/$group - 1969-07-20 20:18 fifo
147 -rw------- $user/$group 1024 1969-07-20 20:18 file
148 srwx------ $user/$group - 1969-07-20 20:18 socket
149 lrwxrwxrwx $user/$group $symlink_size $symlink_date symlink -> file"
150
151 WVPASSEQ "$(bup ls -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
152 "-rw------- $user/$group - 1969-07-20 20:18 .dotfile
153 -rwx------ $user/$group - 1969-07-20 20:18 executable
154 prw------- $user/$group - 1969-07-20 20:18 fifo
155 -rw------- $user/$group 1024 1969-07-20 20:18 file
156 srwx------ $user/$group - 1969-07-20 20:18 socket
157 lrwxrwxrwx $user/$group $symlink_size $symlink_date symlink -> file"
158
159 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
160 "-rwx------ $user/$group - 1969-07-20 20:18 executable*
161 prw------- $user/$group - 1969-07-20 20:18 fifo|
162 -rw------- $user/$group 1024 1969-07-20 20:18 file
163 srwx------ $user/$group - 1969-07-20 20:18 socket=
164 lrwxrwxrwx $user/$group $symlink_size $symlink_date symlink@ -> file"
165
166 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
167 "-rwx------ $user/$group - 1969-07-20 20:18 executable
168 prw------- $user/$group - 1969-07-20 20:18 fifo|
169 -rw------- $user/$group 1024 1969-07-20 20:18 file
170 srwx------ $user/$group - 1969-07-20 20:18 socket=
171 lrwxrwxrwx $user/$group $symlink_size $symlink_date symlink@ -> file"
172
173 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
174 "-rwx------ $uid/$gid - 1969-07-20 20:18 executable
175 prw------- $uid/$gid - 1969-07-20 20:18 fifo
176 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
177 srwx------ $uid/$gid - 1969-07-20 20:18 socket
178 lrwxrwxrwx $uid/$gid $symlink_size $symlink_date symlink -> file"
179
180 WVSTART "ls (backup set - long)"
181 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
182 "l--------- ?/?
183 l--------- ?/?"
184
185 WVSTART "ls (dates TZ != UTC)"
186 export TZ=US/Central
187 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
188 symlink_date_central="$(echo "$symlink_date_central" \
189   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
190 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
191 "-rwx------ $uid/$gid - 1969-07-20 15:18 executable
192 prw------- $uid/$gid - 1969-07-20 15:18 fifo
193 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
194 srwx------ $uid/$gid - 1969-07-20 15:18 socket
195 lrwxrwxrwx $uid/$gid $symlink_size $symlink_date_central symlink -> file"
196 unset TZ
197
198 WVPASS rm -rf "$tmpdir"