os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/fCmd.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
# This file tests the tclFCmd.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-1997 Sun Microsystems, Inc.
sl@0
     8
# Copyright (c) 1999 by Scriptics Corporation.
sl@0
     9
# Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiaries. All rights reserved.  
sl@0
    10
#
sl@0
    11
# See the file "license.terms" for information on usage and redistribution
sl@0
    12
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    13
#
sl@0
    14
# RCS: @(#) $Id: fCmd.test,v 1.26.2.9 2007/05/17 14:18:42 dgp Exp $
sl@0
    15
#
sl@0
    16
sl@0
    17
if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0
    18
    package require tcltest 2
sl@0
    19
    namespace import -force ::tcltest::*
sl@0
    20
}
sl@0
    21
sl@0
    22
tcltest::testConstraint testsetplatform [string equal testsetplatform [info commands testsetplatform]]
sl@0
    23
tcltest::testConstraint testchmod [string equal testchmod [info commands testchmod]]
sl@0
    24
tcltest::testConstraint notNetworkFilesystem 0
sl@0
    25
testConstraint 95or98 [expr {[testConstraint 95] || [testConstraint 98]}]
sl@0
    26
testConstraint 2000orNewer [expr {![testConstraint 95or98]}]
sl@0
    27
sl@0
    28
# Several tests require need to match results against the unix username
sl@0
    29
set user {}
sl@0
    30
if {$tcl_platform(platform) == "unix"} {
sl@0
    31
    catch {set user [exec whoami]}
sl@0
    32
    if {$user == ""} {
sl@0
    33
	catch {regexp {^[^(]*\(([^)]*)\)} [exec id] dummy user}
sl@0
    34
    }
sl@0
    35
    if {$user == ""} {
sl@0
    36
	set user "root"
sl@0
    37
    }
sl@0
    38
}
sl@0
    39
sl@0
    40
proc createfile {file {string a}} {
sl@0
    41
    set f [open $file w]
sl@0
    42
    puts -nonewline $f $string
sl@0
    43
    close $f
sl@0
    44
    return $string
sl@0
    45
}
sl@0
    46
sl@0
    47
# 
sl@0
    48
# checkcontent --
sl@0
    49
#
sl@0
    50
#  Ensures that file "file" contains only the string "matchString"
sl@0
    51
#  returns 0 if the file does not exist, or has a different content
sl@0
    52
#
sl@0
    53
proc checkcontent {file matchString} {
sl@0
    54
    if {[catch {
sl@0
    55
	set f [open $file]
sl@0
    56
	set fileString [read $f]
sl@0
    57
	close $f 
sl@0
    58
    }]} {
sl@0
    59
	return 0
sl@0
    60
    }
sl@0
    61
    return [string match $matchString $fileString]
sl@0
    62
}
sl@0
    63
sl@0
    64
proc openup {path} {
sl@0
    65
    testchmod 777 $path
sl@0
    66
    if {[file isdirectory $path]} {
sl@0
    67
	catch {
sl@0
    68
	    foreach p [glob -directory $path *] {
sl@0
    69
		openup $p
sl@0
    70
	    }
sl@0
    71
	}
sl@0
    72
    }
sl@0
    73
}
sl@0
    74
sl@0
    75
proc cleanup {args} {
sl@0
    76
    if {$::tcl_platform(platform) == "macintosh"} {
sl@0
    77
	set wd [list :]
sl@0
    78
    } else {
sl@0
    79
	set wd [list .]
sl@0
    80
    }
sl@0
    81
    foreach p [concat $wd $args] {
sl@0
    82
	set x ""
sl@0
    83
	catch {
sl@0
    84
	    set x [glob -directory $p tf* td*]
sl@0
    85
	}
sl@0
    86
	foreach file $x {
sl@0
    87
	    if {[catch {file delete -force -- $file}]} {
sl@0
    88
		catch {openup $file}
sl@0
    89
		catch {file delete -force -- $file}
sl@0
    90
	    }
sl@0
    91
	}
sl@0
    92
    }
sl@0
    93
}
sl@0
    94
sl@0
    95
proc contents {file} {
sl@0
    96
    set f [open $file r]
sl@0
    97
    set r [read $f]
sl@0
    98
    close $f
sl@0
    99
    set r
sl@0
   100
}
sl@0
   101
sl@0
   102
cd [temporaryDirectory]
sl@0
   103
sl@0
   104
set ::tcltest::testConstraints(fileSharing) 0
sl@0
   105
set ::tcltest::testConstraints(notFileSharing) 1
sl@0
   106
sl@0
   107
if {$tcl_platform(platform) == "macintosh"} {
sl@0
   108
    catch {file delete -force foo.dir}
sl@0
   109
    file mkdir foo.dir
sl@0
   110
    if {[catch {file attributes foo.dir -readonly 1}] == 0} {
sl@0
   111
    	set ::tcltest::testConstraints(fileSharing) 1
sl@0
   112
    	set ::tcltest::testConstraints(notFileSharing) 0
sl@0
   113
    }
sl@0
   114
    file delete -force foo.dir
sl@0
   115
}
sl@0
   116
sl@0
   117
set ::tcltest::testConstraints(xdev) 0
sl@0
   118
sl@0
   119
if {$tcl_platform(platform) == "unix"} {
sl@0
   120
    if {[catch {set m1 [exec df .]; set m2 [exec df /tmp]}] == 0} {
sl@0
   121
	set m1 [string range $m1 0 [expr [string first " " $m1]-1]]
sl@0
   122
	set m2 [string range $m2 0 [expr [string first " " $m2]-1]]
sl@0
   123
	if {$m1 != "" && $m2 != "" && $m1 != $m2 && [file exists $m1] && [file exists $m2]} {
sl@0
   124
	    set ::tcltest::testConstraints(xdev) 1
sl@0
   125
	}
sl@0
   126
    }
sl@0
   127
}
sl@0
   128
sl@0
   129
set root [lindex [file split [pwd]] 0]
sl@0
   130
sl@0
   131
# A really long file name
sl@0
   132
# length of long is 1216 chars, which should be greater than any static
sl@0
   133
# buffer or allowable filename.
sl@0
   134
sl@0
   135
set long "abcdefghihjllmnopqrstuvwxyz01234567890"
sl@0
   136
append long $long
sl@0
   137
append long $long
sl@0
   138
append long $long
sl@0
   139
append long $long
sl@0
   140
append long $long
sl@0
   141
sl@0
   142
test fCmd-1.1 {TclFileRenameCmd} {notRoot} {
sl@0
   143
    cleanup
sl@0
   144
    createfile tf1
sl@0
   145
    file rename tf1 tf2
sl@0
   146
    glob tf*
sl@0
   147
} {tf2}
sl@0
   148
sl@0
   149
test fCmd-2.1 {TclFileCopyCmd} {notRoot} {
sl@0
   150
    cleanup
sl@0
   151
    createfile tf1
sl@0
   152
    file copy tf1 tf2
sl@0
   153
    lsort [glob tf*]
sl@0
   154
} {tf1 tf2}
sl@0
   155
sl@0
   156
test fCmd-3.1 {FileCopyRename: FileForceOption fails} {notRoot} {
sl@0
   157
    list [catch {file rename -xyz} msg] $msg
sl@0
   158
} {1 {bad option "-xyz": should be -force or --}}
sl@0
   159
test fCmd-3.2 {FileCopyRename: not enough args} {notRoot} {
sl@0
   160
    list [catch {file rename xyz} msg] $msg
sl@0
   161
} {1 {wrong # args: should be "file rename ?options? source ?source ...? target"}}
sl@0
   162
test fCmd-3.3 {FileCopyRename: Tcl_TranslateFileName fails} {notRoot} {
sl@0
   163
    list [catch {file rename xyz ~_totally_bogus_user} msg] $msg
sl@0
   164
} {1 {user "_totally_bogus_user" doesn't exist}}
sl@0
   165
test fCmd-3.4 {FileCopyRename: Tcl_TranslateFileName passes} {notRoot} {
sl@0
   166
    cleanup
sl@0
   167
    list [catch {file copy tf1 ~} msg] $msg
sl@0
   168
} {1 {error copying "tf1": no such file or directory}}
sl@0
   169
test fCmd-3.5 {FileCopyRename: target doesn't exist: stat(target) != 0} {notRoot} {
sl@0
   170
    cleanup
sl@0
   171
    list [catch {file rename tf1 tf2 tf3} msg] $msg
sl@0
   172
} {1 {error renaming: target "tf3" is not a directory}}
sl@0
   173
test fCmd-3.6 {FileCopyRename: target tf3 is not a dir: !S_ISDIR(target)} \
sl@0
   174
	{notRoot} {
sl@0
   175
    cleanup
sl@0
   176
    createfile tf3
sl@0
   177
    list [catch {file rename tf1 tf2 tf3} msg] $msg
sl@0
   178
} {1 {error renaming: target "tf3" is not a directory}}
sl@0
   179
test fCmd-3.7 {FileCopyRename: target exists & is directory} {notRoot} {
sl@0
   180
    cleanup
sl@0
   181
    file mkdir td1
sl@0
   182
    createfile tf1 tf1
sl@0
   183
    file rename tf1 td1
sl@0
   184
    contents [file join td1 tf1]
sl@0
   185
} {tf1}
sl@0
   186
test fCmd-3.8 {FileCopyRename: too many arguments: argc - i > 2} {notRoot} {
sl@0
   187
    cleanup
sl@0
   188
    list [catch {file rename tf1 tf2 tf3} msg] $msg
sl@0
   189
} {1 {error renaming: target "tf3" is not a directory}}
sl@0
   190
test fCmd-3.9 {FileCopyRename: too many arguments: argc - i > 2} {notRoot} {
sl@0
   191
    cleanup
sl@0
   192
    list [catch {file copy -force -- tf1 tf2 tf3} msg] $msg
sl@0
   193
} {1 {error copying: target "tf3" is not a directory}}
sl@0
   194
test fCmd-3.10 {FileCopyRename: just 2 arguments} {notRoot} {
sl@0
   195
    cleanup
sl@0
   196
    createfile tf1 tf1
sl@0
   197
    file rename tf1 tf2
sl@0
   198
    contents tf2
sl@0
   199
} {tf1}
sl@0
   200
test fCmd-3.11 {FileCopyRename: just 2 arguments} {notRoot} {
sl@0
   201
    cleanup
sl@0
   202
    createfile tf1 tf1
sl@0
   203
    file rename -force -force -- tf1 tf2
sl@0
   204
    contents tf2
sl@0
   205
} {tf1}
sl@0
   206
test fCmd-3.12 {FileCopyRename: move each source: 1 source} {notRoot} {
sl@0
   207
    cleanup
sl@0
   208
    createfile tf1 tf1
sl@0
   209
    file mkdir td1
sl@0
   210
    file rename tf1 td1
sl@0
   211
    contents [file join td1 tf1]
sl@0
   212
} {tf1}
sl@0
   213
test fCmd-3.13 {FileCopyRename: move each source: multiple sources} {notRoot} {
sl@0
   214
    cleanup
sl@0
   215
    createfile tf1 tf1
sl@0
   216
    createfile tf2 tf2
sl@0
   217
    createfile tf3 tf3
sl@0
   218
    createfile tf4 tf4
sl@0
   219
    file mkdir td1
sl@0
   220
    file rename tf1 tf2 tf3 tf4 td1
sl@0
   221
    list [contents [file join td1 tf1]] [contents [file join td1 tf2]] \
sl@0
   222
	[contents [file join td1 tf3]] [contents [file join td1 tf4]]
sl@0
   223
} {tf1 tf2 tf3 tf4}
sl@0
   224
test fCmd-3.14 {FileCopyRename: FileBasename fails} {notRoot} {
sl@0
   225
    cleanup
sl@0
   226
    file mkdir td1
sl@0
   227
    list [catch {file rename ~_totally_bogus_user td1} msg] $msg
sl@0
   228
} {1 {user "_totally_bogus_user" doesn't exist}}
sl@0
   229
test fCmd-3.15 {FileCopyRename: source[0] == '\0'} {notRoot unixOrPc} {
sl@0
   230
    cleanup
sl@0
   231
    file mkdir td1
sl@0
   232
    list [catch {file rename / td1} msg] $msg
sl@0
   233
} {1 {error renaming "/" to "td1": file already exists}}
sl@0
   234
test fCmd-3.16 {FileCopyRename: break on first error} {notRoot} {
sl@0
   235
    cleanup
sl@0
   236
    createfile tf1 
sl@0
   237
    createfile tf2 
sl@0
   238
    createfile tf3 
sl@0
   239
    createfile tf4 
sl@0
   240
    file mkdir td1
sl@0
   241
    createfile [file join td1 tf3]
sl@0
   242
    list [catch {file rename tf1 tf2 tf3 tf4 td1} msg] $msg
sl@0
   243
} [subst {1 {error renaming "tf3" to "[file join td1 tf3]": file already exists}}]
sl@0
   244
sl@0
   245
test fCmd-4.1 {TclFileMakeDirsCmd: make each dir: 1 dir} {notRoot} {
sl@0
   246
    cleanup
sl@0
   247
    file mkdir td1
sl@0
   248
    glob td*
sl@0
   249
} {td1}
sl@0
   250
test fCmd-4.2 {TclFileMakeDirsCmd: make each dir: multiple dirs} {notRoot} {
sl@0
   251
    cleanup
sl@0
   252
    file mkdir td1 td2 td3
sl@0
   253
    lsort [glob td*]
sl@0
   254
} {td1 td2 td3}
sl@0
   255
test fCmd-4.3 {TclFileMakeDirsCmd: stops on first error} {notRoot} {
sl@0
   256
    cleanup
sl@0
   257
    createfile tf1
sl@0
   258
    catch {file mkdir td1 td2 tf1 td3 td4}
sl@0
   259
    glob td1 td2 tf1 td3 td4
sl@0
   260
} {td1 td2 tf1}
sl@0
   261
test fCmd-4.4 {TclFileMakeDirsCmd: Tcl_TranslateFileName fails} {notRoot} {
sl@0
   262
    cleanup
sl@0
   263
    list [catch {file mkdir ~_totally_bogus_user} msg] $msg
sl@0
   264
} {1 {user "_totally_bogus_user" doesn't exist}}
sl@0
   265
test fCmd-4.5 {TclFileMakeDirsCmd: Tcl_SplitPath returns 0: *name == '\0'} \
sl@0
   266
	{notRoot} {
sl@0
   267
    cleanup
sl@0
   268
    list [catch {file mkdir ""} msg] $msg
sl@0
   269
} {1 {can't create directory "": no such file or directory}}
sl@0
   270
test fCmd-4.6 {TclFileMakeDirsCmd: one level deep} {notRoot} {
sl@0
   271
    cleanup
sl@0
   272
    file mkdir td1
sl@0
   273
    glob td1
sl@0
   274
} {td1}
sl@0
   275
test fCmd-4.7 {TclFileMakeDirsCmd: multi levels deep} {notRoot} {
sl@0
   276
    cleanup
sl@0
   277
    file mkdir [file join td1 td2 td3 td4]
sl@0
   278
    glob td1 [file join td1 td2]
sl@0
   279
} "td1 [file join td1 td2]"
sl@0
   280
test fCmd-4.8 {TclFileMakeDirsCmd: already exist: lstat(target) == 0} {notRoot} {
sl@0
   281
    cleanup
sl@0
   282
    file mkdir td1
sl@0
   283
    set x [file exists td1]
sl@0
   284
    file mkdir td1
sl@0
   285
    list $x [file exists td1]
sl@0
   286
} {1 1}
sl@0
   287
test fCmd-4.9 {TclFileMakeDirsCmd: exists, not dir} {notRoot} {
sl@0
   288
    cleanup
sl@0
   289
    createfile tf1
sl@0
   290
    list [catch {file mkdir tf1} msg] $msg
sl@0
   291
} [subst {1 {can't create directory "[file join tf1]": file already exists}}]
sl@0
   292
test fCmd-4.10 {TclFileMakeDirsCmd: exists, is dir} {notRoot} {
sl@0
   293
    cleanup
sl@0
   294
    file mkdir td1
sl@0
   295
    set x [file exists td1]
sl@0
   296
    file mkdir td1
sl@0
   297
    list $x [file exists td1]
sl@0
   298
} {1 1}
sl@0
   299
test fCmd-4.11 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} \
sl@0
   300
	{unixOnly notRoot testchmod} {
sl@0
   301
    cleanup
sl@0
   302
    file mkdir td1/td2/td3
sl@0
   303
    testchmod 000 td1/td2
sl@0
   304
    set msg [list [catch {file mkdir td1/td2/td3/td4} msg] $msg]
sl@0
   305
    testchmod 755 td1/td2
sl@0
   306
    set msg
sl@0
   307
} {1 {can't create directory "td1/td2/td3": permission denied}}
sl@0
   308
test fCmd-4.12 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} {macOnly} {
sl@0
   309
    cleanup
sl@0
   310
    list [catch {file mkdir nonexistentvolume:} msg] $msg
sl@0
   311
} {1 {can't create directory "nonexistentvolume:": invalid argument}}
sl@0
   312
test fCmd-4.13 {TclFileMakeDirsCmd: doesn't exist: errno == ENOENT} {notRoot} {
sl@0
   313
    cleanup
sl@0
   314
    set x [file exists td1]
sl@0
   315
    file mkdir td1
sl@0
   316
    list $x [file exists td1]
sl@0
   317
} {0 1}
sl@0
   318
test fCmd-4.14 {TclFileMakeDirsCmd: TclpCreateDirectory fails} \
sl@0
   319
	{unixOnly notRoot} {
sl@0
   320
    cleanup
sl@0
   321
    file delete -force foo
sl@0
   322
    file mkdir foo
sl@0
   323
    file attr foo -perm 040000
sl@0
   324
    set result [list [catch {file mkdir foo/tf1} msg] $msg]
sl@0
   325
    file delete -force foo
sl@0
   326
    set result
sl@0
   327
} {1 {can't create directory "foo/tf1": permission denied}}
sl@0
   328
test fCmd-4.15 {TclFileMakeDirsCmd: TclpCreateDirectory fails} {macOnly} {
sl@0
   329
    list [catch {file mkdir ${root}:} msg] $msg
sl@0
   330
} [subst {1 {can't create directory "${root}:": no such file or directory}}]
sl@0
   331
test fCmd-4.16 {TclFileMakeDirsCmd: TclpCreateDirectory succeeds} {notRoot} {
sl@0
   332
    cleanup
sl@0
   333
    file mkdir tf1
sl@0
   334
    file exists tf1
sl@0
   335
} {1}
sl@0
   336
sl@0
   337
test fCmd-5.1 {TclFileDeleteCmd: FileForceOption fails} {notRoot} {
sl@0
   338
    list [catch {file delete -xyz} msg] $msg
sl@0
   339
} {1 {bad option "-xyz": should be -force or --}}
sl@0
   340
test fCmd-5.2 {TclFileDeleteCmd: not enough args} {notRoot} {
sl@0
   341
    list [catch {file delete -force -force} msg] $msg
sl@0
   342
} {1 {wrong # args: should be "file delete ?options? file ?file ...?"}}
sl@0
   343
test fCmd-5.3 {TclFileDeleteCmd: 1 file} {notRoot} {
sl@0
   344
    cleanup
sl@0
   345
    createfile tf1
sl@0
   346
    createfile tf2
sl@0
   347
    file mkdir td1
sl@0
   348
    file delete tf2
sl@0
   349
    glob tf* td*
sl@0
   350
} {tf1 td1}
sl@0
   351
test fCmd-5.4 {TclFileDeleteCmd: multiple files} {notRoot} {
sl@0
   352
    cleanup
sl@0
   353
    createfile tf1
sl@0
   354
    createfile tf2
sl@0
   355
    file mkdir td1
sl@0
   356
    set x [list [file exists tf1] [file exists tf2] [file exists td1]]
sl@0
   357
    file delete tf1 td1 tf2
sl@0
   358
    lappend x [file exists tf1] [file exists tf2] [file exists tf3]
sl@0
   359
} {1 1 1 0 0 0}
sl@0
   360
test fCmd-5.5 {TclFileDeleteCmd: stop at first error} {notRoot unixOrPc} {
sl@0
   361
    cleanup
sl@0
   362
    createfile tf1
sl@0
   363
    createfile tf2
sl@0
   364
    file mkdir td1
sl@0
   365
    catch {file delete tf1 td1 $root tf2}
sl@0
   366
    list [file exists tf1] [file exists tf2] [file exists td1]
sl@0
   367
} {0 1 0}
sl@0
   368
test fCmd-5.6 {TclFileDeleteCmd: Tcl_TranslateFileName fails} {notRoot} {
sl@0
   369
    list [catch {file delete ~_totally_bogus_user} msg] $msg
sl@0
   370
} {1 {user "_totally_bogus_user" doesn't exist}}
sl@0
   371
test fCmd-5.7 {TclFileDeleteCmd: Tcl_TranslateFileName succeeds} {notRoot} {
sl@0
   372
    catch {file delete ~/tf1}
sl@0
   373
    createfile ~/tf1
sl@0
   374
    file delete ~/tf1
sl@0
   375
} {}
sl@0
   376
test fCmd-5.8 {TclFileDeleteCmd: file doesn't exist: lstat(name) != 0} {notRoot} {
sl@0
   377
    cleanup
sl@0
   378
    set x [file exists tf1]
sl@0
   379
    file delete tf1
sl@0
   380
    list $x [file exists tf1]
sl@0
   381
} {0 0}    
sl@0
   382
test fCmd-5.9 {TclFileDeleteCmd: is directory} {notRoot} {
sl@0
   383
    cleanup
sl@0
   384
    file mkdir td1
sl@0
   385
    file delete td1
sl@0
   386
    file exists td1
sl@0
   387
} {0}
sl@0
   388
test fCmd-5.10 {TclFileDeleteCmd: TclpRemoveDirectory fails} {notRoot} {
sl@0
   389
    cleanup
sl@0
   390
    file mkdir [file join td1 td2]
sl@0
   391
    list [catch {file delete td1} msg] $msg
sl@0
   392
} {1 {error deleting "td1": directory not empty}}
sl@0
   393
test fCmd-5.11 {TclFileDeleteCmd: TclpRemoveDirectory with cwd inside} {notRoot} {
sl@0
   394
    cleanup
sl@0
   395
    set dir [pwd]
sl@0
   396
    file mkdir [file join td1 td2]
sl@0
   397
    cd [file join td1 td2]
sl@0
   398
    set res [list [catch {file delete -force [file dirname [pwd]]} msg]]
sl@0
   399
    cd $dir
sl@0
   400
    lappend res [file exists td1] $msg
sl@0
   401
} {0 0 {}}
sl@0
   402
test fCmd-5.12 {TclFileDeleteCmd: TclpRemoveDirectory with bad perms} {unixOnly} {
sl@0
   403
    cleanup
sl@0
   404
    file mkdir [file join td1 td2]
sl@0
   405
    #exec chmod u-rwx [file join td1 td2]
sl@0
   406
    file attributes [file join td1 td2] -permissions u+rwx
sl@0
   407
    set res [list [catch {file delete -force td1} msg]]
sl@0
   408
    lappend res [file exists td1] $msg
sl@0
   409
} {0 0 {}}
sl@0
   410
sl@0
   411
test fCmd-6.1 {CopyRenameOneFile: bad source} {notRoot} {
sl@0
   412
    # can't test this, because it's caught by FileCopyRename
sl@0
   413
} {}
sl@0
   414
test fCmd-6.2 {CopyRenameOneFile: bad target} {notRoot} {
sl@0
   415
    # can't test this, because it's caught by FileCopyRename
sl@0
   416
} {}
sl@0
   417
test fCmd-6.3 {CopyRenameOneFile: lstat(source) != 0} {notRoot} {
sl@0
   418
    cleanup
sl@0
   419
    list [catch {file rename tf1 tf2} msg] $msg
sl@0
   420
} {1 {error renaming "tf1": no such file or directory}}
sl@0
   421
test fCmd-6.4 {CopyRenameOneFile: lstat(source) == 0} {notRoot} {
sl@0
   422
    cleanup
sl@0
   423
    createfile tf1
sl@0
   424
    file rename tf1 tf2
sl@0
   425
    glob tf*
sl@0
   426
} {tf2}
sl@0
   427
test fCmd-6.5 {CopyRenameOneFile: lstat(target) != 0} {notRoot} {
sl@0
   428
    cleanup
sl@0
   429
    createfile tf1
sl@0
   430
    file rename tf1 tf2
sl@0
   431
    glob tf*
sl@0
   432
} {tf2}
sl@0
   433
test fCmd-6.6 {CopyRenameOneFile: errno != ENOENT} {unixOnly notRoot testchmod} {
sl@0
   434
    cleanup
sl@0
   435
    file mkdir td1
sl@0
   436
    testchmod 000 td1
sl@0
   437
    createfile tf1
sl@0
   438
    set msg [list [catch {file rename tf1 td1} msg] $msg]
sl@0
   439
    testchmod 755 td1
sl@0
   440
    set msg
sl@0
   441
} {1 {error renaming "tf1" to "td1/tf1": permission denied}}
sl@0
   442
test fCmd-6.7 {CopyRenameOneFile: errno != ENOENT} {pcOnly 95} {
sl@0
   443
    cleanup
sl@0
   444
    createfile tf1
sl@0
   445
    list [catch {file rename tf1 $long} msg] $msg
sl@0
   446
} [subst {1 {error renaming "tf1" to "$long": file name too long}}]
sl@0
   447
test fCmd-6.8 {CopyRenameOneFile: errno != ENOENT} {macOnly} {
sl@0
   448
    cleanup
sl@0
   449
    createfile tf1
sl@0
   450
    list [catch {file rename tf1 $long} msg] $msg
sl@0
   451
} [subst {1 {error renaming "tf1" to "$long": file name too long}}]
sl@0
   452
test fCmd-6.9 {CopyRenameOneFile: errno == ENOENT} {unixOnly notRoot} {
sl@0
   453
    cleanup
sl@0
   454
    createfile tf1
sl@0
   455
    file rename tf1 tf2
sl@0
   456
    glob tf*
sl@0
   457
} {tf2}
sl@0
   458
test fCmd-6.10 {CopyRenameOneFile: lstat(target) == 0} {notRoot} {
sl@0
   459
    cleanup
sl@0
   460
    createfile tf1
sl@0
   461
    createfile tf2
sl@0
   462
    list [catch {file rename tf1 tf2} msg] $msg
sl@0
   463
} {1 {error renaming "tf1" to "tf2": file already exists}}
sl@0
   464
test fCmd-6.11 {CopyRenameOneFile: force == 0} {notRoot} {
sl@0
   465
    cleanup
sl@0
   466
    createfile tf1
sl@0
   467
    createfile tf2
sl@0
   468
    list [catch {file rename tf1 tf2} msg] $msg
sl@0
   469
} {1 {error renaming "tf1" to "tf2": file already exists}}
sl@0
   470
test fCmd-6.12 {CopyRenameOneFile: force != 0} {notRoot} {
sl@0
   471
    cleanup
sl@0
   472
    createfile tf1
sl@0
   473
    createfile tf2
sl@0
   474
    file rename -force tf1 tf2
sl@0
   475
    glob tf*
sl@0
   476
} {tf2}
sl@0
   477
test fCmd-6.13 {CopyRenameOneFile: source is dir, target is file} {notRoot} {
sl@0
   478
    cleanup
sl@0
   479
    file mkdir td1
sl@0
   480
    file mkdir td2
sl@0
   481
    createfile [file join td2 td1]
sl@0
   482
    list [catch {file rename -force td1 td2} msg] $msg
sl@0
   483
} [subst {1 {can't overwrite file "[file join td2 td1]" with directory "td1"}}]
sl@0
   484
test fCmd-6.14 {CopyRenameOneFile: source is file, target is dir} {notRoot} {
sl@0
   485
    cleanup
sl@0
   486
    createfile tf1
sl@0
   487
    file mkdir [file join td1 tf1]
sl@0
   488
    list [catch {file rename -force tf1 td1} msg] $msg
sl@0
   489
} [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
sl@0
   490
test fCmd-6.15 {CopyRenameOneFile: TclpRenameFile succeeds} {notRoot notNetworkFilesystem} {
sl@0
   491
    cleanup
sl@0
   492
    file mkdir [file join td1 td2]
sl@0
   493
    file mkdir td2
sl@0
   494
    createfile [file join td2 tf1]
sl@0
   495
    file rename -force td2 td1
sl@0
   496
    file exists [file join td1 td2 tf1]
sl@0
   497
} {1}
sl@0
   498
test fCmd-6.16 {CopyRenameOneFile: TclpCopyRenameOneFile fails} {notRoot} {
sl@0
   499
    cleanup
sl@0
   500
    file mkdir [file join td1 td2]
sl@0
   501
    createfile [file join td1 td2 tf1]
sl@0
   502
    file mkdir td2
sl@0
   503
    list [catch {file rename -force td2 td1} msg] $msg
sl@0
   504
} [subst {1 {error renaming "td2" to "[file join td1 td2]": file already exists}}]
sl@0
   505
sl@0
   506
test fCmd-6.17 {CopyRenameOneFile: errno == EINVAL} {notRoot} {
sl@0
   507
    cleanup
sl@0
   508
    list [catch {file rename -force $root tf1} msg] $msg
sl@0
   509
} [subst {1 {error renaming "$root" to "tf1": trying to rename a volume or move a directory into itself}}]
sl@0
   510
test fCmd-6.18 {CopyRenameOneFile: errno != EXDEV} {notRoot} {
sl@0
   511
    cleanup
sl@0
   512
    file mkdir [file join td1 td2]
sl@0
   513
    createfile [file join td1 td2 tf1]
sl@0
   514
    file mkdir td2
sl@0
   515
    list [catch {file rename -force td2 td1} msg] $msg
sl@0
   516
} [subst {1 {error renaming "td2" to "[file join td1 td2]": file already exists}}]
sl@0
   517
test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} {unixOnly notRoot} {
sl@0
   518
    cleanup /tmp
sl@0
   519
    createfile tf1
sl@0
   520
    file rename tf1 /tmp
sl@0
   521
    glob tf* /tmp/tf1
sl@0
   522
} {/tmp/tf1}
sl@0
   523
test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} {pcOnly} {
sl@0
   524
    catch {file delete -force c:/tcl8975@ d:/tcl8975@}
sl@0
   525
    file mkdir c:/tcl8975@
sl@0
   526
    if [catch {file rename c:/tcl8975@ d:/}] {
sl@0
   527
	set msg d:/tcl8975@
sl@0
   528
    } else {
sl@0
   529
	set msg [glob c:/tcl8975@ d:/tcl8975@]
sl@0
   530
	file delete -force d:/tcl8975@
sl@0
   531
    }
sl@0
   532
    file delete -force c:/tcl8975@
sl@0
   533
    set msg
sl@0
   534
} {d:/tcl8975@}
sl@0
   535
test fCmd-6.21 {CopyRenameOneFile: copy/rename: S_ISDIR(source)} \
sl@0
   536
	{unixOnly notRoot} {
sl@0
   537
    cleanup /tmp
sl@0
   538
    file mkdir td1
sl@0
   539
    file rename td1 /tmp
sl@0
   540
    glob td* /tmp/td*
sl@0
   541
} {/tmp/td1}
sl@0
   542
test fCmd-6.22 {CopyRenameOneFile: copy/rename: !S_ISDIR(source)} \
sl@0
   543
	{unixOnly notRoot} {
sl@0
   544
    cleanup /tmp
sl@0
   545
    createfile tf1
sl@0
   546
    file rename tf1 /tmp
sl@0
   547
    glob tf* /tmp/tf*
sl@0
   548
} {/tmp/tf1}
sl@0
   549
test fCmd-6.23 {CopyRenameOneFile: TclpCopyDirectory failed} \
sl@0
   550
	{unixOnly notRoot xdev} {
sl@0
   551
    cleanup /tmp
sl@0
   552
    file mkdir td1/td2/td3
sl@0
   553
    file attributes td1 -permissions 0000
sl@0
   554
    set msg [list [catch {file rename td1 /tmp} msg] $msg]
sl@0
   555
    file attributes td1 -permissions 0755
sl@0
   556
    set msg 
sl@0
   557
} {1 {error renaming "td1": permission denied}}
sl@0
   558
test fCmd-6.24 {CopyRenameOneFile: error uses original name} \
sl@0
   559
	{unixOnly notRoot} {
sl@0
   560
    cleanup
sl@0
   561
    file mkdir ~/td1/td2
sl@0
   562
    set td1name [file join [file dirname ~] [file tail ~] td1]
sl@0
   563
    file attributes $td1name -permissions 0000
sl@0
   564
    set msg [list [catch {file copy ~/td1 td1} msg] $msg]
sl@0
   565
    file attributes $td1name -permissions 0755
sl@0
   566
    file delete -force ~/td1
sl@0
   567
    set msg
sl@0
   568
} {1 {error copying "~/td1": permission denied}}
sl@0
   569
test fCmd-6.25 {CopyRenameOneFile: error uses original name} \
sl@0
   570
	{unixOnly notRoot} {
sl@0
   571
    cleanup
sl@0
   572
    file mkdir td2
sl@0
   573
    file mkdir ~/td1
sl@0
   574
    set td1name [file join [file dirname ~] [file tail ~] td1]
sl@0
   575
    file attributes $td1name -permissions 0000
sl@0
   576
    set msg [list [catch {file copy td2 ~/td1} msg] $msg]
sl@0
   577
    file attributes $td1name -permissions 0755
sl@0
   578
    file delete -force ~/td1
sl@0
   579
    set msg
sl@0
   580
} {1 {error copying "td2" to "~/td1/td2": permission denied}}
sl@0
   581
test fCmd-6.26 {CopyRenameOneFile: doesn't use original name} \
sl@0
   582
	{unixOnly notRoot} {
sl@0
   583
    cleanup
sl@0
   584
    file mkdir ~/td1/td2
sl@0
   585
    set td2name [file join [file dirname ~] [file tail ~] td1 td2]
sl@0
   586
    file attributes $td2name -permissions 0000
sl@0
   587
    set msg [list [catch {file copy ~/td1 td1} msg] $msg]
sl@0
   588
    file attributes $td2name -permissions 0755
sl@0
   589
    file delete -force ~/td1
sl@0
   590
    set msg
sl@0
   591
} "1 {error copying \"~/td1\" to \"td1\": \"[file join [file dirname ~] [file tail ~] td1 td2]\": permission denied}"
sl@0
   592
test fCmd-6.27 {CopyRenameOneFile: TclpCopyDirectory failed} \
sl@0
   593
	{unixOnly notRoot xdev} {
sl@0
   594
    cleanup /tmp
sl@0
   595
    file mkdir td1/td2/td3
sl@0
   596
    file mkdir /tmp/td1
sl@0
   597
    createfile /tmp/td1/tf1
sl@0
   598
    list [catch {file rename -force td1 /tmp} msg] $msg
sl@0
   599
} {1 {error renaming "td1" to "/tmp/td1": file already exists}}
sl@0
   600
test fCmd-6.28 {CopyRenameOneFile: TclpCopyDirectory failed} \
sl@0
   601
	{unixOnly notRoot xdev} {
sl@0
   602
    cleanup /tmp
sl@0
   603
    file mkdir td1/td2/td3
sl@0
   604
    file attributes td1/td2/td3 -permissions 0000
sl@0
   605
    set msg [list [catch {file rename td1 /tmp} msg] $msg]
sl@0
   606
    file attributes td1/td2/td3 -permissions 0755
sl@0
   607
    set msg
sl@0
   608
} {1 {error renaming "td1" to "/tmp/td1": "td1/td2/td3": permission denied}}
sl@0
   609
test fCmd-6.29 {CopyRenameOneFile: TclpCopyDirectory passed} \
sl@0
   610
	{unixOnly notRoot xdev} {
sl@0
   611
    cleanup /tmp
sl@0
   612
    file mkdir td1/td2/td3
sl@0
   613
    file rename td1 /tmp
sl@0
   614
    glob td* /tmp/td1/t*
sl@0
   615
} {/tmp/td1/td2}
sl@0
   616
test fCmd-6.30 {CopyRenameOneFile: TclpRemoveDirectory failed} \
sl@0
   617
	{unixOnly notRoot} {
sl@0
   618
    cleanup
sl@0
   619
    file mkdir foo/bar
sl@0
   620
    file attr foo -perm 040555
sl@0
   621
    set catchResult [catch {file rename foo/bar /tmp} msg]
sl@0
   622
    set msg [lindex [split $msg :] end]
sl@0
   623
    catch {file delete /tmp/bar}
sl@0
   624
    catch {file attr foo -perm 040777}
sl@0
   625
    catch {file delete -force foo}
sl@0
   626
    list $catchResult $msg
sl@0
   627
} {1 { permission denied}}
sl@0
   628
test fCmd-6.31 {CopyRenameOneFile: TclpDeleteFile passed} \
sl@0
   629
	{unixOnly notRoot xdev} {
sl@0
   630
    catch {cleanup /tmp}
sl@0
   631
    file mkdir /tmp/td1
sl@0
   632
    createfile /tmp/td1/tf1
sl@0
   633
    file rename /tmp/td1/tf1 tf1
sl@0
   634
    list [file exists /tmp/td1/tf1] [file exists tf1]
sl@0
   635
} {0 1}
sl@0
   636
test fCmd-6.32 {CopyRenameOneFile: copy} {notRoot} {
sl@0
   637
    cleanup
sl@0
   638
    list [catch {file copy tf1 tf2} msg] $msg
sl@0
   639
} {1 {error copying "tf1": no such file or directory}}
sl@0
   640
catch {cleanup /tmp}
sl@0
   641
sl@0
   642
test fCmd-7.1 {FileForceOption: none} {notRoot} {
sl@0
   643
    cleanup
sl@0
   644
    file mkdir [file join tf1 tf2]
sl@0
   645
    list [catch {file delete tf1} msg] $msg
sl@0
   646
} {1 {error deleting "tf1": directory not empty}}
sl@0
   647
test fCmd-7.2 {FileForceOption: -force} {notRoot} {
sl@0
   648
    cleanup
sl@0
   649
    file mkdir [file join tf1 tf2]
sl@0
   650
    file delete -force tf1
sl@0
   651
} {}
sl@0
   652
test fCmd-7.3 {FileForceOption: --} {notRoot} {
sl@0
   653
    createfile -tf1
sl@0
   654
    file delete -- -tf1
sl@0
   655
} {}
sl@0
   656
test fCmd-7.4 {FileForceOption: bad option} {notRoot} {
sl@0
   657
    createfile -tf1
sl@0
   658
    set msg [list [catch {file delete -tf1} msg] $msg]
sl@0
   659
    file delete -- -tf1
sl@0
   660
    set msg
sl@0
   661
} {1 {bad option "-tf1": should be -force or --}}
sl@0
   662
test fCmd-7.5 {FileForceOption: multiple times through loop} {notRoot} {
sl@0
   663
    createfile --
sl@0
   664
    createfile -force
sl@0
   665
    file delete -force -force -- -- -force
sl@0
   666
    list [catch {glob -- -- -force} msg] $msg
sl@0
   667
} {1 {no files matched glob patterns "-- -force"}}
sl@0
   668
sl@0
   669
test fCmd-8.1 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
sl@0
   670
	{unixOnly notRoot knownBug} {
sl@0
   671
    # Labelled knownBug because it is dangerous [Bug: 3881]
sl@0
   672
    file mkdir td1
sl@0
   673
    file attr td1 -perm 040000
sl@0
   674
    set result [list [catch {file rename ~$user td1} msg] $msg]
sl@0
   675
    file delete -force td1
sl@0
   676
    set result
sl@0
   677
} "1 {error renaming \"~$user\" to \"td1/[file tail ~$user]\": permission denied}"
sl@0
   678
test fCmd-8.2 {FileBasename: basename of ~user: argc == 1 && *path == ~} {
sl@0
   679
    string equal [file tail ~$user] ~$user
sl@0
   680
} 0
sl@0
   681
test fCmd-8.3 {file copy and path translation: ensure correct error} {
sl@0
   682
    list [catch {file copy ~ [file join this file doesnt exist]} res] $res
sl@0
   683
} [list 1 \
sl@0
   684
  "error copying \"~\" to \"[file join this file doesnt exist]\":\
sl@0
   685
  no such file or directory"]
sl@0
   686
sl@0
   687
test fCmd-9.1 {file rename: comprehensive: EACCES} {unixOnly notRoot} {
sl@0
   688
    cleanup
sl@0
   689
    file mkdir td1
sl@0
   690
    file mkdir td2
sl@0
   691
    file attr td2 -perm 040000
sl@0
   692
    set result [list [catch {file rename td1 td2/} msg] $msg]
sl@0
   693
    file delete -force td2
sl@0
   694
    file delete -force td1
sl@0
   695
    set result
sl@0
   696
} {1 {error renaming "td1" to "td2/td1": permission denied}}
sl@0
   697
test fCmd-9.2 {file rename: comprehensive: source doesn't exist} {notRoot} {
sl@0
   698
    cleanup
sl@0
   699
    list [catch {file rename tf1 tf2} msg] $msg
sl@0
   700
} {1 {error renaming "tf1": no such file or directory}}
sl@0
   701
test fCmd-9.3 {file rename: comprehensive: file to new name} {notRoot testchmod} {
sl@0
   702
    cleanup
sl@0
   703
    createfile tf1
sl@0
   704
    createfile tf2
sl@0
   705
    testchmod 444 tf2
sl@0
   706
    file rename tf1 tf3
sl@0
   707
    file rename tf2 tf4
sl@0
   708
    list [lsort [glob tf*]] [file writable tf3] [file writable tf4]
sl@0
   709
} {{tf3 tf4} 1 0}    
sl@0
   710
test fCmd-9.4 {file rename: comprehensive: dir to new name} {unixOrPc notRoot testchmod} {
sl@0
   711
    cleanup
sl@0
   712
    file mkdir td1 td2
sl@0
   713
    testchmod 555 td2
sl@0
   714
    file rename td1 td3
sl@0
   715
    file rename td2 td4
sl@0
   716
    list [lsort [glob td*]] [file writable td3] [file writable td4]
sl@0
   717
} {{td3 td4} 1 0}    
sl@0
   718
test fCmd-9.5 {file rename: comprehensive: file to self} {notRoot testchmod} {
sl@0
   719
    cleanup
sl@0
   720
    createfile tf1 tf1
sl@0
   721
    createfile tf2 tf2
sl@0
   722
    testchmod 444 tf2
sl@0
   723
    file rename -force tf1 tf1
sl@0
   724
    file rename -force tf2 tf2
sl@0
   725
    list [contents tf1] [contents tf2] [file writable tf1] [file writable tf2]
sl@0
   726
} {tf1 tf2 1 0}    
sl@0
   727
test fCmd-9.6 {file rename: comprehensive: dir to self} {notRoot unixOrPc testchmod} {
sl@0
   728
    cleanup
sl@0
   729
    file mkdir td1
sl@0
   730
    file mkdir td2
sl@0
   731
    testchmod 555 td2
sl@0
   732
    file rename -force td1 .
sl@0
   733
    file rename -force td2 .
sl@0
   734
    list [lsort [glob td*]] [file writable td1] [file writable td2]
sl@0
   735
} {{td1 td2} 1 0}    
sl@0
   736
test fCmd-9.7 {file rename: comprehensive: file to existing file} {notRoot testchmod} {
sl@0
   737
    cleanup
sl@0
   738
    createfile tf1
sl@0
   739
    createfile tf2
sl@0
   740
    createfile tfs1
sl@0
   741
    createfile tfs2
sl@0
   742
    createfile tfs3
sl@0
   743
    createfile tfs4
sl@0
   744
    createfile tfd1
sl@0
   745
    createfile tfd2
sl@0
   746
    createfile tfd3
sl@0
   747
    createfile tfd4
sl@0
   748
    testchmod 444 tfs3
sl@0
   749
    testchmod 444 tfs4
sl@0
   750
    testchmod 444 tfd2
sl@0
   751
    testchmod 444 tfd4
sl@0
   752
    set msg [list [catch {file rename tf1 tf2} msg] $msg]
sl@0
   753
    file rename -force tfs1 tfd1
sl@0
   754
    file rename -force tfs2 tfd2
sl@0
   755
    file rename -force tfs3 tfd3
sl@0
   756
    file rename -force tfs4 tfd4
sl@0
   757
    list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4] 
sl@0
   758
} {{tf1 tf2 tfd1 tfd2 tfd3 tfd4} {1 {error renaming "tf1" to "tf2": file already exists}} 1 1 0 0}
sl@0
   759
test fCmd-9.8 {file rename: comprehensive: dir to empty dir} {notRoot testchmod notNetworkFilesystem} {
sl@0
   760
    # Under unix, you can rename a read-only directory, but you can't
sl@0
   761
    # move it into another directory.
sl@0
   762
sl@0
   763
    cleanup
sl@0
   764
    file mkdir td1
sl@0
   765
    file mkdir [file join td2 td1]
sl@0
   766
    file mkdir tds1
sl@0
   767
    file mkdir tds2
sl@0
   768
    file mkdir tds3
sl@0
   769
    file mkdir tds4
sl@0
   770
    file mkdir [file join tdd1 tds1]
sl@0
   771
    file mkdir [file join tdd2 tds2]
sl@0
   772
    file mkdir [file join tdd3 tds3]
sl@0
   773
    file mkdir [file join tdd4 tds4]
sl@0
   774
    if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
sl@0
   775
	testchmod 555 tds3
sl@0
   776
	testchmod 555 tds4
sl@0
   777
    }
sl@0
   778
    if {$tcl_platform(platform) != "macintosh"} {
sl@0
   779
    	testchmod 555 [file join tdd2 tds2]
sl@0
   780
    	testchmod 555 [file join tdd4 tds4]
sl@0
   781
    }
sl@0
   782
    set msg [list [catch {file rename td1 td2} msg] $msg]
sl@0
   783
    file rename -force tds1 tdd1
sl@0
   784
    file rename -force tds2 tdd2
sl@0
   785
    file rename -force tds3 tdd3
sl@0
   786
    file rename -force tds4 tdd4
sl@0
   787
    if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
sl@0
   788
	set w3 [file writable [file join tdd3 tds3]]
sl@0
   789
	set w4 [file writable [file join tdd4 tds4]]
sl@0
   790
    } else {
sl@0
   791
	set w3 0
sl@0
   792
	set w4 0
sl@0
   793
    }
sl@0
   794
    list [lsort [glob td*]] $msg [file writable [file join tdd1 tds1]] \
sl@0
   795
    [file writable [file join tdd2 tds2]] $w3 $w4
sl@0
   796
} [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4} {1 {error renaming "td1" to "[file join td2 td1]": file already exists}} 1 1 0 0}]
sl@0
   797
test fCmd-9.9 {file rename: comprehensive: dir to non-empty dir} {notRoot testchmod} {
sl@0
   798
    cleanup
sl@0
   799
    file mkdir tds1
sl@0
   800
    file mkdir tds2
sl@0
   801
    file mkdir [file join tdd1 tds1 xxx]
sl@0
   802
    file mkdir [file join tdd2 tds2 xxx]
sl@0
   803
    if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
sl@0
   804
	testchmod 555 tds2
sl@0
   805
    }
sl@0
   806
    set a1 [list [catch {file rename -force tds1 tdd1} msg] $msg]
sl@0
   807
    set a2 [list [catch {file rename -force tds2 tdd2} msg] $msg]
sl@0
   808
    if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
sl@0
   809
	set w2 [file writable tds2]
sl@0
   810
    } else {
sl@0
   811
	set w2 0
sl@0
   812
    }
sl@0
   813
    list [lsort [glob td*]] $a1 $a2 [file writable tds1] $w2
sl@0
   814
} [subst {{tdd1 tdd2 tds1 tds2} {1 {error renaming "tds1" to "[file join tdd1 tds1]": file already exists}} {1 {error renaming "tds2" to "[file join tdd2 tds2]": file already exists}} 1 0}]
sl@0
   815
test fCmd-9.10 {file rename: comprehensive: file to new name and dir} {notRoot testchmod} {
sl@0
   816
    cleanup
sl@0
   817
    createfile tf1
sl@0
   818
    createfile tf2
sl@0
   819
    file mkdir td1
sl@0
   820
    testchmod 444 tf2
sl@0
   821
    file rename tf1 [file join td1 tf3]
sl@0
   822
    file rename tf2 [file join td1 tf4]
sl@0
   823
    list [catch {glob tf*}] [lsort [glob -directory td1 t*]] \
sl@0
   824
    [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
sl@0
   825
} [subst {1 {[file join td1 tf3] [file join td1 tf4]} 1 0}]
sl@0
   826
test fCmd-9.11 {file rename: comprehensive: dir to new name and dir} {notRoot testchmod} {
sl@0
   827
    cleanup
sl@0
   828
    file mkdir td1
sl@0
   829
    file mkdir td2
sl@0
   830
    file mkdir td3
sl@0
   831
    if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
sl@0
   832
	testchmod 555 td2
sl@0
   833
    }
sl@0
   834
    file rename td1 [file join td3 td3]
sl@0
   835
    file rename td2 [file join td3 td4]
sl@0
   836
    if {$tcl_platform(platform) != "unix" && $tcl_platform(platform) != "macintosh"} {
sl@0
   837
	set w4 [file writable [file join td3 td4]]
sl@0
   838
    } else {
sl@0
   839
        set w4 0
sl@0
   840
    }
sl@0
   841
    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
sl@0
   842
    [file writable [file join td3 td3]] $w4
sl@0
   843
} [subst {td3 {[file join td3 td3] [file join td3 td4]} 1 0}]
sl@0
   844
test fCmd-9.12 {file rename: comprehensive: target exists} {notRoot testchmod notNetworkFilesystem} {
sl@0
   845
    cleanup
sl@0
   846
    file mkdir [file join td1 td2] [file join td2 td1]
sl@0
   847
    if {$tcl_platform(platform) != "macintosh"} {
sl@0
   848
    	testchmod 555 [file join td2 td1]
sl@0
   849
    }
sl@0
   850
    file mkdir [file join td3 td4] [file join td4 td3]
sl@0
   851
    file rename -force td3 td4
sl@0
   852
    set msg [list [file exists td3] [file exists [file join td4 td3 td4]] \
sl@0
   853
    [catch {file rename td1 td2} msg] $msg]
sl@0
   854
    if {$tcl_platform(platform) != "macintosh"} {
sl@0
   855
    	testchmod 755 [file join td2 td1]
sl@0
   856
    }
sl@0
   857
    set msg
sl@0
   858
} [subst {0 1 1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
sl@0
   859
test fCmd-9.13 {file rename: comprehensive: can't overwrite target} {notRoot} {
sl@0
   860
    cleanup
sl@0
   861
    file mkdir [file join td1 td2] [file join td2 td1 td4]
sl@0
   862
    list [catch {file rename -force td1 td2} msg] $msg
sl@0
   863
} [subst {1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
sl@0
   864
test fCmd-9.14 {file rename: comprehensive: dir into self} {notRoot} {
sl@0
   865
    cleanup
sl@0
   866
    file mkdir td1
sl@0
   867
    list [glob td*] [list [catch {file rename td1 td1} msg] $msg]
sl@0
   868
} [subst {td1 {1 {error renaming "td1" to "[file join td1 td1]": trying to rename a volume or move a directory into itself}}}]
sl@0
   869
test fCmd-9.15 {file rename: comprehensive: source and target incompatible} \
sl@0
   870
	{notRoot} {
sl@0
   871
    cleanup
sl@0
   872
    file mkdir td1
sl@0
   873
    createfile tf1
sl@0
   874
    list [catch {file rename -force td1 tf1} msg] $msg
sl@0
   875
} {1 {can't overwrite file "tf1" with directory "td1"}}
sl@0
   876
test fCmd-9.16 {file rename: comprehensive: source and target incompatible} \
sl@0
   877
	{notRoot} {
sl@0
   878
    cleanup
sl@0
   879
    file mkdir td1/tf1
sl@0
   880
    createfile tf1
sl@0
   881
    list [catch {file rename -force tf1 td1} msg] $msg
sl@0
   882
} [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
sl@0
   883
sl@0
   884
test fCmd-10.1 {file copy: comprehensive: source doesn't exist} {notRoot} {
sl@0
   885
    cleanup
sl@0
   886
    list [catch {file copy tf1 tf2} msg] $msg
sl@0
   887
} {1 {error copying "tf1": no such file or directory}}
sl@0
   888
test fCmd-10.2 {file copy: comprehensive: file to new name} {notRoot testchmod} {
sl@0
   889
    cleanup
sl@0
   890
    createfile tf1 tf1
sl@0
   891
    createfile tf2 tf2
sl@0
   892
    testchmod 444 tf2
sl@0
   893
    file copy tf1 tf3
sl@0
   894
    file copy tf2 tf4
sl@0
   895
    list [lsort [glob tf*]] [contents tf3] [contents tf4] [file writable tf3] [file writable tf4]
sl@0
   896
} {{tf1 tf2 tf3 tf4} tf1 tf2 1 0}
sl@0
   897
test fCmd-10.3 {file copy: comprehensive: dir to new name} {notRoot unixOrPc 95or98 testchmod} {
sl@0
   898
    cleanup
sl@0
   899
    file mkdir [file join td1 tdx]
sl@0
   900
    file mkdir [file join td2 tdy]
sl@0
   901
    testchmod 555 td2
sl@0
   902
    file copy td1 td3
sl@0
   903
    file copy td2 td4
sl@0
   904
    set msg [list [lsort [glob td*]] [glob -directory td3 t*] \
sl@0
   905
	    [glob -directory td4 t*] [file writable td3] [file writable td4]]
sl@0
   906
    if {$tcl_platform(platform) != "macintosh"} {
sl@0
   907
    	testchmod 755 td2
sl@0
   908
    	testchmod 755 td4
sl@0
   909
    }
sl@0
   910
    set msg
sl@0
   911
} [subst {{td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 0}]
sl@0
   912
test fCmd-10.3.1 {file copy: comprehensive: dir to new name} {notRoot pc 2000orNewer testchmod} {
sl@0
   913
    # On Windows with ACLs, copying a directory is defined like this
sl@0
   914
    cleanup
sl@0
   915
    file mkdir [file join td1 tdx]
sl@0
   916
    file mkdir [file join td2 tdy]
sl@0
   917
    testchmod 555 td2
sl@0
   918
    file copy td1 td3
sl@0
   919
    file copy td2 td4
sl@0
   920
    set msg [list [lsort [glob td*]] [glob -directory td3 t*] \
sl@0
   921
	    [glob -directory td4 t*] [file writable td3] [file writable td4]]
sl@0
   922
    testchmod 755 td2
sl@0
   923
    testchmod 755 td4
sl@0
   924
    set msg
sl@0
   925
} [subst {{td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 1}]
sl@0
   926
test fCmd-10.4 {file copy: comprehensive: file to existing file} {notRoot testchmod} {
sl@0
   927
    cleanup
sl@0
   928
    createfile tf1
sl@0
   929
    createfile tf2
sl@0
   930
    createfile tfs1
sl@0
   931
    createfile tfs2
sl@0
   932
    createfile tfs3
sl@0
   933
    createfile tfs4
sl@0
   934
    createfile tfd1
sl@0
   935
    createfile tfd2
sl@0
   936
    createfile tfd3
sl@0
   937
    createfile tfd4
sl@0
   938
    testchmod 444 tfs3
sl@0
   939
    testchmod 444 tfs4
sl@0
   940
    testchmod 444 tfd2
sl@0
   941
    testchmod 444 tfd4
sl@0
   942
    set msg [list [catch {file copy tf1 tf2} msg] $msg]
sl@0
   943
    file copy -force tfs1 tfd1
sl@0
   944
    file copy -force tfs2 tfd2
sl@0
   945
    file copy -force tfs3 tfd3
sl@0
   946
    file copy -force tfs4 tfd4
sl@0
   947
    list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4] 
sl@0
   948
} {{tf1 tf2 tfd1 tfd2 tfd3 tfd4 tfs1 tfs2 tfs3 tfs4} {1 {error copying "tf1" to "tf2": file already exists}} 1 1 0 0}
sl@0
   949
test fCmd-10.5 {file copy: comprehensive: dir to empty dir} {notRoot testchmod} {
sl@0
   950
    cleanup
sl@0
   951
    file mkdir td1
sl@0
   952
    file mkdir [file join td2 td1]
sl@0
   953
    file mkdir tds1
sl@0
   954
    file mkdir tds2
sl@0
   955
    file mkdir tds3
sl@0
   956
    file mkdir tds4
sl@0
   957
    file mkdir [file join tdd1 tds1]
sl@0
   958
    file mkdir [file join tdd2 tds2]
sl@0
   959
    file mkdir [file join tdd3 tds3]
sl@0
   960
    file mkdir [file join tdd4 tds4]
sl@0
   961
    if {$tcl_platform(platform) != "macintosh"} {
sl@0
   962
	testchmod 555 tds3
sl@0
   963
	testchmod 555 tds4
sl@0
   964
	testchmod 555 [file join tdd2 tds2]
sl@0
   965
	testchmod 555 [file join tdd4 tds4]
sl@0
   966
    }
sl@0
   967
    set a1 [list [catch {file copy td1 td2} msg] $msg]
sl@0
   968
    set a2 [list [catch {file copy -force tds1 tdd1} msg] $msg]
sl@0
   969
    set a3 [catch {file copy -force tds2 tdd2}]
sl@0
   970
    set a4 [catch {file copy -force tds3 tdd3}]
sl@0
   971
    set a5 [catch {file copy -force tds4 tdd4}]
sl@0
   972
    list [lsort [glob td*]] $a1 $a2 $a3 $a4 $a5 
sl@0
   973
} [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4 tds1 tds2 tds3 tds4} {1 {error copying "td1" to "[file join td2 td1]": file already exists}} {1 {error copying "tds1" to "[file join tdd1 tds1]": file already exists}} 1 1 1}]
sl@0
   974
test fCmd-10.6 {file copy: comprehensive: dir to non-empty dir} \
sl@0
   975
	{notRoot unixOrPc testchmod} {
sl@0
   976
    cleanup
sl@0
   977
    file mkdir tds1
sl@0
   978
    file mkdir tds2
sl@0
   979
    file mkdir [file join tdd1 tds1 xxx]
sl@0
   980
    file mkdir [file join tdd2 tds2 xxx]
sl@0
   981
    testchmod 555 tds2
sl@0
   982
    set a1 [list [catch {file copy -force tds1 tdd1} msg] $msg]
sl@0
   983
    set a2 [list [catch {file copy -force tds2 tdd2} msg] $msg]
sl@0
   984
    list [lsort [glob td*]] $a1 $a2 [file writable tds1] [file writable tds2]
sl@0
   985
} [subst {{tdd1 tdd2 tds1 tds2} {1 {error copying "tds1" to "[file join tdd1 tds1]": file already exists}} {1 {error copying "tds2" to "[file join tdd2 tds2]": file already exists}} 1 0}]
sl@0
   986
test fCmd-10.7 {file rename: comprehensive: file to new name and dir} {notRoot testchmod} {
sl@0
   987
    cleanup
sl@0
   988
    createfile tf1
sl@0
   989
    createfile tf2
sl@0
   990
    file mkdir td1
sl@0
   991
    testchmod 444 tf2
sl@0
   992
    file copy tf1 [file join td1 tf3]
sl@0
   993
    file copy tf2 [file join td1 tf4]
sl@0
   994
    list [lsort [glob tf*]] [lsort [glob -directory td1 t*]] \
sl@0
   995
    [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
sl@0
   996
} [subst {{tf1 tf2} {[file join td1 tf3] [file join td1 tf4]} 1 0}]
sl@0
   997
test fCmd-10.8 {file rename: comprehensive: dir to new name and dir} \
sl@0
   998
	{notRoot unixOrPc 95or98 testchmod} {
sl@0
   999
    cleanup
sl@0
  1000
    file mkdir td1
sl@0
  1001
    file mkdir td2
sl@0
  1002
    file mkdir td3
sl@0
  1003
    testchmod 555 td2
sl@0
  1004
    file copy td1 [file join td3 td3]
sl@0
  1005
    file copy td2 [file join td3 td4]
sl@0
  1006
    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
sl@0
  1007
    [file writable [file join td3 td3]] [file writable [file join td3 td4]]
sl@0
  1008
} [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 0}]
sl@0
  1009
test fCmd-10.8.1 {file rename: comprehensive: dir to new name and dir} \
sl@0
  1010
	{notRoot pc 2000orNewer testchmod} {
sl@0
  1011
    # On Windows with ACLs, copying a directory is defined like this
sl@0
  1012
    cleanup
sl@0
  1013
    file mkdir td1
sl@0
  1014
    file mkdir td2
sl@0
  1015
    file mkdir td3
sl@0
  1016
    testchmod 555 td2
sl@0
  1017
    file copy td1 [file join td3 td3]
sl@0
  1018
    file copy td2 [file join td3 td4]
sl@0
  1019
    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
sl@0
  1020
    [file writable [file join td3 td3]] [file writable [file join td3 td4]]
sl@0
  1021
} [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 1}]
sl@0
  1022
test fCmd-10.9 {file copy: comprehensive: source and target incompatible} \
sl@0
  1023
	{notRoot} {
sl@0
  1024
    cleanup
sl@0
  1025
    file mkdir td1
sl@0
  1026
    createfile tf1
sl@0
  1027
    list [catch {file copy -force td1 tf1} msg] $msg
sl@0
  1028
} {1 {can't overwrite file "tf1" with directory "td1"}}
sl@0
  1029
test fCmd-10.10 {file copy: comprehensive: source and target incompatible} \
sl@0
  1030
	{notRoot} {
sl@0
  1031
    cleanup
sl@0
  1032
    file mkdir [file join td1 tf1]
sl@0
  1033
    createfile tf1
sl@0
  1034
    list [catch {file copy -force tf1 td1} msg] $msg
sl@0
  1035
} [subst {1 {can't overwrite directory "[file join td1 tf1]" with file "tf1"}}]
sl@0
  1036
test fCmd-10.11 {file copy: copy to empty file name} {
sl@0
  1037
    cleanup
sl@0
  1038
    createfile tf1
sl@0
  1039
    list [catch {file copy tf1 ""} msg] $msg
sl@0
  1040
} {1 {error copying "tf1" to "": no such file or directory}}
sl@0
  1041
test fCmd-10.12 {file rename: rename to empty file name} {
sl@0
  1042
    cleanup
sl@0
  1043
    createfile tf1
sl@0
  1044
    list [catch {file rename tf1 ""} msg] $msg
sl@0
  1045
} {1 {error renaming "tf1" to "": no such file or directory}}
sl@0
  1046
cleanup    
sl@0
  1047
sl@0
  1048
# old tests    
sl@0
  1049
sl@0
  1050
test fCmd-11.1 {TclFileRenameCmd: -- option } {notRoot} {
sl@0
  1051
    catch {file delete -force -- -tfa1}
sl@0
  1052
    set s [createfile -tfa1]
sl@0
  1053
    file rename -- -tfa1 tfa2
sl@0
  1054
    set result [expr [checkcontent tfa2 $s] && ![file exists -tfa1]]
sl@0
  1055
    file delete tfa2
sl@0
  1056
    set result
sl@0
  1057
} {1}
sl@0
  1058
sl@0
  1059
test fCmd-11.2 {TclFileRenameCmd: bad option } {notRoot} {
sl@0
  1060
    catch {file delete -force -- tfa1}
sl@0
  1061
    set s [createfile tfa1]
sl@0
  1062
    set r1 [catch {file rename -x tfa1 tfa2}]
sl@0
  1063
    set result [expr $r1 && [checkcontent tfa1 $s] && ![file exists tfa2]]
sl@0
  1064
    file delete tfa1
sl@0
  1065
    set result
sl@0
  1066
} {1}
sl@0
  1067
sl@0
  1068
test fCmd-11.3 {TclFileRenameCmd: bad \# args} {
sl@0
  1069
    catch {file rename -- }
sl@0
  1070
} {1}
sl@0
  1071
sl@0
  1072
test fCmd-11.4 {TclFileRenameCmd: target filename translation failing} {notRoot} {
sl@0
  1073
     global env
sl@0
  1074
     set temp $env(HOME)
sl@0
  1075
     unset env(HOME)
sl@0
  1076
     set result [catch {file rename tfa ~/foobar }]
sl@0
  1077
     set env(HOME) $temp
sl@0
  1078
     set result
sl@0
  1079
 } {1}
sl@0
  1080
sl@0
  1081
test fCmd-11.5 {TclFileRenameCmd: > 1 source & target is not a dir} {notRoot} {
sl@0
  1082
    catch {file delete -force -- tfa1 tfa2 tfa3}
sl@0
  1083
    createfile tfa1 
sl@0
  1084
    createfile tfa2 
sl@0
  1085
    createfile tfa3 
sl@0
  1086
    set result [catch {file rename tfa1 tfa2 tfa3}]
sl@0
  1087
    file delete tfa1 tfa2 tfa3
sl@0
  1088
    set result
sl@0
  1089
} {1}
sl@0
  1090
sl@0
  1091
test fCmd-11.6 {TclFileRenameCmd: : single file into directory} {notRoot} {
sl@0
  1092
    catch {file delete -force -- tfa1 tfad}
sl@0
  1093
    set s [createfile tfa1]
sl@0
  1094
    file mkdir tfad
sl@0
  1095
    file rename tfa1 tfad
sl@0
  1096
    set result [expr [checkcontent tfad/tfa1 $s] && ![file exists tfa1]]
sl@0
  1097
    file delete -force tfad
sl@0
  1098
    set result
sl@0
  1099
} {1}
sl@0
  1100
sl@0
  1101
test fCmd-11.7 {TclFileRenameCmd: : multiple files into directory} {notRoot} {
sl@0
  1102
    catch {file delete -force -- tfa1 tfa2 tfad}
sl@0
  1103
    set s1 [createfile tfa1 ]
sl@0
  1104
    set s2 [createfile tfa2 ]
sl@0
  1105
    file mkdir tfad
sl@0
  1106
    file rename tfa1 tfa2 tfad
sl@0
  1107
    set r1 [checkcontent tfad/tfa1 $s1]
sl@0
  1108
    set r2 [checkcontent tfad/tfa2 $s2]
sl@0
  1109
    
sl@0
  1110
    set result [expr $r1 && $r2 && ![file exists tfa1] && ![file exists tfa2]]
sl@0
  1111
	    
sl@0
  1112
    file delete -force tfad
sl@0
  1113
    set result
sl@0
  1114
} {1}
sl@0
  1115
sl@0
  1116
test fCmd-11.8 {TclFileRenameCmd: error renaming file to directory} {notRoot} {
sl@0
  1117
    catch {file delete -force -- tfa tfad}
sl@0
  1118
    set s [createfile tfa ]
sl@0
  1119
    file mkdir tfad
sl@0
  1120
    file mkdir tfad/tfa
sl@0
  1121
    set r1 [catch {file rename tfa tfad}]
sl@0
  1122
    set r2 [checkcontent tfa $s]
sl@0
  1123
    set r3 [file isdir tfad]
sl@0
  1124
    set result [expr $r1 && $r2 && $r3 ]
sl@0
  1125
    file delete -force tfa tfad
sl@0
  1126
    set result
sl@0
  1127
} {1}
sl@0
  1128
sl@0
  1129
#
sl@0
  1130
# Coverage tests for renamefile() ;
sl@0
  1131
#
sl@0
  1132
test fCmd-12.1 {renamefile: source filename translation failing} {notRoot} {
sl@0
  1133
    global env
sl@0
  1134
    set temp $env(HOME)
sl@0
  1135
    unset env(HOME)
sl@0
  1136
    set result [catch {file rename ~/tfa1 tfa2}]
sl@0
  1137
    set env(HOME) $temp
sl@0
  1138
    set result
sl@0
  1139
} {1}
sl@0
  1140
sl@0
  1141
test fCmd-12.2 {renamefile: src filename translation failing} {notRoot} {
sl@0
  1142
    global env
sl@0
  1143
    set temp $env(HOME)
sl@0
  1144
    unset env(HOME)
sl@0
  1145
    set s [createfile tfa1]
sl@0
  1146
    file mkdir tfad
sl@0
  1147
    set result [catch {file rename tfa1 ~/tfa2 tfad}]
sl@0
  1148
    set env(HOME) $temp
sl@0
  1149
    file delete -force tfad
sl@0
  1150
    set result
sl@0
  1151
} {1}
sl@0
  1152
sl@0
  1153
test fCmd-12.3 {renamefile: stat failing on source} {notRoot} {
sl@0
  1154
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1155
    set r1 [catch {file rename tfa1 tfa2}]
sl@0
  1156
    expr {$r1 && ![file exists tfa1] && ![file exists tfa2]}
sl@0
  1157
} {1}
sl@0
  1158
sl@0
  1159
test fCmd-12.4 {renamefile: error renaming file to directory} {notRoot} {
sl@0
  1160
    catch {file delete -force -- tfa tfad}
sl@0
  1161
    set s1 [createfile tfa ]
sl@0
  1162
    file mkdir tfad
sl@0
  1163
    file mkdir tfad/tfa
sl@0
  1164
    set r1 [catch {file rename tfa tfad}]
sl@0
  1165
    set r2 [checkcontent tfa $s1]
sl@0
  1166
    set r3 [file isdir tfad/tfa]
sl@0
  1167
    set result [expr $r1 && $r2 && $r3]
sl@0
  1168
    file delete -force tfa tfad
sl@0
  1169
    set result
sl@0
  1170
} {1}
sl@0
  1171
sl@0
  1172
test fCmd-12.5 {renamefile: error renaming directory to file} {notRoot} {
sl@0
  1173
    catch {file delete -force -- tfa tfad}
sl@0
  1174
    file mkdir tfa
sl@0
  1175
    file mkdir tfad
sl@0
  1176
    set s [createfile tfad/tfa]
sl@0
  1177
    set r1 [catch {file rename tfa tfad}]
sl@0
  1178
    set r2 [checkcontent tfad/tfa $s]
sl@0
  1179
    set r3 [file isdir tfad]
sl@0
  1180
    set r4 [file isdir tfa]
sl@0
  1181
    set result [expr $r1 && $r2 && $r3 && $r4 ]
sl@0
  1182
    file delete -force tfa tfad
sl@0
  1183
    set result
sl@0
  1184
} {1}
sl@0
  1185
sl@0
  1186
test fCmd-12.6 {renamefile: TclRenameFile succeeding} {notRoot} {
sl@0
  1187
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1188
    set s [createfile tfa1]
sl@0
  1189
    file rename tfa1 tfa2
sl@0
  1190
    set result [expr [checkcontent tfa2 $s] && ![file exists tfa1]]
sl@0
  1191
    file delete tfa2
sl@0
  1192
    set result
sl@0
  1193
} {1}
sl@0
  1194
sl@0
  1195
test fCmd-12.7 {renamefile: renaming directory into offspring} {notRoot} {
sl@0
  1196
    catch {file delete -force -- tfad}
sl@0
  1197
    file mkdir tfad
sl@0
  1198
    file mkdir tfad/dir
sl@0
  1199
    set result [catch {file rename tfad tfad/dir}]
sl@0
  1200
    file delete -force tfad 
sl@0
  1201
    set result
sl@0
  1202
} {1}
sl@0
  1203
sl@0
  1204
test fCmd-12.8 {renamefile: generic error} {unixOnly notRoot} {
sl@0
  1205
    catch {file delete -force -- tfa}
sl@0
  1206
    file mkdir tfa
sl@0
  1207
    file mkdir tfa/dir
sl@0
  1208
    file attributes tfa -permissions 0555
sl@0
  1209
    set result [catch {file rename tfa/dir tfa2}]
sl@0
  1210
    file attributes tfa -permissions 0777
sl@0
  1211
    file delete -force tfa
sl@0
  1212
    set result
sl@0
  1213
} {1}
sl@0
  1214
sl@0
  1215
sl@0
  1216
test fCmd-12.9 {renamefile: moving a file across volumes} {unixOnly notRoot} {
sl@0
  1217
    catch {file delete -force -- tfa /tmp/tfa}
sl@0
  1218
    set s [createfile tfa ]
sl@0
  1219
    file rename tfa /tmp
sl@0
  1220
    set result [expr [checkcontent /tmp/tfa $s] && ![file exists tfa]]
sl@0
  1221
    file delete /tmp/tfa
sl@0
  1222
    set result
sl@0
  1223
} {1}
sl@0
  1224
sl@0
  1225
test fCmd-12.10 {renamefile: moving a directory across volumes } \
sl@0
  1226
	{unixOnly notRoot} {
sl@0
  1227
    catch {file delete -force -- tfad /tmp/tfad}
sl@0
  1228
    file mkdir tfad
sl@0
  1229
    set s [createfile tfad/a ]
sl@0
  1230
    file rename tfad /tmp
sl@0
  1231
    set restul [expr [checkcontent /tmp/tfad/a $s] && ![file exists tfad]]
sl@0
  1232
    file delete -force /tmp/tfad
sl@0
  1233
    set result
sl@0
  1234
} {1}
sl@0
  1235
sl@0
  1236
#
sl@0
  1237
# Coverage tests for TclCopyFilesCmd()
sl@0
  1238
#
sl@0
  1239
test fCmd-13.1 {TclCopyFilesCmd: -force option} {notRoot} {
sl@0
  1240
    catch {file delete -force -- tfa1}
sl@0
  1241
    set s [createfile tfa1]
sl@0
  1242
    file copy -force  tfa1 tfa2
sl@0
  1243
    set result [expr [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
sl@0
  1244
    file delete tfa1 tfa2
sl@0
  1245
    set result
sl@0
  1246
} {1}
sl@0
  1247
sl@0
  1248
test fCmd-13.2 {TclCopyFilesCmd: -- option} {notRoot} {
sl@0
  1249
    catch {file delete -force -- tfa1}
sl@0
  1250
    set s [createfile -tfa1]
sl@0
  1251
    file copy --  -tfa1 tfa2
sl@0
  1252
    set result [expr [checkcontent tfa2 $s] &&  [checkcontent -tfa1 $s]]
sl@0
  1253
    file delete -- -tfa1 tfa2
sl@0
  1254
    set result
sl@0
  1255
} {1}
sl@0
  1256
sl@0
  1257
test fCmd-13.3 {TclCopyFilesCmd: bad option} {notRoot} {
sl@0
  1258
    catch {file delete -force -- tfa1}
sl@0
  1259
    set s [createfile tfa1]
sl@0
  1260
    set r1 [catch {file copy -x tfa1 tfa2}]
sl@0
  1261
    set result [expr $r1 && [checkcontent tfa1 $s] && ![file exists tfa2]]
sl@0
  1262
    file delete tfa1
sl@0
  1263
    set result
sl@0
  1264
} {1}
sl@0
  1265
sl@0
  1266
test fCmd-13.4 {TclCopyFilesCmd: bad \# args} {notRoot} {
sl@0
  1267
    catch {file copy -- }
sl@0
  1268
} {1}
sl@0
  1269
sl@0
  1270
test fCmd-13.5 {TclCopyFilesCmd: target filename translation failing} {
sl@0
  1271
     global env
sl@0
  1272
     set temp $env(HOME)
sl@0
  1273
    unset env(HOME)
sl@0
  1274
     set result [catch {file copy tfa ~/foobar }]
sl@0
  1275
     set env(HOME) $temp
sl@0
  1276
     set result
sl@0
  1277
 } {1}
sl@0
  1278
sl@0
  1279
test fCmd-13.6 {TclCopyFilesCmd: > 1 source & target is not a dir} {notRoot} {
sl@0
  1280
    catch {file delete -force -- tfa1 tfa2 tfa3}
sl@0
  1281
    createfile tfa1 
sl@0
  1282
    createfile tfa2 
sl@0
  1283
    createfile tfa3 
sl@0
  1284
    set result [catch {file copy tfa1 tfa2 tfa3}]
sl@0
  1285
    file delete tfa1 tfa2 tfa3
sl@0
  1286
    set result
sl@0
  1287
} {1}
sl@0
  1288
sl@0
  1289
test fCmd-13.7 {TclCopyFilesCmd: single file into directory} {notRoot} {
sl@0
  1290
    catch {file delete -force -- tfa1 tfad}
sl@0
  1291
    set s [createfile tfa1]
sl@0
  1292
    file mkdir tfad
sl@0
  1293
    file copy tfa1 tfad
sl@0
  1294
    set result [expr [checkcontent tfad/tfa1 $s] &&  [checkcontent tfa1 $s]]
sl@0
  1295
    file delete -force tfad tfa1
sl@0
  1296
    set result
sl@0
  1297
} {1}
sl@0
  1298
sl@0
  1299
test fCmd-13.8 {TclCopyFilesCmd: multiple files into directory} {notRoot} {
sl@0
  1300
    catch {file delete -force -- tfa1 tfa2 tfad}
sl@0
  1301
    set s1 [createfile tfa1 ]
sl@0
  1302
    set s2 [createfile tfa2 ]
sl@0
  1303
    file mkdir tfad
sl@0
  1304
    file copy tfa1 tfa2 tfad
sl@0
  1305
    set r1 [checkcontent tfad/tfa1 $s1]
sl@0
  1306
    set r2 [checkcontent tfad/tfa2 $s2]
sl@0
  1307
    set r3 [checkcontent tfa1 $s1]
sl@0
  1308
    set r4 [checkcontent tfa2 $s2]
sl@0
  1309
    set result [expr $r1 && $r2 && $r3 && $r4 ]
sl@0
  1310
	    
sl@0
  1311
    file delete -force tfad tfa1 tfa2
sl@0
  1312
    set result
sl@0
  1313
} {1}
sl@0
  1314
sl@0
  1315
test fCmd-13.9 {TclCopyFilesCmd: error copying file to directory} {notRoot} {
sl@0
  1316
    catch {file delete -force -- tfa tfad}
sl@0
  1317
    set s [createfile tfa ]
sl@0
  1318
    file mkdir tfad
sl@0
  1319
    file mkdir tfad/tfa
sl@0
  1320
    set r1 [catch {file copy tfa tfad}]
sl@0
  1321
    set r2 [expr [checkcontent tfa $s] && [file isdir tfad/tfa]]
sl@0
  1322
    set r3 [file isdir tfad]
sl@0
  1323
    set result [expr $r1 && $r2 && $r3 ]
sl@0
  1324
    file delete -force tfa tfad
sl@0
  1325
    set result
sl@0
  1326
} {1}
sl@0
  1327
sl@0
  1328
#
sl@0
  1329
# Coverage tests for copyfile()
sl@0
  1330
# 
sl@0
  1331
test fCmd-14.1 {copyfile: source filename translation failing} {notRoot} {
sl@0
  1332
    global env
sl@0
  1333
    set temp $env(HOME)
sl@0
  1334
    unset env(HOME)
sl@0
  1335
    set result [catch {file copy ~/tfa1 tfa2}]
sl@0
  1336
    set env(HOME) $temp
sl@0
  1337
    set result
sl@0
  1338
} {1}
sl@0
  1339
sl@0
  1340
test fCmd-14.2 {copyfile: dst filename translation failing} {notRoot} {
sl@0
  1341
    global env
sl@0
  1342
    set temp $env(HOME)
sl@0
  1343
    unset env(HOME)
sl@0
  1344
    set s [createfile tfa1]
sl@0
  1345
    file mkdir tfad
sl@0
  1346
    set r1 [catch {file copy tfa1 ~/tfa2 tfad}]
sl@0
  1347
    set result [expr $r1 && [checkcontent tfad/tfa1 $s]]
sl@0
  1348
    set env(HOME) $temp
sl@0
  1349
    file delete -force tfa1 tfad
sl@0
  1350
    set result
sl@0
  1351
} {1}
sl@0
  1352
sl@0
  1353
test fCmd-14.3 {copyfile: stat failing on source} {notRoot} {
sl@0
  1354
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1355
    set r1 [catch {file copy tfa1 tfa2}]
sl@0
  1356
    expr $r1 && ![file exists tfa1] && ![file exists tfa2]
sl@0
  1357
} {1}
sl@0
  1358
sl@0
  1359
test fCmd-14.4 {copyfile: error copying file to directory} {notRoot} {
sl@0
  1360
    catch {file delete -force -- tfa tfad}
sl@0
  1361
    set s1 [createfile tfa ]
sl@0
  1362
    file mkdir tfad
sl@0
  1363
    file mkdir tfad/tfa
sl@0
  1364
    set r1 [catch {file copy tfa tfad}]
sl@0
  1365
    set r2 [checkcontent tfa $s1]
sl@0
  1366
    set r3 [file isdir tfad]
sl@0
  1367
    set r4 [file isdir tfad/tfa]
sl@0
  1368
    set result [expr $r1 && $r2 && $r3 && $r4 ]
sl@0
  1369
    file delete -force tfa tfad
sl@0
  1370
    set result
sl@0
  1371
} {1}
sl@0
  1372
sl@0
  1373
 test fCmd-14.5 {copyfile: error copying directory to file} {notRoot} {
sl@0
  1374
     catch {file delete -force -- tfa tfad}
sl@0
  1375
     file mkdir tfa
sl@0
  1376
     file mkdir tfad
sl@0
  1377
     set s [createfile tfad/tfa]
sl@0
  1378
     set r1 [catch {file copy tfa tfad}]
sl@0
  1379
     set r2 [checkcontent tfad/tfa $s]
sl@0
  1380
     set r3 [file isdir tfad]
sl@0
  1381
     set r4 [file isdir tfa]
sl@0
  1382
     set result [expr $r1 && $r2 && $r3 && $r4 ]
sl@0
  1383
     file delete -force tfa tfad
sl@0
  1384
     set result
sl@0
  1385
} {1}
sl@0
  1386
sl@0
  1387
test fCmd-14.6 {copyfile: copy file succeeding} {notRoot} {
sl@0
  1388
    catch {file delete -force -- tfa tfa2}
sl@0
  1389
    set s [createfile tfa]
sl@0
  1390
    file copy tfa tfa2
sl@0
  1391
    set result [expr  [checkcontent tfa $s] && [checkcontent tfa2 $s]]
sl@0
  1392
    file delete tfa tfa2
sl@0
  1393
    set result
sl@0
  1394
} {1}
sl@0
  1395
sl@0
  1396
test fCmd-14.7 {copyfile: copy directory succeeding} {notRoot} {
sl@0
  1397
    catch {file delete -force -- tfa tfa2}
sl@0
  1398
    file mkdir tfa
sl@0
  1399
    set s [createfile tfa/file]
sl@0
  1400
    file copy tfa tfa2
sl@0
  1401
    set result [expr [checkcontent tfa/file $s] && [checkcontent tfa2/file $s]]
sl@0
  1402
    file delete -force tfa tfa2
sl@0
  1403
    set result
sl@0
  1404
} {1}
sl@0
  1405
sl@0
  1406
test fCmd-14.8 {copyfile: copy directory failing} {unixOnly notRoot} {
sl@0
  1407
    catch {file delete -force -- tfa}
sl@0
  1408
    file mkdir tfa/dir/a/b/c
sl@0
  1409
    file attributes tfa/dir -permissions 0000
sl@0
  1410
    set r1 [catch {file copy tfa tfa2}]
sl@0
  1411
    file attributes tfa/dir -permissions 0777
sl@0
  1412
    set result $r1
sl@0
  1413
    file delete -force tfa tfa2
sl@0
  1414
    set result
sl@0
  1415
} {1}
sl@0
  1416
sl@0
  1417
#
sl@0
  1418
# Coverage tests for TclMkdirCmd()
sl@0
  1419
#
sl@0
  1420
test fCmd-15.1 {TclMakeDirsCmd: target filename translation failing} {notRoot} {
sl@0
  1421
    global env
sl@0
  1422
    set temp $env(HOME)
sl@0
  1423
    unset env(HOME) 
sl@0
  1424
    set result [catch {file mkdir ~/tfa}]
sl@0
  1425
    set env(HOME) $temp
sl@0
  1426
    set result
sl@0
  1427
} {1}
sl@0
  1428
#
sl@0
  1429
# Can Tcl_SplitPath return argc == 0? If so them we need a
sl@0
  1430
# test for that code.
sl@0
  1431
#
sl@0
  1432
test fCmd-15.2 {TclMakeDirsCmd - one directory } {notRoot} {
sl@0
  1433
    catch {file delete -force -- tfa}
sl@0
  1434
    file mkdir tfa
sl@0
  1435
    set result [file isdirectory tfa]
sl@0
  1436
    file delete tfa
sl@0
  1437
    set result
sl@0
  1438
} {1}
sl@0
  1439
sl@0
  1440
test fCmd-15.3 {TclMakeDirsCmd: - two directories} {notRoot} {
sl@0
  1441
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1442
    file mkdir tfa1 tfa2
sl@0
  1443
    set result [expr [file isdirectory tfa1] && [file isdirectory tfa2]]
sl@0
  1444
    file delete tfa1 tfa2
sl@0
  1445
    set result
sl@0
  1446
} {1}
sl@0
  1447
sl@0
  1448
test fCmd-15.4 {TclMakeDirsCmd - stat failing} {unixOnly notRoot} {
sl@0
  1449
    catch {file delete -force -- tfa}
sl@0
  1450
    file mkdir tfa
sl@0
  1451
    createfile tfa/file
sl@0
  1452
    file attributes tfa -permissions 0000
sl@0
  1453
    set result [catch {file mkdir tfa/file}]
sl@0
  1454
    file attributes tfa -permissions 0777
sl@0
  1455
    file delete -force tfa
sl@0
  1456
    set result
sl@0
  1457
} {1}
sl@0
  1458
sl@0
  1459
test fCmd-15.5 {TclMakeDirsCmd: - making a directory several levels deep} \
sl@0
  1460
	{notRoot} {
sl@0
  1461
    catch {file delete -force -- tfa}
sl@0
  1462
    file mkdir tfa/a/b/c
sl@0
  1463
    set result [file isdir tfa/a/b/c]
sl@0
  1464
    file delete -force tfa
sl@0
  1465
    set result
sl@0
  1466
} {1}
sl@0
  1467
sl@0
  1468
    
sl@0
  1469
test fCmd-15.6 {TclMakeDirsCmd: - trying to overwrite a file} {notRoot} {
sl@0
  1470
    catch {file delete -force -- tfa}
sl@0
  1471
    set s [createfile tfa]
sl@0
  1472
    set r1 [catch {file mkdir tfa}]
sl@0
  1473
    set r2 [file isdir tfa]
sl@0
  1474
    set r3 [file exists tfa]
sl@0
  1475
    set result [expr $r1 && !$r2 && $r3 && [checkcontent tfa $s]]
sl@0
  1476
    file delete tfa
sl@0
  1477
    set result
sl@0
  1478
} {1}
sl@0
  1479
sl@0
  1480
test fCmd-15.7 {TclMakeDirsCmd - making several directories} {notRoot} {
sl@0
  1481
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1482
    file mkdir tfa1 tfa2/a/b/c
sl@0
  1483
    set result [expr [file isdir tfa1] && [file isdir tfa2/a/b/c]]
sl@0
  1484
    file delete -force tfa1 tfa2
sl@0
  1485
    set result
sl@0
  1486
} {1}
sl@0
  1487
sl@0
  1488
test fCmd-15.8 {TclFileMakeDirsCmd: trying to create an existing dir} {notRoot} {
sl@0
  1489
    file mkdir tfa
sl@0
  1490
    file mkdir tfa
sl@0
  1491
    set result [file isdir tfa]
sl@0
  1492
    file delete tfa
sl@0
  1493
    set result
sl@0
  1494
} {1}
sl@0
  1495
sl@0
  1496
sl@0
  1497
# Coverage tests for TclDeleteFilesCommand()
sl@0
  1498
test fCmd-16.1 {test the -- argument} {notRoot} {
sl@0
  1499
    catch {file delete -force -- tfa}
sl@0
  1500
    createfile tfa
sl@0
  1501
    file delete -- tfa
sl@0
  1502
    file exists tfa
sl@0
  1503
} {0}
sl@0
  1504
sl@0
  1505
test fCmd-16.2 {test the -force and -- arguments} {notRoot} {
sl@0
  1506
    catch {file delete -force -- tfa}
sl@0
  1507
    createfile tfa
sl@0
  1508
    file delete -force -- tfa
sl@0
  1509
    file exists tfa
sl@0
  1510
} {0}
sl@0
  1511
sl@0
  1512
test fCmd-16.3 {test bad option} {notRoot} {
sl@0
  1513
    catch {file delete -force -- tfa}
sl@0
  1514
    createfile tfa
sl@0
  1515
    set result [catch {file delete -dog tfa}]
sl@0
  1516
    file delete tfa
sl@0
  1517
    set result
sl@0
  1518
} {1}
sl@0
  1519
sl@0
  1520
test fCmd-16.4 {test not enough args} {notRoot} {
sl@0
  1521
    catch {file delete}
sl@0
  1522
} {1}
sl@0
  1523
sl@0
  1524
test fCmd-16.5 {test not enough args with options} {notRoot} {
sl@0
  1525
    catch {file delete --}
sl@0
  1526
} {1}
sl@0
  1527
sl@0
  1528
test fCmd-16.6 {delete: source filename translation failing} {notRoot} {
sl@0
  1529
    global env
sl@0
  1530
    set temp $env(HOME)
sl@0
  1531
    unset env(HOME)
sl@0
  1532
    set result [catch {file delete ~/tfa}]
sl@0
  1533
    set env(HOME) $temp
sl@0
  1534
    set result
sl@0
  1535
} {1}
sl@0
  1536
sl@0
  1537
test fCmd-16.7 {remove a non-empty directory without -force } {notRoot} {
sl@0
  1538
    catch {file delete -force -- tfa}
sl@0
  1539
    file mkdir tfa
sl@0
  1540
    createfile tfa/a
sl@0
  1541
    set result [catch  {file delete tfa }]
sl@0
  1542
    file delete -force tfa
sl@0
  1543
    set result
sl@0
  1544
} {1}
sl@0
  1545
sl@0
  1546
test fCmd-16.8 {remove a normal file } {notRoot} {
sl@0
  1547
    catch {file delete -force -- tfa}
sl@0
  1548
    file mkdir tfa
sl@0
  1549
    createfile tfa/a
sl@0
  1550
    set result [catch  {file delete tfa }]
sl@0
  1551
    file delete -force tfa
sl@0
  1552
    set result
sl@0
  1553
} {1}
sl@0
  1554
sl@0
  1555
test fCmd-16.9 {error while deleting file } {unixOnly notRoot} {
sl@0
  1556
    catch {file delete -force -- tfa}
sl@0
  1557
    file mkdir tfa
sl@0
  1558
    createfile tfa/a
sl@0
  1559
    file attributes tfa -permissions 0555
sl@0
  1560
    set result [catch  {file delete tfa/a }]
sl@0
  1561
    #######
sl@0
  1562
    #######  If any directory in a tree that is being removed does not 
sl@0
  1563
    #######  have write permission, the process will fail!
sl@0
  1564
    #######  This is also the case with "rm -rf"
sl@0
  1565
    #######
sl@0
  1566
    file attributes tfa -permissions 0777
sl@0
  1567
    file delete -force tfa
sl@0
  1568
    set result
sl@0
  1569
} {1}
sl@0
  1570
sl@0
  1571
test fCmd-16.10 {deleting multiple files} {notRoot} {
sl@0
  1572
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1573
    createfile tfa1
sl@0
  1574
    createfile tfa2
sl@0
  1575
    file delete tfa1 tfa2
sl@0
  1576
    expr ![file exists tfa1] && ![file exists tfa2]
sl@0
  1577
} {1}
sl@0
  1578
sl@0
  1579
test fCmd-16.11 {TclFileDeleteCmd: removing a nonexistant file} {notRoot} {
sl@0
  1580
    catch {file delete -force -- tfa}
sl@0
  1581
    file delete tfa
sl@0
  1582
    set result 1
sl@0
  1583
} {1}
sl@0
  1584
sl@0
  1585
# More coverage tests for mkpath()
sl@0
  1586
 test fCmd-17.1 {mkdir stat failing on target but not ENOENT} {unixOnly notRoot} {
sl@0
  1587
     catch {file delete -force -- tfa1}
sl@0
  1588
     file mkdir tfa1
sl@0
  1589
     file attributes tfa1 -permissions 0555
sl@0
  1590
     set result [catch {file mkdir tfa1/tfa2}]
sl@0
  1591
     file attributes tfa1 -permissions 0777
sl@0
  1592
     file delete -force tfa1
sl@0
  1593
     set result
sl@0
  1594
} {1}
sl@0
  1595
sl@0
  1596
test fCmd-17.2 {mkdir several levels deep - relative } {notRoot} {
sl@0
  1597
    catch {file delete -force -- tfa}
sl@0
  1598
    file mkdir tfa/a/b
sl@0
  1599
    set result [file isdir tfa/a/b ]
sl@0
  1600
    file delete tfa/a/b tfa/a tfa
sl@0
  1601
    set result
sl@0
  1602
} {1}
sl@0
  1603
sl@0
  1604
test fCmd-17.3 {mkdir several levels deep - absolute } {notRoot} {
sl@0
  1605
    catch {file delete -force -- tfa}
sl@0
  1606
    set f [file join [pwd] tfa a ]
sl@0
  1607
    file mkdir $f
sl@0
  1608
    set result [file isdir $f ]
sl@0
  1609
    file delete $f [file join [pwd] tfa]
sl@0
  1610
    set result
sl@0
  1611
} {1}
sl@0
  1612
sl@0
  1613
#
sl@0
  1614
# Functionality tests for TclFileRenameCmd()
sl@0
  1615
#
sl@0
  1616
sl@0
  1617
test fCmd-18.1 {TclFileRenameCmd: rename (first form) in the same directory} \
sl@0
  1618
	{notRoot} {
sl@0
  1619
    catch {file delete -force -- tfad}
sl@0
  1620
    file mkdir tfad/dir
sl@0
  1621
    cd tfad/dir
sl@0
  1622
    set s [createfile foo ]
sl@0
  1623
    file rename  foo bar
sl@0
  1624
    file rename bar ./foo
sl@0
  1625
    file rename ./foo bar
sl@0
  1626
    file rename ./bar ./foo
sl@0
  1627
    file rename foo ../dir/bar
sl@0
  1628
    file rename ../dir/bar ./foo
sl@0
  1629
    file rename ../../tfad/dir/foo ../../tfad/dir/bar
sl@0
  1630
    file rename [file join [pwd] bar] foo
sl@0
  1631
    file rename foo [file join [pwd] bar]
sl@0
  1632
    set result [expr [checkcontent bar $s] && ![file exists foo]]
sl@0
  1633
    cd ../..
sl@0
  1634
    file delete -force tfad
sl@0
  1635
    set result
sl@0
  1636
} {1}
sl@0
  1637
sl@0
  1638
test fCmd-18.2 {TclFileRenameCmd: single dir to nonexistant} {notRoot} {
sl@0
  1639
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1640
    file mkdir tfa1
sl@0
  1641
    file rename tfa1 tfa2
sl@0
  1642
    set result [expr [file exists tfa2] && ![file exists tfa1]]
sl@0
  1643
    file delete tfa2
sl@0
  1644
    set result
sl@0
  1645
} {1}
sl@0
  1646
sl@0
  1647
test fCmd-18.3 {TclFileRenameCmd: mixed dirs and files into directory} {notRoot} {
sl@0
  1648
    catch {file delete -force -- tfa1 tfad1 tfad2}
sl@0
  1649
    set s [createfile tfa1 ]
sl@0
  1650
    file mkdir tfad1 tfad2
sl@0
  1651
    file rename tfa1 tfad1 tfad2
sl@0
  1652
    set r1 [checkcontent  tfad2/tfa1 $s]
sl@0
  1653
    set r2 [file isdir tfad2/tfad1]
sl@0
  1654
    set result [expr $r1 && $r2 && ![file exists tfa1] && ![file exists tfad1]]
sl@0
  1655
    file delete tfad2/tfa1
sl@0
  1656
    file delete -force tfad2
sl@0
  1657
    set result
sl@0
  1658
} {1}
sl@0
  1659
sl@0
  1660
test fCmd-18.4 {TclFileRenameCmd: attempt to replace non-dir with dir} {notRoot} {
sl@0
  1661
    catch {file delete -force -- tfa tfad}
sl@0
  1662
    set s [createfile tfa ]
sl@0
  1663
    file mkdir tfad
sl@0
  1664
    set r1 [catch {file rename tfad tfa}]
sl@0
  1665
    set r2 [checkcontent tfa $s]
sl@0
  1666
    set r3 [file isdir tfad]
sl@0
  1667
    set result [expr $r1 && $r2 && $r3 ]
sl@0
  1668
    file delete tfa tfad
sl@0
  1669
    set result
sl@0
  1670
} {1}
sl@0
  1671
sl@0
  1672
test fCmd-18.5 {TclFileRenameCmd: attempt to replace dir with non-dir} {notRoot} {
sl@0
  1673
    catch {file delete -force -- tfa tfad}
sl@0
  1674
    set s [createfile tfa ]
sl@0
  1675
    file mkdir tfad/tfa
sl@0
  1676
    set r1 [catch {file rename tfa tfad}]
sl@0
  1677
    set r2 [checkcontent tfa $s]
sl@0
  1678
    set r3 [file isdir tfad/tfa]
sl@0
  1679
    set result [expr $r1 && $r2 && $r3 ]
sl@0
  1680
    file delete -force  tfa tfad
sl@0
  1681
    set result
sl@0
  1682
} {1}
sl@0
  1683
sl@0
  1684
#
sl@0
  1685
# On Windows there is no easy way to determine if two files are the same
sl@0
  1686
#
sl@0
  1687
test fCmd-18.6 {TclFileRenameCmd: rename a file to itself} {macOrUnix notRoot} {
sl@0
  1688
    catch {file delete -force -- tfa}
sl@0
  1689
    set s [createfile tfa]
sl@0
  1690
    set r1 [catch {file rename tfa tfa}]
sl@0
  1691
    set result [expr $r1 && [checkcontent tfa $s]]
sl@0
  1692
    file delete tfa
sl@0
  1693
    set result
sl@0
  1694
} {1}
sl@0
  1695
sl@0
  1696
test fCmd-18.7 {TclFileRenameCmd: rename dir on top of another empty dir w/o -force} \
sl@0
  1697
	{notRoot} {
sl@0
  1698
    catch {file delete -force -- tfa tfad}
sl@0
  1699
    file mkdir tfa tfad/tfa
sl@0
  1700
    set r1 [catch {file rename tfa tfad}]
sl@0
  1701
    set result [expr $r1 && [file isdir tfa]]
sl@0
  1702
    file delete -force tfa tfad
sl@0
  1703
    set result
sl@0
  1704
} {1}
sl@0
  1705
sl@0
  1706
test fCmd-18.8 {TclFileRenameCmd: rename dir on top of another empty dir w/ -force} \
sl@0
  1707
	{notRoot notNetworkFilesystem} {
sl@0
  1708
    catch {file delete -force -- tfa tfad}
sl@0
  1709
    file mkdir tfa tfad/tfa
sl@0
  1710
    file rename -force tfa tfad
sl@0
  1711
    set result [expr ![file isdir tfa]]
sl@0
  1712
    file delete -force tfad
sl@0
  1713
    set result
sl@0
  1714
} {1}
sl@0
  1715
sl@0
  1716
test fCmd-18.9 {TclFileRenameCmd: rename dir on top of a non-empty dir w/o -force} \
sl@0
  1717
	{notRoot} {
sl@0
  1718
    catch {file delete -force -- tfa tfad}
sl@0
  1719
    file mkdir tfa tfad/tfa/file
sl@0
  1720
    set r1 [catch {file rename tfa tfad}]
sl@0
  1721
    set result [expr $r1 && [file isdir tfa] && [file isdir tfad/tfa/file]]
sl@0
  1722
    file delete -force tfa tfad
sl@0
  1723
    set result
sl@0
  1724
} {1}
sl@0
  1725
sl@0
  1726
test fCmd-18.10 {TclFileRenameCmd: rename dir on top of a non-empty dir w/ -force} \
sl@0
  1727
	{notRoot notNetworkFilesystem} {
sl@0
  1728
    catch {file delete -force -- tfa tfad}
sl@0
  1729
    file mkdir tfa tfad/tfa/file
sl@0
  1730
    set r1 [catch {file rename -force tfa tfad}]
sl@0
  1731
    set result [expr $r1 && [file isdir tfa] && [file isdir tfad/tfa/file]]
sl@0
  1732
    file delete -force tfa tfad
sl@0
  1733
    set result
sl@0
  1734
} {1}
sl@0
  1735
sl@0
  1736
test fCmd-18.11 {TclFileRenameCmd: rename a non-existant file} {notRoot} {
sl@0
  1737
    catch {file delete -force -- tfa1}
sl@0
  1738
    set r1 [catch {file rename tfa1 tfa2}]
sl@0
  1739
    set result [expr $r1 && ![file exists tfa1] && ![file exists tfa2]]
sl@0
  1740
} {1}
sl@0
  1741
sl@0
  1742
test fCmd-18.12 {TclFileRenameCmd : rename a symbolic link to file} \
sl@0
  1743
	{unixOnly notRoot} {
sl@0
  1744
    catch {file delete -force -- tfa1 tfa2 tfa3}
sl@0
  1745
	
sl@0
  1746
    set s [createfile tfa1]
sl@0
  1747
    file link -symbolic tfa2 tfa1
sl@0
  1748
    file rename tfa2 tfa3
sl@0
  1749
    set t [file type tfa3]
sl@0
  1750
    set result [expr {$t eq "link"}]
sl@0
  1751
    file delete tfa1 tfa3
sl@0
  1752
    set result
sl@0
  1753
} {1}
sl@0
  1754
sl@0
  1755
test fCmd-18.13 {TclFileRenameCmd : rename a symbolic link to dir} \
sl@0
  1756
	{unixOnly notRoot} {
sl@0
  1757
    catch {file delete -force -- tfa1 tfa2 tfa3}
sl@0
  1758
	
sl@0
  1759
    file mkdir tfa1
sl@0
  1760
    file link -symbolic tfa2 tfa1
sl@0
  1761
    file rename tfa2 tfa3
sl@0
  1762
    set t [file type tfa3]
sl@0
  1763
    set result [expr {$t eq "link"}]
sl@0
  1764
    file delete tfa1 tfa3
sl@0
  1765
    set result
sl@0
  1766
} {1}
sl@0
  1767
sl@0
  1768
test fCmd-18.14 {TclFileRenameCmd : rename a path with sym link} \
sl@0
  1769
	{unixOnly notRoot} {
sl@0
  1770
    catch {file delete -force -- tfa1 tfa2 tfa3}
sl@0
  1771
	
sl@0
  1772
    file mkdir tfa1/a/b/c/d
sl@0
  1773
    file mkdir tfa2
sl@0
  1774
    set f [file join [pwd] tfa1/a/b] 
sl@0
  1775
    set f2 [file join [pwd] {tfa2/b alias}]
sl@0
  1776
    file link -symbolic $f2 $f
sl@0
  1777
    file rename {tfa2/b alias/c} tfa3
sl@0
  1778
    set r1 [file isdir tfa3]
sl@0
  1779
    set r2 [file exists tfa1/a/b/c]
sl@0
  1780
    set result [expr $r1 && !$r2]
sl@0
  1781
    file delete -force tfa1 tfa2 tfa3
sl@0
  1782
    set result
sl@0
  1783
} {1}
sl@0
  1784
sl@0
  1785
test fCmd-18.15 {TclFileRenameCmd : rename a file to a symlink dir} \
sl@0
  1786
	{unixOnly notRoot} {
sl@0
  1787
    catch {file delete -force -- tfa1 tfa2 tfalink}
sl@0
  1788
	
sl@0
  1789
    file mkdir tfa1
sl@0
  1790
    set s [createfile tfa2]
sl@0
  1791
    file link -symbolic tfalink tfa1
sl@0
  1792
sl@0
  1793
    file rename tfa2 tfalink
sl@0
  1794
    set result [checkcontent tfa1/tfa2 $s ]
sl@0
  1795
    file delete -force tfa1 tfalink
sl@0
  1796
    set result
sl@0
  1797
} {1}
sl@0
  1798
sl@0
  1799
test fCmd-18.16 {TclFileRenameCmd: rename a dangling symlink} {unixOnly notRoot} {
sl@0
  1800
    catch {file delete -force -- tfa1 tfalink}
sl@0
  1801
	
sl@0
  1802
    file mkdir tfa1
sl@0
  1803
    file link -symbolic tfalink tfa1
sl@0
  1804
    file delete tfa1 
sl@0
  1805
    file rename tfalink tfa2
sl@0
  1806
    set result [expr [string compare [file type tfa2] "link"] == 0]
sl@0
  1807
    file delete tfa2
sl@0
  1808
    set result
sl@0
  1809
} {1}
sl@0
  1810
sl@0
  1811
sl@0
  1812
#
sl@0
  1813
# Coverage tests for TclUnixRmdir
sl@0
  1814
#
sl@0
  1815
test fCmd-19.1 {remove empty directory} {notRoot} {
sl@0
  1816
    catch {file delete -force -- tfa}
sl@0
  1817
    file mkdir tfa
sl@0
  1818
    file delete tfa
sl@0
  1819
    file exists tfa
sl@0
  1820
} {0}
sl@0
  1821
sl@0
  1822
test fCmd-19.2 {rmdir error besides EEXIST} {unixOnly notRoot} {
sl@0
  1823
    catch {file delete -force -- tfa}
sl@0
  1824
    file mkdir tfa
sl@0
  1825
    file mkdir tfa/a
sl@0
  1826
    file attributes tfa -permissions 0555
sl@0
  1827
    set result [catch {file delete tfa/a}]
sl@0
  1828
    file attributes tfa -permissions 0777
sl@0
  1829
    file delete -force tfa
sl@0
  1830
    set result
sl@0
  1831
} {1}
sl@0
  1832
sl@0
  1833
test fCmd-19.3 {recursive remove} {notRoot} {
sl@0
  1834
    catch {file delete -force -- tfa}
sl@0
  1835
    file mkdir tfa
sl@0
  1836
    file mkdir tfa/a
sl@0
  1837
    file delete -force tfa
sl@0
  1838
    file exists tfa
sl@0
  1839
} {0}
sl@0
  1840
sl@0
  1841
#
sl@0
  1842
# TclUnixDeleteFile and TraversalDelete are covered by tests from the 
sl@0
  1843
# TclDeleteFilesCmd suite
sl@0
  1844
#
sl@0
  1845
#
sl@0
  1846
sl@0
  1847
#
sl@0
  1848
# Coverage tests for TraverseUnixTree(), called from TclDeleteFilesCmd
sl@0
  1849
#
sl@0
  1850
sl@0
  1851
test fCmd-20.1 {TraverseUnixTree : failure opening a subdirectory directory } \
sl@0
  1852
	{unixOnly notRoot} {
sl@0
  1853
    catch {file delete -force -- tfa}
sl@0
  1854
    file mkdir tfa
sl@0
  1855
    file mkdir tfa/a
sl@0
  1856
    file attributes tfa/a -permissions 0000
sl@0
  1857
    set result [catch {file delete -force tfa}]
sl@0
  1858
    file attributes tfa/a -permissions 0777
sl@0
  1859
    file delete -force tfa
sl@0
  1860
    set result
sl@0
  1861
} {1}
sl@0
  1862
sl@0
  1863
test fCmd-20.2 {TraverseUnixTree : recursive delete of large directory: Bug 1034337} \
sl@0
  1864
	{unix notRoot} {
sl@0
  1865
    catch {file delete -force -- tfa}
sl@0
  1866
    file mkdir tfa
sl@0
  1867
    for {set i 1} {$i <= 300} {incr i} {createfile tfa/testfile_$i}
sl@0
  1868
    set result [catch {file delete -force tfa} msg]
sl@0
  1869
    while {[catch {file delete -force tfa}]} {}
sl@0
  1870
    list $result $msg
sl@0
  1871
} {0 {}}
sl@0
  1872
sl@0
  1873
#
sl@0
  1874
# Feature testing for TclCopyFilesCmd
sl@0
  1875
# 
sl@0
  1876
test fCmd-21.1 {copy : single file to nonexistant } {notRoot} {
sl@0
  1877
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1878
    set s [createfile tfa1]
sl@0
  1879
    file copy tfa1 tfa2
sl@0
  1880
    set result [expr [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
sl@0
  1881
    file delete tfa1 tfa2
sl@0
  1882
    set result
sl@0
  1883
} {1}
sl@0
  1884
sl@0
  1885
test fCmd-21.2 {copy : single dir to nonexistant } {notRoot} {
sl@0
  1886
    catch {file delete -force -- tfa1 tfa2}
sl@0
  1887
    file mkdir tfa1
sl@0
  1888
    file copy tfa1 tfa2
sl@0
  1889
    set result [expr [file isdir tfa2] && [file isdir tfa1]]
sl@0
  1890
    file delete tfa1 tfa2
sl@0
  1891
    set result
sl@0
  1892
} {1}
sl@0
  1893
sl@0
  1894
test fCmd-21.3 {copy : single file into directory  } {notRoot} {
sl@0
  1895
    catch {file delete -force -- tfa1 tfad}
sl@0
  1896
    set s [createfile tfa1]
sl@0
  1897
    file mkdir tfad
sl@0
  1898
    file copy tfa1 tfad
sl@0
  1899
    set result [expr [checkcontent tfad/tfa1 $s] && [checkcontent tfa1 $s]]
sl@0
  1900
    file delete -force tfa1 tfad
sl@0
  1901
    set result
sl@0
  1902
} {1}
sl@0
  1903
sl@0
  1904
test fCmd-21.4 {copy : more than one source and target is not a directory} \
sl@0
  1905
	{notRoot} {
sl@0
  1906
    catch {file delete -force -- tfa1 tfa2 tfa3}
sl@0
  1907
    createfile tfa1 
sl@0
  1908
    createfile tfa2 
sl@0
  1909
    createfile tfa3 
sl@0
  1910
    set result [catch {file copy tfa1 tfa2 tfa3}]
sl@0
  1911
    file delete tfa1 tfa2 tfa3
sl@0
  1912
    set result
sl@0
  1913
} {1}
sl@0
  1914
sl@0
  1915
test fCmd-21.5 {copy : multiple files into directory  } {notRoot} {
sl@0
  1916
    catch {file delete -force -- tfa1 tfa2 tfad}
sl@0
  1917
    set s1 [createfile tfa1 ]
sl@0
  1918
    set s2 [createfile tfa2 ]
sl@0
  1919
    file mkdir tfad
sl@0
  1920
    file copy tfa1 tfa2 tfad
sl@0
  1921
    set r1 [checkcontent tfad/tfa1 $s1]
sl@0
  1922
    set r2 [checkcontent tfad/tfa2 $s2]
sl@0
  1923
    set r3 [checkcontent tfa1 $s1]
sl@0
  1924
    set r4 [checkcontent tfa2 $s2]
sl@0
  1925
    set result [expr $r1 && $r2 && $r3 && $r4]
sl@0
  1926
    file delete -force tfa1 tfa2 tfad
sl@0
  1927
    set result
sl@0
  1928
} {1}
sl@0
  1929
sl@0
  1930
test fCmd-21.6 {copy: mixed dirs and files into directory} \
sl@0
  1931
	{notRoot notFileSharing} {
sl@0
  1932
    catch {file delete -force -- tfa1 tfad1 tfad2}
sl@0
  1933
    set s [createfile tfa1 ]
sl@0
  1934
    file mkdir tfad1 tfad2
sl@0
  1935
    file copy tfa1 tfad1 tfad2
sl@0
  1936
    set r1 [checkcontent [file join tfad2 tfa1] $s]
sl@0
  1937
    set r2 [file isdir [file join tfad2 tfad1]]
sl@0
  1938
    set r3 [checkcontent tfa1 $s]
sl@0
  1939
    set result [expr $r1 && $r2 && $r3 && [file isdir tfad1]]
sl@0
  1940
    file delete -force tfa1 tfad1 tfad2
sl@0
  1941
    set result
sl@0
  1942
} {1}
sl@0
  1943
sl@0
  1944
test fCmd-21.7.1 {TclCopyFilesCmd: copy a dangling link} {unixOnly notRoot dontCopyLinks} {
sl@0
  1945
    file mkdir tfad1
sl@0
  1946
    file link -symbolic tfalink tfad1
sl@0
  1947
    file delete tfad1
sl@0
  1948
    set result [list [catch {file copy tfalink tfalink2} msg] $msg]
sl@0
  1949
    file delete -force tfalink tfalink2 
sl@0
  1950
    set result
sl@0
  1951
} {1 {error copying "tfalink": the target of this link doesn't exist}}
sl@0
  1952
test fCmd-21.7.2 {TclCopyFilesCmd: copy a dangling link} {unixOnly notRoot} {
sl@0
  1953
    file mkdir tfad1
sl@0
  1954
    file link -symbolic tfalink tfad1
sl@0
  1955
    file delete tfad1
sl@0
  1956
    file copy tfalink tfalink2
sl@0
  1957
    set result [string match [file type tfalink2] link]
sl@0
  1958
    file delete tfalink tfalink2 
sl@0
  1959
    set result
sl@0
  1960
} {1}
sl@0
  1961
sl@0
  1962
test fCmd-21.8.1 {TclCopyFilesCmd: copy a link } {unixOnly notRoot dontCopyLinks} {
sl@0
  1963
    file mkdir tfad1
sl@0
  1964
    file link -symbolic tfalink tfad1
sl@0
  1965
    file copy tfalink tfalink2
sl@0
  1966
    set r1 [file type tfalink]; # link
sl@0
  1967
    set r2 [file type tfalink2]; # directory
sl@0
  1968
    set r3 [file isdir tfad1]; # 1
sl@0
  1969
    set result [expr {("$r1" == "link") && ("$r2" == "directory") && $r3}]
sl@0
  1970
    file delete -force tfad1 tfalink tfalink2
sl@0
  1971
    set result
sl@0
  1972
} {1}
sl@0
  1973
test fCmd-21.8.2 {TclCopyFilesCmd: copy a link } {unixOnly notRoot} {
sl@0
  1974
    file mkdir tfad1
sl@0
  1975
    file link -symbolic tfalink tfad1
sl@0
  1976
    file copy tfalink tfalink2
sl@0
  1977
    set r1 [file type tfalink]; # link
sl@0
  1978
    set r2 [file type tfalink2]; # link
sl@0
  1979
    set r3 [file isdir tfad1]; # 1
sl@0
  1980
    set result [expr {("$r1" == "link") && ("$r2" == "link") && $r3}]
sl@0
  1981
    file delete -force tfad1 tfalink tfalink2
sl@0
  1982
    set result
sl@0
  1983
} {1}
sl@0
  1984
sl@0
  1985
test fCmd-21.9 {TclCopyFilesCmd: copy dir with a link in it} {unixOnly notRoot} {
sl@0
  1986
    file mkdir tfad1
sl@0
  1987
    file link -symbolic tfad1/tfalink "[pwd]/tfad1"
sl@0
  1988
    file copy tfad1 tfad2
sl@0
  1989
    set result [string match [file type tfad2/tfalink] link]
sl@0
  1990
    file delete -force tfad1 tfad2
sl@0
  1991
    set result
sl@0
  1992
} {1}
sl@0
  1993
sl@0
  1994
test fCmd-21.10 {TclFileCopyCmd: copy dir on top of another empty dir w/o -force} \
sl@0
  1995
	{notRoot} {
sl@0
  1996
    catch {file delete -force -- tfa tfad}
sl@0
  1997
    file mkdir tfa [file join tfad tfa]
sl@0
  1998
    set r1 [catch {file copy tfa tfad}]
sl@0
  1999
    set result [expr $r1 && [file isdir tfa]]
sl@0
  2000
    file delete -force tfa tfad
sl@0
  2001
    set result
sl@0
  2002
} {1}
sl@0
  2003
sl@0
  2004
test fCmd-21.11 {TclFileCopyCmd: copy dir on top of a dir w/o -force} {notRoot} {
sl@0
  2005
    catch {file delete -force -- tfa tfad}
sl@0
  2006
    file mkdir tfa [file join tfad tfa file]
sl@0
  2007
    set r1 [catch {file copy tfa tfad}]
sl@0
  2008
    set result [expr $r1 && [file isdir tfa] && [file isdir [file join tfad tfa file]]]
sl@0
  2009
    file delete -force tfa tfad
sl@0
  2010
    set result
sl@0
  2011
} {1}
sl@0
  2012
sl@0
  2013
test fCmd-21.12 {TclFileCopyCmd: copy dir on top of a non-empty dir w/ -force} \
sl@0
  2014
	{notRoot} {
sl@0
  2015
    catch {file delete -force -- tfa tfad}
sl@0
  2016
    file mkdir tfa [file join tfad tfa file]
sl@0
  2017
    set r1 [catch {file copy -force tfa tfad}]
sl@0
  2018
    set result [expr $r1 && [file isdir tfa] && [file isdir [file join tfad tfa file]]]
sl@0
  2019
    file delete -force tfa tfad
sl@0
  2020
    set result
sl@0
  2021
} {1}
sl@0
  2022
sl@0
  2023
#
sl@0
  2024
# Coverage testing for TclpRenameFile
sl@0
  2025
#
sl@0
  2026
test fCmd-22.1 {TclpRenameFile: rename and overwrite in a single dir} {notRoot} {
sl@0
  2027
    catch {file delete -force -- tfa1 tfa2}
sl@0
  2028
    set s [createfile tfa1]
sl@0
  2029
    set s2 [createfile tfa2 q]
sl@0
  2030
	
sl@0
  2031
    set r1 [catch {rename tfa1 tfa2}]
sl@0
  2032
    file rename -force tfa1 tfa2
sl@0
  2033
    set result [expr $r1 && [checkcontent tfa2 $s]]
sl@0
  2034
    file delete [glob tfa1 tfa2]
sl@0
  2035
    set result
sl@0
  2036
} {1}
sl@0
  2037
sl@0
  2038
test fCmd-22.2 {TclpRenameFile: attempt to overwrite itself} {macOrUnix notRoot} {
sl@0
  2039
    catch {file delete -force -- tfa1}
sl@0
  2040
    set s [createfile tfa1]	
sl@0
  2041
    file rename -force tfa1 tfa1
sl@0
  2042
    set result [checkcontent tfa1 $s]
sl@0
  2043
    file delete tfa1 
sl@0
  2044
    set result
sl@0
  2045
} {1}
sl@0
  2046
sl@0
  2047
test fCmd-22.3 {TclpRenameFile: rename dir to existing dir} {notRoot} {
sl@0
  2048
    catch {file delete -force -- d1 tfad}
sl@0
  2049
    file mkdir d1 [file join tfad d1]
sl@0
  2050
    set r1 [catch {file rename d1 tfad}]
sl@0
  2051
    set result [expr $r1 && [file isdir d1] && [file isdir [file join tfad d1]]]
sl@0
  2052
    file delete -force d1 tfad
sl@0
  2053
    set result
sl@0
  2054
} {1}
sl@0
  2055
sl@0
  2056
test fCmd-22.4 {TclpRenameFile: rename dir to dir several levels deep} {notRoot} {
sl@0
  2057
    catch {file delete -force -- d1 tfad}
sl@0
  2058
    file mkdir d1 [file join tfad a b c]
sl@0
  2059
    file rename d1 [file join tfad a b c d1]
sl@0
  2060
    set result [expr ![file isdir d1] && [file isdir [file join tfad a b c d1]]]
sl@0
  2061
    file delete -force [glob d1 tfad]
sl@0
  2062
    set result
sl@0
  2063
} {1}
sl@0
  2064
sl@0
  2065
sl@0
  2066
#
sl@0
  2067
# TclMacCopyFile needs to be redone.
sl@0
  2068
#
sl@0
  2069
test fCmd-22.5 {TclMacCopyFile: copy and overwrite in a single dir} {notRoot} {
sl@0
  2070
    catch {file delete -force -- tfa1 tfa2}
sl@0
  2071
    set s [createfile tfa1]
sl@0
  2072
    set s2 [createfile tfa2 q]
sl@0
  2073
sl@0
  2074
    set r1 [catch {file copy tfa1 tfa2}]
sl@0
  2075
    file copy -force tfa1 tfa2
sl@0
  2076
    set result [expr $r1 && [checkcontent tfa2 $s] && [checkcontent tfa1 $s]]
sl@0
  2077
    file delete tfa1 tfa2
sl@0
  2078
    set result
sl@0
  2079
} {1}
sl@0
  2080
sl@0
  2081
#
sl@0
  2082
# TclMacMkdir - basic cases are covered elsewhere.
sl@0
  2083
# Error cases are not covered.
sl@0
  2084
#
sl@0
  2085
sl@0
  2086
#
sl@0
  2087
# TclMacRmdir
sl@0
  2088
# Error cases are not covered.
sl@0
  2089
#
sl@0
  2090
sl@0
  2091
test fCmd-23.1 {TclMacRmdir: trying to remove a nonempty directory} {notRoot} {
sl@0
  2092
    catch {file delete -force -- tfad}
sl@0
  2093
	
sl@0
  2094
    file mkdir [file join tfad dir]
sl@0
  2095
	
sl@0
  2096
    set result [catch {file delete tfad}]
sl@0
  2097
    file delete -force tfad 
sl@0
  2098
    set result
sl@0
  2099
} {1}
sl@0
  2100
sl@0
  2101
#
sl@0
  2102
# TclMacDeleteFile	
sl@0
  2103
# Error cases are not covered.
sl@0
  2104
#
sl@0
  2105
test fCmd-24.1 {TclMacDeleteFile: deleting a normal file} {notRoot} {
sl@0
  2106
    catch {file delete -force -- tfa1}
sl@0
  2107
	
sl@0
  2108
    createfile tfa1
sl@0
  2109
    file delete tfa1
sl@0
  2110
    file exists tfa1
sl@0
  2111
} {0}
sl@0
  2112
sl@0
  2113
#
sl@0
  2114
# TclMacCopyDirectory
sl@0
  2115
# Error cases are not covered.
sl@0
  2116
#
sl@0
  2117
test fCmd-25.1 {TclMacCopyDirectory: copying a normal directory} {notRoot notFileSharing} {
sl@0
  2118
    catch {file delete -force -- tfad1 tfad2}
sl@0
  2119
		
sl@0
  2120
    file mkdir [file join tfad1 a b c]
sl@0
  2121
    file copy tfad1 tfad2
sl@0
  2122
    set result [expr [file isdir [file join tfad1 a b c]] && [file isdir [file join tfad2 a b c]]]
sl@0
  2123
    file delete -force tfad1 tfad2
sl@0
  2124
    set result
sl@0
  2125
} {1}
sl@0
  2126
sl@0
  2127
test fCmd-25.2 {TclMacCopyDirectory: copying a short path normal directory} {notRoot notFileSharing} {
sl@0
  2128
    catch {file delete -force -- tfad1 tfad2}
sl@0
  2129
		
sl@0
  2130
    file mkdir tfad1
sl@0
  2131
    file copy tfad1 tfad2
sl@0
  2132
    set result [expr [file isdir tfad1] && [file isdir tfad2]]
sl@0
  2133
    file delete tfad1 tfad2
sl@0
  2134
    set result
sl@0
  2135
} {1}
sl@0
  2136
sl@0
  2137
test fCmd-25.3 {TclMacCopyDirectory: copying dirs between different dirs} {notRoot notFileSharing} {
sl@0
  2138
    catch {file delete -force -- tfad1 tfad2}
sl@0
  2139
		
sl@0
  2140
    file mkdir [file join tfad1 x y z]
sl@0
  2141
    file mkdir [file join tfad2 dir]
sl@0
  2142
    file copy tfad1 [file join tfad2 dir]
sl@0
  2143
    set result [expr [file isdir [file join tfad1 x y z]] && [file isdir [file join tfad2 dir tfad1 x y z]]]
sl@0
  2144
    file delete -force tfad1 tfad2
sl@0
  2145
    set result
sl@0
  2146
} {1}
sl@0
  2147
sl@0
  2148
#
sl@0
  2149
# Functionality tests for TclDeleteFilesCmd
sl@0
  2150
#
sl@0
  2151
sl@0
  2152
test fCmd-26.1 {TclDeleteFilesCmd: delete symlink} {unixOnly notRoot} {
sl@0
  2153
    catch {file delete -force -- tfad1 tfad2}
sl@0
  2154
		
sl@0
  2155
    file mkdir tfad1
sl@0
  2156
    file link -symbolic tfalink tfad1
sl@0
  2157
    file delete tfalink
sl@0
  2158
sl@0
  2159
    set r1 [file isdir tfad1]
sl@0
  2160
    set r2 [file exists tfalink]
sl@0
  2161
    
sl@0
  2162
    set result [expr $r1 && !$r2]
sl@0
  2163
    file delete tfad1
sl@0
  2164
    set result
sl@0
  2165
} {1}
sl@0
  2166
sl@0
  2167
test fCmd-26.2 {TclDeleteFilesCmd: delete dir with symlink} {unixOnly notRoot} {
sl@0
  2168
    catch {file delete -force -- tfad1 tfad2}
sl@0
  2169
		
sl@0
  2170
    file mkdir tfad1
sl@0
  2171
    file mkdir tfad2
sl@0
  2172
    file link -symbolic [file join tfad2 link] tfad1
sl@0
  2173
    file delete -force tfad2
sl@0
  2174
sl@0
  2175
    set r1 [file isdir tfad1]
sl@0
  2176
    set r2 [file exists tfad2]
sl@0
  2177
    
sl@0
  2178
    set result [expr $r1 && !$r2]
sl@0
  2179
    file delete tfad1
sl@0
  2180
    set result
sl@0
  2181
} {1}
sl@0
  2182
sl@0
  2183
test fCmd-26.3 {TclDeleteFilesCmd: delete dangling symlink} {unixOnly notRoot} {
sl@0
  2184
    catch {file delete -force -- tfad1 tfad2}
sl@0
  2185
		
sl@0
  2186
    file mkdir tfad1
sl@0
  2187
    file link -symbolic tfad2 tfad1
sl@0
  2188
    file delete tfad1
sl@0
  2189
    file delete tfad2
sl@0
  2190
sl@0
  2191
    set r1 [file exists tfad1]
sl@0
  2192
    set r2 [file exists tfad2]
sl@0
  2193
    
sl@0
  2194
    set result [expr !$r1 && !$r2]
sl@0
  2195
    set result
sl@0
  2196
} {1}
sl@0
  2197
sl@0
  2198
test fCmd-27.2 {TclFileAttrsCmd - Tcl_TranslateFileName fails} {testsetplatform} {
sl@0
  2199
    set platform [testgetplatform]
sl@0
  2200
    testsetplatform unix
sl@0
  2201
    list [catch {file attributes ~_totally_bogus_user} msg] $msg [testsetplatform $platform]
sl@0
  2202
} {1 {user "_totally_bogus_user" doesn't exist} {}}
sl@0
  2203
test fCmd-27.3 {TclFileAttrsCmd - all attributes} {
sl@0
  2204
    catch {file delete -force -- foo.tmp}
sl@0
  2205
    createfile foo.tmp
sl@0
  2206
    list [catch {file attributes foo.tmp} msg] [expr {[llength $msg] > 0}] [file delete -force -- foo.tmp]
sl@0
  2207
} {0 1 {}}
sl@0
  2208
test fCmd-27.4 {TclFileAttrsCmd - getting one option} {
sl@0
  2209
    catch {file delete -force -- foo.tmp}
sl@0
  2210
    createfile foo.tmp
sl@0
  2211
    set attrs [file attributes foo.tmp]
sl@0
  2212
    list [catch {eval file attributes foo.tmp [lindex $attrs 0]}] [file delete -force -- foo.tmp]
sl@0
  2213
} {0 {}}
sl@0
  2214
sl@0
  2215
# Find a group that exists on this Unix system, or else skip tests that
sl@0
  2216
# require Unix groups.
sl@0
  2217
if {$tcl_platform(platform) == "unix"} {
sl@0
  2218
    ::tcltest::testConstraint foundGroup 0
sl@0
  2219
    catch {
sl@0
  2220
	set groupList [exec groups]
sl@0
  2221
	set group [lindex $groupList 0]
sl@0
  2222
	::tcltest::testConstraint foundGroup 1
sl@0
  2223
    }
sl@0
  2224
} else {
sl@0
  2225
    ::tcltest::testConstraint foundGroup 1
sl@0
  2226
}
sl@0
  2227
sl@0
  2228
test fCmd-27.5 {TclFileAttrsCmd - setting one option} {foundGroup} {
sl@0
  2229
    catch {file delete -force -- foo.tmp}
sl@0
  2230
    createfile foo.tmp
sl@0
  2231
    set attrs [file attributes foo.tmp]
sl@0
  2232
    list [catch {eval file attributes foo.tmp [lrange $attrs 0 1]} msg] $msg [file delete -force -- foo.tmp]
sl@0
  2233
} {0 {} {}}
sl@0
  2234
test fCmd-27.6 {TclFileAttrsCmd - setting more than one option} {foundGroup} {
sl@0
  2235
    catch {file delete -force -- foo.tmp}
sl@0
  2236
    createfile foo.tmp
sl@0
  2237
    set attrs [file attributes foo.tmp]
sl@0
  2238
    list [catch {eval file attributes foo.tmp [lrange $attrs 0 3]} msg] $msg [file delete -force -- foo.tmp]
sl@0
  2239
} {0 {} {}}
sl@0
  2240
sl@0
  2241
if {[string equal $tcl_platform(platform) "windows"]} {
sl@0
  2242
    if {[string index $tcl_platform(osVersion) 0] >= 5 \
sl@0
  2243
      && ([lindex [file system [temporaryDirectory]] 1] == "NTFS")} {
sl@0
  2244
	tcltest::testConstraint linkDirectory 1
sl@0
  2245
	tcltest::testConstraint linkFile 1
sl@0
  2246
    } else {
sl@0
  2247
	tcltest::testConstraint linkDirectory 0
sl@0
  2248
	tcltest::testConstraint linkFile 0
sl@0
  2249
    }
sl@0
  2250
} else {
sl@0
  2251
    tcltest::testConstraint linkFile 1
sl@0
  2252
    tcltest::testConstraint linkDirectory 1
sl@0
  2253
    
sl@0
  2254
    if {[string equal $tcl_platform(osSystemName) "Symbian"]} {
sl@0
  2255
       tcltest::testConstraint linkDirectory 0
sl@0
  2256
    }
sl@0
  2257
}
sl@0
  2258
sl@0
  2259
test fCmd-28.1 {file link} {
sl@0
  2260
    list [catch {file link} msg] $msg
sl@0
  2261
} {1 {wrong # args: should be "file link ?-linktype? linkname ?target?"}}
sl@0
  2262
sl@0
  2263
test fCmd-28.2 {file link} {
sl@0
  2264
    list [catch {file link a b c d} msg] $msg
sl@0
  2265
} {1 {wrong # args: should be "file link ?-linktype? linkname ?target?"}}
sl@0
  2266
sl@0
  2267
test fCmd-28.3 {file link} {
sl@0
  2268
    list [catch {file link abc b c} msg] $msg
sl@0
  2269
} {1 {bad switch "abc": must be -symbolic or -hard}}
sl@0
  2270
sl@0
  2271
test fCmd-28.4 {file link} {
sl@0
  2272
    list [catch {file link -abc b c} msg] $msg
sl@0
  2273
} {1 {bad switch "-abc": must be -symbolic or -hard}}
sl@0
  2274
cd [workingDirectory]
sl@0
  2275
sl@0
  2276
makeDirectory abc.dir
sl@0
  2277
makeDirectory abc2.dir
sl@0
  2278
makeFile contents abc.file
sl@0
  2279
makeFile contents abc2.file
sl@0
  2280
sl@0
  2281
cd [temporaryDirectory]
sl@0
  2282
test fCmd-28.5 {file link: source already exists} {linkDirectory} {
sl@0
  2283
    cd [temporaryDirectory]
sl@0
  2284
    set res [list [catch {file link abc.dir abc2.dir} msg] $msg]
sl@0
  2285
    cd [workingDirectory]
sl@0
  2286
    set res
sl@0
  2287
} {1 {could not create new link "abc.dir": that path already exists}}
sl@0
  2288
sl@0
  2289
test fCmd-28.6 {file link: unsupported operation} {linkDirectory macOrWin} {
sl@0
  2290
    cd [temporaryDirectory]
sl@0
  2291
    set res [list [catch {file link -hard abc.link abc.dir} msg] $msg]
sl@0
  2292
    cd [workingDirectory]
sl@0
  2293
    set res
sl@0
  2294
} {1 {could not create new link "abc.link" pointing to "abc.dir": illegal operation on a directory}}
sl@0
  2295
sl@0
  2296
test fCmd-28.7 {file link: source already exists} {linkFile} {
sl@0
  2297
    cd [temporaryDirectory]
sl@0
  2298
    set res [list [catch {file link abc.file abc2.file} msg] $msg]
sl@0
  2299
    cd [workingDirectory]
sl@0
  2300
    set res
sl@0
  2301
} {1 {could not create new link "abc.file": that path already exists}}
sl@0
  2302
sl@0
  2303
test fCmd-28.8 {file link} {linkFile winOnly} {
sl@0
  2304
    cd [temporaryDirectory]
sl@0
  2305
    set res [list [catch {file link -symbolic abc.link abc.file} msg] $msg]
sl@0
  2306
    cd [workingDirectory]
sl@0
  2307
    set res
sl@0
  2308
} {1 {could not create new link "abc.link" pointing to "abc.file": not a directory}}
sl@0
  2309
sl@0
  2310
test fCmd-28.9 {file link: success with file} {linkFile} {
sl@0
  2311
    cd [temporaryDirectory]
sl@0
  2312
    file delete -force abc.link
sl@0
  2313
    set res [list [catch {file link abc.link abc.file} msg] $msg]
sl@0
  2314
    cd [workingDirectory]
sl@0
  2315
    set res
sl@0
  2316
} {0 abc.file}
sl@0
  2317
sl@0
  2318
cd [temporaryDirectory]
sl@0
  2319
catch {file delete -force abc.link}
sl@0
  2320
cd [workingDirectory]
sl@0
  2321
sl@0
  2322
test fCmd-28.10 {file link: linking to nonexistent path} {linkDirectory} {
sl@0
  2323
    cd [temporaryDirectory]
sl@0
  2324
    file delete -force abc.link
sl@0
  2325
    set res [list [catch {file link abc.link abc2.doesnt} msg] $msg]
sl@0
  2326
    cd [workingDirectory]
sl@0
  2327
    set res
sl@0
  2328
} {1 {could not create new link "abc.link" since target "abc2.doesnt" doesn't exist}}
sl@0
  2329
sl@0
  2330
test fCmd-28.11 {file link: success with directory} {linkDirectory} {
sl@0
  2331
    cd [temporaryDirectory]
sl@0
  2332
    file delete -force abc.link
sl@0
  2333
    set res [list [catch {file link abc.link abc.dir} msg] $msg]
sl@0
  2334
    cd [workingDirectory]
sl@0
  2335
    set res
sl@0
  2336
} {0 abc.dir}
sl@0
  2337
sl@0
  2338
test fCmd-28.12 {file link: cd into a link} {linkDirectory} {
sl@0
  2339
    cd [temporaryDirectory]
sl@0
  2340
    file delete -force abc.link
sl@0
  2341
    file link abc.link abc.dir
sl@0
  2342
    set orig [pwd]
sl@0
  2343
    cd abc.link
sl@0
  2344
    set dir [pwd]
sl@0
  2345
    cd ..
sl@0
  2346
    set up [pwd]
sl@0
  2347
    cd $orig
sl@0
  2348
    # now '$up' should be either $orig or [file dirname abc.dir],
sl@0
  2349
    # depending on whether 'cd' actually moves to the destination
sl@0
  2350
    # of a link, or simply treats the link as a directory.
sl@0
  2351
    # (on windows the former, on unix the latter, I believe)
sl@0
  2352
    if {([file normalize $up] != [file normalize $orig]) \
sl@0
  2353
      && ([file normalize $up] != [file normalize [file dirname abc.dir]])} {
sl@0
  2354
	set res "wrong directory with 'cd $link ; cd ..'"
sl@0
  2355
    } else {
sl@0
  2356
	set res "ok"
sl@0
  2357
    }
sl@0
  2358
    cd [workingDirectory]
sl@0
  2359
    set res
sl@0
  2360
} {ok}
sl@0
  2361
sl@0
  2362
test fCmd-28.13 {file link} {linkDirectory} {
sl@0
  2363
    # duplicate link throws error
sl@0
  2364
    cd [temporaryDirectory]
sl@0
  2365
    set res [list [catch {file link abc.link abc.dir} msg] $msg]
sl@0
  2366
    cd [workingDirectory]
sl@0
  2367
    set res
sl@0
  2368
} {1 {could not create new link "abc.link": that path already exists}}
sl@0
  2369
sl@0
  2370
test fCmd-28.14 {file link: deletes link not dir} {linkDirectory} {
sl@0
  2371
    cd [temporaryDirectory]
sl@0
  2372
    file delete -force abc.link
sl@0
  2373
    set res [list [file exists abc.link] [file exists abc.dir]]
sl@0
  2374
    cd [workingDirectory]
sl@0
  2375
    set res
sl@0
  2376
} {0 1}
sl@0
  2377
sl@0
  2378
test fCmd-28.15.1 {file link: copies link not dir} {linkDirectory dontCopyLinks} {
sl@0
  2379
    cd [temporaryDirectory]
sl@0
  2380
    file delete -force abc.link
sl@0
  2381
    file link abc.link abc.dir
sl@0
  2382
    file copy abc.link abc2.link
sl@0
  2383
    # abc2.linkdir was a copy of a link to a dir, so it should end up as
sl@0
  2384
    # a directory, not a link (links trace to endpoint).
sl@0
  2385
    set res [list [file type abc2.link] [file tail [file link abc.link]]]
sl@0
  2386
    cd [workingDirectory]
sl@0
  2387
    set res
sl@0
  2388
} {directory abc.dir}
sl@0
  2389
test fCmd-28.15.2 {file link: copies link not dir} {linkDirectory} {
sl@0
  2390
    cd [temporaryDirectory]
sl@0
  2391
    file delete -force abc.link
sl@0
  2392
    file link abc.link abc.dir
sl@0
  2393
    file copy abc.link abc2.link
sl@0
  2394
    set res [list [file type abc2.link] [file tail [file link abc2.link]]]
sl@0
  2395
    cd [workingDirectory]
sl@0
  2396
    set res
sl@0
  2397
} {link abc.dir}
sl@0
  2398
sl@0
  2399
cd [temporaryDirectory]
sl@0
  2400
file delete -force abc.link
sl@0
  2401
file delete -force abc2.link
sl@0
  2402
sl@0
  2403
file copy abc.file abc.dir
sl@0
  2404
file copy abc2.file abc.dir
sl@0
  2405
cd [workingDirectory]
sl@0
  2406
sl@0
  2407
test fCmd-28.16 {file link: glob inside link} {linkDirectory} {
sl@0
  2408
    cd [temporaryDirectory]
sl@0
  2409
    file delete -force abc.link
sl@0
  2410
    file link abc.link abc.dir
sl@0
  2411
    set res [lsort [glob -dir abc.link -tails *]]
sl@0
  2412
    cd [workingDirectory]
sl@0
  2413
    set res
sl@0
  2414
} [lsort [list abc.file abc2.file]]
sl@0
  2415
sl@0
  2416
test fCmd-28.17 {file link: glob -type l} {linkDirectory} {
sl@0
  2417
    cd [temporaryDirectory]
sl@0
  2418
    set res [glob -dir [pwd] -type l -tails abc*]
sl@0
  2419
    cd [workingDirectory]
sl@0
  2420
    set res
sl@0
  2421
} {abc.link}
sl@0
  2422
sl@0
  2423
test fCmd-28.18 {file link: glob -type d} {linkDirectory} {
sl@0
  2424
    cd [temporaryDirectory]
sl@0
  2425
    set res [lsort [glob -dir [pwd] -type d -tails abc*]]
sl@0
  2426
    cd [workingDirectory]
sl@0
  2427
    set res
sl@0
  2428
} [lsort [list abc.link abc.dir abc2.dir]]
sl@0
  2429
sl@0
  2430
test fCmd-29.1 {weird memory corruption fault} {
sl@0
  2431
    catch {set res [open [file join ~a_totally_bogus_user_id/foo bar]]}
sl@0
  2432
} 1
sl@0
  2433
sl@0
  2434
cd [temporaryDirectory]
sl@0
  2435
file delete -force abc.link
sl@0
  2436
cd [workingDirectory]
sl@0
  2437
sl@0
  2438
removeFile abc2.file
sl@0
  2439
removeFile abc.file
sl@0
  2440
removeDirectory abc2.dir
sl@0
  2441
removeDirectory abc.dir
sl@0
  2442
sl@0
  2443
# cleanup
sl@0
  2444
cleanup
sl@0
  2445
::tcltest::cleanupTests
sl@0
  2446
return