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 65foreach {tn tcl} { 66 1 { 67 set c1 ".ar c ar1" 68 set x1 ".ar x" 69 70 set c2 ".ar cC ar1 ." 71 set x2 ".ar Cx ar3" 72 } 73 74 2 { 75 set c1 ".ar -c ar1" 76 set x1 ".ar -x" 77 78 set c2 ".ar -cC ar1 ." 79 set x2 ".ar -xC ar3" 80 } 81 82 3 { 83 set c1 ".ar --create ar1" 84 set x1 ".ar --extract" 85 86 set c2 ".ar --directory ar1 --create ." 87 set x2 ".ar --extract --dir ar3" 88 } 89 90 4 { 91 set c1 ".ar --cr ar1" 92 set x1 ".ar --e" 93 94 set c2 ".ar -C ar1 -c ." 95 set x2 ".ar -x -C ar3" 96 } 97} { 98 eval $tcl 99 100 # Populate directory "ar1" with some files. 101 # 102 populate_dir ar1 { 103 file1 "abcd" 104 file2 "efgh" 105 dir1/file3 "ijkl" 106 } 107 set expected [dir_to_list ar1] 108 109 do_test 1.$tn.1 { 110 catchcmd test_ar.db $c1 111 file delete -force ar1 112 catchcmd test_ar.db $x1 113 dir_to_list ar1 114 } $expected 115 116 do_test 1.$tn.2 { 117 file delete -force ar3 118 catchcmd test_ar.db $c2 119 catchcmd test_ar.db $x2 120 dir_to_list ar3 121 } $expected 122} 123 124finish_test 125 126 127 128finish_test 129 130