File: tie_growfile.test

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (343 lines) | stat: -rw-r--r-- 9,842 bytes parent folder | download | duplicates (3)
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# Tests for the tie module.                              -*- tcl -*- 
#
# Copyright (c) 2004-2021 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 1.0

support {
    use      snit/snit.tcl snit
    useLocal tie.tcl       tie
}
testing {
    useLocal tie_growfile.tcl tie::std::growfile
}

# -------------------------------------------------------------------------
# Creation of array data sources
# Errors: Undefined variable, scalar, local variable

test tie-growfile-1.0 {file creation, wrong#args} {
    catch {tie::std::growfile} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::growfile::Snit_constructor type selfns win self thepath"}

test tie-growfile-1.1 {file creation, wrong#args} {
    catch {tie::std::growfile x} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::growfile::Snit_constructor type selfns win self thepath"}

test tie-growfile-1.2 {file creation, wrong#args} {
    catch {tie::std::growfile x y z} msg
    set msg
} {Error in constructor: wrong # args: should be "::tie::std::growfile::Snit_constructor type selfns win self thepath"}

test tie-growfile-1.3 {file creation, ok args, unwritable file} {unixOnly notRoot} {
    set f [makeFile {} journal]
    file attributes $f -permissions ugo-w
    catch {tie::std::growfile x $f} msg
    removeFile journal
    string map [list $f @] $msg
} {Error in constructor: couldn't open "@": permission denied}

test tie-growfile-1.4 {file creation, ok args, unwritable file} {winOnly} {
    set f [makeFile {} journal]
    file attributes $f -readonly 1
    catch {tie::std::growfile x $f} msg
    file attributes $f -readonly 0
    removeFile journal
    string map [list $f @] $msg
} {Error in constructor: couldn't open "@": permission denied}

test tie-growfile-1.5 {file creation, ok args, unreadable file} {unixOnly notRoot} {
    set f [makeFile {} journal]
    file attributes $f -permissions ugo-r
    catch {tie::std::growfile x $f} msg
    removeFile journal
     string map [list $f @] $msg
} {Error in constructor: couldn't open "@": permission denied}

test tie-growfile-1.6 {file creation, ok args, uncreateable file} {unixOnly notRoot} {
    set d [makeDirectory jtest]
    set f [makeFile {}   jtest/journal]

    # Delete the created file, we want the tie code to try to generate
    # it (and expect it to fail).
    file delete $f

    file attributes $d -permissions ugo-w

    catch {tie::std::growfile x $f} msg

    removeDirectory jtest
    string map [list $f @] $msg
} {Error in constructor: couldn't open "@": permission denied}

test tie-growfile-1.7 {file creation, ok args, uncreateable file} {knownBug winOnly notRoot} {
    set d [makeDirectory jtest]
    set f [makeFile {}   jtest/journal]
    removeFile jtest/journal
    file attributes $d -readonly 1

    catch {tie::std::growfile x $f} msg

    removeFile      jtest/journal
    removeDirectory jtest
    string map [list $f @] $msg
} {Error in constructor: couldn't open "@": permission denied}

test tie-growfile-1.8 {file creation, fixed name, array} {
    set f [makeFile {} journal]
    set msg [tie::std::growfile x $f]
    x destroy
    removeFile journal
    set msg
} {::x}

test tie-growfile-1.9 {file creation, %AUTO%} {
    set f [makeFile {} journal]
    set msg [tie::std::growfile %AUTO% $f]
    $msg destroy
    removeFile journal
    string match ::growfile\[679] $msg
} 1

# -------------------------------------------------------------------------
## Methods

test tie-growfile-2.0 {file get, wrong#args} {
    set f [makeFile {b 2 a 1} journal]
    tie::std::growfile x $f
    catch {x get a} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodget type selfns win self"}

test tie-growfile-2.1 {file get} {
    set f [makeFile {b 2 a 1} journal]
    tie::std::growfile x $f
    set res [dictsort [x get]]
    x destroy
    removeFile journal
    set res
} {a 1 b 2}


test tie-growfile-3.0 {file set, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x set} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodset type selfns win self dict"}

test tie-growfile-3.1 {file set, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x set a b} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodset type selfns win self dict"}

test tie-growfile-3.2 {file set} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    lappend res [x set {c 3 b 2 a 1}]
    lappend res [viewFile journal]
    x destroy
    removeFile journal
    set res
} {{} {
c 3 b 2 a 1 }}


test tie-growfile-4.0 {file names, wrong#args} {
    set f [makeFile {b 2 a 1} journal]
    tie::std::growfile x $f
    catch {x names a} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodnames type selfns win self"}

test tie-growfile-4.1 {file names} {
    set f [makeFile {b 2 a 1} journal]
    tie::std::growfile x $f
    set res [lsort [x names]]
    x destroy
    removeFile journal
    set res
} {a b}


test tie-growfile-5.0 {file size, wrong#args} {
    set f [makeFile {b 2 a 1} journal]
    tie::std::growfile x $f
    catch {x size a} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodsize type selfns win self"}

test tie-growfile-5.1 {file size} {
    set f [makeFile {b 2 a 1} journal]
    tie::std::growfile x $f
    set res [x size]
    x destroy
    removeFile journal
    set res
} 2


test tie-growfile-6.0 {file unset, wrong#args} {
    set f [makeFile {foo bar fox snarf a 3} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x unset a b} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodunset type selfns win self ?pattern?"}

test tie-growfile-6.1 {file unset, default pattern} {
    set f [makeFile {foo bar fox snarf a 3} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x unset} msg
    x destroy
    removeFile journal
    set msg
} {Deletion of entries is not allowed by this data source}

test tie-growfile-6.2 {file unset, by pattern} {
    set f [makeFile {foo bar fox snarf a 3} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x unset f*} msg
    x destroy
    removeFile journal
    set msg
} {Deletion of entries is not allowed by this data source}


test tie-growfile-7.0 {file getv, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x getv} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodgetv type selfns win self index"}

test tie-growfile-7.1 {file getv, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x getv a b} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodgetv type selfns win self index"}

test tie-growfile-7.2 {file getv} {
    set f [makeFile {a 3 b 4} journal]
    tie::std::growfile x $f
    set     res {}
    lappend res [x getv a]
    x destroy
    removeFile journal
    set res
} 3


test tie-growfile-8.0 {file setv, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x setv} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodsetv type selfns win self index value"}

test tie-growfile-8.1 {file setv, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x setv a} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodsetv type selfns win self index value"}

test tie-growfile-8.2 {file setv, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x setv a b c} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodsetv type selfns win self index value"}

test tie-growfile-8.3 {file setv} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    lappend res [x setv fox snarf]
    lappend res [viewFile journal]
    x destroy
    removeFile journal
    set res
} {{} {
fox snarf }}


test tie-growfile-9.0 {file unsetv, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x unsetv} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodunsetv type selfns win self index"}

test tie-growfile-9.1 {file unsetv, wrong#args} {
    set f [makeFile {} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x unsetv a b} msg
    x destroy
    removeFile journal
    set msg
} {wrong # args: should be "::tie::std::growfile::Snit_methodunsetv type selfns win self index"}

test tie-growfile-9.2 {file unsetv} {
    set f [makeFile {a 3 b 4} journal]
    tie::std::growfile x $f
    set     res {}
    catch {x unsetv a} msg
    x destroy
    removeFile journal
    set msg
} {Deletion of entries is not allowed by this data source}

# -------------------------------------------------------------------------

testsuiteCleanup
return