public
Description: Perl tree-sync project, originally created by Chang Liu
Homepage: http://www.perl.com/CPAN/authors/id/P/PA/PAULPG/tree-sync/
Clone URL: git://github.com/tardate/tree-sync.git
tree-sync / test-tree-sync.cmd
100644 432 lines (384 sloc) 15.546 kb
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
@echo off
echo A very simple tree-sync.pl test script for Windows
echo Tests most of the tree-sync functions assuming an ActivePerl environment
echo This should probably be a Perl script itself ... but hey, so many hours in the day only!
echo ----------------------------------------------------------------
 
setlocal
 
rem CUSTOMISATION NOTE: this will call an external script to set perl environment
rem If you have Perl env already setup, you can ignore this
call setPerlEnv
set PATH=%PATH%;D:\bin\cygwin\bin
set TEMP=c:\temp
rem END CUSTOMISATION NOTE
 
rem CUSTOMISATION NOTE: to perform tests between different drives, modify the
rem srcDir and destDir paths here
set srcDir=%TEMP%
set destDir=%TEMP%
rem Also, set scriptDrive and srcDrive if the srcDir is on
rem different drive from where this script is executed
set scriptDrive=d:
set srcDrive=c:
rem END CUSTOMISATION NOTE
 
set scriptName=tree-sync.pl
set srcFolder=ts-test-src
set destFolder=ts-test-dest
set srcRoot=%srcDir%\%srcFolder%
set destRoot=%destDir%\%destFolder%
set runner="%TEMP%\sync-now.pl"
set log=%TEMP%\tree-sync.log
set optsByCmdFile=-width=130 -cmd=%runner%
set opts=-width=130 -run
 
echo Output logged to: %log%
 
rem Check grep availability
grep 2> nul
set grepstatus=%errorlevel%
if %grepstatus% == 2 goto grepok
echo NOTE: grep command not available. File update tests may not be checked fully.
goto prep
:grepok
set grepstatus=0
goto prep
 
 
:prep
echo ============ Prepare source test files
echo ============ Prepare source test files >> %log%
rmdir /s/q %srcRoot% 2> nul
rmdir /s/q %destRoot% 2> nul
 
mkdir %srcRoot%
echo "test" > "%srcRoot%\file 1.txt"
echo "test" > "%srcRoot%\file 2.txt"
rem this tests for special characters
echo "test" > "%srcRoot%\a @.txt"
echo "test" > "%srcRoot%\b $.txt"
rem this tests for regex special characters
echo "test" > "%srcRoot%\=A - (B) - C - (D,.txt"
mkdir "%srcRoot%\dir 1"
echo "test" > "%srcRoot%\dir 1\file 1.txt"
echo "test" > "%srcRoot%\dir 1\file 2.txt"
echo "test" > "%srcRoot%\dir 1\file 3.txt"
mkdir "%srcRoot%\dir 2"
echo "test" > "%srcRoot%\dir 2\file 1.txt"
echo "test" > "%srcRoot%\dir 2\file 2.txt"
rem this tests for quotes in names
mkdir "%srcRoot%\dir Q"
echo "test" > "%srcRoot%\dir Q\file 1'.txt"
mkdir "%srcRoot%\dir Q 'A"
echo "test" > "%srcRoot%\dir Q 'A\file 1.txt"
 
:test1
echo ============ Test 1: Initial full sync
echo Expected behaviour: dest files created during sync
echo ============ Test 1: Initial full sync > %log%
echo Expected behaviour: dest files created during sync >> %log%
perl %scriptName% %opts% %srcRoot% %destRoot% >> %log%
 
if not exist "%destRoot%\dir 2\file 2.txt" goto fail1
if not exist "%destRoot%\dir Q\file 1'.txt" goto fail1
if not exist "%destRoot%\dir Q 'A\file 1.txt" goto fail1
echo ... pass
echo ... pass >> %log%
goto test2
:fail1
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
:test2
echo ============ Test 2: Add dir + files to source and full sync
echo Expected behaviour: dest files added during sync
echo ============ Test 2: Add dir + files to source and full sync >> %log%
echo Expected behaviour: dest files added during sync >> %log%
mkdir "%srcRoot%\dir 3"
echo "test" > "%srcRoot%\dir 3\file 1.txt"
echo "test" > "%srcRoot%\dir 3\file 2.txt"
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
 
if not exist "%destRoot%\dir 3\file 2.txt" goto fail2
echo ... pass
echo ... pass >> %log%
goto test3
:fail2
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
:test3
echo ============ Test 3: Remove dir + files from source and full sync
echo Expected behaviour: dest files removed during sync
echo ============ Test 3: Remove dir + files from source and full sync >> %log%
echo Expected behaviour: dest files removed during sync >> %log%
rmdir /s/q "%srcRoot%\dir 3"
rmdir /s/q "%srcRoot%\dir Q"
rmdir /s/q "%srcRoot%\dir Q 'A"
 
perl %scriptName% %opts% %srcRoot%/ %destRoot%/ >> %log%
 
if exist "%destRoot%\dir 3" goto fail3
if exist "%destRoot%\dir Q" goto fail3
if exist "%destRoot%\dir Q 'A" goto fail3
echo ... pass
goto test4
:fail3
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
 
:test4
echo ============ Test 4: Remove dir + files from dest and full sync
echo Expected behaviour: dest files restored during sync
echo ============ Test 4: Remove dir + files from dest and full sync >> %log%
echo Expected behaviour: dest files restored during sync >> %log%
rmdir /s/q "%destRoot%\dir 2"
perl %scriptName% %opts% %srcRoot%/ %destRoot%/ >> %log%
 
if not exist "%destRoot%\dir 2" goto fail4
echo ... pass
echo ... pass >> %log%
goto test5
:fail4
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
 
:test5
echo ============ Test 5: Add dir + files to dest and fwdonly sync
echo Expected behaviour: dest files remain during sync
echo ============ Test 5: Add dir + files to dest and fwdonly sync >> %log%
echo Expected behaviour: dest files remain during sync >> %log%
mkdir "%destRoot%\dir 4"
echo "test" > "%destRoot%\dir 4\file 1.txt"
echo "test" > "%destRoot%\dir 4\file 2.txt"
perl %scriptName% %opts% -syncmode=fwdonly %srcRoot%\ %destRoot%\ >> %log%
 
if not exist "%destRoot%\dir 4" goto fail5
echo ... pass
echo ... pass >> %log%
goto test6
:fail5
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
 
:test6
echo ============ Test 6: Add dir + files to dest and full sync
echo Expected behaviour: dest files removed during sync
echo ============ Test 6: Add dir + files to dest and full sync >> %log%
echo Expected behaviour: dest files removed during sync >> %log%
rem files added during test 5
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
 
if exist "%destRoot%\dir 4" goto fail6
echo ... pass
echo ... pass >> %log%
goto test7
:fail6
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
 
:test7
sleep 3
echo ============ Test 7: Update files on source and full sync
echo Expected behaviour: dest files updated during sync
echo ============ Test 7: Update files on source and full sync >> %log%
echo Expected behaviour: dest files updated during sync >> %log%
echo "modified on source" >> "%srcRoot%\file 1.txt"
echo "modified on source" >> "%srcRoot%\dir 1\file 1.txt"
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
 
if %grepstatus% == 0 goto grepcheck7
echo (not checking file explicitly with grep)
if not exist "%destRoot%\dir 1\file 1.txt" goto fail7
echo ... pass
echo ... pass >> %log%
goto test8
:grepcheck7
echo (checking file explicitly with grep)
grep -c "modified on source" "%destRoot%\dir 1\file 1.txt" > nul
if %errorlevel% == 1 goto fail7
echo ... pass
goto test8
:fail7
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
 
:test8
echo ============ Test 8: Update files on dest and full sync
echo Expected behaviour: src files updated during sync
echo ============ Test 8: Update files on dest and full sync >> %log%
echo Expected behaviour: src files updated during sync >> %log%
echo "modified on dest" >> "%destRoot%\file 2.txt"
echo "modified on dest" >> "%destRoot%\dir 1\file 2.txt"
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
 
if %grepstatus% == 0 goto grepcheck8
echo (not checking file explicitly with grep)
if not exist "%srcRoot%\dir 1\file 2.txt" goto fail8
echo ... pass
echo ... pass >> %log%
goto test9
:grepcheck8
echo (checking file explicitly with grep)
grep -c "modified on dest" "%srcRoot%\dir 1\file 2.txt" > nul
if %errorlevel% == 1 goto fail8
echo ... pass
echo ... pass >> %log%
goto test9
:fail8
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
 
:test9
echo ============ Test 9: Update files on dest and fwdonly sync
echo Expected behaviour: src + dest files not updated during sync
echo ============ Test 9: Update files on dest and fwdonly sync >> %log%
echo Expected behaviour: src + dest files not updated during sync >> %log%
echo "test9 modified on dest" >> "%destRoot%\dir 1\file 3.txt"
perl %scriptName% %opts% -syncmode=fwdonly %srcRoot%\ %destRoot%\ >> %log%
 
if %grepstatus% == 0 goto grepcheck9
echo (not checking file explicitly with grep)
if not exist "%srcRoot%\dir 1\file 3.txt" goto fail9
echo ... pass
echo ... pass >> %log%
goto test10
:grepcheck9
echo (checking file explicitly with grep)
grep -c "test9 modified on dest" "%srcRoot%\dir 1\file 3.txt" > nul
if %errorlevel% == 0 goto fail9
echo ... pass
echo ... pass >> %log%
goto test10
:fail9
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
:test10
echo ============ Test 10: Update files on dest and Sync using relative path for source and dest
echo Expected behaviour: source updated ok
echo ============ Test 10: Update files on dest and Sync using relative path for source and dest >> %log%
echo Expected behaviour: source updated ok >> %log%
echo "test9+10 modified on dest" >> "%destRoot%\dir 1\file 3.txt"
rem change drive/directory
%srcDrive%
cd %srcRoot%
perl %scriptDrive%%scriptName% %opts% .\ ..\%destFolder%\ >> %log%
 
if %grepstatus% == 0 goto grepcheck10
echo (not checking file explicitly with grep)
if not exist "%srcRoot%\dir 1\file 3.txt" goto fail10
echo ... pass
echo ... pass >> %log%
goto endtest10
:grepcheck10
echo (checking file explicitly with grep)
grep -c "test9+10 modified on dest" "%srcRoot%\dir 1\file 3.txt" > nul
if %errorlevel% == 1 goto fail10
echo ... pass
echo ... pass >> %log%
goto endtest10
:fail10
%scriptDrive%
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
:endtest10
%scriptDrive%
 
:test11
echo ============ Test 11: Ignore ".csv" files
echo Expected behaviour: dest files not include .csv files after sync
echo ============ Test 11: Ignore ".csv" files >> %log%
echo Expected behaviour: dest files not include .csv files after sync >> %log%
echo "modified on source" >> "%srcRoot%\file 1.csv"
echo "modified on source" >> "%destRoot%\dir 1\file 1.csv"
perl %scriptName% %opts% -ignore csv %srcRoot%\ %destRoot%\ >> %log%
 
if exist "%destRoot%\file 1.csv" goto fail11
if exist "%srcRoot%\dir 1\file 1.csv" goto fail11
echo ... pass
echo ... pass >> %log%
del "%srcRoot%\file 1.csv"
del "%destRoot%\dir 1\file 1.csv"
goto test12
:fail11
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
 
:test12
echo ============ Test 12: Test for sync of read-only files
echo Expected behaviour: read-only files should sync properly
echo ============ Test 12: Test for sync of read-only files >> %log%
echo Expected behaviour: read-only files should sync properly >> %log%
set f="%srcRoot%\file 5.txt"
set fd="%destRoot%\file 5.txt"
echo "Test 12 attrib +R set on source" >> %f%
attrib +R %f%
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
attrib -R %f%
sleep 3
echo "Test 12 OK changed after attrib +R set on source" >> %f%
attrib +R %f%
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
 
if %grepstatus% == 0 goto grepcheck12
echo (not checking file explicitly with grep)
if not exist %fd% goto fail12
echo ... pass
echo ... pass >> %log%
goto test13
:grepcheck12
echo (checking file explicitly with grep)
grep -c "Test 12 OK" %fd% > nul
if %errorlevel% == 1 goto fail12
echo ... pass
goto test13
:fail12
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
:test13
echo ============ Test 13: Test for sync of read-write file where dest has been made read-only
echo Expected behaviour: files should sync properly (-force by default)
echo ============ Test 13: Test for sync of read-write file where dest has been made read-only >> %log%
echo Expected behaviour: files should sync properly (-force by default) >> %log%
set f="%srcRoot%\file 6.txt"
set fd="%destRoot%\file 6.txt"
echo "Test 13 created read-write on source" >> %f%
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
attrib +R %fd%
sleep 3
echo "Test 13 OK changed after attrib +R set on dest" >> %f%
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
 
if %grepstatus% == 0 goto grepcheck13
echo (not checking file explicitly with grep)
if not exist %fd% goto fail13
echo ... pass
echo ... pass >> %log%
goto test14
:grepcheck13
echo (checking file explicitly with grep)
grep -c "Test 13 OK" %fd% > nul
if %errorlevel% == 1 goto fail13
echo ... pass
goto test14
:fail13
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
:test14
echo ============ Test 14: Test for non-sync of read-write file where dest has been made read-only and -noforce specified
echo Expected behaviour: files should not sync (-noforce)
echo ============ Test 14: Test for non-sync of read-write file where dest has been made read-only and -noforce specified >> %log%
echo Expected behaviour: files should not sync (-noforce) >> %log%
set f="%srcRoot%\file 6.txt"
set fd="%destRoot%\file 6.txt"
echo "Test 14 created read-write on source" >> %f%
perl %scriptName% %opts% %srcRoot%\ %destRoot%\ >> %log%
attrib +R %fd%
sleep 3
echo "Test 14 OK changed after attrib +R set on dest and -noforce" >> %f%
perl %scriptName% %opts% -noforce %srcRoot%\ %destRoot%\ >> %log%
 
if %grepstatus% == 0 goto grepcheck14
echo (not checking file explicitly with grep)
if not exist %fd% goto fail14
echo ... pass
echo ... pass >> %log%
goto test15
:grepcheck14
echo (checking file explicitly with grep)
grep -c "Test 14 OK" %fd% > nul
if not %errorlevel% == 1 goto fail13
echo ... pass
goto test15
:fail14
echo ... fail. Error in sync: Check results
echo ... fail. Error in sync: Check results >> %log%
goto end
 
:test15
 
:cleanup
goto end
echo ============ Cleanup test files
echo ============ Cleanup test files >> %log%
rmdir /s/q %srcRoot% 2> nul
rmdir /s/q %destRoot% 2> nul
 
:end
endlocal