os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/cmdAH.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# The file tests the tclCmdAH.c file.
sl@0
     2
#
sl@0
     3
# This file contains a collection of tests for one or more of the Tcl
sl@0
     4
# built-in commands.  Sourcing this file into Tcl runs the tests and
sl@0
     5
# generates output for errors.  No output means no errors were found.
sl@0
     6
#
sl@0
     7
# Copyright (c) 1996-1998 by Sun Microsystems, Inc.
sl@0
     8
# Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0
     9
#
sl@0
    10
# See the file "license.terms" for information on usage and redistribution
sl@0
    11
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    12
#
sl@0
    13
# RCS: @(#) $Id: cmdAH.test,v 1.30.2.6 2006/10/01 13:17:34 patthoyts Exp $
sl@0
    14
sl@0
    15
if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0
    16
    package require tcltest 2.1
sl@0
    17
    namespace import -force ::tcltest::*
sl@0
    18
}
sl@0
    19
sl@0
    20
tcltest::testConstraint testchmod [string equal testchmod [info commands testchmod]]
sl@0
    21
sl@0
    22
global env
sl@0
    23
set cmdAHwd [pwd]
sl@0
    24
catch {set platform [testgetplatform]}
sl@0
    25
sl@0
    26
test cmdAH-0.1 {Tcl_BreakObjCmd, errors} {
sl@0
    27
    list [catch {break foo} msg] $msg
sl@0
    28
} {1 {wrong # args: should be "break"}}
sl@0
    29
test cmdAH-0.2 {Tcl_BreakObjCmd, success} {
sl@0
    30
    list [catch {break} msg] $msg
sl@0
    31
} {3 {}}
sl@0
    32
sl@0
    33
# Tcl_CaseObjCmd is tested in case.test
sl@0
    34
sl@0
    35
test cmdAH-1.1 {Tcl_CatchObjCmd, errors} {
sl@0
    36
    list [catch {catch} msg] $msg
sl@0
    37
} {1 {wrong # args: should be "catch command ?varName?"}}
sl@0
    38
test cmdAH-1.2 {Tcl_CatchObjCmd, errors} {
sl@0
    39
    list [catch {catch foo bar baz} msg] $msg
sl@0
    40
} {1 {wrong # args: should be "catch command ?varName?"}}
sl@0
    41
sl@0
    42
test cmdAH-2.1 {Tcl_CdObjCmd} {
sl@0
    43
    list [catch {cd foo bar} msg] $msg
sl@0
    44
} {1 {wrong # args: should be "cd ?dirName?"}}
sl@0
    45
set foodir [file join [temporaryDirectory] foo]
sl@0
    46
test cmdAH-2.2 {Tcl_CdObjCmd} {
sl@0
    47
    file delete -force $foodir
sl@0
    48
    file mkdir $foodir
sl@0
    49
    cd $foodir
sl@0
    50
    set result [file tail [pwd]]
sl@0
    51
    cd ..
sl@0
    52
    file delete $foodir
sl@0
    53
    set result
sl@0
    54
} foo
sl@0
    55
test cmdAH-2.3 {Tcl_CdObjCmd} {
sl@0
    56
    global env
sl@0
    57
    set oldpwd [pwd]
sl@0
    58
    set temp $env(HOME)
sl@0
    59
    set env(HOME) $oldpwd
sl@0
    60
    file delete -force $foodir
sl@0
    61
    file mkdir $foodir
sl@0
    62
    cd $foodir
sl@0
    63
    cd ~
sl@0
    64
    set result [string equal [pwd] $oldpwd]
sl@0
    65
    file delete $foodir
sl@0
    66
    set env(HOME) $temp
sl@0
    67
    set result
sl@0
    68
} 1
sl@0
    69
test cmdAH-2.4 {Tcl_CdObjCmd} {
sl@0
    70
    global env
sl@0
    71
    set oldpwd [pwd]
sl@0
    72
    set temp $env(HOME)
sl@0
    73
    set env(HOME) $oldpwd
sl@0
    74
    file delete -force $foodir
sl@0
    75
    file mkdir $foodir
sl@0
    76
    cd $foodir
sl@0
    77
    cd
sl@0
    78
    set result [string equal [pwd] $oldpwd]
sl@0
    79
    file delete $foodir
sl@0
    80
    set env(HOME) $temp
sl@0
    81
    set result
sl@0
    82
} 1
sl@0
    83
test cmdAH-2.5 {Tcl_CdObjCmd} {
sl@0
    84
    list [catch {cd ~~} msg] $msg
sl@0
    85
} {1 {user "~" doesn't exist}}
sl@0
    86
test cmdAH-2.6 {Tcl_CdObjCmd} {
sl@0
    87
    list [catch {cd _foobar} msg] $msg
sl@0
    88
} {1 {couldn't change working directory to "_foobar": no such file or directory}}
sl@0
    89
test cmdAH-2.6.1 {Tcl_CdObjCmd} {
sl@0
    90
    list [catch {cd ""} msg] $msg
sl@0
    91
} {1 {couldn't change working directory to "": no such file or directory}}
sl@0
    92
sl@0
    93
test cmdAH-2.7 {Tcl_ConcatObjCmd} {
sl@0
    94
    concat
sl@0
    95
} {}
sl@0
    96
test cmdAH-2.8 {Tcl_ConcatObjCmd} {
sl@0
    97
    concat a
sl@0
    98
} a
sl@0
    99
test cmdAH-2.9 {Tcl_ConcatObjCmd} {
sl@0
   100
    concat a {b c}
sl@0
   101
} {a b c}
sl@0
   102
sl@0
   103
test cmdAH-3.1 {Tcl_ContinueObjCmd, errors} {
sl@0
   104
    list [catch {continue foo} msg] $msg
sl@0
   105
} {1 {wrong # args: should be "continue"}}
sl@0
   106
test cmdAH-3.2 {Tcl_ContinueObjCmd, success} {
sl@0
   107
    list [catch {continue} msg] $msg
sl@0
   108
} {4 {}}
sl@0
   109
sl@0
   110
test cmdAH-4.1 {Tcl_EncodingObjCmd} {
sl@0
   111
    list [catch {encoding} msg] $msg
sl@0
   112
} {1 {wrong # args: should be "encoding option ?arg ...?"}}
sl@0
   113
test cmdAH-4.2 {Tcl_EncodingObjCmd} {
sl@0
   114
    list [catch {encoding foo} msg] $msg
sl@0
   115
} {1 {bad option "foo": must be convertfrom, convertto, names, or system}}
sl@0
   116
test cmdAH-4.3 {Tcl_EncodingObjCmd} {
sl@0
   117
    list [catch {encoding convertto} msg] $msg
sl@0
   118
} {1 {wrong # args: should be "encoding convertto ?encoding? data"}}
sl@0
   119
test cmdAH-4.4 {Tcl_EncodingObjCmd} {
sl@0
   120
    list [catch {encoding convertto foo bar} msg] $msg
sl@0
   121
} {1 {unknown encoding "foo"}}
sl@0
   122
test cmdAH-4.5 {Tcl_EncodingObjCmd} {
sl@0
   123
    set system [encoding system]
sl@0
   124
    encoding system jis0208
sl@0
   125
    set x [encoding convertto \u4e4e]
sl@0
   126
    encoding system $system
sl@0
   127
    set x
sl@0
   128
} 8C
sl@0
   129
test cmdAH-4.6 {Tcl_EncodingObjCmd} {
sl@0
   130
    set system [encoding system]
sl@0
   131
    encoding system identity
sl@0
   132
    set x [encoding convertto jis0208 \u4e4e]
sl@0
   133
    encoding system $system
sl@0
   134
    set x
sl@0
   135
} 8C
sl@0
   136
test cmdAH-4.7 {Tcl_EncodingObjCmd} {
sl@0
   137
    list [catch {encoding convertfrom} msg] $msg
sl@0
   138
} {1 {wrong # args: should be "encoding convertfrom ?encoding? data"}}
sl@0
   139
test cmdAH-4.8 {Tcl_EncodingObjCmd} {
sl@0
   140
    list [catch {encoding convertfrom foo bar} msg] $msg
sl@0
   141
} {1 {unknown encoding "foo"}}
sl@0
   142
test cmdAH-4.9 {Tcl_EncodingObjCmd} {
sl@0
   143
    set system [encoding system]
sl@0
   144
    encoding system jis0208
sl@0
   145
    set x [encoding convertfrom 8C]
sl@0
   146
    encoding system $system
sl@0
   147
    set x
sl@0
   148
} \u4e4e
sl@0
   149
test cmdAH-4.10 {Tcl_EncodingObjCmd} {
sl@0
   150
    set system [encoding system]
sl@0
   151
    encoding system identity
sl@0
   152
    set x [encoding convertfrom jis0208 8C]
sl@0
   153
    encoding system $system
sl@0
   154
    set x
sl@0
   155
} \u4e4e
sl@0
   156
test cmdAH-4.11 {Tcl_EncodingObjCmd} {
sl@0
   157
    list [catch {encoding names foo} msg] $msg
sl@0
   158
} {1 {wrong # args: should be "encoding names"}}
sl@0
   159
test cmdAH-4.12 {Tcl_EncodingObjCmd} {
sl@0
   160
    list [catch {encoding system foo bar} msg] $msg
sl@0
   161
} {1 {wrong # args: should be "encoding system ?encoding?"}}
sl@0
   162
test cmdAH-4.13 {Tcl_EncodingObjCmd} {
sl@0
   163
    set system [encoding system]
sl@0
   164
    encoding system identity
sl@0
   165
    set x [encoding system]
sl@0
   166
    encoding system $system
sl@0
   167
    set x
sl@0
   168
} identity
sl@0
   169
sl@0
   170
test cmdAH-5.1 {Tcl_FileObjCmd} {
sl@0
   171
    list [catch file msg] $msg
sl@0
   172
} {1 {wrong # args: should be "file option ?arg ...?"}}
sl@0
   173
test cmdAH-5.2 {Tcl_FileObjCmd} {
sl@0
   174
    list [catch {file x} msg] $msg
sl@0
   175
} {1 {bad option "x": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
   176
test cmdAH-5.3 {Tcl_FileObjCmd} {
sl@0
   177
    list [catch {file exists} msg] $msg
sl@0
   178
} {1 {wrong # args: should be "file exists name"}}
sl@0
   179
test cmdAH-5.4 {Tcl_FileObjCmd} {
sl@0
   180
    list [catch {file exists ""} msg] $msg
sl@0
   181
} {0 0}
sl@0
   182
sl@0
   183
#volume
sl@0
   184
sl@0
   185
test cmdAH-6.1 {Tcl_FileObjCmd: volumes} {
sl@0
   186
    list [catch {file volumes x} msg] $msg
sl@0
   187
} {1 {wrong # args: should be "file volumes"}}
sl@0
   188
test cmdAH-6.2 {Tcl_FileObjCmd: volumes} {
sl@0
   189
	set volumeList [file volumes]
sl@0
   190
	if { [llength $volumeList] == 0 } {
sl@0
   191
		set result 0
sl@0
   192
	} else {
sl@0
   193
		set result 1
sl@0
   194
	}
sl@0
   195
} {1}
sl@0
   196
test cmdAH-6.3 {Tcl_FileObjCmd: volumes} {macOrUnix} {
sl@0
   197
    set volumeList [file volumes]
sl@0
   198
    catch [list glob -nocomplain [lindex $volumeList 0]*]
sl@0
   199
} {0}
sl@0
   200
test cmdAH-6.4 {Tcl_FileObjCmd: volumes} winOnly {
sl@0
   201
    set volumeList [string tolower [file volumes]]
sl@0
   202
    list [catch {lsearch $volumeList "c:/"} element] [expr $element != -1] [catch {list glob -nocomplain [lindex $volumeList $element]*}]
sl@0
   203
} {0 1 0}
sl@0
   204
sl@0
   205
test cmdAH-6.5 {cd} {unixOnly nonPortable} {
sl@0
   206
    set dir [pwd]
sl@0
   207
    cd /
sl@0
   208
    set res [pwd]
sl@0
   209
    cd $dir
sl@0
   210
    set res
sl@0
   211
} {/}
sl@0
   212
sl@0
   213
# attributes
sl@0
   214
sl@0
   215
test cmdAH-7.1 {Tcl_FileObjCmd - file attrs} {
sl@0
   216
    set foofile [makeFile abcde foo.file]
sl@0
   217
    catch {file delete -force $foofile}
sl@0
   218
    close [open $foofile w]
sl@0
   219
    set res [catch {file attributes $foofile}]
sl@0
   220
    # We used [makeFile] so we undo with [removeFile]
sl@0
   221
    removeFile $foofile
sl@0
   222
    set res
sl@0
   223
} {0}
sl@0
   224
sl@0
   225
# dirname
sl@0
   226
sl@0
   227
if {[info commands testsetplatform] == {}} {
sl@0
   228
    puts "This application hasn't been compiled with the \"testsetplatform\""
sl@0
   229
    puts "command, so I can't test Tcl_FileObjCmd etc."
sl@0
   230
} else {
sl@0
   231
test cmdAH-8.1 {Tcl_FileObjCmd: dirname} {
sl@0
   232
    testsetplatform unix
sl@0
   233
    list [catch {file dirname a b} msg] $msg
sl@0
   234
} {1 {wrong # args: should be "file dirname name"}}
sl@0
   235
test cmdAH-8.2 {Tcl_FileObjCmd: dirname} {
sl@0
   236
    testsetplatform unix
sl@0
   237
    file dirname /a/b
sl@0
   238
} /a
sl@0
   239
test cmdAH-8.3 {Tcl_FileObjCmd: dirname} {
sl@0
   240
    testsetplatform unix
sl@0
   241
    file dirname {}
sl@0
   242
} .
sl@0
   243
test cmdAH-8.4 {Tcl_FileObjCmd: dirname} {
sl@0
   244
    testsetplatform mac
sl@0
   245
    file dirname {}
sl@0
   246
} :
sl@0
   247
test cmdAH-8.5 {Tcl_FileObjCmd: dirname} {
sl@0
   248
    testsetplatform win
sl@0
   249
    file dirname {}
sl@0
   250
} .
sl@0
   251
test cmdAH-8.6 {Tcl_FileObjCmd: dirname} {
sl@0
   252
    testsetplatform unix
sl@0
   253
    file dirname .def
sl@0
   254
} .
sl@0
   255
test cmdAH-8.7 {Tcl_FileObjCmd: dirname} {
sl@0
   256
    testsetplatform mac
sl@0
   257
    file dirname a
sl@0
   258
} :
sl@0
   259
test cmdAH-8.8 {Tcl_FileObjCmd: dirname} {
sl@0
   260
    testsetplatform win
sl@0
   261
    file dirname a
sl@0
   262
} .
sl@0
   263
test cmdAH-8.9 {Tcl_FileObjCmd: dirname} {
sl@0
   264
    testsetplatform unix
sl@0
   265
    file dirname a/b/c.d
sl@0
   266
} a/b
sl@0
   267
test cmdAH-8.10 {Tcl_FileObjCmd: dirname} {
sl@0
   268
    testsetplatform unix
sl@0
   269
    file dirname a/b.c/d
sl@0
   270
} a/b.c
sl@0
   271
test cmdAH-8.11 {Tcl_FileObjCmd: dirname} {
sl@0
   272
    testsetplatform unix
sl@0
   273
    file dirname /.
sl@0
   274
} /
sl@0
   275
test cmdAH-8.12 {Tcl_FileObjCmd: dirname} {
sl@0
   276
    testsetplatform unix
sl@0
   277
    list [catch {file dirname /} msg] $msg
sl@0
   278
} {0 /}
sl@0
   279
test cmdAH-8.13 {Tcl_FileObjCmd: dirname} {
sl@0
   280
    testsetplatform unix
sl@0
   281
    list [catch {file dirname /foo} msg] $msg
sl@0
   282
} {0 /}
sl@0
   283
test cmdAH-8.14 {Tcl_FileObjCmd: dirname} {
sl@0
   284
    testsetplatform unix
sl@0
   285
    list [catch {file dirname //foo} msg] $msg
sl@0
   286
} {0 /}
sl@0
   287
test cmdAH-8.15 {Tcl_FileObjCmd: dirname} {
sl@0
   288
    testsetplatform unix
sl@0
   289
    list [catch {file dirname //foo/bar} msg] $msg
sl@0
   290
} {0 /foo}
sl@0
   291
test cmdAH-8.16 {Tcl_FileObjCmd: dirname} {
sl@0
   292
    testsetplatform unix
sl@0
   293
    list [catch {file dirname {//foo\/bar/baz}} msg] $msg
sl@0
   294
} {0 {/foo\/bar}}
sl@0
   295
test cmdAH-8.17 {Tcl_FileObjCmd: dirname} {
sl@0
   296
    testsetplatform unix
sl@0
   297
    list [catch {file dirname {//foo\/bar/baz/blat}} msg] $msg
sl@0
   298
} {0 {/foo\/bar/baz}}
sl@0
   299
test cmdAH-8.18 {Tcl_FileObjCmd: dirname} {
sl@0
   300
    testsetplatform unix
sl@0
   301
    list [catch {file dirname /foo//} msg] $msg
sl@0
   302
} {0 /}
sl@0
   303
test cmdAH-8.19 {Tcl_FileObjCmd: dirname} {
sl@0
   304
    testsetplatform unix
sl@0
   305
    list [catch {file dirname ./a} msg] $msg
sl@0
   306
} {0 .}
sl@0
   307
test cmdAH-8.20 {Tcl_FileObjCmd: dirname} {
sl@0
   308
    testsetplatform unix
sl@0
   309
    list [catch {file dirname a/.a} msg] $msg
sl@0
   310
} {0 a}
sl@0
   311
test cmdAH-8.21 {Tcl_FileObjCmd: dirname} {
sl@0
   312
    testsetplatform windows
sl@0
   313
    list [catch {file dirname c:foo} msg] $msg
sl@0
   314
} {0 c:}
sl@0
   315
test cmdAH-8.22 {Tcl_FileObjCmd: dirname} {
sl@0
   316
    testsetplatform windows
sl@0
   317
    list [catch {file dirname c:} msg] $msg
sl@0
   318
} {0 c:}
sl@0
   319
test cmdAH-8.23 {Tcl_FileObjCmd: dirname} {
sl@0
   320
    testsetplatform windows
sl@0
   321
    list [catch {file dirname c:/} msg] $msg
sl@0
   322
} {0 c:/}
sl@0
   323
test cmdAH-8.24 {Tcl_FileObjCmd: dirname} {
sl@0
   324
    testsetplatform windows
sl@0
   325
    list [catch {file dirname {c:\foo}} msg] $msg
sl@0
   326
} {0 c:/}
sl@0
   327
test cmdAH-8.25 {Tcl_FileObjCmd: dirname} {
sl@0
   328
    testsetplatform windows
sl@0
   329
    list [catch {file dirname {//foo/bar/baz}} msg] $msg
sl@0
   330
} {0 //foo/bar}
sl@0
   331
test cmdAH-8.26 {Tcl_FileObjCmd: dirname} {
sl@0
   332
    testsetplatform windows
sl@0
   333
    list [catch {file dirname {//foo/bar}} msg] $msg
sl@0
   334
} {0 //foo/bar}
sl@0
   335
test cmdAH-8.27 {Tcl_FileObjCmd: dirname} {
sl@0
   336
    testsetplatform mac
sl@0
   337
    list [catch {file dirname :} msg] $msg
sl@0
   338
} {0 :}
sl@0
   339
test cmdAH-8.28 {Tcl_FileObjCmd: dirname} {
sl@0
   340
    testsetplatform mac
sl@0
   341
    list [catch {file dirname :Foo} msg] $msg
sl@0
   342
} {0 :}
sl@0
   343
test cmdAH-8.29 {Tcl_FileObjCmd: dirname} {
sl@0
   344
    testsetplatform mac
sl@0
   345
    list [catch {file dirname Foo:} msg] $msg
sl@0
   346
} {0 Foo:}
sl@0
   347
test cmdAH-8.30 {Tcl_FileObjCmd: dirname} {
sl@0
   348
    testsetplatform mac
sl@0
   349
    list [catch {file dirname Foo:bar} msg] $msg
sl@0
   350
} {0 Foo:}
sl@0
   351
test cmdAH-8.31 {Tcl_FileObjCmd: dirname} {
sl@0
   352
    testsetplatform mac
sl@0
   353
    list [catch {file dirname :Foo:bar} msg] $msg
sl@0
   354
} {0 :Foo}
sl@0
   355
test cmdAH-8.32 {Tcl_FileObjCmd: dirname} {
sl@0
   356
    testsetplatform mac
sl@0
   357
    list [catch {file dirname ::} msg] $msg
sl@0
   358
} {0 :}
sl@0
   359
test cmdAH-8.33 {Tcl_FileObjCmd: dirname} {
sl@0
   360
    testsetplatform mac
sl@0
   361
    list [catch {file dirname :::} msg] $msg
sl@0
   362
} {0 ::}
sl@0
   363
test cmdAH-8.34 {Tcl_FileObjCmd: dirname} {
sl@0
   364
    testsetplatform mac
sl@0
   365
    list [catch {file dirname /foo/bar/} msg] $msg
sl@0
   366
} {0 foo:}
sl@0
   367
test cmdAH-8.35 {Tcl_FileObjCmd: dirname} {
sl@0
   368
    testsetplatform mac
sl@0
   369
    list [catch {file dirname /foo/bar} msg] $msg
sl@0
   370
} {0 foo:}
sl@0
   371
test cmdAH-8.36 {Tcl_FileObjCmd: dirname} {
sl@0
   372
    testsetplatform mac
sl@0
   373
    list [catch {file dirname /foo} msg] $msg
sl@0
   374
} {0 foo:}
sl@0
   375
test cmdAH-8.37 {Tcl_FileObjCmd: dirname} {
sl@0
   376
    testsetplatform mac
sl@0
   377
    list [catch {file dirname foo} msg] $msg
sl@0
   378
} {0 :}
sl@0
   379
test cmdAH-8.38 {Tcl_FileObjCmd: dirname} {
sl@0
   380
    testsetplatform unix
sl@0
   381
    list [catch {file dirname ~/foo} msg] $msg
sl@0
   382
} {0 ~}
sl@0
   383
test cmdAH-8.39 {Tcl_FileObjCmd: dirname} {
sl@0
   384
    testsetplatform unix
sl@0
   385
    list [catch {file dirname ~bar/foo} msg] $msg
sl@0
   386
} {0 ~bar}
sl@0
   387
test cmdAH-8.40 {Tcl_FileObjCmd: dirname} {
sl@0
   388
    testsetplatform mac
sl@0
   389
    list [catch {file dirname ~bar/foo} msg] $msg
sl@0
   390
} {0 ~bar:}
sl@0
   391
test cmdAH-8.41 {Tcl_FileObjCmd: dirname} {
sl@0
   392
    testsetplatform mac
sl@0
   393
    list [catch {file dirname ~/foo} msg] $msg
sl@0
   394
} {0 ~:}
sl@0
   395
test cmdAH-8.42 {Tcl_FileObjCmd: dirname} {
sl@0
   396
    testsetplatform mac
sl@0
   397
    list [catch {file dirname ~:baz} msg] $msg
sl@0
   398
} {0 ~:}
sl@0
   399
test cmdAH-8.43 {Tcl_FileObjCmd: dirname} {
sl@0
   400
    global env
sl@0
   401
    set temp $env(HOME)
sl@0
   402
    set env(HOME) "/homewontexist/test"
sl@0
   403
    testsetplatform unix
sl@0
   404
    set result [list [catch {file dirname ~} msg] $msg]
sl@0
   405
    set env(HOME) $temp
sl@0
   406
    set result
sl@0
   407
} {0 /homewontexist}
sl@0
   408
test cmdAH-8.44 {Tcl_FileObjCmd: dirname} {
sl@0
   409
    global env
sl@0
   410
    set temp $env(HOME)
sl@0
   411
    set env(HOME) "~"
sl@0
   412
    testsetplatform unix
sl@0
   413
    set result [list [catch {file dirname ~} msg] $msg]
sl@0
   414
    set env(HOME) $temp
sl@0
   415
    set result
sl@0
   416
} {0 ~}
sl@0
   417
test cmdAH-8.45 {Tcl_FileObjCmd: dirname} {
sl@0
   418
    global env
sl@0
   419
    set temp $env(HOME)
sl@0
   420
    set env(HOME) "/homewontexist/test"
sl@0
   421
    testsetplatform windows
sl@0
   422
    set result [list [catch {file dirname ~} msg] $msg]
sl@0
   423
    set env(HOME) $temp
sl@0
   424
    set result
sl@0
   425
} {0 /homewontexist}
sl@0
   426
test cmdAH-8.46 {Tcl_FileObjCmd: dirname} {
sl@0
   427
    global env
sl@0
   428
    set temp $env(HOME)
sl@0
   429
    set env(HOME) "/home/test"
sl@0
   430
    testsetplatform mac
sl@0
   431
    set result [list [catch {file dirname ~} msg] $msg]
sl@0
   432
    set env(HOME) $temp
sl@0
   433
    set result
sl@0
   434
} {0 home:}
sl@0
   435
sl@0
   436
# tail
sl@0
   437
sl@0
   438
test cmdAH-9.1 {Tcl_FileObjCmd: tail} {
sl@0
   439
    testsetplatform unix
sl@0
   440
    list [catch {file tail a b} msg] $msg
sl@0
   441
} {1 {wrong # args: should be "file tail name"}}
sl@0
   442
test cmdAH-9.2 {Tcl_FileObjCmd: tail} {
sl@0
   443
    testsetplatform unix
sl@0
   444
    file tail /a/b
sl@0
   445
} b
sl@0
   446
test cmdAH-9.3 {Tcl_FileObjCmd: tail} {
sl@0
   447
    testsetplatform unix
sl@0
   448
    file tail {}
sl@0
   449
} {}
sl@0
   450
test cmdAH-9.4 {Tcl_FileObjCmd: tail} {
sl@0
   451
    testsetplatform mac
sl@0
   452
    file tail {}
sl@0
   453
} {}
sl@0
   454
test cmdAH-9.5 {Tcl_FileObjCmd: tail} {
sl@0
   455
    testsetplatform win
sl@0
   456
    file tail {}
sl@0
   457
} {}
sl@0
   458
test cmdAH-9.6 {Tcl_FileObjCmd: tail} {
sl@0
   459
    testsetplatform unix
sl@0
   460
    file tail .def
sl@0
   461
} .def
sl@0
   462
test cmdAH-9.7 {Tcl_FileObjCmd: tail} {
sl@0
   463
    testsetplatform mac
sl@0
   464
    file tail a
sl@0
   465
} a
sl@0
   466
test cmdAH-9.8 {Tcl_FileObjCmd: tail} {
sl@0
   467
    testsetplatform win
sl@0
   468
    file tail a
sl@0
   469
} a
sl@0
   470
test cmdAH-9.9 {Tcl_FileObjCmd: tail} {
sl@0
   471
    testsetplatform unix
sl@0
   472
    file ta a/b/c.d
sl@0
   473
} c.d
sl@0
   474
test cmdAH-9.10 {Tcl_FileObjCmd: tail} {
sl@0
   475
    testsetplatform unix
sl@0
   476
    file tail a/b.c/d
sl@0
   477
} d
sl@0
   478
test cmdAH-9.11 {Tcl_FileObjCmd: tail} {
sl@0
   479
    testsetplatform unix
sl@0
   480
    file tail /.
sl@0
   481
} .
sl@0
   482
test cmdAH-9.12 {Tcl_FileObjCmd: tail} {
sl@0
   483
    testsetplatform unix
sl@0
   484
    file tail /
sl@0
   485
} {}
sl@0
   486
test cmdAH-9.13 {Tcl_FileObjCmd: tail} {
sl@0
   487
    testsetplatform unix
sl@0
   488
    file tail /foo
sl@0
   489
} foo
sl@0
   490
test cmdAH-9.14 {Tcl_FileObjCmd: tail} {
sl@0
   491
    testsetplatform unix
sl@0
   492
    file tail //foo
sl@0
   493
} foo
sl@0
   494
test cmdAH-9.15 {Tcl_FileObjCmd: tail} {
sl@0
   495
    testsetplatform unix
sl@0
   496
    file tail //foo/bar
sl@0
   497
} bar
sl@0
   498
test cmdAH-9.16 {Tcl_FileObjCmd: tail} {
sl@0
   499
    testsetplatform unix
sl@0
   500
    file tail {//foo\/bar/baz}
sl@0
   501
} baz
sl@0
   502
test cmdAH-9.17 {Tcl_FileObjCmd: tail} {
sl@0
   503
    testsetplatform unix
sl@0
   504
    file tail {//foo\/bar/baz/blat}
sl@0
   505
} blat
sl@0
   506
test cmdAH-9.18 {Tcl_FileObjCmd: tail} {
sl@0
   507
    testsetplatform unix
sl@0
   508
    file tail /foo//
sl@0
   509
} foo
sl@0
   510
test cmdAH-9.19 {Tcl_FileObjCmd: tail} {
sl@0
   511
    testsetplatform unix
sl@0
   512
    file tail ./a
sl@0
   513
} a
sl@0
   514
test cmdAH-9.20 {Tcl_FileObjCmd: tail} {
sl@0
   515
    testsetplatform unix
sl@0
   516
    file tail a/.a
sl@0
   517
} .a
sl@0
   518
test cmdAH-9.21 {Tcl_FileObjCmd: tail} {
sl@0
   519
    testsetplatform windows
sl@0
   520
    file tail c:foo
sl@0
   521
} foo
sl@0
   522
test cmdAH-9.22 {Tcl_FileObjCmd: tail} {
sl@0
   523
    testsetplatform windows
sl@0
   524
    file tail c:
sl@0
   525
} {}
sl@0
   526
test cmdAH-9.23 {Tcl_FileObjCmd: tail} {
sl@0
   527
    testsetplatform windows
sl@0
   528
    file tail c:/
sl@0
   529
} {}
sl@0
   530
test cmdAH-9.24 {Tcl_FileObjCmd: tail} {
sl@0
   531
    testsetplatform windows
sl@0
   532
    file tail {c:\foo}
sl@0
   533
} foo
sl@0
   534
test cmdAH-9.25 {Tcl_FileObjCmd: tail} {
sl@0
   535
    testsetplatform windows
sl@0
   536
    file tail {//foo/bar/baz}
sl@0
   537
} baz
sl@0
   538
test cmdAH-9.26 {Tcl_FileObjCmd: tail} {
sl@0
   539
    testsetplatform windows
sl@0
   540
    file tail {//foo/bar}
sl@0
   541
} {}
sl@0
   542
test cmdAH-9.27 {Tcl_FileObjCmd: tail} {
sl@0
   543
    testsetplatform mac
sl@0
   544
    file tail :
sl@0
   545
} :
sl@0
   546
test cmdAH-9.28 {Tcl_FileObjCmd: tail} {
sl@0
   547
    testsetplatform mac
sl@0
   548
    file tail :Foo
sl@0
   549
} Foo
sl@0
   550
test cmdAH-9.29 {Tcl_FileObjCmd: tail} {
sl@0
   551
    testsetplatform mac
sl@0
   552
    file tail Foo:
sl@0
   553
} {}
sl@0
   554
test cmdAH-9.30 {Tcl_FileObjCmd: tail} {
sl@0
   555
    testsetplatform mac
sl@0
   556
    file tail Foo:bar
sl@0
   557
} bar
sl@0
   558
test cmdAH-9.31 {Tcl_FileObjCmd: tail} {
sl@0
   559
    testsetplatform mac
sl@0
   560
    file tail :Foo:bar
sl@0
   561
} bar
sl@0
   562
test cmdAH-9.32 {Tcl_FileObjCmd: tail} {
sl@0
   563
    testsetplatform mac
sl@0
   564
    file tail ::
sl@0
   565
} ::
sl@0
   566
test cmdAH-9.33 {Tcl_FileObjCmd: tail} {
sl@0
   567
    testsetplatform mac
sl@0
   568
    file tail :::
sl@0
   569
} ::
sl@0
   570
test cmdAH-9.34 {Tcl_FileObjCmd: tail} {
sl@0
   571
    testsetplatform mac
sl@0
   572
    file tail /foo/bar/
sl@0
   573
} bar
sl@0
   574
test cmdAH-9.35 {Tcl_FileObjCmd: tail} {
sl@0
   575
    testsetplatform mac
sl@0
   576
    file tail /foo/bar
sl@0
   577
} bar
sl@0
   578
test cmdAH-9.36 {Tcl_FileObjCmd: tail} {
sl@0
   579
    testsetplatform mac
sl@0
   580
    file tail /foo
sl@0
   581
} {}
sl@0
   582
test cmdAH-9.37 {Tcl_FileObjCmd: tail} {
sl@0
   583
    testsetplatform mac
sl@0
   584
    file tail foo
sl@0
   585
} foo
sl@0
   586
test cmdAH-9.38 {Tcl_FileObjCmd: tail} {
sl@0
   587
    testsetplatform mac
sl@0
   588
    file tail ~:foo
sl@0
   589
} foo
sl@0
   590
test cmdAH-9.39 {Tcl_FileObjCmd: tail} {
sl@0
   591
    testsetplatform mac
sl@0
   592
    file tail ~bar:foo
sl@0
   593
} foo
sl@0
   594
test cmdAH-9.40 {Tcl_FileObjCmd: tail} {
sl@0
   595
    testsetplatform mac
sl@0
   596
    file tail ~bar/foo
sl@0
   597
} foo
sl@0
   598
test cmdAH-9.41 {Tcl_FileObjCmd: tail} {
sl@0
   599
    testsetplatform mac
sl@0
   600
    file tail ~/foo
sl@0
   601
} foo
sl@0
   602
test cmdAH-9.42 {Tcl_FileObjCmd: tail} {
sl@0
   603
    global env
sl@0
   604
    set temp $env(HOME)
sl@0
   605
    set env(HOME) "/home/test"
sl@0
   606
    testsetplatform unix
sl@0
   607
    set result [file tail ~]
sl@0
   608
    set env(HOME) $temp
sl@0
   609
    set result
sl@0
   610
} test
sl@0
   611
test cmdAH-9.43 {Tcl_FileObjCmd: tail} {
sl@0
   612
    global env
sl@0
   613
    set temp $env(HOME)
sl@0
   614
    set env(HOME) "~"
sl@0
   615
    testsetplatform unix
sl@0
   616
    set result [file tail ~]
sl@0
   617
    set env(HOME) $temp
sl@0
   618
    set result
sl@0
   619
} {}
sl@0
   620
test cmdAH-9.44 {Tcl_FileObjCmd: tail} {
sl@0
   621
    global env
sl@0
   622
    set temp $env(HOME)
sl@0
   623
    set env(HOME) "/home/test"
sl@0
   624
    testsetplatform windows
sl@0
   625
    set result [file tail ~]
sl@0
   626
    set env(HOME) $temp
sl@0
   627
    set result
sl@0
   628
} test
sl@0
   629
test cmdAH-9.45 {Tcl_FileObjCmd: tail} {
sl@0
   630
    global env
sl@0
   631
    set temp $env(HOME)
sl@0
   632
    set env(HOME) "/home/test"
sl@0
   633
    testsetplatform mac
sl@0
   634
    set result [file tail ~]
sl@0
   635
    set env(HOME) $temp
sl@0
   636
    set result
sl@0
   637
} test
sl@0
   638
test cmdAH-9.46 {Tcl_FileObjCmd: tail} {
sl@0
   639
    testsetplatform unix
sl@0
   640
    file tail {f.oo\bar/baz.bat}
sl@0
   641
} baz.bat
sl@0
   642
test cmdAH-9.47 {Tcl_FileObjCmd: tail} {
sl@0
   643
    testsetplatform windows
sl@0
   644
    file tail c:foo
sl@0
   645
} foo
sl@0
   646
test cmdAH-9.48 {Tcl_FileObjCmd: tail} {
sl@0
   647
    testsetplatform windows
sl@0
   648
    file tail c:
sl@0
   649
} {}
sl@0
   650
test cmdAH-9.49 {Tcl_FileObjCmd: tail} {
sl@0
   651
    testsetplatform windows
sl@0
   652
    file tail c:/foo
sl@0
   653
} foo
sl@0
   654
test cmdAH-9.50 {Tcl_FileObjCmd: tail} {
sl@0
   655
    testsetplatform windows
sl@0
   656
    file tail {c:/foo\bar}
sl@0
   657
} bar
sl@0
   658
test cmdAH-9.51 {Tcl_FileObjCmd: tail} {
sl@0
   659
    testsetplatform windows
sl@0
   660
    file tail {foo\bar}
sl@0
   661
} bar
sl@0
   662
sl@0
   663
# rootname
sl@0
   664
sl@0
   665
test cmdAH-10.1 {Tcl_FileObjCmd: rootname} {
sl@0
   666
    testsetplatform unix
sl@0
   667
    list [catch {file rootname a b} msg] $msg
sl@0
   668
} {1 {wrong # args: should be "file rootname name"}}
sl@0
   669
test cmdAH-10.2 {Tcl_FileObjCmd: rootname} {
sl@0
   670
    testsetplatform unix
sl@0
   671
    file rootname {}
sl@0
   672
} {}
sl@0
   673
test cmdAH-10.3 {Tcl_FileObjCmd: rootname} {
sl@0
   674
    testsetplatform unix
sl@0
   675
    file ro foo
sl@0
   676
} foo
sl@0
   677
test cmdAH-10.4 {Tcl_FileObjCmd: rootname} {
sl@0
   678
    testsetplatform unix
sl@0
   679
    file rootname foo.
sl@0
   680
} foo
sl@0
   681
test cmdAH-10.5 {Tcl_FileObjCmd: rootname} {
sl@0
   682
    testsetplatform unix
sl@0
   683
    file rootname .foo
sl@0
   684
} {}
sl@0
   685
test cmdAH-10.6 {Tcl_FileObjCmd: rootname} {
sl@0
   686
    testsetplatform unix
sl@0
   687
    file rootname abc.def
sl@0
   688
} abc
sl@0
   689
test cmdAH-10.7 {Tcl_FileObjCmd: rootname} {
sl@0
   690
    testsetplatform unix
sl@0
   691
    file rootname abc.def.ghi
sl@0
   692
} abc.def
sl@0
   693
test cmdAH-10.8 {Tcl_FileObjCmd: rootname} {
sl@0
   694
    testsetplatform unix
sl@0
   695
    file rootname a/b/c.d
sl@0
   696
} a/b/c
sl@0
   697
test cmdAH-10.9 {Tcl_FileObjCmd: rootname} {
sl@0
   698
    testsetplatform unix
sl@0
   699
    file rootname a/b.c/d
sl@0
   700
} a/b.c/d
sl@0
   701
test cmdAH-10.10 {Tcl_FileObjCmd: rootname} {
sl@0
   702
    testsetplatform unix
sl@0
   703
    file rootname a/b.c/
sl@0
   704
} a/b.c/
sl@0
   705
test cmdAH-10.11 {Tcl_FileObjCmd: rootname} {
sl@0
   706
    testsetplatform mac
sl@0
   707
    file ro foo
sl@0
   708
} foo
sl@0
   709
test cmdAH-10.12 {Tcl_FileObjCmd: rootname} {
sl@0
   710
    testsetplatform mac
sl@0
   711
    file rootname {}
sl@0
   712
} {}
sl@0
   713
test cmdAH-10.13 {Tcl_FileObjCmd: rootname} {
sl@0
   714
    testsetplatform mac
sl@0
   715
    file rootname foo.
sl@0
   716
} foo
sl@0
   717
test cmdAH-10.14 {Tcl_FileObjCmd: rootname} {
sl@0
   718
    testsetplatform mac
sl@0
   719
    file rootname .foo
sl@0
   720
} {}
sl@0
   721
test cmdAH-10.15 {Tcl_FileObjCmd: rootname} {
sl@0
   722
    testsetplatform mac
sl@0
   723
    file rootname abc.def
sl@0
   724
} abc
sl@0
   725
test cmdAH-10.16 {Tcl_FileObjCmd: rootname} {
sl@0
   726
    testsetplatform mac
sl@0
   727
    file rootname abc.def.ghi
sl@0
   728
} abc.def
sl@0
   729
test cmdAH-10.17 {Tcl_FileObjCmd: rootname} {
sl@0
   730
    testsetplatform mac
sl@0
   731
    file rootname a:b:c.d
sl@0
   732
} a:b:c
sl@0
   733
test cmdAH-10.18 {Tcl_FileObjCmd: rootname} {
sl@0
   734
    testsetplatform mac
sl@0
   735
    file rootname a:b.c:d
sl@0
   736
} a:b.c:d
sl@0
   737
test cmdAH-10.19 {Tcl_FileObjCmd: rootname} {
sl@0
   738
    testsetplatform mac
sl@0
   739
    file rootname a/b/c.d
sl@0
   740
} a/b/c
sl@0
   741
test cmdAH-10.20 {Tcl_FileObjCmd: rootname} {
sl@0
   742
    testsetplatform mac
sl@0
   743
    file rootname a/b.c/d
sl@0
   744
} a/b.c/d
sl@0
   745
test cmdAH-10.21 {Tcl_FileObjCmd: rootname} {
sl@0
   746
    testsetplatform mac
sl@0
   747
    file rootname /a.b
sl@0
   748
} /a
sl@0
   749
test cmdAH-10.22 {Tcl_FileObjCmd: rootname} {
sl@0
   750
    testsetplatform mac
sl@0
   751
    file rootname foo.c:
sl@0
   752
} foo.c:
sl@0
   753
test cmdAH-10.23 {Tcl_FileObjCmd: rootname} {
sl@0
   754
    testsetplatform windows
sl@0
   755
    file rootname {}
sl@0
   756
} {}
sl@0
   757
test cmdAH-10.24 {Tcl_FileObjCmd: rootname} {
sl@0
   758
    testsetplatform windows
sl@0
   759
    file ro foo
sl@0
   760
} foo
sl@0
   761
test cmdAH-10.25 {Tcl_FileObjCmd: rootname} {
sl@0
   762
    testsetplatform windows
sl@0
   763
    file rootname foo.
sl@0
   764
} foo
sl@0
   765
test cmdAH-10.26 {Tcl_FileObjCmd: rootname} {
sl@0
   766
    testsetplatform windows
sl@0
   767
    file rootname .foo
sl@0
   768
} {}
sl@0
   769
test cmdAH-10.27 {Tcl_FileObjCmd: rootname} {
sl@0
   770
    testsetplatform windows
sl@0
   771
    file rootname abc.def
sl@0
   772
} abc
sl@0
   773
test cmdAH-10.28 {Tcl_FileObjCmd: rootname} {
sl@0
   774
    testsetplatform windows
sl@0
   775
    file rootname abc.def.ghi
sl@0
   776
} abc.def
sl@0
   777
test cmdAH-10.29 {Tcl_FileObjCmd: rootname} {
sl@0
   778
    testsetplatform windows
sl@0
   779
    file rootname a/b/c.d
sl@0
   780
} a/b/c
sl@0
   781
test cmdAH-10.30 {Tcl_FileObjCmd: rootname} {
sl@0
   782
    testsetplatform windows
sl@0
   783
    file rootname a/b.c/d
sl@0
   784
} a/b.c/d
sl@0
   785
test cmdAH-10.31 {Tcl_FileObjCmd: rootname} {
sl@0
   786
    testsetplatform windows
sl@0
   787
    file rootname a\\b.c\\
sl@0
   788
} a\\b.c\\
sl@0
   789
test cmdAH-10.32 {Tcl_FileObjCmd: rootname} {
sl@0
   790
    testsetplatform windows
sl@0
   791
    file rootname a\\b\\c.d
sl@0
   792
} a\\b\\c
sl@0
   793
test cmdAH-10.33 {Tcl_FileObjCmd: rootname} {
sl@0
   794
    testsetplatform windows
sl@0
   795
    file rootname a\\b.c\\d
sl@0
   796
} a\\b.c\\d
sl@0
   797
test cmdAH-10.34 {Tcl_FileObjCmd: rootname} {
sl@0
   798
    testsetplatform windows
sl@0
   799
    file rootname a\\b.c\\
sl@0
   800
} a\\b.c\\
sl@0
   801
set num 35
sl@0
   802
foreach outer { {} a .a a. a.a } {
sl@0
   803
  foreach inner { {} a .a a. a.a } {
sl@0
   804
    set thing [format %s/%s $outer $inner]
sl@0
   805
;   test cmdAH-6.$num {Tcl_FileObjCmd: rootname and extension options} {
sl@0
   806
	testsetplatform unix
sl@0
   807
	format %s%s [file rootname $thing] [file ext $thing]
sl@0
   808
    } $thing
sl@0
   809
    set num [expr $num+1]
sl@0
   810
  }
sl@0
   811
}
sl@0
   812
sl@0
   813
# extension
sl@0
   814
sl@0
   815
test cmdAH-11.1 {Tcl_FileObjCmd: extension} {
sl@0
   816
    testsetplatform unix
sl@0
   817
    list [catch {file extension a b} msg] $msg
sl@0
   818
} {1 {wrong # args: should be "file extension name"}}
sl@0
   819
test cmdAH-11.2 {Tcl_FileObjCmd: extension} {
sl@0
   820
    testsetplatform unix
sl@0
   821
    file extension {}
sl@0
   822
} {}
sl@0
   823
test cmdAH-11.3 {Tcl_FileObjCmd: extension} {
sl@0
   824
    testsetplatform unix
sl@0
   825
    file ext foo
sl@0
   826
} {}
sl@0
   827
test cmdAH-11.4 {Tcl_FileObjCmd: extension} {
sl@0
   828
    testsetplatform unix
sl@0
   829
    file extension foo.
sl@0
   830
} .
sl@0
   831
test cmdAH-11.5 {Tcl_FileObjCmd: extension} {
sl@0
   832
    testsetplatform unix
sl@0
   833
    file extension .foo
sl@0
   834
} .foo
sl@0
   835
test cmdAH-11.6 {Tcl_FileObjCmd: extension} {
sl@0
   836
    testsetplatform unix
sl@0
   837
    file extension abc.def
sl@0
   838
} .def
sl@0
   839
test cmdAH-11.7 {Tcl_FileObjCmd: extension} {
sl@0
   840
    testsetplatform unix
sl@0
   841
    file extension abc.def.ghi
sl@0
   842
} .ghi
sl@0
   843
test cmdAH-11.8 {Tcl_FileObjCmd: extension} {
sl@0
   844
    testsetplatform unix
sl@0
   845
    file extension a/b/c.d
sl@0
   846
} .d
sl@0
   847
test cmdAH-11.9 {Tcl_FileObjCmd: extension} {
sl@0
   848
    testsetplatform unix
sl@0
   849
    file extension a/b.c/d
sl@0
   850
} {}
sl@0
   851
test cmdAH-11.10 {Tcl_FileObjCmd: extension} {
sl@0
   852
    testsetplatform unix
sl@0
   853
    file extension a/b.c/
sl@0
   854
} {}
sl@0
   855
test cmdAH-11.11 {Tcl_FileObjCmd: extension} {
sl@0
   856
    testsetplatform mac
sl@0
   857
    file ext foo
sl@0
   858
} {}
sl@0
   859
test cmdAH-11.12 {Tcl_FileObjCmd: extension} {
sl@0
   860
    testsetplatform mac
sl@0
   861
    file extension {}
sl@0
   862
} {}
sl@0
   863
test cmdAH-11.13 {Tcl_FileObjCmd: extension} {
sl@0
   864
    testsetplatform mac
sl@0
   865
    file extension foo.
sl@0
   866
} .
sl@0
   867
test cmdAH-11.14 {Tcl_FileObjCmd: extension} {
sl@0
   868
    testsetplatform mac
sl@0
   869
    file extension .foo
sl@0
   870
} .foo
sl@0
   871
test cmdAH-11.15 {Tcl_FileObjCmd: extension} {
sl@0
   872
    testsetplatform mac
sl@0
   873
    file extension abc.def
sl@0
   874
} .def
sl@0
   875
test cmdAH-11.16 {Tcl_FileObjCmd: extension} {
sl@0
   876
    testsetplatform mac
sl@0
   877
    file extension abc.def.ghi
sl@0
   878
} .ghi
sl@0
   879
test cmdAH-11.17 {Tcl_FileObjCmd: extension} {
sl@0
   880
    testsetplatform mac
sl@0
   881
    file extension a:b:c.d
sl@0
   882
} .d
sl@0
   883
test cmdAH-11.18 {Tcl_FileObjCmd: extension} {
sl@0
   884
    testsetplatform mac
sl@0
   885
    file extension a:b.c:d
sl@0
   886
} {}
sl@0
   887
test cmdAH-11.19 {Tcl_FileObjCmd: extension} {
sl@0
   888
    testsetplatform mac
sl@0
   889
    file extension a/b/c.d
sl@0
   890
} .d
sl@0
   891
test cmdAH-11.20 {Tcl_FileObjCmd: extension} {
sl@0
   892
    testsetplatform mac
sl@0
   893
    file extension a/b.c/d
sl@0
   894
} {}
sl@0
   895
test cmdAH-11.21 {Tcl_FileObjCmd: extension} {
sl@0
   896
    testsetplatform mac
sl@0
   897
    file extension /a.b
sl@0
   898
} .b
sl@0
   899
test cmdAH-11.22 {Tcl_FileObjCmd: extension} {
sl@0
   900
    testsetplatform mac
sl@0
   901
    file extension foo.c:
sl@0
   902
} {}
sl@0
   903
test cmdAH-11.23 {Tcl_FileObjCmd: extension} {
sl@0
   904
    testsetplatform windows
sl@0
   905
    file extension {}
sl@0
   906
} {}
sl@0
   907
test cmdAH-11.24 {Tcl_FileObjCmd: extension} {
sl@0
   908
    testsetplatform windows
sl@0
   909
    file ext foo
sl@0
   910
} {}
sl@0
   911
test cmdAH-11.25 {Tcl_FileObjCmd: extension} {
sl@0
   912
    testsetplatform windows
sl@0
   913
    file extension foo.
sl@0
   914
} .
sl@0
   915
test cmdAH-11.26 {Tcl_FileObjCmd: extension} {
sl@0
   916
    testsetplatform windows
sl@0
   917
    file extension .foo
sl@0
   918
} .foo
sl@0
   919
test cmdAH-11.27 {Tcl_FileObjCmd: extension} {
sl@0
   920
    testsetplatform windows
sl@0
   921
    file extension abc.def
sl@0
   922
} .def
sl@0
   923
test cmdAH-11.28 {Tcl_FileObjCmd: extension} {
sl@0
   924
    testsetplatform windows
sl@0
   925
    file extension abc.def.ghi
sl@0
   926
} .ghi
sl@0
   927
test cmdAH-11.29 {Tcl_FileObjCmd: extension} {
sl@0
   928
    testsetplatform windows
sl@0
   929
    file extension a/b/c.d
sl@0
   930
} .d
sl@0
   931
test cmdAH-11.30 {Tcl_FileObjCmd: extension} {
sl@0
   932
    testsetplatform windows
sl@0
   933
    file extension a/b.c/d
sl@0
   934
} {}
sl@0
   935
test cmdAH-11.31 {Tcl_FileObjCmd: extension} {
sl@0
   936
    testsetplatform windows
sl@0
   937
    file extension a\\b.c\\
sl@0
   938
} {}
sl@0
   939
test cmdAH-11.32 {Tcl_FileObjCmd: extension} {
sl@0
   940
    testsetplatform windows
sl@0
   941
    file extension a\\b\\c.d
sl@0
   942
} .d
sl@0
   943
test cmdAH-11.33 {Tcl_FileObjCmd: extension} {
sl@0
   944
    testsetplatform windows
sl@0
   945
    file extension a\\b.c\\d
sl@0
   946
} {}
sl@0
   947
test cmdAH-11.34 {Tcl_FileObjCmd: extension} {
sl@0
   948
    testsetplatform windows
sl@0
   949
    file extension a\\b.c\\
sl@0
   950
} {}
sl@0
   951
set num 35
sl@0
   952
foreach value {a..b a...b a.c..b ..b} result {.b .b .b .b} {
sl@0
   953
    foreach p {unix mac windows} {
sl@0
   954
;	test cmdAH-7.$num {Tcl_FileObjCmd: extension} "
sl@0
   955
	    testsetplatform $p
sl@0
   956
	    file extension $value
sl@0
   957
	" $result
sl@0
   958
	incr num
sl@0
   959
    }
sl@0
   960
}
sl@0
   961
sl@0
   962
# pathtype
sl@0
   963
sl@0
   964
test cmdAH-12.1 {Tcl_FileObjCmd: pathtype} {
sl@0
   965
    testsetplatform unix
sl@0
   966
    list [catch {file pathtype a b} msg] $msg
sl@0
   967
} {1 {wrong # args: should be "file pathtype name"}}
sl@0
   968
test cmdAH-12.2 {Tcl_FileObjCmd: pathtype} {
sl@0
   969
    testsetplatform unix
sl@0
   970
    file pathtype /a
sl@0
   971
} absolute
sl@0
   972
test cmdAH-12.3 {Tcl_FileObjCmd: pathtype} {
sl@0
   973
    testsetplatform unix
sl@0
   974
    file p a
sl@0
   975
} relative
sl@0
   976
test cmdAH-12.4 {Tcl_FileObjCmd: pathtype} {
sl@0
   977
    testsetplatform windows
sl@0
   978
    file pathtype c:a
sl@0
   979
} volumerelative
sl@0
   980
sl@0
   981
# split
sl@0
   982
sl@0
   983
test cmdAH-13.1 {Tcl_FileObjCmd: split} {
sl@0
   984
    testsetplatform unix
sl@0
   985
    list [catch {file split a b} msg] $msg
sl@0
   986
} {1 {wrong # args: should be "file split name"}}
sl@0
   987
test cmdAH-13.2 {Tcl_FileObjCmd: split} {
sl@0
   988
    testsetplatform unix
sl@0
   989
    file split a
sl@0
   990
} a
sl@0
   991
test cmdAH-13.3 {Tcl_FileObjCmd: split} {
sl@0
   992
    testsetplatform unix
sl@0
   993
    file split a/b
sl@0
   994
} {a b}
sl@0
   995
sl@0
   996
# join
sl@0
   997
sl@0
   998
test cmdAH-14.1 {Tcl_FileObjCmd: join} {
sl@0
   999
    testsetplatform unix
sl@0
  1000
    file join a
sl@0
  1001
} a
sl@0
  1002
test cmdAH-14.2 {Tcl_FileObjCmd: join} {
sl@0
  1003
    testsetplatform unix
sl@0
  1004
    file join a b
sl@0
  1005
} a/b
sl@0
  1006
test cmdAH-14.3 {Tcl_FileObjCmd: join} {
sl@0
  1007
    testsetplatform unix
sl@0
  1008
    file join a b c d
sl@0
  1009
} a/b/c/d
sl@0
  1010
sl@0
  1011
# error handling of Tcl_TranslateFileName
sl@0
  1012
sl@0
  1013
test cmdAH-15.1 {Tcl_FileObjCmd} {
sl@0
  1014
    testsetplatform unix
sl@0
  1015
    list [catch {file atime ~_bad_user} msg] $msg
sl@0
  1016
} {1 {user "_bad_user" doesn't exist}}
sl@0
  1017
sl@0
  1018
testsetplatform $platform
sl@0
  1019
}
sl@0
  1020
sl@0
  1021
# readable
sl@0
  1022
sl@0
  1023
set gorpfile [makeFile abcde gorp.file]
sl@0
  1024
set dirfile [makeDirectory dir.file]
sl@0
  1025
sl@0
  1026
if {[info commands testchmod] == {}} {
sl@0
  1027
    puts "This application hasn't been compiled with the \"testchmod\""
sl@0
  1028
    puts "command, so I can't test Tcl_FileObjCmd etc."
sl@0
  1029
} else {
sl@0
  1030
test cmdAH-16.1 {Tcl_FileObjCmd: readable} {testchmod} {
sl@0
  1031
    list [catch {file readable a b} msg] $msg
sl@0
  1032
} {1 {wrong # args: should be "file readable name"}}
sl@0
  1033
testchmod 0444 $gorpfile
sl@0
  1034
test cmdAH-16.2 {Tcl_FileObjCmd: readable} {testchmod} {
sl@0
  1035
    file readable $gorpfile
sl@0
  1036
} 1
sl@0
  1037
testchmod 0333 $gorpfile
sl@0
  1038
test cmdAH-16.3 {Tcl_FileObjCmd: readable} {unixOnly notRoot testchmod} {
sl@0
  1039
    file reada $gorpfile
sl@0
  1040
} 0
sl@0
  1041
sl@0
  1042
# writable
sl@0
  1043
sl@0
  1044
test cmdAH-17.1 {Tcl_FileObjCmd: writable} {testchmod} {
sl@0
  1045
    list [catch {file writable a b} msg] $msg
sl@0
  1046
} {1 {wrong # args: should be "file writable name"}}
sl@0
  1047
testchmod 0555 $gorpfile
sl@0
  1048
test cmdAH-17.2 {Tcl_FileObjCmd: writable} {notRoot testchmod} {
sl@0
  1049
    file writable $gorpfile
sl@0
  1050
} 0
sl@0
  1051
testchmod 0222 $gorpfile
sl@0
  1052
test cmdAH-17.3 {Tcl_FileObjCmd: writable} {testchmod} {
sl@0
  1053
    file writable $gorpfile
sl@0
  1054
} 1
sl@0
  1055
}
sl@0
  1056
sl@0
  1057
# executable
sl@0
  1058
sl@0
  1059
removeFile $gorpfile
sl@0
  1060
removeDirectory $dirfile
sl@0
  1061
set dirfile [makeDirectory dir.file]
sl@0
  1062
set gorpfile [makeFile abcde gorp.file]
sl@0
  1063
sl@0
  1064
test cmdAH-18.1 {Tcl_FileObjCmd: executable} {testchmod} {
sl@0
  1065
    list [catch {file executable a b} msg] $msg
sl@0
  1066
} {1 {wrong # args: should be "file executable name"}}
sl@0
  1067
test cmdAH-18.2 {Tcl_FileObjCmd: executable} {testchmod notRoot} {
sl@0
  1068
    file executable $gorpfile
sl@0
  1069
} 0
sl@0
  1070
test cmdAH-18.3 {Tcl_FileObjCmd: executable} {unixOnly testchmod} {
sl@0
  1071
    # Only on unix will setting the execute bit on a regular file
sl@0
  1072
    # cause that file to be executable.
sl@0
  1073
sl@0
  1074
    testchmod 0775 $gorpfile
sl@0
  1075
    file exe $gorpfile
sl@0
  1076
} 1
sl@0
  1077
sl@0
  1078
test cmdAH-18.4 {Tcl_FileObjCmd: executable} {macOnly testchmod} {
sl@0
  1079
    # On mac, the only executable files are of type APPL.
sl@0
  1080
sl@0
  1081
    set x [file exe $gorpfile]
sl@0
  1082
    file attrib $gorpfile -type APPL
sl@0
  1083
    lappend x [file exe $gorpfile]
sl@0
  1084
} {0 1}
sl@0
  1085
test cmdAH-18.5 {Tcl_FileObjCmd: executable} {winOnly testchmod} {
sl@0
  1086
    # On pc, must be a .exe, .com, etc.
sl@0
  1087
sl@0
  1088
    set x [file exe $gorpfile]
sl@0
  1089
    set gorpexe [makeFile foo gorp.exe]
sl@0
  1090
    lappend x [file exe $gorpexe]
sl@0
  1091
    removeFile $gorpexe
sl@0
  1092
    set x
sl@0
  1093
} {0 1}
sl@0
  1094
test cmdAH-18.6 {Tcl_FileObjCmd: executable} {testchmod} {
sl@0
  1095
    # Directories are always executable.
sl@0
  1096
sl@0
  1097
    file exe $dirfile
sl@0
  1098
} 1
sl@0
  1099
sl@0
  1100
removeDirectory $dirfile
sl@0
  1101
removeFile $gorpfile
sl@0
  1102
set linkfile [file join [temporaryDirectory] link.file]
sl@0
  1103
file delete $linkfile
sl@0
  1104
sl@0
  1105
# exists
sl@0
  1106
sl@0
  1107
test cmdAH-19.1 {Tcl_FileObjCmd: exists} {
sl@0
  1108
    list [catch {file exists a b} msg] $msg
sl@0
  1109
} {1 {wrong # args: should be "file exists name"}}
sl@0
  1110
test cmdAH-19.2 {Tcl_FileObjCmd: exists} {file exists $gorpfile} 0
sl@0
  1111
test cmdAH-19.3 {Tcl_FileObjCmd: exists} {
sl@0
  1112
    file exists [file join [temporaryDirectory] dir.file gorp.file]
sl@0
  1113
} 0
sl@0
  1114
catch {
sl@0
  1115
    set gorpfile [makeFile abcde gorp.file]
sl@0
  1116
    set dirfile [makeDirectory dir.file]
sl@0
  1117
    set subgorp [makeFile 12345 [file join $dirfile gorp.file]]
sl@0
  1118
}
sl@0
  1119
test cmdAH-19.4 {Tcl_FileObjCmd: exists} {
sl@0
  1120
    file exists $gorpfile
sl@0
  1121
} 1
sl@0
  1122
test cmdAH-19.5 {Tcl_FileObjCmd: exists} {
sl@0
  1123
    file exists $subgorp
sl@0
  1124
} 1
sl@0
  1125
sl@0
  1126
# nativename
sl@0
  1127
if {[info commands testsetplatform] == {}} {
sl@0
  1128
    puts "This application hasn't been compiled with the \"testsetplatform\""
sl@0
  1129
    puts "command, so I can't test Tcl_FileObjCmd etc."
sl@0
  1130
} else {
sl@0
  1131
test cmdAH-19.6 {Tcl_FileObjCmd: nativename} {
sl@0
  1132
    testsetplatform unix
sl@0
  1133
    list [catch {file nativename a/b} msg] $msg [testsetplatform $platform]
sl@0
  1134
} {0 a/b {}}
sl@0
  1135
test cmdAH-19.7 {Tcl_FileObjCmd: nativename} {
sl@0
  1136
    testsetplatform windows
sl@0
  1137
    list [catch {file nativename a/b} msg] $msg [testsetplatform $platform]
sl@0
  1138
} {0 {a\b} {}}
sl@0
  1139
test cmdAH-19.8 {Tcl_FileObjCmd: nativename} {
sl@0
  1140
    testsetplatform mac
sl@0
  1141
    list [catch {file nativename a/b} msg] $msg [testsetplatform $platform]
sl@0
  1142
} {0 :a:b {}}
sl@0
  1143
}
sl@0
  1144
sl@0
  1145
test cmdAH-19.9 {Tcl_FileObjCmd: ~ : exists} {
sl@0
  1146
    file exists ~nOsUcHuSeR
sl@0
  1147
} 0
sl@0
  1148
test cmdAH-19.10 {Tcl_FileObjCmd: ~ : nativename} {
sl@0
  1149
    # should probably be 0 in fact...
sl@0
  1150
    catch {file nativename ~nOsUcHuSeR}
sl@0
  1151
} 1
sl@0
  1152
sl@0
  1153
# The test below has to be done in /tmp rather than the current
sl@0
  1154
# directory in order to guarantee (?) a local file system:  some
sl@0
  1155
# NFS file systems won't do the stuff below correctly.
sl@0
  1156
sl@0
  1157
test cmdAH-19.11 {Tcl_FileObjCmd: exists} {unixOnly notRoot} {
sl@0
  1158
    file delete -force /tmp/tcl.foo.dir/file
sl@0
  1159
    file delete -force /tmp/tcl.foo.dir
sl@0
  1160
    makeDirectory /tmp/tcl.foo.dir
sl@0
  1161
    makeFile 12345 /tmp/tcl.foo.dir/file
sl@0
  1162
    file attributes /tmp/tcl.foo.dir -permissions 0000
sl@0
  1163
sl@0
  1164
    set result [file exists /tmp/tcl.foo.dir/file]
sl@0
  1165
sl@0
  1166
    file attributes /tmp/tcl.foo.dir -permissions 0775
sl@0
  1167
    removeFile /tmp/tcl.foo.dir/file
sl@0
  1168
    removeDirectory /tmp/tcl.foo.dir
sl@0
  1169
    set result
sl@0
  1170
} 0
sl@0
  1171
sl@0
  1172
# Stat related commands
sl@0
  1173
sl@0
  1174
catch {testsetplatform $platform}
sl@0
  1175
removeFile $gorpfile
sl@0
  1176
set gorpfile [makeFile "Test string" gorp.file]
sl@0
  1177
catch {file attributes $gorpfile -permissions 0765}
sl@0
  1178
sl@0
  1179
# atime
sl@0
  1180
sl@0
  1181
set file [makeFile "data" touch.me]
sl@0
  1182
sl@0
  1183
test cmdAH-20.1 {Tcl_FileObjCmd: atime} {
sl@0
  1184
    list [catch {file atime a b c} msg] $msg
sl@0
  1185
} {1 {wrong # args: should be "file atime name ?time?"}}
sl@0
  1186
test cmdAH-20.2 {Tcl_FileObjCmd: atime} {
sl@0
  1187
    catch {unset stat}
sl@0
  1188
    file stat $gorpfile stat
sl@0
  1189
    list [expr {[file mtime $gorpfile] == $stat(mtime)}] \
sl@0
  1190
	    [expr {[file atime $gorpfile] == $stat(atime)}]
sl@0
  1191
} {1 1}
sl@0
  1192
test cmdAH-20.3 {Tcl_FileObjCmd: atime} {
sl@0
  1193
    string tolower [list [catch {file atime _bogus_} msg] \
sl@0
  1194
	    $msg $errorCode]
sl@0
  1195
} {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1196
test cmdAH-20.4 {Tcl_FileObjCmd: atime} {
sl@0
  1197
    list [catch {file atime $file notint} msg] $msg
sl@0
  1198
} {1 {expected integer but got "notint"}}
sl@0
  1199
test cmdAH-20.5 {Tcl_FileObjCmd: atime touch} {unixOrPc} {
sl@0
  1200
    if {[string equal $tcl_platform(platform) "windows"]} {
sl@0
  1201
	set old [pwd]
sl@0
  1202
	cd $::tcltest::temporaryDirectory
sl@0
  1203
	if {![string equal "NTFS" [testvolumetype]]} {
sl@0
  1204
	    # Windows FAT doesn't understand atime, but NTFS does
sl@0
  1205
	    # May also fail for Windows on NFS mounted disks
sl@0
  1206
	    cd $old
sl@0
  1207
	    return 1
sl@0
  1208
	}
sl@0
  1209
	cd $old
sl@0
  1210
    }
sl@0
  1211
    set atime [file atime $file]
sl@0
  1212
    after 1100; # pause a sec to notice change in atime
sl@0
  1213
    set newatime [clock seconds]
sl@0
  1214
    set modatime [file atime $file $newatime]
sl@0
  1215
    expr {$newatime == $modatime ? 1 : "$newatime != $modatime"}
sl@0
  1216
} 1
sl@0
  1217
sl@0
  1218
removeFile touch.me
sl@0
  1219
# isdirectory
sl@0
  1220
sl@0
  1221
test cmdAH-21.1 {Tcl_FileObjCmd: isdirectory} {
sl@0
  1222
    list [catch {file isdirectory a b} msg] $msg
sl@0
  1223
} {1 {wrong # args: should be "file isdirectory name"}}
sl@0
  1224
test cmdAH-21.2 {Tcl_FileObjCmd: isdirectory} {
sl@0
  1225
    file isdirectory $gorpfile
sl@0
  1226
} 0
sl@0
  1227
test cmdAH-21.3 {Tcl_FileObjCmd: isdirectory} {
sl@0
  1228
    file isd $dirfile
sl@0
  1229
} 1
sl@0
  1230
sl@0
  1231
# isfile
sl@0
  1232
sl@0
  1233
test cmdAH-22.1 {Tcl_FileObjCmd: isfile} {
sl@0
  1234
    list [catch {file isfile a b} msg] $msg
sl@0
  1235
} {1 {wrong # args: should be "file isfile name"}}
sl@0
  1236
test cmdAH-22.2 {Tcl_FileObjCmd: isfile} {file isfile $gorpfile} 1
sl@0
  1237
test cmdAH-22.3 {Tcl_FileObjCmd: isfile} {file isfile $dirfile} 0
sl@0
  1238
sl@0
  1239
# lstat and readlink:  don't run these tests everywhere, since not all
sl@0
  1240
# sites will have symbolic links
sl@0
  1241
sl@0
  1242
catch {file link -symbolic $linkfile $gorpfile}
sl@0
  1243
test cmdAH-23.1 {Tcl_FileObjCmd: lstat} {
sl@0
  1244
    list [catch {file lstat a} msg] $msg
sl@0
  1245
} {1 {wrong # args: should be "file lstat name varName"}}
sl@0
  1246
test cmdAH-23.2 {Tcl_FileObjCmd: lstat} {
sl@0
  1247
    list [catch {file lstat a b c} msg] $msg
sl@0
  1248
} {1 {wrong # args: should be "file lstat name varName"}}
sl@0
  1249
test cmdAH-23.3 {Tcl_FileObjCmd: lstat} {unixOnly nonPortable} {
sl@0
  1250
    catch {unset stat}
sl@0
  1251
    file lstat $linkfile stat
sl@0
  1252
    lsort [array names stat]
sl@0
  1253
} {atime ctime dev gid ino mode mtime nlink size type uid}
sl@0
  1254
test cmdAH-23.4 {Tcl_FileObjCmd: lstat} {unixOnly nonPortable} {
sl@0
  1255
    catch {unset stat}
sl@0
  1256
    file lstat $linkfile stat
sl@0
  1257
    list $stat(nlink) [expr $stat(mode)&0777] $stat(type)
sl@0
  1258
} {1 511 link}
sl@0
  1259
test cmdAH-23.5 {Tcl_FileObjCmd: lstat errors} {nonPortable} {
sl@0
  1260
    string tolower [list [catch {file lstat _bogus_ stat} msg] \
sl@0
  1261
	    $msg $errorCode]
sl@0
  1262
} {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1263
test cmdAH-23.6 {Tcl_FileObjCmd: lstat errors} {
sl@0
  1264
    catch {unset x}
sl@0
  1265
    set x 44
sl@0
  1266
    list [catch {file lstat $gorpfile x} msg] $msg $errorCode
sl@0
  1267
} {1 {can't set "x(dev)": variable isn't array} NONE}
sl@0
  1268
catch {unset stat}
sl@0
  1269
sl@0
  1270
# mkdir
sl@0
  1271
sl@0
  1272
set dirA [file join [temporaryDirectory] a]
sl@0
  1273
set dirB [file join [temporaryDirectory] a]
sl@0
  1274
test cmdAH-23.7 {Tcl_FileObjCmd: mkdir} {
sl@0
  1275
    catch {file delete -force $dirA}
sl@0
  1276
    file mkdir $dirA
sl@0
  1277
    set res [file isdirectory $dirA]
sl@0
  1278
    file delete $dirA
sl@0
  1279
    set res
sl@0
  1280
} {1}
sl@0
  1281
test cmdAH-23.8 {Tcl_FileObjCmd: mkdir} {
sl@0
  1282
    catch {file delete -force $dirA}
sl@0
  1283
    file mkdir $dirA/b
sl@0
  1284
    set res [file isdirectory $dirA/b]
sl@0
  1285
    file delete -force $dirA
sl@0
  1286
    set res
sl@0
  1287
} {1}
sl@0
  1288
test cmdAH-23.9 {Tcl_FileObjCmd: mkdir} {
sl@0
  1289
    catch {file delete -force $dirA}
sl@0
  1290
    file mkdir $dirA/b/c
sl@0
  1291
    set res [file isdirectory $dirA/b/c]
sl@0
  1292
    file delete -force $dirA
sl@0
  1293
    set res
sl@0
  1294
} {1}
sl@0
  1295
test cmdAH-23.10 {Tcl_FileObjCmd: mkdir} {
sl@0
  1296
    catch {file delete -force $dirA}
sl@0
  1297
    catch {file delete -force $dirB}
sl@0
  1298
    file mkdir $dirA/b $dirB/a/c
sl@0
  1299
    set res [list [file isdirectory $dirA/b] [file isdirectory $dirB/a/c]]
sl@0
  1300
    file delete -force $dirA
sl@0
  1301
    file delete -force $dirB
sl@0
  1302
    set res
sl@0
  1303
} {1 1}
sl@0
  1304
sl@0
  1305
# mtime
sl@0
  1306
sl@0
  1307
proc waitForEvenSecondForFAT {} {
sl@0
  1308
    # Windows 9x uses filesystems (the FAT* family of FSes) without
sl@0
  1309
    # enough data in its timestamps for even per-second-accurate
sl@0
  1310
    # timings.  :^(
sl@0
  1311
    # This procedure based on work by Helmut Giese
sl@0
  1312
sl@0
  1313
    global tcl_platform
sl@0
  1314
    if {$tcl_platform(platform) ne "windows"} {return}
sl@0
  1315
    if {[lindex [file system [temporaryDirectory]] 1] == "NTFS"} {return}
sl@0
  1316
    # Assume non-NTFS means FAT{12,16,32} and hence in need of special help
sl@0
  1317
    set start [clock seconds]
sl@0
  1318
    while {1} {
sl@0
  1319
	set now [clock seconds]
sl@0
  1320
	if {$now!=$start && !($now & 1)} {
sl@0
  1321
	    return
sl@0
  1322
	}
sl@0
  1323
	after 50
sl@0
  1324
    }
sl@0
  1325
}
sl@0
  1326
set file [makeFile "data" touch.me]
sl@0
  1327
sl@0
  1328
test cmdAH-24.1 {Tcl_FileObjCmd: mtime} {
sl@0
  1329
    list [catch {file mtime a b c} msg] $msg
sl@0
  1330
} {1 {wrong # args: should be "file mtime name ?time?"}}
sl@0
  1331
# Check (allowing for clock-skew and OS interrupts as best we can)
sl@0
  1332
# that the change in mtime on a file being written is the time elapsed
sl@0
  1333
# between writes.  Note that this can still fail on very busy systems
sl@0
  1334
# if there are long preemptions between the writes and the reading of
sl@0
  1335
# the clock, but there's not much you can do about that other than the
sl@0
  1336
# completely horrible "keep on trying to write until you managed to do
sl@0
  1337
# it all in less than a second."  - DKF
sl@0
  1338
test cmdAH-24.2 {Tcl_FileObjCmd: mtime} {
sl@0
  1339
    waitForEvenSecondForFAT
sl@0
  1340
    set f [open $gorpfile w]
sl@0
  1341
    puts $f "More text"
sl@0
  1342
    close $f
sl@0
  1343
    set clockOld [clock seconds]
sl@0
  1344
    set fileOld [file mtime $gorpfile]
sl@0
  1345
    after 2000
sl@0
  1346
    set f [open $gorpfile w]
sl@0
  1347
    puts $f "More text"
sl@0
  1348
    close $f
sl@0
  1349
    set clockNew [clock seconds]
sl@0
  1350
    set fileNew [file mtime $gorpfile]
sl@0
  1351
    expr {
sl@0
  1352
	(($fileNew > $fileOld) && ($clockNew > $clockOld) &&
sl@0
  1353
	(abs(($fileNew-$fileOld) - ($clockNew-$clockOld)) <= 1)) ? "1" :
sl@0
  1354
	"file:($fileOld=>$fileNew) clock:($clockOld=>$clockNew)"
sl@0
  1355
    }
sl@0
  1356
} {1}
sl@0
  1357
test cmdAH-24.3 {Tcl_FileObjCmd: mtime} {
sl@0
  1358
    catch {unset stat}
sl@0
  1359
    file stat $gorpfile stat
sl@0
  1360
    list [expr {[file mtime $gorpfile] == $stat(mtime)}] \
sl@0
  1361
	    [expr {[file atime $gorpfile] == $stat(atime)}]
sl@0
  1362
} {1 1}
sl@0
  1363
test cmdAH-24.4 {Tcl_FileObjCmd: mtime} {
sl@0
  1364
    string tolower [list [catch {file mtime _bogus_} msg] $msg \
sl@0
  1365
	    $errorCode]
sl@0
  1366
} {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1367
test cmdAH-24.5 {Tcl_FileObjCmd: mtime} {
sl@0
  1368
    # Under Unix, use a file in /tmp to avoid clock skew due to NFS.
sl@0
  1369
    # On other platforms, just use a file in the local directory.
sl@0
  1370
sl@0
  1371
    if {[string equal $tcl_platform(platform) "unix"]} {
sl@0
  1372
	set name /tmp/tcl.test.[pid]
sl@0
  1373
    } else {
sl@0
  1374
	set name [file join [temporaryDirectory] tf]
sl@0
  1375
    }
sl@0
  1376
sl@0
  1377
    # Make sure that a new file's time is correct.  10 seconds variance
sl@0
  1378
    # is allowed used due to slow networks or clock skew on a network drive.
sl@0
  1379
sl@0
  1380
    file delete -force $name
sl@0
  1381
    close [open $name w]
sl@0
  1382
    set a [expr abs([clock seconds]-[file mtime $name])<10]
sl@0
  1383
    file delete $name
sl@0
  1384
    set a
sl@0
  1385
} {1}
sl@0
  1386
test cmdAH-24.7 {Tcl_FileObjCmd: mtime} {
sl@0
  1387
    list [catch {file mtime $file notint} msg] $msg
sl@0
  1388
} {1 {expected integer but got "notint"}}
sl@0
  1389
test cmdAH-24.8 {Tcl_FileObjCmd: mtime touch} macOrUnix {
sl@0
  1390
    set mtime [file mtime $file]
sl@0
  1391
    after 1100; # pause a sec to notice change in mtime
sl@0
  1392
    set newmtime [clock seconds]
sl@0
  1393
    set modmtime [file mtime $file $newmtime]
sl@0
  1394
    expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"}
sl@0
  1395
} 1
sl@0
  1396
test cmdAH-24.9 {Tcl_FileObjCmd: mtime touch with non-ascii chars} macOrUnix {
sl@0
  1397
    set oldfile $file
sl@0
  1398
    # introduce some non-ascii characters.
sl@0
  1399
    append file \u2022
sl@0
  1400
    file delete -force $file
sl@0
  1401
    file rename $oldfile $file
sl@0
  1402
    set mtime [file mtime $file]
sl@0
  1403
    after 1100; # pause a sec to notice change in mtime
sl@0
  1404
    set newmtime [clock seconds]
sl@0
  1405
    set err [catch {file mtime $file $newmtime} modmtime]
sl@0
  1406
    file rename $file $oldfile
sl@0
  1407
    if {$err} {
sl@0
  1408
	error $modmtime
sl@0
  1409
    }
sl@0
  1410
    expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"}
sl@0
  1411
} 1
sl@0
  1412
test cmdAH-24.10 {Tcl_FileObjCmd: mtime touch} winOnly {
sl@0
  1413
    waitForEvenSecondForFAT
sl@0
  1414
    set mtime [file mtime $file]
sl@0
  1415
    after 2100; # pause two secs to notice change in mtime on FAT fs'es
sl@0
  1416
    set newmtime [clock seconds]
sl@0
  1417
    set modmtime [file mtime $file $newmtime]
sl@0
  1418
    expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"}
sl@0
  1419
} 1
sl@0
  1420
test cmdAH-24.11 {Tcl_FileObjCmd: mtime touch with non-ascii chars} winOnly {
sl@0
  1421
    waitForEvenSecondForFAT
sl@0
  1422
    set oldfile $file
sl@0
  1423
    # introduce some non-ascii characters.
sl@0
  1424
    append file \u2022
sl@0
  1425
    file delete -force $file
sl@0
  1426
    file rename $oldfile $file
sl@0
  1427
    set mtime [file mtime $file]
sl@0
  1428
    after 2100; # pause two secs to notice change in mtime on FAT fs'es
sl@0
  1429
    set newmtime [clock seconds]
sl@0
  1430
    set err [catch {file mtime $file $newmtime} modmtime]
sl@0
  1431
    file rename $file $oldfile
sl@0
  1432
    if {$err} {
sl@0
  1433
	error $modmtime
sl@0
  1434
    }
sl@0
  1435
    expr {$newmtime == $modmtime ? 1 : "$newmtime != $modmtime"}
sl@0
  1436
} 1
sl@0
  1437
removeFile touch.me
sl@0
  1438
rename waitForEvenSecondForFAT {}
sl@0
  1439
sl@0
  1440
test cmdAH-24.12 {Tcl_FileObjCmd: mtime and daylight savings} {
sl@0
  1441
    set name [file join [temporaryDirectory] clockchange]
sl@0
  1442
sl@0
  1443
    file delete -force $name
sl@0
  1444
    close [open $name w]
sl@0
  1445
    set time [clock scan "21:00:00 October 30 2004 GMT"]
sl@0
  1446
    file mtime $name $time
sl@0
  1447
    set newmtime [file mtime $name]
sl@0
  1448
    file delete $name
sl@0
  1449
    expr {$newmtime == $time ? 1 : "$newmtime != $time"}
sl@0
  1450
} {1}
sl@0
  1451
sl@0
  1452
# bug 1420432: setting mtime fails for directories on windows.
sl@0
  1453
test cmdAH-24.13 {Tcl_FileObjCmd: directory mtime} {
sl@0
  1454
    set dirname [file join [temporaryDirectory] tmp[pid]]
sl@0
  1455
    file delete -force $dirname
sl@0
  1456
    file mkdir $dirname
sl@0
  1457
    set res [catch {
sl@0
  1458
        set old [file mtime $dirname]
sl@0
  1459
        file mtime $dirname 0
sl@0
  1460
        set new [file mtime $dirname]
sl@0
  1461
        list $new [expr {$old != $new}]
sl@0
  1462
    } err]
sl@0
  1463
    file delete -force $dirname
sl@0
  1464
    list $res $err
sl@0
  1465
} {0 {0 1}}
sl@0
  1466
sl@0
  1467
# owned
sl@0
  1468
sl@0
  1469
test cmdAH-25.1 {Tcl_FileObjCmd: owned} {
sl@0
  1470
    list [catch {file owned a b} msg] $msg
sl@0
  1471
} {1 {wrong # args: should be "file owned name"}}
sl@0
  1472
test cmdAH-25.2 {Tcl_FileObjCmd: owned} {
sl@0
  1473
    file owned $gorpfile
sl@0
  1474
} 1
sl@0
  1475
test cmdAH-25.3 {Tcl_FileObjCmd: owned} {unixOnly notRoot} {
sl@0
  1476
    file owned /
sl@0
  1477
} 0
sl@0
  1478
sl@0
  1479
# readlink
sl@0
  1480
sl@0
  1481
test cmdAH-26.1 {Tcl_FileObjCmd: readlink} {
sl@0
  1482
    list [catch {file readlink a b} msg] $msg
sl@0
  1483
} {1 {wrong # args: should be "file readlink name"}}
sl@0
  1484
test cmdAH-26.2 {Tcl_FileObjCmd: readlink} {unixOnly nonPortable} {
sl@0
  1485
    file readlink $linkfile
sl@0
  1486
} $gorpfile
sl@0
  1487
test cmdAH-26.3 {Tcl_FileObjCmd: readlink errors} {unixOnly nonPortable} {
sl@0
  1488
    list [catch {file readlink _bogus_} msg] [string tolower $msg] \
sl@0
  1489
	    [string tolower $errorCode]
sl@0
  1490
} {1 {could not readlink "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1491
test cmdAH-26.4 {Tcl_FileObjCmd: readlink errors} {macOnly nonPortable} {
sl@0
  1492
    list [catch {file readlink _bogus_} msg] [string tolower $msg] \
sl@0
  1493
	    [string tolower $errorCode]
sl@0
  1494
} {1 {could not readlink "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1495
test cmdAH-26.5 {Tcl_FileObjCmd: readlink errors} {winOnly nonPortable} {
sl@0
  1496
    list [catch {file readlink _bogus_} msg] [string tolower $msg] \
sl@0
  1497
	    [string tolower $errorCode]
sl@0
  1498
} {1 {could not readlink "_bogus_": invalid argument} {posix einval {invalid argument}}}
sl@0
  1499
sl@0
  1500
# size
sl@0
  1501
sl@0
  1502
test cmdAH-27.1 {Tcl_FileObjCmd: size} {
sl@0
  1503
    list [catch {file size a b} msg] $msg
sl@0
  1504
} {1 {wrong # args: should be "file size name"}}
sl@0
  1505
test cmdAH-27.2 {Tcl_FileObjCmd: size} {
sl@0
  1506
    set oldsize [file size $gorpfile]
sl@0
  1507
    set f [open $gorpfile a]
sl@0
  1508
    fconfigure $f -translation lf -eofchar {}
sl@0
  1509
    puts $f "More text"
sl@0
  1510
    close $f
sl@0
  1511
    expr {[file size $gorpfile] - $oldsize}
sl@0
  1512
} {10}
sl@0
  1513
test cmdAH-27.3 {Tcl_FileObjCmd: size} {
sl@0
  1514
    string tolower [list [catch {file size _bogus_} msg] $msg \
sl@0
  1515
	    $errorCode]
sl@0
  1516
} {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1517
sl@0
  1518
# stat
sl@0
  1519
sl@0
  1520
catch {testsetplatform $platform}
sl@0
  1521
removeFile $gorpfile
sl@0
  1522
set gorpfile [makeFile "Test string" gorp.file]
sl@0
  1523
catch {file attributes $gorpfile -permissions 0765}
sl@0
  1524
sl@0
  1525
test cmdAH-28.1 {Tcl_FileObjCmd: stat} {
sl@0
  1526
    list [catch {file stat _bogus_} msg] $msg $errorCode
sl@0
  1527
} {1 {wrong # args: should be "file stat name varName"} NONE}
sl@0
  1528
test cmdAH-28.2 {Tcl_FileObjCmd: stat} {
sl@0
  1529
    list [catch {file stat _bogus_ a b} msg] $msg $errorCode
sl@0
  1530
} {1 {wrong # args: should be "file stat name varName"} NONE}
sl@0
  1531
test cmdAH-28.3 {Tcl_FileObjCmd: stat} {
sl@0
  1532
    catch {unset stat}
sl@0
  1533
    file stat $gorpfile stat
sl@0
  1534
    lsort [array names stat]
sl@0
  1535
} {atime ctime dev gid ino mode mtime nlink size type uid}
sl@0
  1536
test cmdAH-28.4 {Tcl_FileObjCmd: stat} {
sl@0
  1537
    catch {unset stat}
sl@0
  1538
    file stat $gorpfile stat
sl@0
  1539
    list $stat(nlink) $stat(size) $stat(type)
sl@0
  1540
} {1 12 file}
sl@0
  1541
test cmdAH-28.5 {Tcl_FileObjCmd: stat} {unixOnly} {
sl@0
  1542
    catch {unset stat}
sl@0
  1543
    file stat $gorpfile stat
sl@0
  1544
    expr $stat(mode)&0777
sl@0
  1545
} {501}
sl@0
  1546
test cmdAH-28.6 {Tcl_FileObjCmd: stat} {
sl@0
  1547
    string tolower [list [catch {file stat _bogus_ stat} msg] \
sl@0
  1548
	    $msg $errorCode]
sl@0
  1549
} {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1550
test cmdAH-28.7 {Tcl_FileObjCmd: stat} {
sl@0
  1551
    catch {unset x}
sl@0
  1552
    set x 44
sl@0
  1553
    list [catch {file stat $gorpfile x} msg] $msg $errorCode
sl@0
  1554
} {1 {can't set "x(dev)": variable isn't array} NONE}
sl@0
  1555
test cmdAH-28.8 {Tcl_FileObjCmd: stat} {
sl@0
  1556
    # Sign extension of purported unsigned short to int.
sl@0
  1557
sl@0
  1558
    set filename [makeFile "" foo.text]
sl@0
  1559
    file stat $filename stat
sl@0
  1560
    set x [expr {$stat(mode) > 0}]
sl@0
  1561
    removeFile $filename
sl@0
  1562
    set x
sl@0
  1563
} 1
sl@0
  1564
test cmdAH-28.9 {Tcl_FileObjCmd: stat} winOnly {
sl@0
  1565
    # stat of root directory was failing.
sl@0
  1566
    # don't care about answer, just that test runs.
sl@0
  1567
sl@0
  1568
    # relative paths that resolve to root
sl@0
  1569
    set old [pwd]
sl@0
  1570
    cd c:/
sl@0
  1571
    file stat c: stat
sl@0
  1572
    file stat c:. stat
sl@0
  1573
    file stat . stat
sl@0
  1574
    cd $old
sl@0
  1575
sl@0
  1576
    file stat / stat
sl@0
  1577
    file stat c:/ stat
sl@0
  1578
    file stat c:/. stat
sl@0
  1579
} {}
sl@0
  1580
test cmdAH-28.10 {Tcl_FileObjCmd: stat} {winOnly nonPortable} {
sl@0
  1581
    # stat of root directory was failing.
sl@0
  1582
    # don't care about answer, just that test runs.
sl@0
  1583
sl@0
  1584
    file stat //pop/$env(USERNAME) stat
sl@0
  1585
    file stat //pop/$env(USERNAME)/ stat
sl@0
  1586
    file stat //pop/$env(USERNAME)/. stat
sl@0
  1587
} {}
sl@0
  1588
test cmdAH-28.11 {Tcl_FileObjCmd: stat} {winOnly nonPortable} {
sl@0
  1589
    # stat of network directory was returning id of current local drive.
sl@0
  1590
sl@0
  1591
    set old [pwd]
sl@0
  1592
    cd c:/
sl@0
  1593
sl@0
  1594
    file stat //pop/$env(USERNAME) stat
sl@0
  1595
    cd $old
sl@0
  1596
    expr {$stat(dev) == 2}
sl@0
  1597
} 0
sl@0
  1598
test cmdAH-28.12 {Tcl_FileObjCmd: stat} {
sl@0
  1599
    # stat(mode) with S_IFREG flag was returned as a negative number
sl@0
  1600
    # if mode_t was a short instead of an unsigned short.
sl@0
  1601
sl@0
  1602
    set filename [makeFile "" foo.test]
sl@0
  1603
    file stat $filename stat
sl@0
  1604
    removeFile $filename
sl@0
  1605
    expr {$stat(mode) > 0}
sl@0
  1606
} 1
sl@0
  1607
catch {unset stat}
sl@0
  1608
sl@0
  1609
# type
sl@0
  1610
sl@0
  1611
test cmdAH-29.1 {Tcl_FileObjCmd: type} {
sl@0
  1612
    list [catch {file size a b} msg] $msg
sl@0
  1613
} {1 {wrong # args: should be "file size name"}}
sl@0
  1614
test cmdAH-29.2 {Tcl_FileObjCmd: type} {
sl@0
  1615
    file type $dirfile
sl@0
  1616
} directory
sl@0
  1617
test cmdAH-29.3.0 {Tcl_FileObjCmd: delete removes link not file} {unixOnly nonPortable} {
sl@0
  1618
    set exists [list [file exists $linkfile] [file exists $gorpfile]]
sl@0
  1619
    file delete $linkfile
sl@0
  1620
    set exists2	[list [file exists $linkfile] [file exists $gorpfile]]
sl@0
  1621
    list $exists $exists2
sl@0
  1622
} {{1 1} {0 1}}
sl@0
  1623
test cmdAH-29.3 {Tcl_FileObjCmd: type} {
sl@0
  1624
    file type $gorpfile
sl@0
  1625
} file
sl@0
  1626
test cmdAH-29.4 {Tcl_FileObjCmd: type} {unixOnly} {
sl@0
  1627
    catch {file delete $linkfile}
sl@0
  1628
    # Unlike [exec ln -s], [file link] requires an existing target
sl@0
  1629
    file link -symbolic $linkfile $gorpfile
sl@0
  1630
    set result [file type $linkfile]
sl@0
  1631
    file delete $linkfile
sl@0
  1632
    set result
sl@0
  1633
} link
sl@0
  1634
if {[string equal $tcl_platform(platform) "windows"]} {
sl@0
  1635
    if {[string index $tcl_platform(osVersion) 0] >= 5 \
sl@0
  1636
      && ([lindex [file system [temporaryDirectory]] 1] == "NTFS")} {
sl@0
  1637
	tcltest::testConstraint linkDirectory 1
sl@0
  1638
    } else {
sl@0
  1639
	tcltest::testConstraint linkDirectory 0
sl@0
  1640
    }
sl@0
  1641
} else {
sl@0
  1642
    tcltest::testConstraint linkDirectory 1
sl@0
  1643
}
sl@0
  1644
test cmdAH-29.4.1 {Tcl_FileObjCmd: type} {linkDirectory} {
sl@0
  1645
    set tempdir [makeDirectory temp]
sl@0
  1646
    set linkdir [file join [temporaryDirectory] link.dir]
sl@0
  1647
    file link -symbolic $linkdir $tempdir
sl@0
  1648
    set result [file type $linkdir]
sl@0
  1649
    file delete $linkdir
sl@0
  1650
    removeDirectory $tempdir
sl@0
  1651
    set result
sl@0
  1652
} link
sl@0
  1653
test cmdAH-29.5 {Tcl_FileObjCmd: type} {
sl@0
  1654
    string tolower [list [catch {file type _bogus_} msg] $msg $errorCode]
sl@0
  1655
} {1 {could not read "_bogus_": no such file or directory} {posix enoent {no such file or directory}}}
sl@0
  1656
sl@0
  1657
# Error conditions
sl@0
  1658
sl@0
  1659
test cmdAH-30.1 {Tcl_FileObjCmd: error conditions} {
sl@0
  1660
    list [catch {file gorp x} msg] $msg
sl@0
  1661
} {1 {bad option "gorp": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
  1662
test cmdAH-30.2 {Tcl_FileObjCmd: error conditions} {
sl@0
  1663
    list [catch {file ex x} msg] $msg
sl@0
  1664
} {1 {ambiguous option "ex": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
  1665
test cmdAH-30.3 {Tcl_FileObjCmd: error conditions} {
sl@0
  1666
    list [catch {file is x} msg] $msg
sl@0
  1667
} {1 {ambiguous option "is": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
  1668
test cmdAH-30.4 {Tcl_FileObjCmd: error conditions} {
sl@0
  1669
    list [catch {file z x} msg] $msg
sl@0
  1670
} {1 {bad option "z": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
  1671
test cmdAH-30.5 {Tcl_FileObjCmd: error conditions} {
sl@0
  1672
    list [catch {file read x} msg] $msg
sl@0
  1673
} {1 {ambiguous option "read": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
  1674
test cmdAH-30.6 {Tcl_FileObjCmd: error conditions} {
sl@0
  1675
    list [catch {file s x} msg] $msg
sl@0
  1676
} {1 {ambiguous option "s": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
  1677
test cmdAH-30.7 {Tcl_FileObjCmd: error conditions} {
sl@0
  1678
    list [catch {file t x} msg] $msg
sl@0
  1679
} {1 {ambiguous option "t": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, link, lstat, mtime, mkdir, nativename, normalize, owned, pathtype, readable, readlink, rename, rootname, separator, size, split, stat, system, tail, type, volumes, or writable}}
sl@0
  1680
test cmdAH-30.8 {Tcl_FileObjCmd: error conditions} {
sl@0
  1681
    list [catch {file dirname ~woohgy} msg] $msg
sl@0
  1682
} {1 {user "woohgy" doesn't exist}}
sl@0
  1683
sl@0
  1684
# channels
sl@0
  1685
# In testing 'file channels', we need to make sure that a channel
sl@0
  1686
# created in one interp isn't visible in another.
sl@0
  1687
sl@0
  1688
interp create simpleInterp
sl@0
  1689
interp create -safe safeInterp
sl@0
  1690
interp c
sl@0
  1691
safeInterp expose file file
sl@0
  1692
sl@0
  1693
test cmdAH-31.1 {Tcl_FileObjCmd: channels, too many args} {
sl@0
  1694
    list [catch {file channels a b} msg] $msg
sl@0
  1695
} {1 {wrong # args: should be "file channels ?pattern?"}}
sl@0
  1696
test cmdAH-31.2 {Tcl_FileObjCmd: channels, too many args} {
sl@0
  1697
    # Normal interps start out with only the standard channels
sl@0
  1698
    lsort [simpleInterp eval [list file chan]]
sl@0
  1699
} [lsort {stderr stdout stdin}]
sl@0
  1700
test cmdAH-31.3 {Tcl_FileObjCmd: channels, globbing} {
sl@0
  1701
    string equal [file channels] [file channels *]
sl@0
  1702
} {1}
sl@0
  1703
test cmdAH-31.4 {Tcl_FileObjCmd: channels, globbing} {
sl@0
  1704
    lsort [file channels std*]
sl@0
  1705
} [lsort {stdout stderr stdin}]
sl@0
  1706
sl@0
  1707
set newFileId [open $gorpfile w]
sl@0
  1708
sl@0
  1709
test cmdAH-31.5 {Tcl_FileObjCmd: channels} {
sl@0
  1710
    set res [file channels $newFileId]
sl@0
  1711
    string equal $newFileId $res
sl@0
  1712
} {1}
sl@0
  1713
test cmdAH-31.6 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1714
    # Safe interps start out with no channels
sl@0
  1715
    safeInterp eval [list file channels]
sl@0
  1716
} {}
sl@0
  1717
test cmdAH-31.7 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1718
    list [catch {safeInterp eval [list puts $newFileId "hello"]} msg] $msg
sl@0
  1719
} [list 1 "can not find channel named \"$newFileId\""]
sl@0
  1720
sl@0
  1721
interp share {} $newFileId safeInterp
sl@0
  1722
interp share {} stdout safeInterp
sl@0
  1723
sl@0
  1724
test cmdAH-31.8 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1725
    # $newFileId should now be visible in both interps
sl@0
  1726
    list [file channels $newFileId] \
sl@0
  1727
	    [safeInterp eval [list file channels $newFileId]]
sl@0
  1728
} [list $newFileId $newFileId]
sl@0
  1729
test cmdAH-31.9 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1730
    lsort [safeInterp eval [list file channels]]
sl@0
  1731
} [lsort [list stdout $newFileId]]
sl@0
  1732
test cmdAH-31.10 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1733
    # we can now write to $newFileId from slave
sl@0
  1734
    safeInterp eval [list puts $newFileId "hello"]
sl@0
  1735
} {}
sl@0
  1736
sl@0
  1737
interp transfer {} $newFileId safeInterp
sl@0
  1738
sl@0
  1739
test cmdAH-31.11 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1740
    # $newFileId should now be visible only in safeInterp
sl@0
  1741
    list [file channels $newFileId] \
sl@0
  1742
	    [safeInterp eval [list file channels $newFileId]]
sl@0
  1743
} [list {} $newFileId]
sl@0
  1744
test cmdAH-31.12 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1745
    lsort [safeInterp eval [list file channels]]
sl@0
  1746
} [lsort [list stdout $newFileId]]
sl@0
  1747
test cmdAH-31.13 {Tcl_FileObjCmd: channels in other interp} {
sl@0
  1748
    safeInterp eval [list close $newFileId]
sl@0
  1749
    safeInterp eval [list file channels]
sl@0
  1750
} {stdout}
sl@0
  1751
sl@0
  1752
# This shouldn't work, but just in case a test above failed...
sl@0
  1753
catch {close $newFileId}
sl@0
  1754
sl@0
  1755
interp delete safeInterp
sl@0
  1756
interp delete simpleInterp
sl@0
  1757
sl@0
  1758
# cleanup
sl@0
  1759
catch {testsetplatform $platform}
sl@0
  1760
catch {unset platform}
sl@0
  1761
sl@0
  1762
# Tcl_ForObjCmd is tested in for.test
sl@0
  1763
sl@0
  1764
catch {file attributes $dirfile -permissions 0777}
sl@0
  1765
removeDirectory $dirfile
sl@0
  1766
removeFile $gorpfile
sl@0
  1767
# No idea how well [removeFile] copes with links...
sl@0
  1768
file delete $linkfile
sl@0
  1769
sl@0
  1770
cd $cmdAHwd
sl@0
  1771
sl@0
  1772
::tcltest::cleanupTests
sl@0
  1773
return