Fossil SCM

Add tests for the 'unversioned revert' and 'unversioned sync' commands.

mistachkin 2016-10-05 05:00 trunk
Commit 1c99c13398f38b2e2d8839b8a5350d71831ecec4
2 files changed +77 -3 +122 -9
+77 -3
--- test/tester.tcl
+++ test/tester.tcl
@@ -560,14 +560,14 @@
560560
# NOTE: Check if we can use any of the environment variables.
561561
#
562562
foreach name $names {
563563
set value [getEnvironmentVariable $name]
564564
565
- if {[string length $value] > 0} then {
565
+ if {[string length $value] > 0} {
566566
set value [file normalize $value]
567567
568
- if {[file exists $value] && [file isdirectory $value]} then {
568
+ if {[file exists $value] && [file isdirectory $value]} {
569569
return $value
570570
}
571571
}
572572
}
573573
@@ -575,11 +575,11 @@
575575
# NOTE: On non-Windows systems, fallback to /tmp if it is usable.
576576
#
577577
if {$::tcl_platform(platform) ne "windows"} {
578578
set value /tmp
579579
580
- if {[file exists $value] && [file isdirectory $value]} then {
580
+ if {[file exists $value] && [file isdirectory $value]} {
581581
return $value
582582
}
583583
}
584584
585585
#
@@ -732,10 +732,84 @@
732732
}
733733
append out \n$line
734734
}
735735
return [string range $out 1 end]
736736
}
737
+
738
+# This procedure executes the "fossil server" command. The return value
739
+# is the new process identifier. The varName argument refers to a variable
740
+# where the "stop argument" is to be stored. This value must eventually be
741
+# passed to the [test_stop_server] procedure.
742
+proc test_start_server { repository {varName ""} } {
743
+ global fossilexe
744
+ set command [list exec $fossilexe server]
745
+ if {[string length $varName] > 0} {
746
+ upvar 1 $varName stopArg
747
+ }
748
+ if {$::tcl_platform(platform) eq "windows"} {
749
+ set stopArg [file join [getTemporaryPath] [appendArgs \
750
+ [string trim [clock seconds] -] _ [getSeqNo] .stopper]]
751
+ lappend command --stopper $stopArg
752
+ }
753
+ lappend command $repository &
754
+ set pid [eval $command]
755
+ if {$::tcl_platform(platform) ne "windows"} {
756
+ set stopArg $pid
757
+ }
758
+ return $pid
759
+}
760
+
761
+# This procedure stops a Fossil server instance that was previously started
762
+# by the [test_start_server] procedure. The value of the "stop argument"
763
+# will vary by platform as will the exact method used to stop the server.
764
+proc test_stop_server { stopArg pid } {
765
+ if {$::tcl_platform(platform) eq "windows"} {
766
+ #
767
+ # NOTE: On Windows, the "stop argument" must be the name of a file
768
+ # that does NOT already exist.
769
+ #
770
+ if {![file exists $stopArg] && \
771
+ [catch {write_file $stopArg [clock seconds]}] == 0} then {
772
+ while {1} {
773
+ if {[catch {
774
+ #
775
+ # NOTE: Using the TaskList utility requires Windows XP or
776
+ # later.
777
+ #
778
+ exec tasklist.exe /FI "PID eq $pid"
779
+ } result] != 0 || ![regexp -- " $pid " $result]} then {
780
+ break
781
+ }
782
+ after 1000; # wait a bit...
783
+ }
784
+ file delete $stopArg
785
+ return true
786
+ }
787
+ } else {
788
+ #
789
+ # NOTE: On Unix, the "stop argument" must be an integer identifier
790
+ # that refers to an existing process.
791
+ #
792
+ if {[regexp {^(?:-)?\d+$} $stopArg] && \
793
+ [catch {exec kill -TERM $stopArg}] == 0} then {
794
+ while {1} {
795
+ if {[catch {
796
+ #
797
+ # TODO: Is this portable to all the supported variants of
798
+ # Unix? It should be, it's POSIX.
799
+ #
800
+ exec ps -p $pid
801
+ } result] != 0 || ![regexp -- "(?:^$pid| $pid) " $result]} then {
802
+ break
803
+ }
804
+ after 1000; # wait a bit...
805
+ }
806
+ return true
807
+ }
808
+ }
809
+ return false
810
+}
737811
738812
# Executes the "fossil http" command. The entire content of the HTTP request
739813
# is read from the data file name, with [subst] being performed on it prior to
740814
# submission. Temporary input and output files are created and deleted. The
741815
# result will be the contents of the temoprary output file.
742816
--- test/tester.tcl
+++ test/tester.tcl
@@ -560,14 +560,14 @@
560 # NOTE: Check if we can use any of the environment variables.
561 #
562 foreach name $names {
563 set value [getEnvironmentVariable $name]
564
565 if {[string length $value] > 0} then {
566 set value [file normalize $value]
567
568 if {[file exists $value] && [file isdirectory $value]} then {
569 return $value
570 }
571 }
572 }
573
@@ -575,11 +575,11 @@
575 # NOTE: On non-Windows systems, fallback to /tmp if it is usable.
576 #
577 if {$::tcl_platform(platform) ne "windows"} {
578 set value /tmp
579
580 if {[file exists $value] && [file isdirectory $value]} then {
581 return $value
582 }
583 }
584
585 #
@@ -732,10 +732,84 @@
732 }
733 append out \n$line
734 }
735 return [string range $out 1 end]
736 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
737
738 # Executes the "fossil http" command. The entire content of the HTTP request
739 # is read from the data file name, with [subst] being performed on it prior to
740 # submission. Temporary input and output files are created and deleted. The
741 # result will be the contents of the temoprary output file.
742
--- test/tester.tcl
+++ test/tester.tcl
@@ -560,14 +560,14 @@
560 # NOTE: Check if we can use any of the environment variables.
561 #
562 foreach name $names {
563 set value [getEnvironmentVariable $name]
564
565 if {[string length $value] > 0} {
566 set value [file normalize $value]
567
568 if {[file exists $value] && [file isdirectory $value]} {
569 return $value
570 }
571 }
572 }
573
@@ -575,11 +575,11 @@
575 # NOTE: On non-Windows systems, fallback to /tmp if it is usable.
576 #
577 if {$::tcl_platform(platform) ne "windows"} {
578 set value /tmp
579
580 if {[file exists $value] && [file isdirectory $value]} {
581 return $value
582 }
583 }
584
585 #
@@ -732,10 +732,84 @@
732 }
733 append out \n$line
734 }
735 return [string range $out 1 end]
736 }
737
738 # This procedure executes the "fossil server" command. The return value
739 # is the new process identifier. The varName argument refers to a variable
740 # where the "stop argument" is to be stored. This value must eventually be
741 # passed to the [test_stop_server] procedure.
742 proc test_start_server { repository {varName ""} } {
743 global fossilexe
744 set command [list exec $fossilexe server]
745 if {[string length $varName] > 0} {
746 upvar 1 $varName stopArg
747 }
748 if {$::tcl_platform(platform) eq "windows"} {
749 set stopArg [file join [getTemporaryPath] [appendArgs \
750 [string trim [clock seconds] -] _ [getSeqNo] .stopper]]
751 lappend command --stopper $stopArg
752 }
753 lappend command $repository &
754 set pid [eval $command]
755 if {$::tcl_platform(platform) ne "windows"} {
756 set stopArg $pid
757 }
758 return $pid
759 }
760
761 # This procedure stops a Fossil server instance that was previously started
762 # by the [test_start_server] procedure. The value of the "stop argument"
763 # will vary by platform as will the exact method used to stop the server.
764 proc test_stop_server { stopArg pid } {
765 if {$::tcl_platform(platform) eq "windows"} {
766 #
767 # NOTE: On Windows, the "stop argument" must be the name of a file
768 # that does NOT already exist.
769 #
770 if {![file exists $stopArg] && \
771 [catch {write_file $stopArg [clock seconds]}] == 0} then {
772 while {1} {
773 if {[catch {
774 #
775 # NOTE: Using the TaskList utility requires Windows XP or
776 # later.
777 #
778 exec tasklist.exe /FI "PID eq $pid"
779 } result] != 0 || ![regexp -- " $pid " $result]} then {
780 break
781 }
782 after 1000; # wait a bit...
783 }
784 file delete $stopArg
785 return true
786 }
787 } else {
788 #
789 # NOTE: On Unix, the "stop argument" must be an integer identifier
790 # that refers to an existing process.
791 #
792 if {[regexp {^(?:-)?\d+$} $stopArg] && \
793 [catch {exec kill -TERM $stopArg}] == 0} then {
794 while {1} {
795 if {[catch {
796 #
797 # TODO: Is this portable to all the supported variants of
798 # Unix? It should be, it's POSIX.
799 #
800 exec ps -p $pid
801 } result] != 0 || ![regexp -- "(?:^$pid| $pid) " $result]} then {
802 break
803 }
804 after 1000; # wait a bit...
805 }
806 return true
807 }
808 }
809 return false
810 }
811
812 # Executes the "fossil http" command. The entire content of the HTTP request
813 # is read from the data file name, with [subst] being performed on it prior to
814 # submission. Temporary input and output files are created and deleted. The
815 # result will be the contents of the temoprary output file.
816
--- test/unversioned.test
+++ test/unversioned.test
@@ -26,17 +26,28 @@
2626
}
2727
2828
require_no_open_checkout
2929
3030
test_setup; set rootDir [file normalize [pwd]]
31
+
32
+fossil test-th-eval --open-config {repository}
33
+set repository [normalize_result]
34
+
35
+if {[string length $repository] == 0} {
36
+ puts "Detection of the open repository file failed."
37
+ test_cleanup_then_return
38
+}
3139
3240
write_file unversioned1.txt "This is unversioned file #1."
3341
write_file unversioned2.txt " This is unversioned file #2. "
3442
write_file "unversioned space.txt" "\nThis is unversioned file #3.\n"
3543
write_file unversioned4.txt "This is unversioned file #4."
3644
write_file unversioned5.txt "This is unversioned file #5."
3745
46
+set env(VISUAL) [appendArgs \
47
+ [info nameofexecutable] " " [file join $path fake-editor.tcl]]
48
+
3849
###############################################################################
3950
4051
fossil unversioned
4152
test unversioned-1 {[normalize_result] eq \
4253
[string map [list %fossil% [file nativename $fossilexe]] {Usage: %fossil%\
@@ -190,13 +201,10 @@
190201
test unversioned-27 {$hash(before) eq \
191202
{b48ba8e2d0b498321dfd13de84867effda399af5}}
192203
193204
###############################################################################
194205
195
-set env(VISUAL) [appendArgs \
196
- [info nameofexecutable] " " [file join $path fake-editor.tcl]]
197
-
198206
fossil unversioned edit unversioned4.txt
199207
test unversioned-28 {[normalize_result] eq {}}
200208
201209
###############################################################################
202210
@@ -295,14 +303,119 @@
295303
{^[0-9a-f]{12} 2016-10-01 00:00:00 30 30 unversioned2\.txt
296304
[0-9a-f]{12} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 28 28\
297305
unversioned5\.txt$} [normalize_result]]}
298306
299307
###############################################################################
300
-#
301
-# TODO: Add tests for the unversioned "revert" and "sync" sub-commands.
302
-#
303
-# revert --verbose --dryrun
304
-# sync
305
-#
308
+
309
+set password [string trim [clock seconds] -]
310
+set remote [appendArgs http://uvtester: $password @localhost:8080/]
311
+
312
+fossil user new uvtester "Unversioned Test User" $password
313
+fossil user capabilities uvtester oy
314
+
315
+###############################################################################
316
+
317
+set pid [test_start_server $repository stopArg]
318
+puts [appendArgs "Started Fossil server, pid \"" $pid \".]
319
+
320
+###############################################################################
321
+
322
+set clientDir [file join $tempPath [appendArgs \
323
+ uvtest_ [string trim [clock seconds] -] _ [getSeqNo]]]
324
+
325
+set savedPwd [pwd]
326
+file mkdir $clientDir; cd $clientDir
327
+puts [appendArgs "Now in client directory \"" [pwd] \".]
328
+
329
+###############################################################################
330
+
331
+fossil_maybe_answer y clone $remote uvrepo.fossil
332
+fossil open uvrepo.fossil
333
+
334
+###############################################################################
335
+
336
+fossil unversioned list
337
+test unversioned-45 {[normalize_result] eq {}}
338
+
339
+###############################################################################
340
+
341
+fossil_maybe_answer y unversioned sync $remote
342
+test unversioned-46 {[regexp \
343
+{Round-trips: 1 Artifacts sent: 0 received: 0
344
+Round-trips: 1 Artifacts sent: 0 received: 0
345
+Round-trips: 2 Artifacts sent: 0 received: 0
346
+Round-trips: 2 Artifacts sent: 0 received: 2
347
+
348
+ done, sent: \d+ received: \d+ ip: 127.0.0.1} [normalize_result]]}
349
+
350
+###############################################################################
351
+
352
+fossil unversioned ls
353
+test unversioned-47 {[normalize_result] eq {unversioned2.txt
354
+unversioned5.txt}}
355
+
356
+###############################################################################
357
+
358
+set env(FAKE_EDITOR_SCRIPT) "append data this_is_a_test"; # deterministic
359
+
360
+fossil unversioned edit unversioned2.txt
361
+test unversioned-48 {[normalize_result] eq {}}
362
+
363
+unset env(FAKE_EDITOR_SCRIPT)
364
+
365
+###############################################################################
366
+
367
+fossil unversioned remove unversioned5.txt
368
+test unversioned-49 {[normalize_result] eq {}}
369
+
370
+###############################################################################
371
+
372
+fossil unversioned list --all
373
+test unversioned-50 {[regexp \
374
+{^[0-9a-f]{12} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 44 44\
375
+unversioned2\.txt
376
+ \(deleted\) \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0 0\
377
+unversioned5\.txt$} [normalize_result]]}
378
+
379
+###############################################################################
380
+
381
+fossil_maybe_answer y unversioned revert $remote
382
+test unversioned-51 {[regexp \
383
+{Round-trips: 1 Artifacts sent: 0 received: 0
384
+Round-trips: 1 Artifacts sent: 0 received: 0
385
+Round-trips: 2 Artifacts sent: 0 received: 0
386
+Round-trips: 2 Artifacts sent: 0 received: 2
387
+
388
+ done, sent: \d+ received: \d+ ip: 127.0.0.1} [normalize_result]]}
389
+
390
+###############################################################################
391
+
392
+fossil unversioned list
393
+test unversioned-52 {[regexp \
394
+{^[0-9a-f]{12} 2016-10-01 00:00:00 30 30\
395
+unversioned2\.txt
396
+[0-9a-f]{12} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 28 28\
397
+unversioned5\.txt$} [normalize_result]]}
398
+
399
+###############################################################################
400
+
401
+fossil close
402
+test unversioned-53 {[normalize_result] eq {}}
403
+
404
+###############################################################################
405
+
406
+cd $savedPwd; unset savedPwd
407
+file delete -force $clientDir
408
+puts [appendArgs "Now in server directory \"" [pwd] \".]
409
+
410
+###############################################################################
411
+
412
+set stopped [test_stop_server $stopArg $pid]
413
+
414
+puts [appendArgs \
415
+ [expr {$stopped ? "Stopped" : "Could not stop"}] \
416
+ " Fossil server, pid \"" $pid "\", using argument \"" \
417
+ $stopArg \".]
418
+
306419
###############################################################################
307420
308421
test_cleanup
309422
--- test/unversioned.test
+++ test/unversioned.test
@@ -26,17 +26,28 @@
26 }
27
28 require_no_open_checkout
29
30 test_setup; set rootDir [file normalize [pwd]]
 
 
 
 
 
 
 
 
31
32 write_file unversioned1.txt "This is unversioned file #1."
33 write_file unversioned2.txt " This is unversioned file #2. "
34 write_file "unversioned space.txt" "\nThis is unversioned file #3.\n"
35 write_file unversioned4.txt "This is unversioned file #4."
36 write_file unversioned5.txt "This is unversioned file #5."
37
 
 
 
38 ###############################################################################
39
40 fossil unversioned
41 test unversioned-1 {[normalize_result] eq \
42 [string map [list %fossil% [file nativename $fossilexe]] {Usage: %fossil%\
@@ -190,13 +201,10 @@
190 test unversioned-27 {$hash(before) eq \
191 {b48ba8e2d0b498321dfd13de84867effda399af5}}
192
193 ###############################################################################
194
195 set env(VISUAL) [appendArgs \
196 [info nameofexecutable] " " [file join $path fake-editor.tcl]]
197
198 fossil unversioned edit unversioned4.txt
199 test unversioned-28 {[normalize_result] eq {}}
200
201 ###############################################################################
202
@@ -295,14 +303,119 @@
295 {^[0-9a-f]{12} 2016-10-01 00:00:00 30 30 unversioned2\.txt
296 [0-9a-f]{12} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 28 28\
297 unversioned5\.txt$} [normalize_result]]}
298
299 ###############################################################################
300 #
301 # TODO: Add tests for the unversioned "revert" and "sync" sub-commands.
302 #
303 # revert --verbose --dryrun
304 # sync
305 #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306 ###############################################################################
307
308 test_cleanup
309
--- test/unversioned.test
+++ test/unversioned.test
@@ -26,17 +26,28 @@
26 }
27
28 require_no_open_checkout
29
30 test_setup; set rootDir [file normalize [pwd]]
31
32 fossil test-th-eval --open-config {repository}
33 set repository [normalize_result]
34
35 if {[string length $repository] == 0} {
36 puts "Detection of the open repository file failed."
37 test_cleanup_then_return
38 }
39
40 write_file unversioned1.txt "This is unversioned file #1."
41 write_file unversioned2.txt " This is unversioned file #2. "
42 write_file "unversioned space.txt" "\nThis is unversioned file #3.\n"
43 write_file unversioned4.txt "This is unversioned file #4."
44 write_file unversioned5.txt "This is unversioned file #5."
45
46 set env(VISUAL) [appendArgs \
47 [info nameofexecutable] " " [file join $path fake-editor.tcl]]
48
49 ###############################################################################
50
51 fossil unversioned
52 test unversioned-1 {[normalize_result] eq \
53 [string map [list %fossil% [file nativename $fossilexe]] {Usage: %fossil%\
@@ -190,13 +201,10 @@
201 test unversioned-27 {$hash(before) eq \
202 {b48ba8e2d0b498321dfd13de84867effda399af5}}
203
204 ###############################################################################
205
 
 
 
206 fossil unversioned edit unversioned4.txt
207 test unversioned-28 {[normalize_result] eq {}}
208
209 ###############################################################################
210
@@ -295,14 +303,119 @@
303 {^[0-9a-f]{12} 2016-10-01 00:00:00 30 30 unversioned2\.txt
304 [0-9a-f]{12} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 28 28\
305 unversioned5\.txt$} [normalize_result]]}
306
307 ###############################################################################
308
309 set password [string trim [clock seconds] -]
310 set remote [appendArgs http://uvtester: $password @localhost:8080/]
311
312 fossil user new uvtester "Unversioned Test User" $password
313 fossil user capabilities uvtester oy
314
315 ###############################################################################
316
317 set pid [test_start_server $repository stopArg]
318 puts [appendArgs "Started Fossil server, pid \"" $pid \".]
319
320 ###############################################################################
321
322 set clientDir [file join $tempPath [appendArgs \
323 uvtest_ [string trim [clock seconds] -] _ [getSeqNo]]]
324
325 set savedPwd [pwd]
326 file mkdir $clientDir; cd $clientDir
327 puts [appendArgs "Now in client directory \"" [pwd] \".]
328
329 ###############################################################################
330
331 fossil_maybe_answer y clone $remote uvrepo.fossil
332 fossil open uvrepo.fossil
333
334 ###############################################################################
335
336 fossil unversioned list
337 test unversioned-45 {[normalize_result] eq {}}
338
339 ###############################################################################
340
341 fossil_maybe_answer y unversioned sync $remote
342 test unversioned-46 {[regexp \
343 {Round-trips: 1 Artifacts sent: 0 received: 0
344 Round-trips: 1 Artifacts sent: 0 received: 0
345 Round-trips: 2 Artifacts sent: 0 received: 0
346 Round-trips: 2 Artifacts sent: 0 received: 2
347
348 done, sent: \d+ received: \d+ ip: 127.0.0.1} [normalize_result]]}
349
350 ###############################################################################
351
352 fossil unversioned ls
353 test unversioned-47 {[normalize_result] eq {unversioned2.txt
354 unversioned5.txt}}
355
356 ###############################################################################
357
358 set env(FAKE_EDITOR_SCRIPT) "append data this_is_a_test"; # deterministic
359
360 fossil unversioned edit unversioned2.txt
361 test unversioned-48 {[normalize_result] eq {}}
362
363 unset env(FAKE_EDITOR_SCRIPT)
364
365 ###############################################################################
366
367 fossil unversioned remove unversioned5.txt
368 test unversioned-49 {[normalize_result] eq {}}
369
370 ###############################################################################
371
372 fossil unversioned list --all
373 test unversioned-50 {[regexp \
374 {^[0-9a-f]{12} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 44 44\
375 unversioned2\.txt
376 \(deleted\) \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 0 0\
377 unversioned5\.txt$} [normalize_result]]}
378
379 ###############################################################################
380
381 fossil_maybe_answer y unversioned revert $remote
382 test unversioned-51 {[regexp \
383 {Round-trips: 1 Artifacts sent: 0 received: 0
384 Round-trips: 1 Artifacts sent: 0 received: 0
385 Round-trips: 2 Artifacts sent: 0 received: 0
386 Round-trips: 2 Artifacts sent: 0 received: 2
387
388 done, sent: \d+ received: \d+ ip: 127.0.0.1} [normalize_result]]}
389
390 ###############################################################################
391
392 fossil unversioned list
393 test unversioned-52 {[regexp \
394 {^[0-9a-f]{12} 2016-10-01 00:00:00 30 30\
395 unversioned2\.txt
396 [0-9a-f]{12} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} 28 28\
397 unversioned5\.txt$} [normalize_result]]}
398
399 ###############################################################################
400
401 fossil close
402 test unversioned-53 {[normalize_result] eq {}}
403
404 ###############################################################################
405
406 cd $savedPwd; unset savedPwd
407 file delete -force $clientDir
408 puts [appendArgs "Now in server directory \"" [pwd] \".]
409
410 ###############################################################################
411
412 set stopped [test_stop_server $stopArg $pid]
413
414 puts [appendArgs \
415 [expr {$stopped ? "Stopped" : "Could not stop"}] \
416 " Fossil server, pid \"" $pid "\", using argument \"" \
417 $stopArg \".]
418
419 ###############################################################################
420
421 test_cleanup
422

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button