1# 2017 December 9 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# 12# Test the shell tool ".ar" command. 13# 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set testprefix shell8 18set CLI [test_find_cli] 19 20proc populate_dir {dirname spec} { 21 # First delete the current tree, if one exists. 22 file delete -force $dirname 23 24 # Recreate the root of the new tree. 25 file mkdir $dirname 26 27 # Add each file to the new tree. 28 foreach {f d} $spec { 29 set path [file join $dirname $f] 30 file mkdir [file dirname $path] 31 set fd [open $path w] 32 puts -nonewline $fd $d 33 close $fd 34 } 35} 36 37proc dir_to_list {dirname {n -1}} { 38 if {$n<0} {set n [llength [file split $dirname]]} 39 40 set res [list] 41 foreach f [glob -nocomplain $dirname/*] { 42 set mtime [file mtime $f] 43 set perm [file attributes $f -perm] 44 set relpath [file join {*}[lrange [file split $f] $n end]] 45 lappend res 46 if {[file isdirectory $f]} { 47 lappend res [list $relpath / $mtime $perm] 48 lappend res {*}[dir_to_list $f] 49 } else { 50 set fd [open $f] 51 set data [read $fd] 52 close $fd 53 lappend res [list $relpath $data $mtime $perm] 54 } 55 } 56 lsort $res 57} 58 59proc dir_compare {d1 d2} { 60 set l1 [dir_to_list $d1] 61 set l2 [dir_to_list $d1] 62 string compare $l1 $l2 63} 64 65populate_dir ar1 { 66 file1 "abcd" 67 file2 "efgh" 68 dir1/file3 "ijkl" 69} 70 71set expected [dir_to_list ar1] 72# puts "# $expected" 73do_test 1.1 { 74 forcedelete test_ar.db 75 76 catchcmd test_ar.db ".ar c ar1" 77 file delete -force ar1 78 catchcmd test_ar.db ".ar x" 79 80 dir_to_list ar1 81} $expected 82 83do_test 1.2 { 84 file delete -force ar3 85 file mkdir ar3 86 catchcmd test_ar.db ".ar xvC ar3" 87 dir_to_list ar3/ar1 88} $expected 89 90 91 92finish_test 93