xref: /sqlite-3.40.0/test/shell8.test (revision 88be0209)
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} {
38  set res [list]
39  foreach f [glob -nocomplain $dirname/*] {
40    set mtime [file mtime $f]
41    set perm [file attributes $f -perm]
42    set relpath [file join {*}[lrange [file split $f] 1 end]]
43    lappend res
44    if {[file isdirectory $f]} {
45      lappend res [list $relpath / $mtime $perm]
46      lappend res {*}[dir_to_list $f]
47    } else {
48      set fd [open $f]
49      set data [read $fd]
50      close $fd
51      lappend res [list $relpath $data $mtime $perm]
52    }
53  }
54  lsort $res
55}
56
57proc dir_compare {d1 d2} {
58  set l1 [dir_to_list $d1]
59  set l2 [dir_to_list $d1]
60  string compare $l1 $l2
61}
62
63populate_dir ar1 {
64  file1 "abcd"
65  file2 "efgh"
66  dir1/file3 "ijkl"
67}
68
69set expected [dir_to_list ar1]
70# puts "# $expected"
71do_test 1.1 {
72  forcedelete test_ar.db
73
74  catchcmd test_ar.db ".ar c ar1"
75  file delete -force ar1
76  catchcmd test_ar.db ".ar x"
77
78  dir_to_list ar1
79} $expected
80
81
82
83finish_test
84