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_cli_invocation]
24 # Check to make sure the shell has been compiled with ".archive" support.
26 if {[string match {*unknown command*} [catchcmd :memory: .archive]]} {
30 proc populate_dir {dirname spec} {
31 # First delete the current tree, if one exists.
32 file delete -force $dirname
34 # Recreate the root of the new tree.
37 # Add each file to the new tree.
39 set path [file join $dirname $f]
40 file mkdir [file dirname $path]
42 puts -nonewline $fd $d
47 proc dir_content {dirname} {
48 lsort [glob -nocomplain $dirname/*]
51 proc dir_to_list {dirname {n -1}} {
52 if {$n<0} {set n [llength [file split $dirname]]}
55 foreach f [glob -nocomplain $dirname/*] {
56 set mtime [file mtime $f]
57 if {$::tcl_platform(platform)!="windows"} {
58 set perm [file attributes $f -perm]
62 set relpath [file join {*}[lrange [file split $f] $n end]]
64 if {[file isdirectory $f]} {
65 lappend res [list $relpath / $mtime $perm]
66 lappend res {*}[dir_to_list $f]
71 lappend res [list $relpath $data $mtime $perm]
77 proc dir_compare {d1 d2} {
78 set l1 [dir_to_list $d1]
79 set l2 [dir_to_list $d1]
80 string compare $l1 $l2
91 set c3 ".ar cCf ar1 test_xyz.db ."
92 set x3 ".ar Cfx ar3 test_xyz.db"
99 set c2 ".ar -cC ar1 ."
102 set c3 ".ar -cCar1 -ftest_xyz.db ."
103 set x3 ".ar -x -C ar3 -f test_xyz.db"
107 set c1 ".ar --create ar1"
108 set x1 ".ar --extract"
110 set c2 ".ar --directory ar1 --create ."
111 set x2 ".ar --extract --dir ar3"
113 set c3 ".ar --creat --dir ar1 --file test_xyz.db ."
114 set x3 ".ar --e --dir ar3 --f test_xyz.db"
118 set c1 ".ar --cr ar1"
121 set c2 ".ar -C ar1 -c ."
122 set x2 ".ar -x -C ar3"
124 set c3 ".ar -c --directory ar1 --file test_xyz.db ."
125 set x3 ".ar -x --directory ar3 --file test_xyz.db"
130 # Populate directory "ar1" with some files.
137 set expected [dir_to_list ar1]
140 catchcmd test_ar.db $c1
141 file delete -force ar1
142 catchcmd test_ar.db $x1
147 file delete -force ar3
148 catchcmd test_ar.db $c2
149 catchcmd test_ar.db $x2
154 file delete -force ar3
155 file delete -force test_xyz.db
156 catchcmd ":memory:" $c3
157 catchcmd ":memory:" $x3
161 # This is a repeat of test 1.$tn.1, except that there is a 2 second
162 # pause between creating the archive and extracting its contents.
163 # This is to test that timestamps are set correctly.
165 # Because it is slow, only do this for $tn==1.
168 catchcmd test_ar.db $c1
169 file delete -force ar1
171 catchcmd test_ar.db $x1
188 catchcmd shell8.db {.ar -c}
189 catchcmd shell8.db {.ar -C ar2 -i .}
190 catchcmd shell8.db {.ar -r ./file2 ./dir1}
191 catchcmd shell8.db {.ar -g -r ./ju*2}
192 catchcmd shell8.db {.ar -C ar4 -x .}
193 regsub -all {ar4} [dir_content ar4] ar2
194 } {ar2/file1 ar2/file2 ar2/junk1}