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 #***********************************************************************
13 # Test the shell tool ".ar" command.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
23 set CLI [test_cli_invocation]
25 # Check to make sure the shell has been compiled with ".archive" support.
27 if {[string match {*unknown command*} [catchcmd :memory: .archive]]} {
31 proc populate_dir {dirname spec} {
32 # First delete the current tree, if one exists.
33 file delete -force $dirname
35 # Recreate the root of the new tree.
38 # Add each file to the new tree.
40 set path [file join $dirname $f]
41 file mkdir [file dirname $path]
43 puts -nonewline $fd $d
48 proc dir_content {dirname} {
49 lsort [glob -nocomplain $dirname/*]
52 proc dir_to_list {dirname {n -1}} {
53 if {$n<0} {set n [llength [file split $dirname]]}
56 foreach f [glob -nocomplain $dirname/*] {
57 set mtime [file mtime $f]
58 if {$::tcl_platform(platform)!="windows"} {
59 set perm [file attributes $f -perm]
63 set relpath [file join {*}[lrange [file split $f] $n end]]
65 if {[file isdirectory $f]} {
66 lappend res [list $relpath / $mtime $perm]
67 lappend res {*}[dir_to_list $f]
72 lappend res [list $relpath $data $mtime $perm]
78 proc dir_compare {d1 d2} {
79 set l1 [dir_to_list $d1]
80 set l2 [dir_to_list $d1]
81 string compare $l1 $l2
92 set c3 ".ar cCf ar1 test_xyz.db ."
93 set x3 ".ar Cfx ar3 test_xyz.db"
100 set c2 ".ar -cC ar1 ."
103 set c3 ".ar -cCar1 -ftest_xyz.db ."
104 set x3 ".ar -x -C ar3 -f test_xyz.db"
108 set c1 ".ar --create ar1"
109 set x1 ".ar --extract"
111 set c2 ".ar --directory ar1 --create ."
112 set x2 ".ar --extract --dir ar3"
114 set c3 ".ar --creat --dir ar1 --file test_xyz.db ."
115 set x3 ".ar --e --dir ar3 --f test_xyz.db"
119 set c1 ".ar --cr ar1"
122 set c2 ".ar -C ar1 -c ."
123 set x2 ".ar -x -C ar3"
125 set c3 ".ar -c --directory ar1 --file test_xyz.db ."
126 set x3 ".ar -x --directory ar3 --file test_xyz.db"
131 # Populate directory "ar1" with some files.
138 set expected [dir_to_list ar1]
141 catchcmd test_ar.db $c1
142 file delete -force ar1
143 catchcmd test_ar.db $x1
148 file delete -force ar3
149 catchcmd test_ar.db $c2
150 catchcmd test_ar.db $x2
155 file delete -force ar3
156 file delete -force test_xyz.db
157 catchcmd ":memory:" $c3
158 catchcmd ":memory:" $x3
162 # This is a repeat of test 1.$tn.1, except that there is a 2 second
163 # pause between creating the archive and extracting its contents.
164 # This is to test that timestamps are set correctly.
166 # Because it is slow, only do this for $tn==1.
169 catchcmd test_ar.db $c1
170 file delete -force ar1
172 catchcmd test_ar.db $x1
189 catchcmd shell8.db {.ar -c}
190 catchcmd shell8.db {.ar -C ar2 -i .}
191 catchcmd shell8.db {.ar -r ./file2 ./dir1}
192 catchcmd shell8.db {.ar -g -r ./ju*2}
193 catchcmd shell8.db {.ar -C ar4 -x .}
194 regsub -all {ar4} [dir_content ar4] ar2
195 } {ar2/file1 ar2/file2 ar2/junk1}
197 # Test symbolic links.
199 if {$tcl_platform(platform)=="unix"} {
204 file link ar2/link1 file1
206 forcedelete shell8.db
210 catchcmd shell8.db {.ar -C ar2 -c file2 link1 }
214 catchcmd shell8.db {.ar -x}
218 catchcmd shell8.db {.ar -x}