/
entry.tcl
188 lines (152 loc) · 6.94 KB
/
entry.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Test file for registry::entry
# Syntax:
# tclsh entry.tcl registry.dylib
proc main {pextlibname} {
load $pextlibname
# totally lame that file delete won't do it
exec -ignorestderr rm -f {*}[glob -nocomplain test.db*]
# can't create registry in some brain-dead place or in protected place
test_throws {registry::open /some/brain/dead/place} registry::cannot-init
# This would actually work when testing with sudo :(
#test_throws {registry::open /etc/macports_test_prot~} registry::cannot-init
# can't use registry before it's opened
test_throws {registry::write {}} registry::misuse
registry::open test.db
# no nested transactions
registry::write {
test_throws {registry::read {}} registry::misuse
}
# write transaction
registry::write {
# create some (somewhat contrived) ports to play with
set vim1 [registry::entry create vim 7.1.000 0 +cscope+multibyte 0]
set vim2 [registry::entry create vim 7.1.002 0 {} 0]
set vim3 [registry::entry create vim 7.1.002 0 +cscope+multibyte 0]
set zlib [registry::entry create zlib 1.2.3 1 {} 0]
set pcre [registry::entry create pcre 7.1 1 +utf8 0]
# check that their properties can be set
$vim1 state imaged
$vim2 state imaged
$vim3 state installed
$zlib state installed
$pcre state imaged
$vim1 installtype image
$vim2 installtype image
$vim3 installtype image
$zlib installtype direct
$pcre installtype image
}
# check that their properties can be retrieved
# (also try a read transaction)
registry::read {
test_equal {[$vim1 name]} vim
test_equal {[$vim2 epoch]} 0
test_equal {[$vim3 version]} 7.1.002
test_equal {[$zlib revision]} 1
test_equal {[$pcre variants]} +utf8
# check that imaged and installed give correct results
test_set {[registry::entry imaged]} {$vim1 $vim2 $vim3 $zlib $pcre}
test_set {[registry::entry installed]} {$vim3 $zlib}
test_set {[registry::entry imaged vim]} {$vim1 $vim2 $vim3}
test_set {[registry::entry imaged vim 7.1.000]} {$vim1}
test_set {[registry::entry imaged vim 7.1.002]} {$vim2 $vim3}
test_set {[registry::entry imaged vim 7.1.002 0 {}]} {$vim2}
test_set {[registry::entry imaged vim 7.1.002 0 +cscope+multibyte]} \
{$vim3}
# try searching for ports
# note that 7.1.2 != 7.1.002 but the VERSION collation should be smart
# enough to ignore the zeroes
test_set {[registry::entry search name vim version 7.1.2]} {$vim2 $vim3}
test_set {[registry::entry search variants {}]} {$vim2 $zlib}
test_set {[registry::entry search name -glob vi*]} {$vim1 $vim2 $vim3}
test_set {[registry::entry search name -regexp {zlib|pcre}]} \
{$zlib $pcre}
# test that passing in confusing arguments doesn't crash
test {[catch {registry::entry search name vim1 --}] == 1}
}
# try mapping files and checking their owners
registry::write {
test_equal {[registry::entry owner /opt/local/bin/vimtutor]} {}
test_equal {[$vim3 files]} {}
$vim1 map {}
$vim1 map /opt/local/bin/vim
$vim1 map [list /opt/local/bin/vimdiff /opt/local/bin/vimtutor]
$vim2 map [$vim1 imagefiles]
$vim3 map [$vim1 imagefiles]
test_equal {[registry::entry owner /opt/local/bin/vimtutor]} {}
test_equal {[$vim3 files]} {}
$vim3 activate [$vim3 imagefiles]
test_equal {[registry::entry owner /opt/local/bin/vimtutor]} {$vim3}
test_equal {[registry::entry owner /opt/local/bin/emacs]} {}
test_set {[$vim3 imagefiles]} {/opt/local/bin/vim \
/opt/local/bin/vimdiff /opt/local/bin/vimtutor}
test_set {[$vim3 files]} [$vim3 imagefiles]
test_set {[$zlib imagefiles]} {}
# try activating over files
test_throws {$vim2 activate [$vim2 imagefiles]} registry::already-active
# try unmapping and remapping
$vim3 unmap /opt/local/bin/vimtutor
test_equal {[registry::entry owner /opt/local/bin/vimtutor]} {}
$vim3 deactivate /opt/local/bin/vim
test_equal {[registry::entry owner /opt/local/bin/vim]} {}
$vim3 unmap /opt/local/bin/vim
test_equal {[registry::entry owner /opt/local/bin/vim]} {}
$vim3 map /opt/local/bin/vim
test_equal {[registry::entry owner /opt/local/bin/vim]} {}
$vim3 activate /opt/local/bin/vim
puts [$vim3 files]
puts [registry::entry owner /opt/local/bin/vim]
test_equal {[registry::entry owner /opt/local/bin/vim]} {$vim3}
# activate to a different location
$vim3 deactivate /opt/local/bin/vimdiff
$vim3 activate /opt/local/bin/vimdiff /opt/local/bin/vimdiff.0
$vim2 activate /opt/local/bin/vimdiff
test_set {[$vim3 files]} {/opt/local/bin/vim /opt/local/bin/vimdiff.0}
test_set {[$vim3 imagefiles]} {/opt/local/bin/vim \
/opt/local/bin/vimdiff}
test_equal {[registry::entry owner /opt/local/bin/vimdiff]} {$vim2}
test_equal {[registry::entry owner /opt/local/bin/vimdiff.0]} {$vim3}
# make sure you can't unmap a file you don't own
test_throws {$zlib unmap [list /opt/local/bin/vim]} registry::invalid
test_throws {$zlib unmap [list /opt/local/bin/emacs]} registry::invalid
}
test_set {[$vim3 imagefiles]} {/opt/local/bin/vim /opt/local/bin/vimdiff}
test_set {[$vim3 files]} {/opt/local/bin/vim /opt/local/bin/vimdiff.0}
# try some deletions
test_set {[registry::entry installed zlib]} {$zlib}
test_set {[registry::entry imaged pcre]} {$pcre}
# try rolling a deletion back
registry::write {
registry::entry delete $zlib
break
}
test_equal {[registry::entry open zlib 1.2.3 1 {} 0]} {$zlib}
# try actually deleting something
registry::entry delete $pcre
test_throws {registry::entry open pcre 7.1 1 +utf8 0} \
registry::not-found
test {![registry::entry exists $pcre]}
# close vim1
test {[registry::entry exists $vim1]}
registry::entry close $vim1
test {![registry::entry exists $vim1]}
# close the registry; make sure the registry isn't usable after being
# closed, then ensure state persists between open sessions
registry::close
test_throws {registry::entry search} registry::misuse
test {![registry::entry exists $vim3]}
registry::open test.db
# check that the same vim is installed from before
set vim3 [registry::entry installed vim]
test_equal {[$vim3 version]} 7.1.002
# find the zlib we inserted before
set zlib [registry::entry open zlib 1.2.3 1 {} 0]
test {[registry::entry exists $zlib]}
# check that pcre is still gone
test_throws {registry::entry open pcre 7.1 1 +utf8 0} \
registry::not-found
registry::close
file delete test.db
}
source tests/common.tcl
main $argv