-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
441 lines (343 loc) · 10.5 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/bin/bash
# fcom tester
TESTS=()
TESTS+=(copy list move sync touch trash)
TESTS+=(help hex md5 textcount utf8 html)
CMDS_WIN=(reg_search)
# pic unico
if test "$#" -lt 1 ; then
echo "Usage: bash test.sh (all | CMD...)"
echo "CMD: ${TESTS[@]}"
exit 1
fi
CMDS=("$@")
if test "$1" == "all" ; then
CMDS=("${TESTS[@]}")
fi
set -x
set -e
test_help() {
./fcom -h
}
test_copy_update() {
cd fcomtest
echo hello >file
../fcom -V copy --update "file" -o "file-u" ; diff file file-u
../fcom -D copy --update "file" -o "file-u" | grep -E 'update.*skipping' ; diff file file-u
echo hellohello >file-rd
touch "file-rd" -t 12310000
../fcom -V copy --update --replace-date "file" -o "file-rd" | grep 'replace date'
../fcom list -l "file" "file-rd"
cd ..
}
test_copy_recursive() {
cd fcomtest
echo hello >file
mkdir -p dir
echo hello >dir/file
# dir -> dir
mkdir -p dirempty dircopy
../fcom -V copy "dir" "dirempty" -C "dircopy"
diff dir/file dircopy/dir/file
test -d dircopy/dirempty
rm -rf dircopy
# dir/dir -> dir/dir
mkdir dir/d2 dircopy
echo hello >dir/d2/file
../fcom -V copy `realpath .`"/dir" -C "dircopy"
diff dir/d2/file dircopy/dir/d2/file
rm -rf dircopy dir
# Exclude: dir -> dir
mkdir dir dir/d2 dircopy
echo hello >dir/file
echo hello >dir/file.doc
echo hello >dir/file.docx
echo hello >dir/file.txt
echo hello >dir/d2/file.docx
../fcom -V -D copy "dir" -C "dircopy" -E "*/d2" -E "*.txt" -E "*.doc"
diff dir/file dircopy/dir/file
diff dir/file.docx dircopy/dir/file.docx
test -f dircopy/dir/file.doc && false
test -f dircopy/dir/file.txt && false
test -d dircopy/dir/d2 && false
rm -rf dircopy/*
# Include: dir -> dir
../fcom -V copy "dir" -C "dircopy" -I "*.txt" -I "*.doc"
diff dir/file.doc dircopy/dir/file.doc
diff dir/file.txt dircopy/dir/file.txt
test -f dircopy/dir/file.docx && false
test -f dircopy/dir/file && false
rm -rf dircopy/*
# Include-Exclude: dir -> dir
../fcom -V copy "dir" -C "dircopy" -I "*.d*" -E "*.doc"
diff dir/file.docx dircopy/dir/file.docx
test -f dircopy/dir/file.doc && false
test -f dircopy/dir/file.txt && false
test -f dircopy/dir/file && false
rm -rf dircopy/*
# Include: --Include accepts directory
echo hello >dir/d2/file.doc
../fcom -V copy "dir" -C "dircopy" -I "*.doc"
diff dir/d2/file.doc dircopy/dir/d2/file.doc
cd ..
}
test_copy() {
cd fcomtest
echo hello >file
# file -> file
chmod a+x file
../fcom copy "file" -o "file.out"
diff file file.out
ls -l file file.out
# file -> file (exists)
../fcom copy "file" -o "file.out" || true
# file -> file (overwrite)
../fcom copy "file" -o "file.out" --overwrite
# file -> dir/file
mkdir dir
../fcom copy "file" -C "dir"
diff file dir/file
# file -> dir/file
../fcom copy "file" -C "dir" -o "testfile2"
diff file dir/testfile2
# dir -> dir
mkdir dirempty
../fcom copy "dirempty" -o "dirempty2"
test -d dirempty2
# Verify
../fcom copy "file" -o "file.out.md5" --md5
../fcom copy "file" -o "file.out.verify" --verify -f
# Crypt
../fcom copy "file" -o "file.out.encrypt" --encrypt "123"
../fcom copy "file.out.encrypt" -o "file.out.decrypt" --decrypt "123"
diff file file.out.decrypt
../fcom copy "file.out.encrypt" -o "file.out.decrypt" --decrypt "123" --verify -f
diff file file.out.decrypt
cd ..
test_copy_update
test_copy_recursive
}
test_hex() {
echo abc123 >fcomtest/hex
echo qwerqwerqwerqwerqwerqwerqwerqwer >fcomtest/hex2
./fcom hex fcomtest/hex*
}
test_list() {
echo hello >fcomtest/list
./fcom list
./fcom list "fcomtest" "."
test "$(./fcom list --oneline "fcomtest" "./fcom")" == '"fcomtest/list" "./fcom" '
./fcom list -l "fcomtest" "."
}
test_md5() {
echo 1234567890123456789012345678901234567890 >fcomtest/file
echo qwerqwerqwerqwerqwerqwerqwerqwer >fcomtest/file2
local rr='21740c1ad4d727f1a0f6159fc84c44d8 *fcomtest/file
fd25ea23edc3df0d9c8ecd50a808c014 *fcomtest/file2'
local r=$(./fcom md5 "fcomtest/file" "fcomtest/file2")
test "$r" == "$rr"
./fcom md5 "fcomtest/file" "fcomtest/file2" -o "fcomtest/md5"
test "$(cat fcomtest/md5)" == "$rr"
echo zxcvzxcv >fcomtest/file3
./fcom md5 -u fcomtest/md5 "fcomtest/file" "fcomtest/file2" "fcomtest/file3"
./fcom -V md5 -c fcomtest/md5
echo 1 >>fcomtest/file
! ./fcom -V md5 -c fcomtest/md5
}
test_move() {
mkdir fcomtest/unbranch
mkdir fcomtest/unbranch/a
# unbranch
echo hi >>fcomtest/unbranch/a/hi
./fcom -V move --unbranch "fcomtest/unbranch"
test -f "fcomtest/unbranch - a - hi"
# unbranch + replace
echo hi >>fcomtest/unbranch/a/hi
./fcom -V move --unbranch "fcomtest/unbranch" --search "a - " --replace "new - "
test -f "fcomtest/unbranch - new - hi"
# replace
echo hi >>fcomtest/unbranch/a/test
./fcom -V move "fcomtest/unbranch/a/test" --search "test" --replace "new"
test -f fcomtest/unbranch/a/new
# replace in directory name
mkdir -p fcomtest/dir1
./fcom -V move "fcomtest/dir1" --search "1" --replace "2"
! test -d fcomtest/dir1
test -d fcomtest/dir2
# unbranch-flat
cd fcomtest
echo hi >>unbranch/a/hi
../fcom -V move --unbranch-flat "./unbranch"
test -f hi
cd ..
# tree
mkdir -p fcomtest/idir fcomtest/idir/idir2
echo hi >>fcomtest/idir/idir2/hi
./fcom move fcomtest/idir -C fcomtest/odir --tree
test -f fcomtest/odir/fcomtest/idir/idir2/hi
}
test_pic() {
spectacle -o fcomtest/fileo.bmp -b
# bmp -> bmp
./fcom pic "fcomtest/fileo.bmp" -o "fcomtest/file.bmp"
test -f fcomtest/file.bmp
# diff fcomtest/fileo.bmp fcomtest/file.bmp
# bmp -> jpg
./fcom pic "fcomtest/file.bmp" -o "fcomtest/file.jpg"
test -f fcomtest/file.jpg
# bmp -> png
./fcom pic "fcomtest/file.bmp" -o "fcomtest/file.png"
test -f fcomtest/file.png
# png -> jpg
./fcom pic "fcomtest/file.png" -o "fcomtest/filepng.jpg"
diff fcomtest/file.jpg fcomtest/filepng.jpg
# jpg -> png
./fcom pic "fcomtest/file.jpg" -o "fcomtest/filejpg.png"
test -f fcomtest/filejpg.png
# jpg -> bmp
./fcom pic "fcomtest/file.jpg" -o "fcomtest/filejpg.bmp"
test -f fcomtest/filejpg.bmp
# png -> bmp
./fcom pic "fcomtest/file.png" -o "fcomtest/filepng.bmp"
test -f fcomtest/filepng.bmp
# autoname
mkdir fcomtest/multi
cd fcomtest/multi
../../fcom -V pic "../file.bmp" "../filepng.bmp" -o ".jpg"
cd ../..
diff fcomtest/multi/file.jpg fcomtest/multi/filepng.jpg
# autoname + -C
mkdir -p fcomtest/dir1 fcomtest/dir1/dir2
mv fcomtest/file.bmp fcomtest/filepng.bmp fcomtest/dir1/dir2/
./fcom -V pic fcomtest/dir1 -C "fcomtest/multi" -o ".jpg"
diff fcomtest/multi/dir1/dir2/file.jpg fcomtest/multi/dir1/dir2/filepng.jpg
}
test_unico() {
./fcom unico "fmedia.ico"
./fcom -V pic "fmedia-1.png" -o ".bmp"
}
test_reg_search() {
wine ./fcom reg search "HKEY_CURRENT_USER" "CaretWidth" "MenuShowDelay" >LOG
grep 'HKEY_CURRENT_USER\\Control Panel\\Desktop\\CaretWidth = "0x00000001 (1)"' LOG
grep 'HKEY_CURRENT_USER\\Control Panel\\Desktop\\MenuShowDelay = "400"' LOG
}
test_sync_prepare() {
cd fcomtest
mkdir -p left right left/d right/d
echo eq >left/d/eq ; cp -a left/d/eq right/d/eq
echo moved >left/d/mv ; cp -a left/d/mv right/mv
echo renamed >left/d/renamed ; cp -a left/d/renamed right/renamed2
echo leftmod >left/d/mod
sleep .1
echo rightmod >right/d/mod
echo mod_date >left/d/mod_date
echo mod_date >right/d/mod_date ; ../fcom touch --date "2001-01-01 01:01:01" "right/d/mod_date"
echo l >left/l
echo r >right/r
cd ..
}
test_sync() {
echo hello >fcomtest/file
# write snapshot
./fcom -V sync "fcomtest" --snapshot -o "fcomtest/fcomtest.snap"
cat fcomtest/fcomtest.snap
test_sync_prepare
cd fcomtest
# diff 2 dirs
../fcom -V sync --diff U --diff-time-sec "left" -o "right"
../fcom -V sync --diff "" "left" -o "right"
../fcom -V sync --diff "" --diff-no-dir "left" -o "right"
../fcom -V sync --diff "A" --plain "left" -o "right"
../fcom -V sync --diff "U" --plain "left" -o "right"
echo left >left/d/l_old
touch left/d/l_old -t 0001010000
../fcom -V sync --diff "" --recent 30 "left" -o "right"
rm left/d/l_old
# write snapshot, diff snapshot and dir
../fcom -V sync --snapshot "left" -o "fcomtest.snap" -f
../fcom -V sync --diff "" --source-snap "fcomtest.snap" -o "right" >LOG
grep 'moved:1 add:2 del:2 upd:3 eq:1 total:7/7' LOG
# diff 2 snapshots
../fcom -V sync --snapshot "right" -o "fcomtest-right.snap" -f
../fcom -V sync --diff "" --source-snap "fcomtest.snap" --target-snap -o "fcomtest-right.snap" >LOG
grep 'moved:1 add:2 del:2 upd:3 eq:1 total:7/7' LOG
# snapshot 2 dirs
../fcom -V sync --snapshot "left" "right" -o "fcomtest2.snap" -f
cat fcomtest2.snap
# sync 2 dirs
../fcom -V sync "left" -o "right" --add
../fcom -V sync "left" -o "right" --delete -f
cd ..
}
test_sync_zip() {
mkdir fcomtest/dir fcomtest/dir2
./fcom touch "fcomtest/dir/file1"
./fcom touch "fcomtest/dir/file2"
./fcom touch "fcomtest/dir2/file3"
./fcom zip "fcomtest/dir" "fcomtest/dir2" -o "fcomtest/sync.zip"
./fcom -D sync --snapshot "fcomtest" --zip-expand -o "fcomtest/snap.txt"
cat fcomtest/snap.txt
}
test_gsync() {
test_sync_prepare
cd fcomtest
mkdir -p left-a left-b
touch left-a/a
touch left-b/b
../fcom gsync "./left*" "./right"
}
test_textcount() {
echo 123 >>fcomtest/textcount
echo 3456 >>fcomtest/textcount
echo 7890 >>fcomtest/textcount
./fcom -V textcount -R "fcomtest"
}
test_touch() {
echo 123 >fcomtest/touch
echo 123 >fcomtest/touch2
./fcom -V touch "fcomtest/touch" --date "2022-09-01 01:02:03"
ls -l fcomtest/touch
./fcom -V touch "fcomtest/touch" --date "2022-09-01"
ls -l fcomtest/touch
./fcom -V touch "fcomtest/touch2" --reference "fcomtest/touch"
ls -l fcomtest/touch2
./fcom -V touch "fcomtest/touch"
ls -l fcomtest/touch
mkdir fcomtest/dirtouch fcomtest/dirtouch/d2
echo 123 >fcomtest/dirtouch/touch
echo 123 >fcomtest/dirtouch/d2/touch2
./fcom -V touch -R "fcomtest/dirtouch" --date "2022-09-01 01:02:03"
ls -Rl fcomtest/dirtouch
}
test_trash() {
echo 123 >fcomtest/trash
echo 123 >fcomtest/trash2
./fcom -V trash "fcomtest/trash" "fcomtest/trash2" -f
echo 123 >fcomtest/trash
echo 123 >fcomtest/trash2
./fcom -V trash "fcomtest/trash" "fcomtest/trash2" --rename -f
echo 123 >fcomtest/trash
echo 123 >fcomtest/trash2
./fcom -V trash "fcomtest/trash" "fcomtest/trash2" --wipe --rename -f
}
test_utf8() {
# ./fcom utf8 "fcomtest/file-utf16" -o "fcomtest/file-utf8"
# diff fcomtest/file fcomtest/file-utf8
echo
}
test_html() {
cat <<EOF >fcomtest/html
<tag attr="123"></tag>
<tag attr="234"/>
EOF
./fcom html "fcomtest/html" --filter "tag.attr" | grep 123
./fcom html "fcomtest/html" --filter "tag.attr" | grep 234
}
source "$(dirname $0)/test-pack.sh"
mkdir -p fcomtest
for cmd in "${CMDS[@]}" ; do
rm -rf ./fcomtest/*
test_$cmd
done
rm -rf ./fcomtest
echo DONE