OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [cmdAH.test] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# The file tests the tclCmdAH.c file.
2
#
3
# This file contains a collection of tests for one or more of the Tcl
4
# built-in commands.  Sourcing this file into Tcl runs the tests and
5
# generates output for errors.  No output means no errors were found.
6
#
7
# Copyright (c) 1996-1997 by Sun Microsystems, Inc.
8
#
9
# See the file "license.terms" for information on usage and redistribution
10
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
#
12
# RCS: @(#) $Id: cmdAH.test,v 1.1.1.1 2002-01-16 10:25:35 markom Exp $
13
 
14
if {[string compare test [info procs test]] == 1} then {source defs}
15
 
16
global env
17
catch {set platform [testgetplatform]}
18
 
19
test cmdAH-1.1 {Tcl_FileObjCmd} {
20
    list [catch file msg] $msg
21
} {1 {wrong # args: should be "file option ?arg ...?"}}
22
test cmdAH-1.2 {Tcl_FileObjCmd} {
23
    list [catch {file x} msg] $msg
24
} {1 {bad option "x": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
25
test cmdAH-1.3 {Tcl_FileObjCmd} {
26
    list [catch {file atime} msg] $msg
27
} {1 {wrong # args: should be "file atime name ?arg ...?"}}
28
 
29
 
30
#volume
31
 
32
test cmdAH-2.1 {Tcl_FileObjCmd: volumes} {
33
    list [catch {file volumes x} msg] $msg
34
} {1 {wrong # args: should be "file volumes"}}
35
test cmdAH-2.2 {Tcl_FileObjCmd: volumes} {
36
        set volumeList [file volumes]
37
        if { [llength $volumeList] == 0 } {
38
                set result 0
39
        } else {
40
                set result 1
41
        }
42
} {1}
43
test cmdAH-2.3 {Tcl_FileObjCmd: volumes} {macOrUnix} {
44
    set volumeList [file volumes]
45
    catch [list glob -nocomplain [lindex $volumeList 0]*]
46
} {0}
47
test cmdAH-2.4 {Tcl_FileObjCmd: volumes} {pcOnly} {
48
    set volumeList [file volumes]
49
    list [catch {lsearch $volumeList "c:/"} element] [expr $element != -1] [catch {list glob -nocomplain [lindex $volumeList $element]*}]
50
} {0 1 0}
51
 
52
# attributes
53
 
54
test cmdAH-3.1 {Tcl_FileObjCmd - file attrs} {
55
    catch {file delete -force foo.file}
56
    close [open foo.file w]
57
    list [catch {file attributes foo.file}] [file delete -force foo.file]
58
} {0 {}}
59
 
60
# dirname
61
 
62
if {[info commands testsetplatform] == {}} {
63
    puts "This application hasn't been compiled with the \"testsetplatform\""
64
    puts "command, so I can't test Tcl_FileObjCmd etc."
65
} else {
66
test cmdAH-4.1 {Tcl_FileObjCmd: dirname} {
67
    testsetplatform unix
68
    list [catch {file dirname a b} msg] $msg
69
} {1 {wrong # args: should be "file dirname name"}}
70
test cmdAH-4.2 {Tcl_FileObjCmd: dirname} {
71
    testsetplatform unix
72
    file dirname /a/b
73
} /a
74
test cmdAH-4.3 {Tcl_FileObjCmd: dirname} {
75
    testsetplatform unix
76
    file dirname {}
77
} .
78
test cmdAH-4.4 {Tcl_FileObjCmd: dirname} {
79
    testsetplatform mac
80
    file dirname {}
81
} :
82
test cmdAH-4.5 {Tcl_FileObjCmd: dirname} {
83
    testsetplatform win
84
    file dirname {}
85
} .
86
test cmdAH-4.6 {Tcl_FileObjCmd: dirname} {
87
    testsetplatform unix
88
    file dirname .def
89
} .
90
test cmdAH-4.7 {Tcl_FileObjCmd: dirname} {
91
    testsetplatform mac
92
    file dirname a
93
} :
94
test cmdAH-4.8 {Tcl_FileObjCmd: dirname} {
95
    testsetplatform win
96
    file dirname a
97
} .
98
test cmdAH-4.9 {Tcl_FileObjCmd: dirname} {
99
    testsetplatform unix
100
    file dirname a/b/c.d
101
} a/b
102
test cmdAH-4.10 {Tcl_FileObjCmd: dirname} {
103
    testsetplatform unix
104
    file dirname a/b.c/d
105
} a/b.c
106
test cmdAH-4.11 {Tcl_FileObjCmd: dirname} {
107
    testsetplatform unix
108
    file dirname /.
109
} /
110
test cmdAH-4.12 {Tcl_FileObjCmd: dirname} {
111
    testsetplatform unix
112
    list [catch {file dirname /} msg] $msg
113
} {0 /}
114
test cmdAH-4.13 {Tcl_FileObjCmd: dirname} {
115
    testsetplatform unix
116
    list [catch {file dirname /foo} msg] $msg
117
} {0 /}
118
test cmdAH-4.14 {Tcl_FileObjCmd: dirname} {
119
    testsetplatform unix
120
    list [catch {file dirname //foo} msg] $msg
121
} {0 /}
122
test cmdAH-4.15 {Tcl_FileObjCmd: dirname} {
123
    testsetplatform unix
124
    list [catch {file dirname //foo/bar} msg] $msg
125
} {0 /foo}
126
test cmdAH-4.16 {Tcl_FileObjCmd: dirname} {
127
    testsetplatform unix
128
    list [catch {file dirname {//foo\/bar/baz}} msg] $msg
129
} {0 {/foo\/bar}}
130
test cmdAH-4.17 {Tcl_FileObjCmd: dirname} {
131
    testsetplatform unix
132
    list [catch {file dirname {//foo\/bar/baz/blat}} msg] $msg
133
} {0 {/foo\/bar/baz}}
134
test cmdAH-4.18 {Tcl_FileObjCmd: dirname} {
135
    testsetplatform unix
136
    list [catch {file dirname /foo//} msg] $msg
137
} {0 /}
138
test cmdAH-4.19 {Tcl_FileObjCmd: dirname} {
139
    testsetplatform unix
140
    list [catch {file dirname ./a} msg] $msg
141
} {0 .}
142
test cmdAH-4.20 {Tcl_FileObjCmd: dirname} {
143
    testsetplatform unix
144
    list [catch {file dirname a/.a} msg] $msg
145
} {0 a}
146
test cmdAH-4.21 {Tcl_FileObjCmd: dirname} {
147
    testsetplatform windows
148
    list [catch {file dirname c:foo} msg] $msg
149
} {0 c:}
150
test cmdAH-4.22 {Tcl_FileObjCmd: dirname} {
151
    testsetplatform windows
152
    list [catch {file dirname c:} msg] $msg
153
} {0 c:}
154
test cmdAH-4.23 {Tcl_FileObjCmd: dirname} {
155
    testsetplatform windows
156
    list [catch {file dirname c:/} msg] $msg
157
} {0 c:/}
158
test cmdAH-4.24 {Tcl_FileObjCmd: dirname} {
159
    testsetplatform windows
160
    list [catch {file dirname {c:\foo}} msg] $msg
161
} {0 c:/}
162
test cmdAH-4.25 {Tcl_FileObjCmd: dirname} {
163
    testsetplatform windows
164
    list [catch {file dirname {//foo/bar/baz}} msg] $msg
165
} {0 //foo/bar}
166
test cmdAH-4.26 {Tcl_FileObjCmd: dirname} {
167
    testsetplatform windows
168
    list [catch {file dirname {//foo/bar}} msg] $msg
169
} {0 //foo/bar}
170
test cmdAH-4.27 {Tcl_FileObjCmd: dirname} {
171
    testsetplatform mac
172
    list [catch {file dirname :} msg] $msg
173
} {0 :}
174
test cmdAH-4.28 {Tcl_FileObjCmd: dirname} {
175
    testsetplatform mac
176
    list [catch {file dirname :Foo} msg] $msg
177
} {0 :}
178
test cmdAH-4.29 {Tcl_FileObjCmd: dirname} {
179
    testsetplatform mac
180
    list [catch {file dirname Foo:} msg] $msg
181
} {0 Foo:}
182
test cmdAH-4.30 {Tcl_FileObjCmd: dirname} {
183
    testsetplatform mac
184
    list [catch {file dirname Foo:bar} msg] $msg
185
} {0 Foo:}
186
test cmdAH-4.31 {Tcl_FileObjCmd: dirname} {
187
    testsetplatform mac
188
    list [catch {file dirname :Foo:bar} msg] $msg
189
} {0 :Foo}
190
test cmdAH-4.32 {Tcl_FileObjCmd: dirname} {
191
    testsetplatform mac
192
    list [catch {file dirname ::} msg] $msg
193
} {0 :}
194
test cmdAH-4.33 {Tcl_FileObjCmd: dirname} {
195
    testsetplatform mac
196
    list [catch {file dirname :::} msg] $msg
197
} {0 ::}
198
test cmdAH-4.34 {Tcl_FileObjCmd: dirname} {
199
    testsetplatform mac
200
    list [catch {file dirname /foo/bar/} msg] $msg
201
} {0 foo:}
202
test cmdAH-4.35 {Tcl_FileObjCmd: dirname} {
203
    testsetplatform mac
204
    list [catch {file dirname /foo/bar} msg] $msg
205
} {0 foo:}
206
test cmdAH-4.36 {Tcl_FileObjCmd: dirname} {
207
    testsetplatform mac
208
    list [catch {file dirname /foo} msg] $msg
209
} {0 foo:}
210
test cmdAH-4.37 {Tcl_FileObjCmd: dirname} {
211
    testsetplatform mac
212
    list [catch {file dirname foo} msg] $msg
213
} {0 :}
214
test cmdAH-4.38 {Tcl_FileObjCmd: dirname} {
215
    testsetplatform unix
216
    list [catch {file dirname ~/foo} msg] $msg
217
} {0 ~}
218
test cmdAH-4.39 {Tcl_FileObjCmd: dirname} {
219
    testsetplatform unix
220
    list [catch {file dirname ~bar/foo} msg] $msg
221
} {0 ~bar}
222
test cmdAH-4.40 {Tcl_FileObjCmd: dirname} {
223
    testsetplatform mac
224
    list [catch {file dirname ~bar/foo} msg] $msg
225
} {0 ~bar:}
226
test cmdAH-4.41 {Tcl_FileObjCmd: dirname} {
227
    testsetplatform mac
228
    list [catch {file dirname ~/foo} msg] $msg
229
} {0 ~:}
230
test cmdAH-4.42 {Tcl_FileObjCmd: dirname} {
231
    testsetplatform mac
232
    list [catch {file dirname ~:baz} msg] $msg
233
} {0 ~:}
234
test cmdAH-4.43 {Tcl_FileObjCmd: dirname} {
235
    global env
236
    set temp $env(HOME)
237
    set env(HOME) "/home/test"
238
    testsetplatform unix
239
    set result [list [catch {file dirname ~} msg] $msg]
240
    set env(HOME) $temp
241
    set result
242
} {0 /home}
243
test cmdAH-4.44 {Tcl_FileObjCmd: dirname} {
244
    global env
245
    set temp $env(HOME)
246
    set env(HOME) "~"
247
    testsetplatform unix
248
    set result [list [catch {file dirname ~} msg] $msg]
249
    set env(HOME) $temp
250
    set result
251
} {0 ~}
252
test cmdAH-4.45 {Tcl_FileObjCmd: dirname} {
253
    global env
254
    set temp $env(HOME)
255
    set env(HOME) "/home/test"
256
    testsetplatform windows
257
    set result [list [catch {file dirname ~} msg] $msg]
258
    set env(HOME) $temp
259
    set result
260
} {0 /home}
261
test cmdAH-4.46 {Tcl_FileObjCmd: dirname} {
262
    global env
263
    set temp $env(HOME)
264
    set env(HOME) "/home/test"
265
    testsetplatform mac
266
    set result [list [catch {file dirname ~} msg] $msg]
267
    set env(HOME) $temp
268
    set result
269
} {0 home:}
270
 
271
# tail
272
 
273
test cmdAH-5.1 {Tcl_FileObjCmd: tail} {
274
    testsetplatform unix
275
    list [catch {file tail a b} msg] $msg
276
} {1 {wrong # args: should be "file tail name"}}
277
test cmdAH-5.2 {Tcl_FileObjCmd: tail} {
278
    testsetplatform unix
279
    file tail /a/b
280
} b
281
test cmdAH-5.3 {Tcl_FileObjCmd: tail} {
282
    testsetplatform unix
283
    file tail {}
284
} {}
285
test cmdAH-5.4 {Tcl_FileObjCmd: tail} {
286
    testsetplatform mac
287
    file tail {}
288
} {}
289
test cmdAH-5.5 {Tcl_FileObjCmd: tail} {
290
    testsetplatform win
291
    file tail {}
292
} {}
293
test cmdAH-5.6 {Tcl_FileObjCmd: tail} {
294
    testsetplatform unix
295
    file tail .def
296
} .def
297
test cmdAH-5.7 {Tcl_FileObjCmd: tail} {
298
    testsetplatform mac
299
    file tail a
300
} a
301
test cmdAH-5.8 {Tcl_FileObjCmd: tail} {
302
    testsetplatform win
303
    file tail a
304
} a
305
test cmdAH-5.9 {Tcl_FileObjCmd: tail} {
306
    testsetplatform unix
307
    file ta a/b/c.d
308
} c.d
309
test cmdAH-5.10 {Tcl_FileObjCmd: tail} {
310
    testsetplatform unix
311
    file tail a/b.c/d
312
} d
313
test cmdAH-5.11 {Tcl_FileObjCmd: tail} {
314
    testsetplatform unix
315
    file tail /.
316
} .
317
test cmdAH-5.12 {Tcl_FileObjCmd: tail} {
318
    testsetplatform unix
319
    file tail /
320
} {}
321
test cmdAH-5.13 {Tcl_FileObjCmd: tail} {
322
    testsetplatform unix
323
    file tail /foo
324
} foo
325
test cmdAH-5.14 {Tcl_FileObjCmd: tail} {
326
    testsetplatform unix
327
    file tail //foo
328
} foo
329
test cmdAH-5.15 {Tcl_FileObjCmd: tail} {
330
    testsetplatform unix
331
    file tail //foo/bar
332
} bar
333
test cmdAH-5.16 {Tcl_FileObjCmd: tail} {
334
    testsetplatform unix
335
    file tail {//foo\/bar/baz}
336
} baz
337
test cmdAH-5.17 {Tcl_FileObjCmd: tail} {
338
    testsetplatform unix
339
    file tail {//foo\/bar/baz/blat}
340
} blat
341
test cmdAH-5.18 {Tcl_FileObjCmd: tail} {
342
    testsetplatform unix
343
    file tail /foo//
344
} foo
345
test cmdAH-5.19 {Tcl_FileObjCmd: tail} {
346
    testsetplatform unix
347
    file tail ./a
348
} a
349
test cmdAH-5.20 {Tcl_FileObjCmd: tail} {
350
    testsetplatform unix
351
    file tail a/.a
352
} .a
353
test cmdAH-5.21 {Tcl_FileObjCmd: tail} {
354
    testsetplatform windows
355
    file tail c:foo
356
} foo
357
test cmdAH-5.22 {Tcl_FileObjCmd: tail} {
358
    testsetplatform windows
359
    file tail c:
360
} {}
361
test cmdAH-5.23 {Tcl_FileObjCmd: tail} {
362
    testsetplatform windows
363
    file tail c:/
364
} {}
365
test cmdAH-5.24 {Tcl_FileObjCmd: tail} {
366
    testsetplatform windows
367
    file tail {c:\foo}
368
} foo
369
test cmdAH-5.25 {Tcl_FileObjCmd: tail} {
370
    testsetplatform windows
371
    file tail {//foo/bar/baz}
372
} baz
373
test cmdAH-5.26 {Tcl_FileObjCmd: tail} {
374
    testsetplatform windows
375
    file tail {//foo/bar}
376
} {}
377
test cmdAH-5.27 {Tcl_FileObjCmd: tail} {
378
    testsetplatform mac
379
    file tail :
380
} :
381
test cmdAH-5.28 {Tcl_FileObjCmd: tail} {
382
    testsetplatform mac
383
    file tail :Foo
384
} Foo
385
test cmdAH-5.29 {Tcl_FileObjCmd: tail} {
386
    testsetplatform mac
387
    file tail Foo:
388
} {}
389
test cmdAH-5.30 {Tcl_FileObjCmd: tail} {
390
    testsetplatform mac
391
    file tail Foo:bar
392
} bar
393
test cmdAH-5.31 {Tcl_FileObjCmd: tail} {
394
    testsetplatform mac
395
    file tail :Foo:bar
396
} bar
397
test cmdAH-5.32 {Tcl_FileObjCmd: tail} {
398
    testsetplatform mac
399
    file tail ::
400
} ::
401
test cmdAH-5.33 {Tcl_FileObjCmd: tail} {
402
    testsetplatform mac
403
    file tail :::
404
} ::
405
test cmdAH-5.34 {Tcl_FileObjCmd: tail} {
406
    testsetplatform mac
407
    file tail /foo/bar/
408
} bar
409
test cmdAH-5.35 {Tcl_FileObjCmd: tail} {
410
    testsetplatform mac
411
    file tail /foo/bar
412
} bar
413
test cmdAH-5.36 {Tcl_FileObjCmd: tail} {
414
    testsetplatform mac
415
    file tail /foo
416
} {}
417
test cmdAH-5.37 {Tcl_FileObjCmd: tail} {
418
    testsetplatform mac
419
    file tail foo
420
} foo
421
test cmdAH-5.38 {Tcl_FileObjCmd: tail} {
422
    testsetplatform mac
423
    file tail ~:foo
424
} foo
425
test cmdAH-5.39 {Tcl_FileObjCmd: tail} {
426
    testsetplatform mac
427
    file tail ~bar:foo
428
} foo
429
test cmdAH-5.40 {Tcl_FileObjCmd: tail} {
430
    testsetplatform mac
431
    file tail ~bar/foo
432
} foo
433
test cmdAH-5.41 {Tcl_FileObjCmd: tail} {
434
    testsetplatform mac
435
    file tail ~/foo
436
} foo
437
test cmdAH-5.42 {Tcl_FileObjCmd: tail} {
438
    global env
439
    set temp $env(HOME)
440
    set env(HOME) "/home/test"
441
    testsetplatform unix
442
    set result [file tail ~]
443
    set env(HOME) $temp
444
    set result
445
} test
446
test cmdAH-5.43 {Tcl_FileObjCmd: tail} {
447
    global env
448
    set temp $env(HOME)
449
    set env(HOME) "~"
450
    testsetplatform unix
451
    set result [file tail ~]
452
    set env(HOME) $temp
453
    set result
454
} {}
455
test cmdAH-5.44 {Tcl_FileObjCmd: tail} {
456
    global env
457
    set temp $env(HOME)
458
    set env(HOME) "/home/test"
459
    testsetplatform windows
460
    set result [file tail ~]
461
    set env(HOME) $temp
462
    set result
463
} test
464
test cmdAH-5.45 {Tcl_FileObjCmd: tail} {
465
    global env
466
    set temp $env(HOME)
467
    set env(HOME) "/home/test"
468
    testsetplatform mac
469
    set result [file tail ~]
470
    set env(HOME) $temp
471
    set result
472
} test
473
test cmdAH-5.46 {Tcl_FileObjCmd: tail} {
474
    testsetplatform unix
475
    file tail {f.oo\bar/baz.bat}
476
} baz.bat
477
test cmdAH-5.47 {Tcl_FileObjCmd: tail} {
478
    testsetplatform windows
479
    file tail c:foo
480
} foo
481
test cmdAH-5.48 {Tcl_FileObjCmd: tail} {
482
    testsetplatform windows
483
    file tail c:
484
} {}
485
test cmdAH-5.49 {Tcl_FileObjCmd: tail} {
486
    testsetplatform windows
487
    file tail c:/foo
488
} foo
489
test cmdAH-5.50 {Tcl_FileObjCmd: tail} {
490
    testsetplatform windows
491
    file tail {c:/foo\bar}
492
} bar
493
test cmdAH-5.51 {Tcl_FileObjCmd: tail} {
494
    testsetplatform windows
495
    file tail {foo\bar}
496
} bar
497
 
498
# rootname
499
 
500
test cmdAH-6.1 {Tcl_FileObjCmd: rootname} {
501
    testsetplatform unix
502
    list [catch {file rootname a b} msg] $msg
503
} {1 {wrong # args: should be "file rootname name"}}
504
test cmdAH-6.2 {Tcl_FileObjCmd: rootname} {
505
    testsetplatform unix
506
    file rootname {}
507
} {}
508
test cmdAH-6.3 {Tcl_FileObjCmd: rootname} {
509
    testsetplatform unix
510
    file ro foo
511
} foo
512
test cmdAH-6.4 {Tcl_FileObjCmd: rootname} {
513
    testsetplatform unix
514
    file rootname foo.
515
} foo
516
test cmdAH-6.5 {Tcl_FileObjCmd: rootname} {
517
    testsetplatform unix
518
    file rootname .foo
519
} {}
520
test cmdAH-6.6 {Tcl_FileObjCmd: rootname} {
521
    testsetplatform unix
522
    file rootname abc.def
523
} abc
524
test cmdAH-6.7 {Tcl_FileObjCmd: rootname} {
525
    testsetplatform unix
526
    file rootname abc.def.ghi
527
} abc.def
528
test cmdAH-6.8 {Tcl_FileObjCmd: rootname} {
529
    testsetplatform unix
530
    file rootname a/b/c.d
531
} a/b/c
532
test cmdAH-6.9 {Tcl_FileObjCmd: rootname} {
533
    testsetplatform unix
534
    file rootname a/b.c/d
535
} a/b.c/d
536
test cmdAH-6.10 {Tcl_FileObjCmd: rootname} {
537
    testsetplatform unix
538
    file rootname a/b.c/
539
} a/b.c/
540
test cmdAH-6.11 {Tcl_FileObjCmd: rootname} {
541
    testsetplatform mac
542
    file ro foo
543
} foo
544
test cmdAH-6.12 {Tcl_FileObjCmd: rootname} {
545
    testsetplatform mac
546
    file rootname {}
547
} {}
548
test cmdAH-6.13 {Tcl_FileObjCmd: rootname} {
549
    testsetplatform mac
550
    file rootname foo.
551
} foo
552
test cmdAH-6.14 {Tcl_FileObjCmd: rootname} {
553
    testsetplatform mac
554
    file rootname .foo
555
} {}
556
test cmdAH-6.15 {Tcl_FileObjCmd: rootname} {
557
    testsetplatform mac
558
    file rootname abc.def
559
} abc
560
test cmdAH-6.16 {Tcl_FileObjCmd: rootname} {
561
    testsetplatform mac
562
    file rootname abc.def.ghi
563
} abc.def
564
test cmdAH-6.17 {Tcl_FileObjCmd: rootname} {
565
    testsetplatform mac
566
    file rootname a:b:c.d
567
} a:b:c
568
test cmdAH-6.18 {Tcl_FileObjCmd: rootname} {
569
    testsetplatform mac
570
    file rootname a:b.c:d
571
} a:b.c:d
572
test cmdAH-6.19 {Tcl_FileObjCmd: rootname} {
573
    testsetplatform mac
574
    file rootname a/b/c.d
575
} a/b/c
576
test cmdAH-6.20 {Tcl_FileObjCmd: rootname} {
577
    testsetplatform mac
578
    file rootname a/b.c/d
579
} a/b.c/d
580
test cmdAH-6.21 {Tcl_FileObjCmd: rootname} {
581
    testsetplatform mac
582
    file rootname /a.b
583
} /a
584
test cmdAH-6.22 {Tcl_FileObjCmd: rootname} {
585
    testsetplatform mac
586
    file rootname foo.c:
587
} foo.c:
588
test cmdAH-6.23 {Tcl_FileObjCmd: rootname} {
589
    testsetplatform windows
590
    file rootname {}
591
} {}
592
test cmdAH-6.24 {Tcl_FileObjCmd: rootname} {
593
    testsetplatform windows
594
    file ro foo
595
} foo
596
test cmdAH-6.25 {Tcl_FileObjCmd: rootname} {
597
    testsetplatform windows
598
    file rootname foo.
599
} foo
600
test cmdAH-6.26 {Tcl_FileObjCmd: rootname} {
601
    testsetplatform windows
602
    file rootname .foo
603
} {}
604
test cmdAH-6.27 {Tcl_FileObjCmd: rootname} {
605
    testsetplatform windows
606
    file rootname abc.def
607
} abc
608
test cmdAH-6.28 {Tcl_FileObjCmd: rootname} {
609
    testsetplatform windows
610
    file rootname abc.def.ghi
611
} abc.def
612
test cmdAH-6.29 {Tcl_FileObjCmd: rootname} {
613
    testsetplatform windows
614
    file rootname a/b/c.d
615
} a/b/c
616
test cmdAH-6.30 {Tcl_FileObjCmd: rootname} {
617
    testsetplatform windows
618
    file rootname a/b.c/d
619
} a/b.c/d
620
test cmdAH-6.31 {Tcl_FileObjCmd: rootname} {
621
    testsetplatform windows
622
    file rootname a\\b.c\\
623
} a\\b.c\\
624
test cmdAH-6.32 {Tcl_FileObjCmd: rootname} {
625
    testsetplatform windows
626
    file rootname a\\b\\c.d
627
} a\\b\\c
628
test cmdAH-6.33 {Tcl_FileObjCmd: rootname} {
629
    testsetplatform windows
630
    file rootname a\\b.c\\d
631
} a\\b.c\\d
632
test cmdAH-6.34 {Tcl_FileObjCmd: rootname} {
633
    testsetplatform windows
634
    file rootname a\\b.c\\
635
} a\\b.c\\
636
set num 35
637
foreach outer { {} a .a a. a.a } {
638
  foreach inner { {} a .a a. a.a } {
639
    set thing [format %s/%s $outer $inner]
640
;   test cmdAH-6.$num {Tcl_FileObjCmd: rootname and extension options} {
641
        testsetplatform unix
642
        format %s%s [file rootname $thing] [file ext $thing]
643
    } $thing
644
    set num [expr $num+1]
645
  }
646
}
647
 
648
# extension
649
 
650
test cmdAH-7.1 {Tcl_FileObjCmd: extension} {
651
    testsetplatform unix
652
    list [catch {file extension a b} msg] $msg
653
} {1 {wrong # args: should be "file extension name"}}
654
test cmdAH-7.2 {Tcl_FileObjCmd: extension} {
655
    testsetplatform unix
656
    file extension {}
657
} {}
658
test cmdAH-7.3 {Tcl_FileObjCmd: extension} {
659
    testsetplatform unix
660
    file ext foo
661
} {}
662
test cmdAH-7.4 {Tcl_FileObjCmd: extension} {
663
    testsetplatform unix
664
    file extension foo.
665
} .
666
test cmdAH-7.5 {Tcl_FileObjCmd: extension} {
667
    testsetplatform unix
668
    file extension .foo
669
} .foo
670
test cmdAH-7.6 {Tcl_FileObjCmd: extension} {
671
    testsetplatform unix
672
    file extension abc.def
673
} .def
674
test cmdAH-7.7 {Tcl_FileObjCmd: extension} {
675
    testsetplatform unix
676
    file extension abc.def.ghi
677
} .ghi
678
test cmdAH-7.8 {Tcl_FileObjCmd: extension} {
679
    testsetplatform unix
680
    file extension a/b/c.d
681
} .d
682
test cmdAH-7.9 {Tcl_FileObjCmd: extension} {
683
    testsetplatform unix
684
    file extension a/b.c/d
685
} {}
686
test cmdAH-7.10 {Tcl_FileObjCmd: extension} {
687
    testsetplatform unix
688
    file extension a/b.c/
689
} {}
690
test cmdAH-7.11 {Tcl_FileObjCmd: extension} {
691
    testsetplatform mac
692
    file ext foo
693
} {}
694
test cmdAH-7.12 {Tcl_FileObjCmd: extension} {
695
    testsetplatform mac
696
    file extension {}
697
} {}
698
test cmdAH-7.13 {Tcl_FileObjCmd: extension} {
699
    testsetplatform mac
700
    file extension foo.
701
} .
702
test cmdAH-7.14 {Tcl_FileObjCmd: extension} {
703
    testsetplatform mac
704
    file extension .foo
705
} .foo
706
test cmdAH-7.15 {Tcl_FileObjCmd: extension} {
707
    testsetplatform mac
708
    file extension abc.def
709
} .def
710
test cmdAH-7.16 {Tcl_FileObjCmd: extension} {
711
    testsetplatform mac
712
    file extension abc.def.ghi
713
} .ghi
714
test cmdAH-7.17 {Tcl_FileObjCmd: extension} {
715
    testsetplatform mac
716
    file extension a:b:c.d
717
} .d
718
test cmdAH-7.18 {Tcl_FileObjCmd: extension} {
719
    testsetplatform mac
720
    file extension a:b.c:d
721
} {}
722
test cmdAH-7.19 {Tcl_FileObjCmd: extension} {
723
    testsetplatform mac
724
    file extension a/b/c.d
725
} .d
726
test cmdAH-7.20 {Tcl_FileObjCmd: extension} {
727
    testsetplatform mac
728
    file extension a/b.c/d
729
} {}
730
test cmdAH-7.21 {Tcl_FileObjCmd: extension} {
731
    testsetplatform mac
732
    file extension /a.b
733
} .b
734
test cmdAH-7.22 {Tcl_FileObjCmd: extension} {
735
    testsetplatform mac
736
    file extension foo.c:
737
} {}
738
test cmdAH-7.23 {Tcl_FileObjCmd: extension} {
739
    testsetplatform windows
740
    file extension {}
741
} {}
742
test cmdAH-7.24 {Tcl_FileObjCmd: extension} {
743
    testsetplatform windows
744
    file ext foo
745
} {}
746
test cmdAH-7.25 {Tcl_FileObjCmd: extension} {
747
    testsetplatform windows
748
    file extension foo.
749
} .
750
test cmdAH-7.26 {Tcl_FileObjCmd: extension} {
751
    testsetplatform windows
752
    file extension .foo
753
} .foo
754
test cmdAH-7.27 {Tcl_FileObjCmd: extension} {
755
    testsetplatform windows
756
    file extension abc.def
757
} .def
758
test cmdAH-7.28 {Tcl_FileObjCmd: extension} {
759
    testsetplatform windows
760
    file extension abc.def.ghi
761
} .ghi
762
test cmdAH-7.29 {Tcl_FileObjCmd: extension} {
763
    testsetplatform windows
764
    file extension a/b/c.d
765
} .d
766
test cmdAH-7.30 {Tcl_FileObjCmd: extension} {
767
    testsetplatform windows
768
    file extension a/b.c/d
769
} {}
770
test cmdAH-7.31 {Tcl_FileObjCmd: extension} {
771
    testsetplatform windows
772
    file extension a\\b.c\\
773
} {}
774
test cmdAH-7.32 {Tcl_FileObjCmd: extension} {
775
    testsetplatform windows
776
    file extension a\\b\\c.d
777
} .d
778
test cmdAH-7.33 {Tcl_FileObjCmd: extension} {
779
    testsetplatform windows
780
    file extension a\\b.c\\d
781
} {}
782
test cmdAH-7.34 {Tcl_FileObjCmd: extension} {
783
    testsetplatform windows
784
    file extension a\\b.c\\
785
} {}
786
set num 35
787
foreach value {a..b a...b a.c..b ..b} result {..b ...b ..b ..b} {
788
    foreach p {unix mac windows} {
789
;       test cmdAH-7.$num {Tcl_FileObjCmd: extension} "
790
            testsetplatform $p
791
            file extension $value
792
        " $result
793
        incr num
794
    }
795
}
796
 
797
# pathtype
798
 
799
test cmdAH-8.1 {Tcl_FileObjCmd: pathtype} {
800
    testsetplatform unix
801
    list [catch {file pathtype a b} msg] $msg
802
} {1 {wrong # args: should be "file pathtype name"}}
803
test cmdAH-8.2 {Tcl_FileObjCmd: pathtype} {
804
    testsetplatform unix
805
    file pathtype /a
806
} absolute
807
test cmdAH-8.3 {Tcl_FileObjCmd: pathtype} {
808
    testsetplatform unix
809
    file p a
810
} relative
811
test cmdAH-8.4 {Tcl_FileObjCmd: pathtype} {
812
    testsetplatform windows
813
    file pathtype c:a
814
} volumerelative
815
 
816
# split
817
 
818
test cmdAH-9.1 {Tcl_FileObjCmd: split} {
819
    testsetplatform unix
820
    list [catch {file split a b} msg] $msg
821
} {1 {wrong # args: should be "file split name"}}
822
test cmdAH-9.2 {Tcl_FileObjCmd: split} {
823
    testsetplatform unix
824
    file split a
825
} a
826
test cmdAH-9.3 {Tcl_FileObjCmd: split} {
827
    testsetplatform unix
828
    file split a/b
829
} {a b}
830
 
831
# join
832
 
833
test cmdAH-10.1 {Tcl_FileObjCmd: join} {
834
    testsetplatform unix
835
    file join a
836
} a
837
test cmdAH-10.2 {Tcl_FileObjCmd: join} {
838
    testsetplatform unix
839
    file join a b
840
} a/b
841
test cmdAH-10.3 {Tcl_FileObjCmd: join} {
842
    testsetplatform unix
843
    file join a b c d
844
} a/b/c/d
845
 
846
# error handling of Tcl_TranslateFileName
847
 
848
test cmdAH-11.1 {Tcl_FileObjCmd} {
849
    testsetplatform unix
850
    list [catch {file atime ~_bad_user} msg] $msg
851
} {1 {user "_bad_user" doesn't exist}}
852
 
853
testsetplatform $platform
854
}
855
 
856
# readable
857
 
858
if {[info commands testchmod] == {}} {
859
    puts "This application hasn't been compiled with the \"testchmod\""
860
    puts "command, so I can't test Tcl_FileObjCmd etc."
861
} else {
862
makeFile abcde gorp.file
863
makeDirectory dir.file
864
 
865
test cmdAH-12.1 {Tcl_FileObjCmd: readable} {
866
    list [catch {file readable a b} msg] $msg
867
} {1 {wrong # args: should be "file readable name"}}
868
testchmod 444 gorp.file
869
test cmdAH-12.2 {Tcl_FileObjCmd: readable} {
870
    file readable gorp.file
871
} 1
872
testchmod 333 gorp.file
873
test cmdAH-12.3 {Tcl_FileObjCmd: readable} {unixOnly && !root} {
874
    file reada gorp.file
875
} 0
876
 
877
# writable
878
 
879
test cmdAH-13.1 {Tcl_FileObjCmd: writable} {
880
    list [catch {file writable a b} msg] $msg
881
} {1 {wrong # args: should be "file writable name"}}
882
testchmod 555 gorp.file
883
test cmdAH-13.2 {Tcl_FileObjCmd: writable} {!root} {
884
    file writable gorp.file
885
} 0
886
testchmod 222 gorp.file
887
test cmdAH-13.3 {Tcl_FileObjCmd: writable} {
888
    file writable gorp.file
889
} 1
890
 
891
# executable
892
 
893
file delete -force dir.file gorp.file
894
file mkdir dir.file
895
makeFile abcde gorp.file
896
 
897
test cmdAH-14.1 {Tcl_FileObjCmd: executable} {
898
    list [catch {file executable a b} msg] $msg
899
} {1 {wrong # args: should be "file executable name"}}
900
test cmdAH-14.2 {Tcl_FileObjCmd: executable} {
901
    file executable gorp.file
902
} 0
903
test cmdAH-14.3 {Tcl_FileObjCmd: executable} {unix} {
904
    # Only on unix will setting the execute bit on a regular file
905
    # cause that file to be executable.
906
 
907
    testchmod 775 gorp.file
908
    file exe gorp.file
909
} 1
910
 
911
test cmdAH-14.4 {Tcl_FileObjCmd: executable} {mac} {
912
    # On mac, the only executable files are of type APPL.
913
 
914
    set x [file exe gorp.file]
915
    file attrib gorp.file -type APPL
916
    lappend x [file exe gorp.file]
917
} {0 1}
918
test cmdAH-14.5 {Tcl_FileObjCmd: executable} {pc} {
919
    # On pc, must be a .exe, .com, etc.
920
 
921
    set x [file exe gorp.file]
922
    makeFile foo gorp.exe
923
    lappend x [file exe gorp.exe]
924
    file delete gorp.exe
925
    set x
926
} {0 1}
927
test cmdAH-14.6 {Tcl_FileObjCmd: executable} {
928
    # Directories are always executable.
929
 
930
    file exe dir.file
931
} 1
932
 
933
file delete -force dir.file
934
file delete gorp.file
935
file delete link.file
936
}
937
 
938
# exists
939
 
940
test cmdAH-15.1 {Tcl_FileObjCmd: exists} {
941
    list [catch {file exists a b} msg] $msg
942
} {1 {wrong # args: should be "file exists name"}}
943
test cmdAH-15.2 {Tcl_FileObjCmd: exists} {file exists gorp.file} 0
944
test cmdAH-15.3 {Tcl_FileObjCmd: exists} {
945
    file exists [file join dir.file gorp.file]
946
} 0
947
catch {
948
    makeFile abcde gorp.file
949
    makeDirectory dir.file
950
    makeFile 12345 [file join dir.file gorp.file]
951
}
952
test cmdAH-15.4 {Tcl_FileObjCmd: exists} {
953
    file exists gorp.file
954
} 1
955
test cmdAH-15.5 {Tcl_FileObjCmd: exists} {
956
    file exists [file join dir.file gorp.file]
957
} 1
958
 
959
# nativename
960
if {[info commands testsetplatform] == {}} {
961
    puts "This application hasn't been compiled with the \"testsetplatform\""
962
    puts "command, so I can't test Tcl_FileObjCmd etc."
963
} else {
964
test cmdAH-15.6 {Tcl_FileObjCmd: nativename} {
965
    testsetplatform unix
966
    list [catch {file nativename a/b} msg] $msg [testsetplatform $platform]
967
} {0 a/b {}}
968
test cmdAH-15.7 {Tcl_FileObjCmd: nativename} {
969
    testsetplatform windows
970
    list [catch {file nativename a/b} msg] $msg [testsetplatform $platform]
971
} {0 {a\b} {}}
972
test cmdAH-15.8 {Tcl_FileObjCmd: nativename} {
973
    testsetplatform mac
974
    list [catch {file nativename a/b} msg] $msg [testsetplatform $platform]
975
} {0 :a:b {}}
976
}
977
 
978
test cmdAH-15.9 {Tcl_FileObjCmd: ~ : exists} {
979
    file exists ~nOsUcHuSeR
980
} 0
981
test cmdAH-15.10 {Tcl_FileObjCmd: ~ : nativename} {
982
    # should probably be 0 in fact...
983
    catch {file nativename ~nOsUcHuSeR}
984
} 1
985
 
986
# The test below has to be done in /tmp rather than the current
987
# directory in order to guarantee (?) a local file system:  some
988
# NFS file systems won't do the stuff below correctly.
989
 
990
if {$tcl_platform(platform) == "unix"} {
991
    file delete /tmp/tcl.foo.dir/file
992
    removeDirectory /tmp/tcl.foo.dir
993
    makeDirectory /tmp/tcl.foo.dir
994
    makeFile 12345 /tmp/tcl.foo.dir/file
995
    exec chmod 000 /tmp/tcl.foo.dir
996
    if {$user != "root"} {
997
        test cmdAH-15.9 {Tcl_FileObjCmd: exists} {
998
            file exists /tmp/tcl.foo.dir/file
999
        } 0
1000
    }
1001
    exec chmod 775 /tmp/tcl.foo.dir
1002
    file delete /tmp/tcl.foo.dir/file
1003
    removeDirectory /tmp/tcl.foo.dir
1004
}
1005
 
1006
# Stat related commands
1007
 
1008
catch {testsetplatform $platform}
1009
file delete gorp.file
1010
makeFile "Test string" gorp.file
1011
catch {exec chmod 765 gorp.file}
1012
 
1013
# atime
1014
 
1015
test cmdAH-16.1 {Tcl_FileObjCmd: atime} {
1016
    list [catch {file atime a b} msg] $msg
1017
} {1 {wrong # args: should be "file atime name"}}
1018
test cmdAH-16.2 {Tcl_FileObjCmd: atime} {
1019
    catch {unset stat}
1020
    file stat gorp.file stat
1021
    list [expr {[file mtime gorp.file] == $stat(mtime)}] \
1022
            [expr {[file atime gorp.file] == $stat(atime)}]
1023
} {1 1}
1024
test cmdAH-16.3 {Tcl_FileObjCmd: atime} {
1025
    string tolower [list [catch {file atime _bogus_} msg] \
1026
            $msg $errorCode]
1027
} {1 {couldn't stat "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1028
 
1029
# isdirectory
1030
 
1031
test cmdAH-17.1 {Tcl_FileObjCmd: isdirectory} {
1032
    list [catch {file isdirectory a b} msg] $msg
1033
} {1 {wrong # args: should be "file isdirectory name"}}
1034
test cmdAH-17.2 {Tcl_FileObjCmd: isdirectory} {
1035
    file isdirectory gorp.file
1036
} 0
1037
test cmdAH-17.3 {Tcl_FileObjCmd: isdirectory} {
1038
    file isd dir.file
1039
} 1
1040
 
1041
# isfile
1042
 
1043
test cmdAH-18.1 {Tcl_FileObjCmd: isfile} {
1044
    list [catch {file isfile a b} msg] $msg
1045
} {1 {wrong # args: should be "file isfile name"}}
1046
test cmdAH-18.2 {Tcl_FileObjCmd: isfile} {file isfile gorp.file} 1
1047
test cmdAH-18.3 {Tcl_FileObjCmd: isfile} {file isfile dir.file} 0
1048
 
1049
# lstat and readlink:  don't run these tests everywhere, since not all
1050
# sites will have symbolic links
1051
 
1052
catch {exec ln -s gorp.file link.file}
1053
test cmdAH-19.1 {Tcl_FileObjCmd: lstat} {
1054
    list [catch {file lstat a} msg] $msg
1055
} {1 {wrong # args: should be "file lstat name varName"}}
1056
test cmdAH-19.2 {Tcl_FileObjCmd: lstat} {
1057
    list [catch {file lstat a b c} msg] $msg
1058
} {1 {wrong # args: should be "file lstat name varName"}}
1059
test cmdAH-19.3 {Tcl_FileObjCmd: lstat} {unixOnly nonPortable} {
1060
    catch {unset stat}
1061
    file lstat link.file stat
1062
    lsort [array names stat]
1063
} {atime ctime dev gid ino mode mtime nlink size type uid}
1064
test cmdAH-19.4 {Tcl_FileObjCmd: lstat} {unixOnly nonPortable} {
1065
    catch {unset stat}
1066
    file lstat link.file stat
1067
    list $stat(nlink) [expr $stat(mode)&0777] $stat(type)
1068
} {1 511 link}
1069
test cmdAH-19.5 {Tcl_FileObjCmd: lstat errors} {nonPortable} {
1070
    string tolower [list [catch {file lstat _bogus_ stat} msg] \
1071
            $msg $errorCode]
1072
} {1 {couldn't lstat "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1073
test cmdAH-19.6 {Tcl_FileObjCmd: lstat errors} {
1074
    catch {unset x}
1075
    set x 44
1076
    list [catch {file lstat gorp.file x} msg] $msg $errorCode
1077
} {1 {can't set "x(dev)": variable isn't array} NONE}
1078
catch {unset stat}
1079
 
1080
# mtime
1081
 
1082
test cmdAH-20.1 {Tcl_FileObjCmd: mtime} {
1083
    list [catch {file mtime a b} msg] $msg
1084
} {1 {wrong # args: should be "file mtime name"}}
1085
test cmdAH-20.2 {Tcl_FileObjCmd: mtime} {
1086
    set old [file mtime gorp.file]
1087
    after 2000
1088
    set f [open gorp.file w]
1089
    puts $f "More text"
1090
    close $f
1091
    set new [file mtime gorp.file]
1092
    expr {($new > $old) && ($new <= ($old+5))}
1093
} {1}
1094
test cmdAH-20.3 {Tcl_FileObjCmd: mtime} {
1095
    catch {unset stat}
1096
    file stat gorp.file stat
1097
    list [expr {[file mtime gorp.file] == $stat(mtime)}] \
1098
            [expr {[file atime gorp.file] == $stat(atime)}]
1099
} {1 1}
1100
test cmdAH-20.4 {Tcl_FileObjCmd: mtime} {
1101
    string tolower [list [catch {file mtime _bogus_} msg] $msg \
1102
            $errorCode]
1103
} {1 {couldn't stat "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1104
test cmdAH-20.5 {Tcl_FileObjCmd: mtime} {
1105
    # Under Unix, use a file in /tmp to avoid clock skew due to NFS.
1106
    # On other platforms, just use a file in the local directory.
1107
 
1108
    if {$tcl_platform(platform) == "unix"} {
1109
         set name /tmp/tcl.test
1110
    } else {
1111
        set name tf
1112
    }
1113
 
1114
    # Borland file times were off by timezone.  Make sure that a new file's
1115
    # time is correct.  10 seconds variance is allowed used due to slow
1116
    # networks or clock skew on a network drive.
1117
 
1118
    file delete -force $name
1119
    close [open $name w]
1120
    set a [expr abs([clock seconds]-[file mtime $name])<10]
1121
    file delete $name
1122
    set a
1123
} {1}
1124
 
1125
 
1126
# owned
1127
 
1128
test cmdAH-21.1 {Tcl_FileObjCmd: owned} {
1129
    list [catch {file owned a b} msg] $msg
1130
} {1 {wrong # args: should be "file owned name"}}
1131
test cmdAH-21.2 {Tcl_FileObjCmd: owned} {
1132
    file owned gorp.file
1133
} 1
1134
test cmdAH-21.3 {Tcl_FileObjCmd: owned} {unixOnly && !root} {
1135
    file owned /
1136
} 0
1137
 
1138
# readlink
1139
 
1140
test cmdAH-22.1 {Tcl_FileObjCmd: readlink} {
1141
    list [catch {file readlink a b} msg] $msg
1142
} {1 {wrong # args: should be "file readlink name"}}
1143
test cmdAH-22.2 {Tcl_FileObjCmd: readlink} {unixOnly nonPortable} {
1144
    file readlink link.file
1145
} gorp.file
1146
test cmdAH-22.3 {Tcl_FileObjCmd: readlink errors} {unixOnly nonPortable} {
1147
    list [catch {file readlink _bogus_} msg] [string tolower $msg] \
1148
            [string tolower $errorCode]
1149
} {1 {couldn't readlink "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1150
test cmdAH-22.4 {Tcl_FileObjCmd: readlink errors} {macOnly nonPortable} {
1151
    list [catch {file readlink _bogus_} msg] [string tolower $msg] \
1152
            [string tolower $errorCode]
1153
} {1 {couldn't readlink "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1154
test cmdAH-22.5 {Tcl_FileObjCmd: readlink errors} {pcOnly nonPortable} {
1155
    list [catch {file readlink _bogus_} msg] [string tolower $msg] \
1156
            [string tolower $errorCode]
1157
} {1 {couldn't readlink "_bogus_": invalid argument} {posix einval {invalid argument}}}
1158
 
1159
# size
1160
 
1161
test cmdAH-23.1 {Tcl_FileObjCmd: size} {
1162
    list [catch {file size a b} msg] $msg
1163
} {1 {wrong # args: should be "file size name"}}
1164
test cmdAH-23.2 {Tcl_FileObjCmd: size} {
1165
    set oldsize [file size gorp.file]
1166
    set f [open gorp.file a]
1167
    fconfigure $f -translation lf -eofchar {}
1168
    puts $f "More text"
1169
    close $f
1170
    expr {[file size gorp.file] - $oldsize}
1171
} {10}
1172
test cmdAH-23.3 {Tcl_FileObjCmd: size} {
1173
    string tolower [list [catch {file size _bogus_} msg] $msg \
1174
            $errorCode]
1175
} {1 {couldn't stat "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1176
 
1177
# stat
1178
 
1179
catch {testsetplatform $platform}
1180
makeFile "Test string" gorp.file
1181
catch {exec chmod 765 gorp.file}
1182
 
1183
test cmdAH-24.1 {Tcl_FileObjCmd: stat} {
1184
    list [catch {file stat _bogus_} msg] $msg $errorCode
1185
} {1 {wrong # args: should be "file stat name varName"} NONE}
1186
test cmdAH-24.2 {Tcl_FileObjCmd: stat} {
1187
    list [catch {file stat _bogus_ a b} msg] $msg $errorCode
1188
} {1 {wrong # args: should be "file stat name varName"} NONE}
1189
test cmdAH-24.3 {Tcl_FileObjCmd: stat} {
1190
    catch {unset stat}
1191
    file stat gorp.file stat
1192
    lsort [array names stat]
1193
} {atime ctime dev gid ino mode mtime nlink size type uid}
1194
test cmdAH-24.4 {Tcl_FileObjCmd: stat} {
1195
    catch {unset stat}
1196
    file stat gorp.file stat
1197
    list $stat(nlink) $stat(size) $stat(type)
1198
} {1 12 file}
1199
test cmdAH-24.5 {Tcl_FileObjCmd: stat} {unix} {
1200
    catch {unset stat}
1201
    file stat gorp.file stat
1202
    expr $stat(mode)&0777
1203
} {501}
1204
test cmdAH-24.6 {Tcl_FileObjCmd: stat} {
1205
    string tolower [list [catch {file stat _bogus_ stat} msg] \
1206
            $msg $errorCode]
1207
} {1 {couldn't stat "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1208
test cmdAH-24.7 {Tcl_FileObjCmd: stat} {
1209
    catch {unset x}
1210
    set x 44
1211
    list [catch {file stat gorp.file x} msg] $msg $errorCode
1212
} {1 {can't set "x(dev)": variable isn't array} NONE}
1213
catch {unset stat}
1214
 
1215
# type
1216
 
1217
file delete link.file
1218
 
1219
test cmdAH-25.1 {Tcl_FileObjCmd: type} {
1220
    list [catch {file size a b} msg] $msg
1221
} {1 {wrong # args: should be "file size name"}}
1222
test cmdAH-25.2 {Tcl_FileObjCmd: type} {
1223
    file type dir.file
1224
} directory
1225
test cmdAH-25.3 {Tcl_FileObjCmd: type} {
1226
    file type gorp.file
1227
} file
1228
test cmdAH-25.4 {Tcl_FileObjCmd: type} {unixOnly nonPortable} {
1229
    exec ln -s a/b/c link.file
1230
    set result [file type link.file]
1231
    file delete link.file
1232
    set result
1233
} link
1234
test cmdAH-25.5 {Tcl_FileObjCmd: type} {
1235
    string tolower [list [catch {file type _bogus_} msg] $msg $errorCode]
1236
} {1 {couldn't stat "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
1237
 
1238
# Error conditions
1239
 
1240
test cmdAH-26.1 {error conditions} {
1241
    list [catch {file gorp x} msg] $msg
1242
} {1 {bad option "gorp": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
1243
test cmdAH-26.2 {error conditions} {
1244
    list [catch {file ex x} msg] $msg
1245
} {1 {ambiguous option "ex": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
1246
test cmdAH-26.3 {error conditions} {
1247
    list [catch {file is x} msg] $msg
1248
} {1 {ambiguous option "is": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
1249
test cmdAH-26.4 {error conditions} {
1250
    list [catch {file z x} msg] $msg
1251
} {1 {bad option "z": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
1252
test cmdAH-26.5 {error conditions} {
1253
    list [catch {file read x} msg] $msg
1254
} {1 {ambiguous option "read": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
1255
test cmdAH-26.6 {error conditions} {
1256
    list [catch {file s x} msg] $msg
1257
} {1 {ambiguous option "s": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
1258
test cmdAH-26.7 {error conditions} {
1259
    list [catch {file t x} msg] $msg
1260
} {1 {ambiguous option "t": must be atime, attributes, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable}}
1261
test cmdAH-26.8 {error conditions} {
1262
    list [catch {file dirname ~woohgy} msg] $msg
1263
} {1 {user "woohgy" doesn't exist}}
1264
 
1265
catch {testsetplatform $platform}
1266
catch {unset platform}
1267
 
1268
catch {exec chmod 777 dir.file}
1269
file delete -force dir.file
1270
file delete gorp.file
1271
file delete link.file
1272
 
1273
concat ""

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.