PageRenderTime 174ms CodeModel.GetById 4ms app.highlight 158ms RepoModel.GetById 1ms app.codeStats 0ms

/brlcad/branches/dmtogl/src/other/tcl/tests/fCmd.test

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
Unknown | 2537 lines | 2471 code | 66 blank | 0 comment | 0 complexity | 9c1c36b9def7a727d9cf24ab654efbc1 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1# This file tests the tclFCmd.c file.
   2#
   3# This file contains a collection of tests for one or more of the Tcl built-in
   4# commands. Sourcing this file into Tcl runs the tests and generates output
   5# for errors. No output means no errors were found.
   6#
   7# Copyright (c) 1996-1997 Sun Microsystems, Inc.
   8# Copyright (c) 1999 by Scriptics Corporation.
   9#
  10# See the file "license.terms" for information on usage and redistribution of
  11# this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12#
  13# RCS: @(#) $Id$
  14#
  15
  16if {[lsearch [namespace children] ::tcltest] == -1} {
  17    package require tcltest 2
  18    namespace import -force ::tcltest::*
  19}
  20
  21testConstraint testsetplatform [llength [info commands testsetplatform]]
  22testConstraint testchmod [llength [info commands testchmod]]
  23testConstraint winVista 0
  24testConstraint win2000orXP 0
  25testConstraint winOlderThan2000 0
  26# Don't know how to determine this constraint correctly
  27testConstraint notNetworkFilesystem 0
  28testConstraint 95or98 [expr {[testConstraint 95] || [testConstraint 98]}]
  29testConstraint 2000orNewer [expr {![testConstraint 95or98]}]
  30
  31# Find a group that exists on this Unix system, or else skip tests that
  32# require Unix groups.
  33testConstraint foundGroup [expr {![testConstraint unix]}]
  34if {[testConstraint unix]} {
  35    catch {
  36	set groupList [exec groups]
  37	set group [lindex $groupList 0]
  38	testConstraint foundGroup 1
  39    }
  40}
  41
  42# Also used in winFCmd...
  43if {[testConstraint winOnly]} {
  44    set major [string index $tcl_platform(osVersion) 0]
  45    if {[testConstraint nt] && $major > 4} {
  46        if {$major > 5} {
  47            testConstraint winVista 1
  48        } elseif {$major == 5} {
  49            testConstraint win2000orXP 1
  50        }
  51    } else {
  52        testConstraint winOlderThan2000 1
  53    }
  54}
  55
  56testConstraint darwin9 [expr {[testConstraint unix] &&
  57	$tcl_platform(os) eq "Darwin" &&
  58	int([string range $tcl_platform(osVersion) 0 \
  59	[string first . $tcl_platform(osVersion)]]) >= 9}]
  60testConstraint notDarwin9 [expr {![testConstraint darwin9]}]
  61
  62testConstraint fileSharing 0
  63testConstraint notFileSharing 1
  64testConstraint linkFile 1
  65testConstraint linkDirectory 1
  66
  67# Several tests require need to match results against the unix username
  68set user {}
  69if {[testConstraint unix]} {
  70    catch {
  71	set user [exec whoami]
  72    }
  73    if {$user eq ""} {
  74	catch {
  75	    regexp {^[^(]*\(([^)]*)\)} [exec id] -> user
  76	}
  77    }
  78    if {$user eq ""} {
  79	set user "root"
  80    }
  81}
  82
  83proc createfile {file {string a}} {
  84    set f [open $file w]
  85    puts -nonewline $f $string
  86    close $f
  87    return $string
  88}
  89
  90#
  91# checkcontent --
  92#
  93#  Ensures that file "file" contains only the string "matchString" returns 0
  94#  if the file does not exist, or has a different content
  95#
  96proc checkcontent {file matchString} {
  97    if {[catch {
  98	set f [open $file]
  99	set fileString [read $f]
 100	close $f
 101    }]} {
 102	return 0
 103    }
 104    return [string match $matchString $fileString]
 105}
 106
 107proc openup {path} {
 108    testchmod 777 $path
 109    if {[file isdirectory $path]} {
 110	catch {
 111	    foreach p [glob -directory $path *] {
 112		openup $p
 113	    }
 114	}
 115    }
 116}
 117
 118proc cleanup {args} {
 119    set wd [list .]
 120    foreach p [concat $wd $args] {
 121	set x ""
 122	catch {
 123	    set x [glob -directory $p tf* td*]
 124	}
 125	foreach file $x {
 126	    if {
 127		[catch {file delete -force -- $file}]
 128		&& [testConstraint testchmod]
 129	    } then {
 130		catch {openup $file}
 131		catch {file delete -force -- $file}
 132	    }
 133	}
 134    }
 135}
 136
 137proc contents {file} {
 138    set f [open $file]
 139    set r [read $f]
 140    close $f
 141    return $r
 142}
 143
 144cd [temporaryDirectory]
 145
 146proc dev dir {
 147    file stat $dir stat
 148    return $stat(dev)
 149}
 150testConstraint xdev [expr {[testConstraint unix] && ([dev .] != [dev /tmp])}]
 151
 152set root [lindex [file split [pwd]] 0]
 153
 154# A really long file name
 155# length of long is 1216 chars, which should be greater than any static buffer
 156# or allowable filename.
 157
 158set long "abcdefghihjllmnopqrstuvwxyz01234567890"
 159append long $long
 160append long $long
 161append long $long
 162append long $long
 163append long $long
 164
 165test fCmd-1.1 {TclFileRenameCmd} {notRoot} {
 166    cleanup
 167    createfile tf1
 168    file rename tf1 tf2
 169    glob tf*
 170} {tf2}
 171
 172test fCmd-2.1 {TclFileCopyCmd} {notRoot} {
 173    cleanup
 174    createfile tf1
 175    file copy tf1 tf2
 176    lsort [glob tf*]
 177} {tf1 tf2}
 178
 179test fCmd-3.1 {FileCopyRename: FileForceOption fails} -constraints {notRoot} -body {
 180    file rename -xyz
 181} -returnCodes error -result {bad option "-xyz": should be -force or --}
 182test fCmd-3.2 {FileCopyRename: not enough args} -constraints {notRoot} -body {
 183    file rename xyz
 184} -returnCodes error -result {wrong # args: should be "file rename ?options? source ?source ...? target"}
 185test fCmd-3.3 {FileCopyRename: Tcl_TranslateFileName fails} -constraints {notRoot} -body {
 186    file rename xyz ~_totally_bogus_user
 187} -returnCodes error -result {user "_totally_bogus_user" doesn't exist}
 188test fCmd-3.4 {FileCopyRename: Tcl_TranslateFileName passes} -setup {
 189    cleanup
 190} -constraints {notRoot} -returnCodes error -body {
 191    file copy tf1 ~
 192} -result {error copying "tf1": no such file or directory}
 193test fCmd-3.5 {FileCopyRename: target doesn't exist: stat(target) != 0} -setup {
 194    cleanup
 195} -constraints {notRoot} -returnCodes error -body {
 196    file rename tf1 tf2 tf3
 197} -result {error renaming: target "tf3" is not a directory}
 198test fCmd-3.6 {FileCopyRename: target tf3 is not a dir: !S_ISDIR(target)} -setup {
 199    cleanup
 200} -constraints {notRoot} -returnCodes error -body {
 201    createfile tf3
 202    file rename tf1 tf2 tf3
 203} -result {error renaming: target "tf3" is not a directory}
 204test fCmd-3.7 {FileCopyRename: target exists & is directory} -setup {
 205    cleanup
 206} -constraints {notRoot} -body {
 207    file mkdir td1
 208    createfile tf1 tf1
 209    file rename tf1 td1
 210    contents [file join td1 tf1]
 211} -result {tf1}
 212test fCmd-3.8 {FileCopyRename: too many arguments: argc - i > 2} -setup {
 213    cleanup
 214} -constraints {notRoot} -returnCodes error -body {
 215    file rename tf1 tf2 tf3
 216} -result {error renaming: target "tf3" is not a directory}
 217test fCmd-3.9 {FileCopyRename: too many arguments: argc - i > 2} -setup {
 218    cleanup
 219} -constraints {notRoot} -returnCodes error -body {
 220    file copy -force -- tf1 tf2 tf3
 221} -result {error copying: target "tf3" is not a directory}
 222test fCmd-3.10 {FileCopyRename: just 2 arguments} {notRoot} {
 223    cleanup
 224    createfile tf1 tf1
 225    file rename tf1 tf2
 226    contents tf2
 227} {tf1}
 228test fCmd-3.11 {FileCopyRename: just 2 arguments} {notRoot} {
 229    cleanup
 230    createfile tf1 tf1
 231    file rename -force -force -- tf1 tf2
 232    contents tf2
 233} {tf1}
 234test fCmd-3.12 {FileCopyRename: move each source: 1 source} {notRoot} {
 235    cleanup
 236    createfile tf1 tf1
 237    file mkdir td1
 238    file rename tf1 td1
 239    contents [file join td1 tf1]
 240} {tf1}
 241test fCmd-3.13 {FileCopyRename: move each source: multiple sources} {notRoot} {
 242    cleanup
 243    createfile tf1 tf1
 244    createfile tf2 tf2
 245    createfile tf3 tf3
 246    createfile tf4 tf4
 247    file mkdir td1
 248    file rename tf1 tf2 tf3 tf4 td1
 249    list [contents [file join td1 tf1]] [contents [file join td1 tf2]] \
 250	[contents [file join td1 tf3]] [contents [file join td1 tf4]]
 251} {tf1 tf2 tf3 tf4}
 252test fCmd-3.14 {FileCopyRename: FileBasename fails} -setup {
 253    cleanup
 254} -constraints {notRoot} -returnCodes error -body {
 255    file mkdir td1
 256    file rename ~_totally_bogus_user td1
 257} -result {user "_totally_bogus_user" doesn't exist}
 258test fCmd-3.15 {FileCopyRename: source[0] == '\0'} -setup {
 259    cleanup
 260} -constraints {notRoot unixOrPc} -returnCodes error -body {
 261    file mkdir td1
 262    file rename / td1
 263} -result {error renaming "/" to "td1": file already exists}
 264test fCmd-3.16 {FileCopyRename: break on first error} -setup {
 265    cleanup
 266} -constraints {notRoot} -returnCodes error -body {
 267    createfile tf1
 268    createfile tf2
 269    createfile tf3
 270    createfile tf4
 271    file mkdir td1
 272    createfile [file join td1 tf3]
 273    file rename tf1 tf2 tf3 tf4 td1
 274} -result [subst {error renaming "tf3" to "[file join td1 tf3]": file already exists}]
 275
 276test fCmd-4.1 {TclFileMakeDirsCmd: make each dir: 1 dir} {notRoot} {
 277    cleanup
 278    file mkdir td1
 279    glob td*
 280} {td1}
 281test fCmd-4.2 {TclFileMakeDirsCmd: make each dir: multiple dirs} {notRoot} {
 282    cleanup
 283    file mkdir td1 td2 td3
 284    lsort [glob td*]
 285} {td1 td2 td3}
 286test fCmd-4.3 {TclFileMakeDirsCmd: stops on first error} {notRoot} {
 287    cleanup
 288    createfile tf1
 289    catch {file mkdir td1 td2 tf1 td3 td4}
 290    glob td1 td2 tf1 td3 td4
 291} {td1 td2 tf1}
 292test fCmd-4.4 {TclFileMakeDirsCmd: Tcl_TranslateFileName fails} -setup {
 293    cleanup
 294} -constraints {notRoot} -returnCodes error -body {
 295    file mkdir ~_totally_bogus_user
 296} -result {user "_totally_bogus_user" doesn't exist}
 297test fCmd-4.5 {TclFileMakeDirsCmd: Tcl_SplitPath returns 0: *name == '\0'} -setup {
 298    cleanup
 299} -constraints {notRoot} -returnCodes error -body {
 300    file mkdir ""
 301} -result {can't create directory "": no such file or directory}
 302test fCmd-4.6 {TclFileMakeDirsCmd: one level deep} {notRoot} {
 303    cleanup
 304    file mkdir td1
 305    glob td1
 306} {td1}
 307test fCmd-4.7 {TclFileMakeDirsCmd: multi levels deep} {notRoot} {
 308    cleanup
 309    file mkdir [file join td1 td2 td3 td4]
 310    glob td1 [file join td1 td2]
 311} "td1 [file join td1 td2]"
 312test fCmd-4.8 {TclFileMakeDirsCmd: already exist: lstat(target) == 0} {notRoot} {
 313    cleanup
 314    file mkdir td1
 315    set x [file exists td1]
 316    file mkdir td1
 317    list $x [file exists td1]
 318} {1 1}
 319test fCmd-4.9 {TclFileMakeDirsCmd: exists, not dir} -setup {
 320    cleanup
 321} -constraints {notRoot} -returnCodes error -body {
 322    createfile tf1
 323    file mkdir tf1
 324} -result [subst {can't create directory "[file join tf1]": file already exists}]
 325test fCmd-4.10 {TclFileMakeDirsCmd: exists, is dir} {notRoot} {
 326    cleanup
 327    file mkdir td1
 328    set x [file exists td1]
 329    file mkdir td1
 330    list $x [file exists td1]
 331} {1 1}
 332test fCmd-4.11 {TclFileMakeDirsCmd: doesn't exist: errno != ENOENT} -setup {
 333    cleanup
 334} -constraints {unix notRoot testchmod} -returnCodes error -body {
 335    file mkdir td1/td2/td3
 336    testchmod 000 td1/td2
 337    file mkdir td1/td2/td3/td4
 338} -cleanup {
 339    testchmod 755 td1/td2
 340    cleanup
 341} -result {can't create directory "td1/td2/td3": permission denied}
 342test fCmd-4.13 {TclFileMakeDirsCmd: doesn't exist: errno == ENOENT} -setup {
 343    cleanup
 344} -constraints {notRoot} -body {
 345    set x [file exists td1]
 346    file mkdir td1
 347    list $x [file exists td1]
 348} -result {0 1}
 349test fCmd-4.14 {TclFileMakeDirsCmd: TclpCreateDirectory fails} -setup {
 350    cleanup
 351    file delete -force foo
 352} -constraints {unix notRoot} -body {
 353    file mkdir foo
 354    file attr foo -perm 040000
 355    file mkdir foo/tf1
 356} -returnCodes error -cleanup {
 357    file delete -force foo
 358} -result {can't create directory "foo/tf1": permission denied}
 359test fCmd-4.16 {TclFileMakeDirsCmd: TclpCreateDirectory succeeds} {notRoot} {
 360    cleanup
 361    file mkdir tf1
 362    file exists tf1
 363} {1}
 364
 365test fCmd-5.1 {TclFileDeleteCmd: FileForceOption fails} -constraints {notRoot} -body {
 366    file delete -xyz
 367} -returnCodes error -result {bad option "-xyz": should be -force or --}
 368test fCmd-5.2 {TclFileDeleteCmd: not enough args} -constraints {notRoot} -body {
 369    file delete -force -force
 370} -returnCodes error -result {wrong # args: should be "file delete ?options? file ?file ...?"}
 371test fCmd-5.3 {TclFileDeleteCmd: 1 file} {notRoot} {
 372    cleanup
 373    createfile tf1
 374    createfile tf2
 375    file mkdir td1
 376    file delete tf2
 377    glob tf* td*
 378} {tf1 td1}
 379test fCmd-5.4 {TclFileDeleteCmd: multiple files} {notRoot} {
 380    cleanup
 381    createfile tf1
 382    createfile tf2
 383    file mkdir td1
 384    set x [list [file exists tf1] [file exists tf2] [file exists td1]]
 385    file delete tf1 td1 tf2
 386    lappend x [file exists tf1] [file exists tf2] [file exists tf3]
 387} {1 1 1 0 0 0}
 388test fCmd-5.5 {TclFileDeleteCmd: stop at first error} {notRoot unixOrPc} {
 389    cleanup
 390    createfile tf1
 391    createfile tf2
 392    file mkdir td1
 393    catch {file delete tf1 td1 $root tf2}
 394    list [file exists tf1] [file exists tf2] [file exists td1]
 395} {0 1 0}
 396test fCmd-5.6 {TclFileDeleteCmd: Tcl_TranslateFileName fails} -constraints {notRoot} -body {
 397    file delete ~_totally_bogus_user
 398} -returnCodes error -result {user "_totally_bogus_user" doesn't exist}
 399test fCmd-5.7 {TclFileDeleteCmd: Tcl_TranslateFileName succeeds} {notRoot} {
 400    catch {file delete ~/tf1}
 401    createfile ~/tf1
 402    file delete ~/tf1
 403} {}
 404test fCmd-5.8 {TclFileDeleteCmd: file doesn't exist: lstat(name) != 0} {notRoot} {
 405    cleanup
 406    set x [file exists tf1]
 407    file delete tf1
 408    list $x [file exists tf1]
 409} {0 0}
 410test fCmd-5.9 {TclFileDeleteCmd: is directory} {notRoot} {
 411    cleanup
 412    file mkdir td1
 413    file delete td1
 414    file exists td1
 415} {0}
 416test fCmd-5.10 {TclFileDeleteCmd: TclpRemoveDirectory fails} -setup {
 417    cleanup
 418} -constraints {notRoot} -returnCodes error -body {
 419    file mkdir [file join td1 td2]
 420    file delete td1
 421} -result {error deleting "td1": directory not empty}
 422test fCmd-5.11 {TclFileDeleteCmd: TclpRemoveDirectory with cwd inside} -setup {
 423    cleanup
 424    set dir [pwd]
 425} -constraints {notRoot} -body {
 426    file mkdir [file join td1 td2]
 427    cd [file join td1 td2]
 428    set res [list [catch {file delete -force [file dirname [pwd]]} msg]]
 429    cd $dir
 430    lappend res [file exists td1] $msg
 431} -cleanup {
 432    cd $dir
 433} -result {0 0 {}}
 434test fCmd-5.12 {TclFileDeleteCmd: TclpRemoveDirectory with bad perms} {unix} {
 435    cleanup
 436    file mkdir [file join td1 td2]
 437    #exec chmod u-rwx [file join td1 td2]
 438    file attributes [file join td1 td2] -permissions u+rwx
 439    set res [list [catch {file delete -force td1} msg]]
 440    lappend res [file exists td1] $msg
 441} {0 0 {}}
 442
 443test fCmd-6.1 {CopyRenameOneFile: bad source} {notRoot emptyTest} {
 444    # can't test this, because it's caught by FileCopyRename
 445} {}
 446test fCmd-6.2 {CopyRenameOneFile: bad target} {notRoot emptyTest} {
 447    # can't test this, because it's caught by FileCopyRename
 448} {}
 449test fCmd-6.3 {CopyRenameOneFile: lstat(source) != 0} -setup {
 450    cleanup
 451} -constraints {notRoot} -returnCodes error -body {
 452    file rename tf1 tf2
 453} -result {error renaming "tf1": no such file or directory}
 454test fCmd-6.4 {CopyRenameOneFile: lstat(source) == 0} {notRoot} {
 455    cleanup
 456    createfile tf1
 457    file rename tf1 tf2
 458    glob tf*
 459} {tf2}
 460test fCmd-6.5 {CopyRenameOneFile: lstat(target) != 0} {notRoot} {
 461    cleanup
 462    createfile tf1
 463    file rename tf1 tf2
 464    glob tf*
 465} {tf2}
 466test fCmd-6.6 {CopyRenameOneFile: errno != ENOENT} -setup {
 467    cleanup
 468} -constraints {unix notRoot testchmod} -body {
 469    file mkdir td1
 470    testchmod 000 td1
 471    createfile tf1
 472    file rename tf1 td1
 473} -returnCodes error -cleanup {
 474    testchmod 755 td1
 475} -result {error renaming "tf1" to "td1/tf1": permission denied}
 476test fCmd-6.7 {CopyRenameOneFile: errno != ENOENT} -setup {
 477    cleanup
 478} -constraints {win 95} -returnCodes error -body {
 479    createfile tf1
 480    file rename tf1 $long
 481} -result [subst {error renaming "tf1" to "$long": file name too long}]
 482test fCmd-6.9 {CopyRenameOneFile: errno == ENOENT} {unix notRoot} {
 483    cleanup
 484    createfile tf1
 485    file rename tf1 tf2
 486    glob tf*
 487} {tf2}
 488test fCmd-6.10 {CopyRenameOneFile: lstat(target) == 0} -setup {
 489    cleanup
 490} -constraints {notRoot} -returnCodes error -body {
 491    createfile tf1
 492    createfile tf2
 493    file rename tf1 tf2
 494} -result {error renaming "tf1" to "tf2": file already exists}
 495test fCmd-6.11 {CopyRenameOneFile: force == 0} -setup {
 496    cleanup
 497} -constraints {notRoot} -returnCodes error -body {
 498    createfile tf1
 499    createfile tf2
 500    file rename tf1 tf2
 501} -result {error renaming "tf1" to "tf2": file already exists}
 502test fCmd-6.12 {CopyRenameOneFile: force != 0} {notRoot} {
 503    cleanup
 504    createfile tf1
 505    createfile tf2
 506    file rename -force tf1 tf2
 507    glob tf*
 508} {tf2}
 509test fCmd-6.13 {CopyRenameOneFile: source is dir, target is file} -setup {
 510    cleanup
 511} -constraints {notRoot} -returnCodes error -body {
 512    file mkdir td1
 513    file mkdir td2
 514    createfile [file join td2 td1]
 515    file rename -force td1 td2
 516} -result [subst {can't overwrite file "[file join td2 td1]" with directory "td1"}]
 517test fCmd-6.14 {CopyRenameOneFile: source is file, target is dir} -setup {
 518    cleanup
 519} -constraints {notRoot} -returnCodes error -body {
 520    createfile tf1
 521    file mkdir [file join td1 tf1]
 522    file rename -force tf1 td1
 523} -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
 524test fCmd-6.15 {CopyRenameOneFile: TclpRenameFile succeeds} -setup {
 525    cleanup
 526} -constraints {notRoot notNetworkFilesystem} -body {
 527    file mkdir [file join td1 td2]
 528    file mkdir td2
 529    createfile [file join td2 tf1]
 530    file rename -force td2 td1
 531    file exists [file join td1 td2 tf1]
 532} -result 1
 533test fCmd-6.16 {CopyRenameOneFile: TclpCopyRenameOneFile fails} -setup {
 534    cleanup
 535} -constraints {notRoot} -body {
 536    file mkdir [file join td1 td2]
 537    createfile [file join td1 td2 tf1]
 538    file mkdir td2
 539    file rename -force td2 td1
 540} -returnCodes error -match glob -result \
 541    [subst {error renaming "td2" to "[file join td1 td2]": file *}]
 542test fCmd-6.17 {CopyRenameOneFile: errno == EINVAL} -setup {
 543    cleanup
 544} -constraints {notRoot} -returnCodes error -body {
 545    file rename -force $root tf1
 546} -result [subst {error renaming "$root" to "tf1": trying to rename a volume or move a directory into itself}]
 547test fCmd-6.18 {CopyRenameOneFile: errno != EXDEV} -setup {
 548    cleanup
 549} -constraints {notRoot} -body {
 550    file mkdir [file join td1 td2]
 551    createfile [file join td1 td2 tf1]
 552    file mkdir td2
 553    file rename -force td2 td1
 554} -returnCodes error -match glob -result \
 555    [subst {error renaming "td2" to "[file join td1 td2]": file *}]
 556test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} {unix notRoot} {
 557    cleanup /tmp
 558    createfile tf1
 559    file rename tf1 /tmp
 560    glob -nocomplain tf* /tmp/tf1
 561} {/tmp/tf1}
 562test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} -constraints {win} -setup {
 563    catch {file delete -force c:/tcl8975@ d:/tcl8975@}
 564} -body {
 565    file mkdir c:/tcl8975@
 566    if {[catch {file rename c:/tcl8975@ d:/}]} {
 567	return d:/tcl8975@
 568    }
 569    glob c:/tcl8975@ d:/tcl8975@
 570} -cleanup {
 571    file delete -force c:/tcl8975@
 572    catch {file delete -force d:/tcl8975@}
 573} -result {d:/tcl8975@}
 574test fCmd-6.21 {CopyRenameOneFile: copy/rename: S_ISDIR(source)} \
 575	{unix notRoot} {
 576    cleanup /tmp
 577    file mkdir td1
 578    file rename td1 /tmp
 579    glob -nocomplain td* /tmp/td*
 580} {/tmp/td1}
 581test fCmd-6.22 {CopyRenameOneFile: copy/rename: !S_ISDIR(source)} \
 582	{unix notRoot} {
 583    cleanup /tmp
 584    createfile tf1
 585    file rename tf1 /tmp
 586    glob -nocomplain tf* /tmp/tf*
 587} {/tmp/tf1}
 588test fCmd-6.23 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
 589    cleanup /tmp
 590} -constraints {unix notRoot xdev} -body {
 591    file mkdir td1/td2/td3
 592    file attributes td1 -permissions 0000
 593    file rename td1 /tmp
 594} -returnCodes error -cleanup {
 595    file attributes td1 -permissions 0755
 596} -match regexp -result {^error renaming "td1"( to "/tmp/td1")?: permission denied$}
 597test fCmd-6.24 {CopyRenameOneFile: error uses original name} -setup {
 598    cleanup
 599} -constraints {unix notRoot} -body {
 600    file mkdir ~/td1/td2
 601    set td1name [file join [file dirname ~] [file tail ~] td1]
 602    file attributes $td1name -permissions 0000
 603    file copy ~/td1 td1
 604} -returnCodes error -cleanup {
 605    file attributes $td1name -permissions 0755
 606    file delete -force ~/td1
 607} -result {error copying "~/td1": permission denied}
 608test fCmd-6.25 {CopyRenameOneFile: error uses original name} -setup {
 609    cleanup
 610} -constraints {unix notRoot} -body {
 611    file mkdir td2
 612    file mkdir ~/td1
 613    set td1name [file join [file dirname ~] [file tail ~] td1]
 614    file attributes $td1name -permissions 0000
 615    file copy td2 ~/td1
 616} -returnCodes error -cleanup {
 617    file attributes $td1name -permissions 0755
 618    file delete -force ~/td1
 619} -result {error copying "td2" to "~/td1/td2": permission denied}
 620test fCmd-6.26 {CopyRenameOneFile: doesn't use original name} -setup {
 621    cleanup
 622} -constraints {unix notRoot} -body {
 623    file mkdir ~/td1/td2
 624    set td2name [file join [file dirname ~] [file tail ~] td1 td2]
 625    file attributes $td2name -permissions 0000
 626    file copy ~/td1 td1
 627} -returnCodes error -cleanup {
 628    file attributes $td2name -permissions 0755
 629    file delete -force ~/td1
 630} -result "error copying \"~/td1\" to \"td1\": \"[file join $::env(HOME) td1 td2]\": permission denied"
 631test fCmd-6.27 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
 632    cleanup /tmp
 633} -constraints {unix notRoot xdev} -returnCodes error -body {
 634    file mkdir td1/td2/td3
 635    file mkdir /tmp/td1
 636    createfile /tmp/td1/tf1
 637    file rename -force td1 /tmp
 638} -result {error renaming "td1" to "/tmp/td1": file already exists}
 639test fCmd-6.28 {CopyRenameOneFile: TclpCopyDirectory failed} -setup {
 640    cleanup /tmp
 641} -constraints {unix notRoot xdev} -body {
 642    file mkdir td1/td2/td3
 643    file attributes td1/td2/td3 -permissions 0000
 644    file rename td1 /tmp
 645} -returnCodes error -cleanup {
 646    file attributes td1/td2/td3 -permissions 0755
 647} -result {error renaming "td1" to "/tmp/td1": "td1/td2/td3": permission denied}
 648test fCmd-6.29 {CopyRenameOneFile: TclpCopyDirectory passed} -setup {
 649    cleanup /tmp
 650} -constraints {unix notRoot xdev} -body {
 651    file mkdir td1/td2/td3
 652    file rename td1 /tmp
 653    glob td* /tmp/td1/t*
 654} -result {/tmp/td1/td2}
 655test fCmd-6.30 {CopyRenameOneFile: TclpRemoveDirectory failed} -setup {
 656    cleanup
 657} -constraints {unix notRoot} -body {
 658    file mkdir foo/bar
 659    file attr foo -perm 040555
 660    file rename foo/bar /tmp
 661} -returnCodes error -cleanup {
 662    catch {file delete /tmp/bar}
 663    catch {file attr foo -perm 040777}
 664    catch {file delete -force foo}
 665} -match glob -result {*: permission denied}
 666test fCmd-6.31 {CopyRenameOneFile: TclpDeleteFile passed} -setup {
 667    catch {cleanup /tmp}
 668} -constraints {unix notRoot xdev} -body {
 669    file mkdir /tmp/td1
 670    createfile /tmp/td1/tf1
 671    file rename /tmp/td1/tf1 tf1
 672    list [file exists /tmp/td1/tf1] [file exists tf1]
 673} -result {0 1}
 674test fCmd-6.32 {CopyRenameOneFile: copy} -constraints {notRoot} -setup {
 675    cleanup
 676} -returnCodes error -body {
 677    file copy tf1 tf2
 678} -result {error copying "tf1": no such file or directory}
 679catch {cleanup /tmp}
 680
 681test fCmd-7.1 {FileForceOption: none} -constraints {notRoot} -setup {
 682    cleanup
 683} -returnCodes error -body {
 684    file mkdir [file join tf1 tf2]
 685    file delete tf1
 686} -result {error deleting "tf1": directory not empty}
 687test fCmd-7.2 {FileForceOption: -force} {notRoot} {
 688    cleanup
 689    file mkdir [file join tf1 tf2]
 690    file delete -force tf1
 691} {}
 692test fCmd-7.3 {FileForceOption: --} {notRoot} {
 693    createfile -tf1
 694    file delete -- -tf1
 695} {}
 696test fCmd-7.4 {FileForceOption: bad option} -constraints {notRoot} -setup {
 697    createfile -tf1
 698} -body {
 699    file delete -tf1
 700} -returnCodes error -cleanup {
 701    file delete -- -tf1
 702} -result {bad option "-tf1": should be -force or --}
 703test fCmd-7.5 {FileForceOption: multiple times through loop} -setup {
 704    cleanup
 705} -constraints {notRoot} -returnCodes error -body {
 706    createfile --
 707    createfile -force
 708    file delete -force -force -- -- -force
 709    glob -- -- -force
 710} -result {no files matched glob patterns "-- -force"}
 711
 712test fCmd-8.1 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
 713    -constraints {unix notRoot knownBug} -body {
 714    # Labelled knownBug because it is dangerous [Bug: 3881]
 715    file mkdir td1
 716    file attr td1 -perm 040000
 717    file rename ~$user td1
 718} -returnCodes error -cleanup {
 719    file delete -force td1
 720} -result "error renaming \"~$user\" to \"td1/[file tail ~$user]\": permission denied"
 721test fCmd-8.2 {FileBasename: basename of ~user: argc == 1 && *path == ~} \
 722	{unix notRoot} {
 723    string equal [file tail ~$user] ~$user
 724} 0
 725test fCmd-8.3 {file copy and path translation: ensure correct error} -body {
 726    file copy ~ [file join this file doesnt exist]
 727} -returnCodes error -result [subst \
 728	{error copying "~" to "[file join this file doesnt exist]": no such file or directory}]
 729
 730test fCmd-9.1 {file rename: comprehensive: EACCES} -setup {
 731    cleanup
 732} -constraints {unix notRoot} -body {
 733    file mkdir td1
 734    file mkdir td2
 735    file attr td2 -perm 040000
 736    file rename td1 td2/
 737} -returnCodes error -cleanup {
 738    file delete -force td2
 739    file delete -force td1
 740} -result {error renaming "td1" to "td2/td1": permission denied}
 741test fCmd-9.2 {file rename: comprehensive: source doesn't exist} -setup {
 742    cleanup
 743} -constraints {notRoot} -returnCodes error -body {
 744    file rename tf1 tf2
 745} -result {error renaming "tf1": no such file or directory}
 746test fCmd-9.3 {file rename: comprehensive: file to new name} -setup {
 747    cleanup
 748} -constraints {notRoot testchmod} -body {
 749    createfile tf1
 750    createfile tf2
 751    testchmod 444 tf2
 752    file rename tf1 tf3
 753    file rename tf2 tf4
 754    list [lsort [glob tf*]] [file writable tf3] [file writable tf4]
 755} -result {{tf3 tf4} 1 0}
 756test fCmd-9.4 {file rename: comprehensive: dir to new name} -setup {
 757    cleanup
 758} -constraints {unixOrPc notRoot testchmod notDarwin9 win2000orXP} -body {
 759    file mkdir td1 td2
 760    testchmod 555 td2
 761    file rename td1 td3
 762    file rename td2 td4
 763    list [lsort [glob td*]] [file writable td3] [file writable td4]
 764} -cleanup {
 765    cleanup
 766} -result {{td3 td4} 1 0}
 767test fCmd-9.5 {file rename: comprehensive: file to self} {notRoot testchmod} {
 768    cleanup
 769    createfile tf1 tf1
 770    createfile tf2 tf2
 771    testchmod 444 tf2
 772    file rename -force tf1 tf1
 773    file rename -force tf2 tf2
 774    list [contents tf1] [contents tf2] [file writable tf1] [file writable tf2]
 775} {tf1 tf2 1 0}
 776test fCmd-9.6 {file rename: comprehensive: dir to self} -setup {
 777    cleanup
 778} -constraints {notRoot unixOrPc testchmod win2000orXP} -body {
 779    file mkdir td1
 780    file mkdir td2
 781    testchmod 555 td2
 782    file rename -force td1 .
 783    file rename -force td2 .
 784    list [lsort [glob td*]] [file writable td1] [file writable td2]
 785} -result {{td1 td2} 1 0}
 786test fCmd-9.7 {file rename: comprehensive: file to existing file} -setup {
 787    cleanup
 788} -constraints {notRoot testchmod} -body {
 789    createfile tf1
 790    createfile tf2
 791    createfile tfs1
 792    createfile tfs2
 793    createfile tfs3
 794    createfile tfs4
 795    createfile tfd1
 796    createfile tfd2
 797    createfile tfd3
 798    createfile tfd4
 799    testchmod 444 tfs3
 800    testchmod 444 tfs4
 801    testchmod 444 tfd2
 802    testchmod 444 tfd4
 803    set msg [list [catch {file rename tf1 tf2} msg] $msg]
 804    file rename -force tfs1 tfd1
 805    file rename -force tfs2 tfd2
 806    file rename -force tfs3 tfd3
 807    file rename -force tfs4 tfd4
 808    list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
 809} -result {{tf1 tf2 tfd1 tfd2 tfd3 tfd4} {1 {error renaming "tf1" to "tf2": file already exists}} 1 1 0 0}
 810test fCmd-9.8 {file rename: comprehensive: dir to empty dir} -setup {
 811    cleanup
 812} -constraints {notRoot testchmod notNetworkFilesystem} -body {
 813    # Under unix, you can rename a read-only directory, but you can't
 814    # move it into another directory.
 815
 816    file mkdir td1
 817    file mkdir [file join td2 td1]
 818    file mkdir tds1
 819    file mkdir tds2
 820    file mkdir tds3
 821    file mkdir tds4
 822    file mkdir [file join tdd1 tds1]
 823    file mkdir [file join tdd2 tds2]
 824    file mkdir [file join tdd3 tds3]
 825    file mkdir [file join tdd4 tds4]
 826    if {![testConstraint unix]} {
 827	testchmod 555 tds3
 828	testchmod 555 tds4
 829    }
 830    testchmod 555 [file join tdd2 tds2]
 831    testchmod 555 [file join tdd4 tds4]
 832    set msg [list [catch {file rename td1 td2} msg] $msg]
 833    file rename -force tds1 tdd1
 834    file rename -force tds2 tdd2
 835    file rename -force tds3 tdd3
 836    file rename -force tds4 tdd4
 837    if {[testConstraint unix]} {
 838	set w3 0
 839	set w4 0
 840    } else {
 841	set w3 [file writable [file join tdd3 tds3]]
 842	set w4 [file writable [file join tdd4 tds4]]
 843    }
 844    list [lsort [glob td*]] $msg [file writable [file join tdd1 tds1]] \
 845    [file writable [file join tdd2 tds2]] $w3 $w4
 846} -result [subst {{td1 td2 tdd1 tdd2 tdd3 tdd4} {1 {error renaming "td1" to "[file join td2 td1]": file already exists}} 1 1 0 0}]
 847# Test can hit EEXIST or EBUSY, depending on underlying filesystem
 848test fCmd-9.9 {file rename: comprehensive: dir to non-empty dir} -setup {
 849    cleanup
 850} -constraints {notRoot testchmod} -body {
 851    file mkdir tds1
 852    file mkdir tds2
 853    file mkdir [file join tdd1 tds1 xxx]
 854    file mkdir [file join tdd2 tds2 xxx]
 855    if {!([testConstraint unix] || [testConstraint winVista])} {
 856	testchmod 555 tds2
 857    }
 858    set a1 [list [catch {file rename -force tds1 tdd1} msg] $msg]
 859    set a2 [list [catch {file rename -force tds2 tdd2} msg] $msg]
 860    if {[testConstraint unix] || [testConstraint winVista]} {
 861	set w2 0
 862    } else {
 863	set w2 [file writable tds2]
 864    }
 865    list [lsort [glob td*]] $a1 $a2 [file writable tds1] $w2
 866} -match glob -result \
 867    [subst {{tdd1 tdd2 tds1 tds2} {1 {error renaming "tds1" to "[file join tdd1 tds1]": file *}} {1 {error renaming "tds2" to "[file join tdd2 tds2]": file *}} 1 0}]
 868test fCmd-9.10 {file rename: comprehensive: file to new name and dir} {notRoot testchmod} {
 869    cleanup
 870    createfile tf1
 871    createfile tf2
 872    file mkdir td1
 873    testchmod 444 tf2
 874    file rename tf1 [file join td1 tf3]
 875    file rename tf2 [file join td1 tf4]
 876    list [catch {glob tf*}] [lsort [glob -directory td1 t*]] \
 877    [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
 878} [subst {1 {[file join td1 tf3] [file join td1 tf4]} 1 0}]
 879test fCmd-9.11 {file rename: comprehensive: dir to new name and dir} {notRoot testchmod} {
 880    cleanup
 881    file mkdir td1
 882    file mkdir td2
 883    file mkdir td3
 884    if {!([testConstraint unix] || [testConstraint winVista])} {
 885	testchmod 555 td2
 886    }
 887    file rename td1 [file join td3 td3]
 888    file rename td2 [file join td3 td4]
 889    if {[testConstraint unix] || [testConstraint winVista]} {
 890        set w4 0
 891    } else {
 892	set w4 [file writable [file join td3 td4]]
 893    }
 894    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
 895    [file writable [file join td3 td3]] $w4
 896} [subst {td3 {[file join td3 td3] [file join td3 td4]} 1 0}]
 897test fCmd-9.12 {file rename: comprehensive: target exists} -setup {
 898    cleanup
 899} -constraints {notRoot testchmod notNetworkFilesystem} -body {
 900    file mkdir [file join td1 td2] [file join td2 td1]
 901    testchmod 555 [file join td2 td1]
 902    file mkdir [file join td3 td4] [file join td4 td3]
 903    file rename -force td3 td4
 904    list [file exists td3] [file exists [file join td4 td3 td4]] \
 905	[catch {file rename td1 td2} msg] $msg
 906} -cleanup {
 907    testchmod 755 [file join td2 td1]
 908} -result [subst {0 1 1 {error renaming "td1" to "[file join td2 td1]": file already exists}}]
 909# Test can hit EEXIST or EBUSY, depending on underlying filesystem
 910test fCmd-9.13 {file rename: comprehensive: can't overwrite target} -setup {
 911    cleanup
 912} -constraints {notRoot} -body {
 913    file mkdir [file join td1 td2] [file join td2 td1 td4]
 914    file rename -force td1 td2
 915} -returnCodes error -match glob -result \
 916    [subst {error renaming "td1" to "[file join td2 td1]": file *}]
 917test fCmd-9.14 {file rename: comprehensive: dir into self} {notRoot} {
 918    cleanup
 919    file mkdir td1
 920    list [glob td*] [list [catch {file rename td1 td1} msg] $msg]
 921} [subst {td1 {1 {error renaming "td1" to "[file join td1 td1]": trying to rename a volume or move a directory into itself}}}]
 922test fCmd-9.14.1 {file rename: comprehensive: dir into self} {notRoot} {
 923    cleanup
 924    file mkdir td1
 925    file rename td1 td1x
 926    file rename td1x td1
 927    set msg "ok"
 928} {ok}
 929test fCmd-9.14.2 {file rename: comprehensive: dir into self} -setup {
 930    cleanup
 931    set dir [pwd]
 932} -constraints {nonPortable notRoot} -body {
 933    file mkdir td1
 934    cd td1
 935    file rename [file join .. td1] [file join .. td1x]
 936} -returnCodes error -cleanup {
 937    cd $dir
 938} -result [subst {error renaming "[file join .. td1]" to "[file join .. td1x]": permission denied}]
 939test fCmd-9.14.3 {file rename: comprehensive: dir into self} -setup {
 940    cleanup
 941    set dir [pwd]
 942} -constraints {notRoot} -body {
 943    file mkdir td1
 944    cd td1
 945    file rename [file join .. td1] [file join .. td1 foo]
 946} -returnCodes error -cleanup {
 947    cd $dir
 948} -result [subst {error renaming "[file join .. td1]" to "[file join .. td1 foo]": trying to rename a volume or move a directory into itself}]
 949test fCmd-9.15 {file rename: comprehensive: source and target incompatible} -setup {
 950    cleanup
 951} -constraints {notRoot} -returnCodes error -body {
 952    file mkdir td1
 953    createfile tf1
 954    file rename -force td1 tf1
 955} -cleanup {
 956    cleanup
 957} -result {can't overwrite file "tf1" with directory "td1"}
 958test fCmd-9.16 {file rename: comprehensive: source and target incompatible} -setup {
 959    cleanup
 960} -constraints {notRoot} -returnCodes error -body {
 961    file mkdir td1/tf1
 962    createfile tf1
 963    file rename -force tf1 td1
 964} -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
 965
 966test fCmd-10.1 {file copy: comprehensive: source doesn't exist} -setup {
 967    cleanup
 968} -constraints {notRoot} -returnCodes error -body {
 969    file copy tf1 tf2
 970} -result {error copying "tf1": no such file or directory}
 971test fCmd-10.2 {file copy: comprehensive: file to new name} {notRoot testchmod} {
 972    cleanup
 973    createfile tf1 tf1
 974    createfile tf2 tf2
 975    testchmod 444 tf2
 976    file copy tf1 tf3
 977    file copy tf2 tf4
 978    list [lsort [glob tf*]] [contents tf3] [contents tf4] [file writable tf3] [file writable tf4]
 979} {{tf1 tf2 tf3 tf4} tf1 tf2 1 0}
 980test fCmd-10.3 {file copy: comprehensive: dir to new name} -setup {
 981    cleanup
 982} -constraints {notRoot unixOrPc 95or98 testchmod} -body {
 983    file mkdir [file join td1 tdx]
 984    file mkdir [file join td2 tdy]
 985    testchmod 555 td2
 986    file copy td1 td3
 987    file copy td2 td4
 988    list [lsort [glob td*]] [glob -directory td3 t*] \
 989	    [glob -directory td4 t*] [file writable td3] [file writable td4]
 990} -cleanup {
 991    testchmod 755 td2
 992    testchmod 755 td4
 993} -result [list {td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 0]
 994test fCmd-10.3.1 {file copy: comprehensive: dir to new name} -setup {
 995    cleanup
 996} -constraints {notRoot win 2000orNewer testchmod} -body {
 997    # On Windows with ACLs, copying a directory is defined like this
 998    file mkdir [file join td1 tdx]
 999    file mkdir [file join td2 tdy]
1000    testchmod 555 td2
1001    file copy td1 td3
1002    file copy td2 td4
1003    list [lsort [glob td*]] [glob -directory td3 t*] \
1004	    [glob -directory td4 t*] [file writable td3] [file writable td4]
1005} -cleanup {
1006    testchmod 755 td2
1007    testchmod 755 td4
1008} -result [list {td1 td2 td3 td4} [file join td3 tdx] [file join td4 tdy] 1 1]
1009test fCmd-10.4 {file copy: comprehensive: file to existing file} -setup {
1010    cleanup
1011} -constraints {notRoot testchmod} -body {
1012    createfile tf1
1013    createfile tf2
1014    createfile tfs1
1015    createfile tfs2
1016    createfile tfs3
1017    createfile tfs4
1018    createfile tfd1
1019    createfile tfd2
1020    createfile tfd3
1021    createfile tfd4
1022    testchmod 444 tfs3
1023    testchmod 444 tfs4
1024    testchmod 444 tfd2
1025    testchmod 444 tfd4
1026    set msg [list [catch {file copy tf1 tf2} msg] $msg]
1027    file copy -force tfs1 tfd1
1028    file copy -force tfs2 tfd2
1029    file copy -force tfs3 tfd3
1030    file copy -force tfs4 tfd4
1031    list [lsort [glob tf*]] $msg [file writable tfd1] [file writable tfd2] [file writable tfd3] [file writable tfd4]
1032} -result {{tf1 tf2 tfd1 tfd2 tfd3 tfd4 tfs1 tfs2 tfs3 tfs4} {1 {error copying "tf1" to "tf2": file already exists}} 1 1 0 0}
1033test fCmd-10.5 {file copy: comprehensive: dir to empty dir} -setup {
1034    cleanup
1035} -constraints {notRoot testchmod} -body {
1036    file mkdir td1
1037    file mkdir [file join td2 td1]
1038    file mkdir tds1
1039    file mkdir tds2
1040    file mkdir tds3
1041    file mkdir tds4
1042    file mkdir [file join tdd1 tds1]
1043    file mkdir [file join tdd2 tds2]
1044    file mkdir [file join tdd3 tds3]
1045    file mkdir [file join tdd4 tds4]
1046    testchmod 555 tds3
1047    testchmod 555 tds4
1048    testchmod 555 [file join tdd2 tds2]
1049    testchmod 555 [file join tdd4 tds4]
1050    set a1 [list [catch {file copy td1 td2} msg] $msg]
1051    set a2 [list [catch {file copy -force tds1 tdd1} msg] $msg]
1052    set a3 [catch {file copy -force tds2 tdd2}]
1053    set a4 [catch {file copy -force tds3 tdd3}]
1054    set a5 [catch {file copy -force tds4 tdd4}]
1055    list [lsort [glob td*]] $a1 $a2 $a3 $a4 $a5
1056} -result [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}]
1057test fCmd-10.6 {file copy: comprehensive: dir to non-empty dir} -setup {
1058    cleanup
1059} -constraints {notRoot unixOrPc testchmod} -body {
1060    file mkdir tds1
1061    file mkdir tds2
1062    file mkdir [file join tdd1 tds1 xxx]
1063    file mkdir [file join tdd2 tds2 xxx]
1064    testchmod 555 tds2
1065    set a1 [list [catch {file copy -force tds1 tdd1} msg] $msg]
1066    set a2 [list [catch {file copy -force tds2 tdd2} msg] $msg]
1067    list [lsort [glob td*]] $a1 $a2 [file writable tds1] [file writable tds2]
1068} -result [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}]
1069test fCmd-10.7 {file rename: comprehensive: file to new name and dir} -setup {
1070    cleanup
1071} -constraints {notRoot testchmod} -body {
1072    createfile tf1
1073    createfile tf2
1074    file mkdir td1
1075    testchmod 444 tf2
1076    file copy tf1 [file join td1 tf3]
1077    file copy tf2 [file join td1 tf4]
1078    list [lsort [glob tf*]] [lsort [glob -directory td1 t*]] \
1079    [file writable [file join td1 tf3]] [file writable [file join td1 tf4]]
1080} -result [subst {{tf1 tf2} {[file join td1 tf3] [file join td1 tf4]} 1 0}]
1081test fCmd-10.8 {file rename: comprehensive: dir to new name and dir} -setup {
1082    cleanup
1083} -constraints {notRoot unixOrPc 95or98 testchmod} -body {
1084    file mkdir td1
1085    file mkdir td2
1086    file mkdir td3
1087    testchmod 555 td2
1088    file copy td1 [file join td3 td3]
1089    file copy td2 [file join td3 td4]
1090    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
1091    [file writable [file join td3 td3]] [file writable [file join td3 td4]]
1092} -result [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 0}]
1093test fCmd-10.8.1 {file rename: comprehensive: dir to new name and dir} -setup {
1094    cleanup
1095} -constraints {notRoot win 2000orNewer testchmod} -body {
1096    # On Windows with ACLs, copying a directory is defined like this
1097    file mkdir td1
1098    file mkdir td2
1099    file mkdir td3
1100    testchmod 555 td2
1101    file copy td1 [file join td3 td3]
1102    file copy td2 [file join td3 td4]
1103    list [lsort [glob td*]] [lsort [glob -directory td3 t*]] \
1104    [file writable [file join td3 td3]] [file writable [file join td3 td4]]
1105} -result [subst {{td1 td2 td3} {[file join td3 td3] [file join td3 td4]} 1 1}]
1106test fCmd-10.9 {file copy: comprehensive: source and target incompatible} -setup {
1107    cleanup
1108} -constraints {notRoot} -returnCodes error -body {
1109    file mkdir td1
1110    createfile tf1
1111    file copy -force td1 tf1
1112} -result {can't overwrite file "tf1" with directory "td1"}
1113test fCmd-10.10 {file copy: comprehensive: source and target incompatible} -setup {
1114    cleanup
1115} -constraints {notRoot} -returnCodes error -body {
1116    file mkdir [file join td1 tf1]
1117    createfile tf1
1118    file copy -force tf1 td1
1119} -result [subst {can't overwrite directory "[file join td1 tf1]" with file "tf1"}]
1120test fCmd-10.11 {file copy: copy to empty file name} -setup {
1121    cleanup
1122} -returnCodes error -body {
1123    createfile tf1
1124    file copy tf1 ""
1125} -result {error copying "tf1" to "": no such file or directory}
1126test fCmd-10.12 {file rename: rename to empty file name} -setup {
1127    cleanup
1128} -returnCodes error -body {
1129    createfile tf1
1130    file rename tf1 ""
1131} -result {error renaming "tf1" to "": no such file or directory}
1132cleanup
1133
1134# old tests
1135
1136test fCmd-11.1 {TclFileRenameCmd: -- option } -constraints notRoot -setup {
1137    catch {file delete -force -- -tfa1}
1138} -body {
1139    set s [createfile -tfa1]
1140    file rename -- -tfa1 tfa2
1141    list [checkcontent tfa2 $s] [file exists -tfa1]
1142} -cleanup {
1143    file delete tfa2
1144} -result {1 0}
1145test fCmd-11.2 {TclFileRenameCmd: bad option } -constraints notRoot -setup {
1146    catch {file delete -force -- tfa1}
1147} -body {
1148    set s [createfile tfa1]
1149    list [catch {file rename -x tfa1 tfa2}] \
1150	[checkcontent tfa1 $s] [file exists tfa2]
1151} -cleanup {
1152    file delete tfa1
1153} -result {1 1 0}
1154test fCmd-11.3 {TclFileRenameCmd: bad \# args} {
1155    catch {file rename -- }
1156} {1}
1157test fCmd-11.4 {TclFileRenameCmd: target filename translation failing} -setup {
1158    set temp $::env(HOME)
1159} -constraints notRoot -body {
1160    global env
1161    unset env(HOME)
1162    catch { file rename tfa ~/foobar }
1163} -cleanup {
1164    set ::env(HOME) $temp
1165} -result 1
1166test fCmd-11.5 {TclFileRenameCmd: > 1 source & target is not a dir} -setup {
1167    catch {file delete -force -- tfa1 tfa2 tfa3}
1168} -constraints {notRoot} -body {
1169    createfile tfa1
1170    createfile tfa2
1171    createfile tfa3
1172    catch {file rename tfa1 tfa2 tfa3}
1173} -cleanup {
1174    file delete tfa1 tfa2 tfa3
1175} -result {1}
1176test fCmd-11.6 {TclFileRenameCmd: : single file into directory} -setup {
1177    catch {file delete -force -- tfa1 tfad}
1178} -constraints {notRoot} -body {
1179    set s [createfile tfa1]
1180    file mkdir tfad
1181    file rename tfa1 tfad
1182    list [checkcontent tfad/tfa1 $s] [file exists tfa1]
1183} -cleanup {
1184    file delete -force tfad
1185} -result {1 0}
1186test fCmd-11.7 {TclFileRenameCmd: : multiple files into directory} -setup {
1187    catch {file delete -force -- tfa1 tfa2 tfad}
1188} -constraints {notRoot} -body {
1189    set s1 [createfile tfa1]
1190    set s2 [createfile tfa2]
1191    file mkdir tfad
1192    file rename tfa1 tfa2 tfad
1193    list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
1194	[file exists tfa1] [file exists tfa2]
1195} -cleanup {
1196    file delete -force tfad
1197} -result {1 1 0 0}
1198test fCmd-11.8 {TclFileRenameCmd: error renaming file to directory} -setup {
1199    catch {file delete -force -- tfa tfad}
1200} -constraints {notRoot} -body {
1201    set s [createfile tfa]
1202    file mkdir tfad
1203    file mkdir tfad/tfa
1204    list [catch {file rename tfa tfad}] [checkcontent tfa $s] [file isdir tfad]
1205} -cleanup {
1206    file delete -force tfa tfad
1207} -result {1 1 1}
1208
1209#
1210# Coverage tests for renamefile() ;
1211#
1212test fCmd-12.1 {renamefile: source filename translation failing} -setup {
1213    set temp $::env(HOME)
1214} -constraints {notRoot} -body {
1215    global env
1216    unset env(HOME)
1217    catch {file rename ~/tfa1 tfa2}
1218} -cleanup {
1219    set ::env(HOME) $temp
1220} -result {1}
1221test fCmd-12.2 {renamefile: src filename translation failing} -setup {
1222    set temp $::env(HOME)
1223} -constraints {notRoot} -body {
1224    global env
1225    unset env(HOME)
1226    set s [createfile tfa1]
1227    file mkdir tfad
1228    catch {file rename tfa1 ~/tfa2 tfad}
1229} -cleanup {
1230    set ::env(HOME) $temp
1231    file delete -force tfad
1232} -result {1}
1233test fCmd-12.3 {renamefile: stat failing on source} -setup {
1234    catch {file delete -force -- tfa1 tfa2}
1235} -constraints {notRoot} -body {
1236    list [catch {file rename tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
1237} -result {1 0 0}
1238test fCmd-12.4 {renamefile: error renaming file to directory} -setup {
1239    catch {file delete -force -- tfa tfad}
1240} -constraints {notRoot} -body {
1241    set s1 [createfile tfa]
1242    file mkdir tfad
1243    file mkdir tfad/tfa
1244    list [catch {file rename tfa tfad}] [checkcontent tfa $s1] \
1245	[file isdir tfad/tfa]
1246} -cleanup {
1247    file delete -force tfa tfad
1248} -result {1 1 1}
1249test fCmd-12.5 {renamefile: error renaming directory to file} -setup {
1250    catch {file delete -force -- tfa tfad}
1251} -constraints {notRoot} -body {
1252    file mkdir tfa
1253    file mkdir tfad
1254    set s [createfile tfad/tfa]
1255    list [catch {file rename tfa tfad}] [checkcontent tfad/tfa $s] \
1256	[file isdir tfad] [file isdir tfa]
1257} -cleanup {
1258    file delete -force tfa tfad
1259} -result {1 1 1 1}
1260test fCmd-12.6 {renamefile: TclRenameFile succeeding} -setup {
1261    catch {file delete -force -- tfa1 tfa2}
1262} -constraints {notRoot} -body {
1263    set s [createfile tfa1]
1264    file rename tfa1 tfa2
1265    list [checkcontent tfa2 $s] [file exists tfa1]
1266} -cleanup {
1267    file delete tfa2
1268} -result {1 0}
1269test fCmd-12.7 {renamefile: renaming directory into offspring} -setup {
1270    catch {file delete -force -- tfad}
1271} -constraints {notRoot} -body {
1272    file mkdir tfad
1273    file mkdir tfad/dir
1274    catch {file rename tfad tfad/dir}
1275} -cleanup {
1276    file delete -force tfad
1277} -result {1}
1278test fCmd-12.8 {renamefile: generic error} -setup {
1279    catch {file delete -force -- tfa}
1280} -constraints {unix notRoot} -body {
1281    file mkdir tfa
1282    file mkdir tfa/dir
1283    file attributes tfa -permissions 0555
1284    catch {file rename tfa/dir tfa2}
1285} -cleanup {
1286    catch {file attributes tfa -permissions 0777}
1287    file delete -force tfa
1288} -result {1}
1289test fCmd-12.9 {renamefile: moving a file across volumes} -setup {
1290    catch {file delete -force -- tfa /tmp/tfa}
1291} -constraints {unix notRoot} -body {
1292    set s [createfile tfa]
1293    file rename tfa /tmp
1294    list [checkcontent /tmp/tfa $s] [file exists tfa]
1295} -cleanup {
1296    file delete /tmp/tfa
1297} -result {1 0}
1298test fCmd-12.10 {renamefile: moving a directory across volumes} -setup {
1299    catch {file delete -force -- tfad /tmp/tfad}
1300} -constraints {unix notRoot} -body {
1301    file mkdir tfad
1302    set s [createfile tfad/a]
1303    file rename tfad /tmp
1304    list [checkcontent /tmp/tfad/a $s] [file exists tfad]
1305} -cleanup {
1306    file delete -force /tmp/tfad
1307} -result {1 0}
1308
1309#
1310# Coverage tests for TclCopyFilesCmd()
1311#
1312test fCmd-13.1 {TclCopyFilesCmd: -force option} -constraints notRoot -setup {
1313    catch {file delete -force -- tfa1}
1314} -body {
1315    set s [createfile tfa1]
1316    file copy -force  tfa1 tfa2
1317    list [checkcontent tfa2 $s] [checkcontent tfa1 $s]
1318} -cleanup {
1319    file delete tfa1 tfa2
1320} -result {1 1}
1321test fCmd-13.2 {TclCopyFilesCmd: -- option} -constraints {notRoot} -setup {
1322    catch {file delete -force -- tfa1}
1323} -body {
1324    set s [createfile -tfa1]
1325    file copy --  -tfa1 tfa2
1326    list [checkcontent tfa2 $s] [checkcontent -tfa1 $s]
1327} -cleanup {
1328    file delete -- -tfa1 tfa2
1329} -result {1 1}
1330test fCmd-13.3 {TclCopyFilesCmd: bad option} -constraints {notRoot} -setup {
1331    catch {file delete -force -- tfa1}
1332} -body {
1333    set s [createfile tfa1]
1334    list [catch {file copy -x tfa1 tfa2}] \
1335	[checkcontent tfa1 $s] [file exists tfa2]
1336} -cleanup {
1337    file delete tfa1
1338} -result {1 1 0}
1339test fCmd-13.4 {TclCopyFilesCmd: bad \# args} {notRoot} {
1340    catch {file copy -- }
1341} {1}
1342test fCmd-13.5 {TclCopyFilesCmd: target filename translation failing} -setup {
1343    set temp $::env(HOME)
1344} -body {
1345    global env
1346    unset env(HOME)
1347    catch { file copy tfa ~/foobar }
1348} -cleanup {
1349    set ::env(HOME) $temp
1350} -result {1}
1351test fCmd-13.6 {TclCopyFilesCmd: > 1 source & target is not a dir} -setup {
1352    catch {file delete -force -- tfa1 tfa2 tfa3}
1353} -constraints {notRoot} -body {
1354    createfile tfa1
1355    createfile tfa2
1356    createfile tfa3
1357    catch {file copy tfa1 tfa2 tfa3}
1358} -cleanup {
1359    file delete tfa1 tfa2 tfa3
1360} -result {1}
1361test fCmd-13.7 {TclCopyFilesCmd: single file into directory} -setup {
1362    catch {file delete -force -- tfa1 tfad}
1363} -constraints {notRoot} -body {
1364    set s [createfile tfa1]
1365    file mkdir tfad
1366    file copy tfa1 tfad
1367    list [checkcontent tfad/tfa1 $s] [checkcontent tfa1 $s]
1368} -cleanup {
1369    file delete -force tfad tfa1
1370} -result {1 1}
1371test fCmd-13.8 {TclCopyFilesCmd: multiple files into directory} -setup {
1372    catch {file delete -force -- tfa1 tfa2 tfad}
1373} -constraints {notRoot} -body {
1374    set s1 [createfile tfa1 ]
1375    set s2 [createfile tfa2 ]
1376    file mkdir tfad
1377    file copy tfa1 tfa2 tfad
1378    list [checkcontent tfad/tfa1 $s1] [checkcontent tfad/tfa2 $s2] \
1379	[checkcontent tfa1 $s1] [checkcontent tfa2 $s2]
1380} -cleanup {
1381    file delete -force tfad tfa1 tfa2
1382} -result {1 1 1 1}
1383test fCmd-13.9 {TclCopyFilesCmd: error copying file to directory} -setup {
1384    catch {file delete -force -- tfa tfad}
1385} -constraints {notRoot} -body {
1386    set s [createfile tfa]
1387    file mkdir tfad
1388    file mkdir tfad/tfa
1389    list [catch {file copy tfa tfad}] [checkcontent tfa $s] \
1390	[file isdir tfad/tfa] [file isdir tfad]
1391} -cleanup {
1392    file delete -force tfa tfad
1393} -result {1 1 1 1}
1394
1395#
1396# Coverage tests for copyfile()
1397#
1398test fCmd-14.1 {copyfile: source filename translation failing} -setup {
1399    set temp $::env(HOME)
1400} -constraints {notRoot} -body {
1401    global env
1402    unset env(HOME)
1403    catch {file copy ~/tfa1 tfa2}
1404} -cleanup {
1405    set ::env(HOME) $temp
1406} -result {1}
1407test fCmd-14.2 {copyfile: dst filename translation failing} -setup {
1408    set temp $::env(HOME)
1409} -constraints {notRoot} -body {
1410    global env
1411    unset env(HOME)
1412    set s [createfile tfa1]
1413    file mkdir tfad
1414    list [catch {file copy tfa1 ~/tfa2 tfad}] [checkcontent tfad/tfa1 $s]
1415} -cleanup {
1416    set ::env(HOME) $temp
1417    file delete -force tfa1 tfad
1418} -result {1 1}
1419test fCmd-14.3 {copyfile: stat failing on source} -setup {
1420    catch {file delete -force -- tfa1 tfa2}
1421} -constraints notRoot -body {
1422    list [catch {file copy tfa1 tfa2}] [file exists tfa1] [file exists tfa2]
1423} -result {1 0 0}
1424test fCmd-14.4 {copyfile: error copying file to directory} -setup {
1425    catch {file delete -force -- tfa tfad}
1426} -constraints {notRoot} -body {
1427    set s1 [createfile tfa ]
1428    file mkdir tfad
1429    file mkdir tfad/tfa
1430    list [catch {file copy tfa tfad}] [checkcontent tfa $s1] \
1431	[file isdir tfad] [file isdir tfad/tfa]
1432} -cleanup {
1433    file delete -force tfa tfad
1434} -result {1 1 1 1}
1435test fCmd-14.5 {copyfile: error copying directory to file} -setup {
1436    catch {file delete -force -- tfa tfad}
1437} -constraints {notRoot} -body {
1438    file mkdir tfa
1439    file mkdir tfad
1440    set s [createfile tfad/tfa]
1441    list [catch {file copy tfa tfad}] [checkcontent tfad/tfa $s] \
1442	[file isdir tfad] [file isdir tfa]
1443} -cleanup {
1444     file delete -force tfa tfad
1445} -result {1 1 1 1}
1446test fCmd-14.6 {copyfile: copy file succeeding} -constraints notRoot -setup {
1447    catch {file delete -

Large files files are truncated, but you can click here to view the full file