3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # Test the shell tool ".ar" command.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
22 set CLI [test_find_cli]
24 proc populate_dir {dirname spec} {
25 # First delete the current tree, if one exists.
26 file delete -force $dirname
28 # Recreate the root of the new tree.
31 # Add each file to the new tree.
33 set path [file join $dirname $f]
34 file mkdir [file dirname $path]
36 puts -nonewline $fd $d
41 proc dir_to_list {dirname {n -1}} {
42 if {$n<0} {set n [llength [file split $dirname]]}
45 foreach f [glob -nocomplain $dirname/*] {
46 set mtime [file mtime $f]
47 if {$::tcl_platform(platform)!="windows"} {
48 set perm [file attributes $f -perm]
52 set relpath [file join {*}[lrange [file split $f] $n end]]
54 if {[file isdirectory $f]} {
55 lappend res [list $relpath / $mtime $perm]
56 lappend res {*}[dir_to_list $f]
61 lappend res [list $relpath $data $mtime $perm]
67 proc dir_compare {d1 d2} {
68 set l1 [dir_to_list $d1]
69 set l2 [dir_to_list $d1]
70 string compare $l1 $l2
81 set c3 ".ar cCf ar1 test_xyz.db ."
82 set x3 ".ar Cfx ar3 test_xyz.db"
89 set c2 ".ar -cC ar1 ."
92 set c3 ".ar -cCar1 -ftest_xyz.db ."
93 set x3 ".ar -x -C ar3 -f test_xyz.db"
97 set c1 ".ar --create ar1"
98 set x1 ".ar --extract"
100 set c2 ".ar --directory ar1 --create ."
101 set x2 ".ar --extract --dir ar3"
103 set c3 ".ar --creat --dir ar1 --file test_xyz.db ."
104 set x3 ".ar --e --dir ar3 --f test_xyz.db"
108 set c1 ".ar --cr ar1"
111 set c2 ".ar -C ar1 -c ."
112 set x2 ".ar -x -C ar3"
114 set c3 ".ar -c --directory ar1 --file test_xyz.db ."
115 set x3 ".ar -x --directory ar3 --file test_xyz.db"
120 # Populate directory "ar1" with some files.
127 set expected [dir_to_list ar1]
130 catchcmd test_ar.db $c1
131 file delete -force ar1
132 catchcmd test_ar.db $x1
137 file delete -force ar3
138 catchcmd test_ar.db $c2
139 catchcmd test_ar.db $x2
144 file delete -force ar3
145 file delete -force test_xyz.db
146 catchcmd ":memory:" $c3
147 catchcmd ":memory:" $x3
151 # This is a repeat of test 1.$tn.1, except that there is a 2 second
152 # pause between creating the archive and extracting its contents.
153 # This is to test that timestamps are set correctly.
155 # Because it is slow, only do this for $tn==1.
158 catchcmd test_ar.db $c1
159 file delete -force ar1
161 catchcmd test_ar.db $x1