diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fCmd.test | 132 | ||||
-rw-r--r-- | tests/safe.test | 46 |
2 files changed, 116 insertions, 62 deletions
diff --git a/tests/fCmd.test b/tests/fCmd.test index 37867f3..00147bb 100644 --- a/tests/fCmd.test +++ b/tests/fCmd.test @@ -15,6 +15,8 @@ if {[lsearch [namespace children] ::tcltest] == -1} { namespace import -force ::tcltest::* } +cd [temporaryDirectory] + testConstraint testsetplatform [llength [info commands testsetplatform]] testConstraint testchmod [llength [info commands testchmod]] testConstraint winVista 0 @@ -34,6 +36,15 @@ if {[testConstraint unix]} { set group [lindex $groupList 0] testConstraint foundGroup 1 } + + proc dev dir { + file stat $dir stat + return $stat(dev) + } + + if {[catch {makeDirectory tcl[pid] /tmp} tmpspace] == 0} { + testConstraint xdev [expr {([dev .] != [dev $tmpspace])}] + } } # Also used in winFCmd... @@ -138,13 +149,6 @@ proc contents {file} { return $r } -cd [temporaryDirectory] - -proc dev dir { - file stat $dir stat - return $stat(dev) -} -testConstraint xdev [expr {[testConstraint unix] && ([dev .] != [dev /tmp])}] set root [lindex [file split [pwd]] 0] @@ -550,12 +554,12 @@ test fCmd-6.18 {CopyRenameOneFile: errno != EXDEV} -setup { file rename -force td2 td1 } -returnCodes error -match glob -result \ [subst {error renaming "td2" to "[file join td1 td2]": file *}] -test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} {unix notRoot} { - cleanup /tmp +test fCmd-6.19 {CopyRenameOneFile: errno == EXDEV} {xdev notRoot} { + cleanup $tmpspace createfile tf1 - file rename tf1 /tmp - glob -nocomplain tf* /tmp/tf1 -} {/tmp/tf1} + file rename tf1 $tmpspace + glob -nocomplain tf* [file join $tmpspace tf1] +} [file join $tmpspace tf1] test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} -constraints {win} -setup { catch {file delete -force c:/tcl8975@ d:/tcl8975@} } -body { @@ -569,28 +573,29 @@ test fCmd-6.20 {CopyRenameOneFile: errno == EXDEV} -constraints {win} -setup { catch {file delete -force d:/tcl8975@} } -result {d:/tcl8975@} test fCmd-6.21 {CopyRenameOneFile: copy/rename: S_ISDIR(source)} \ - {unix notRoot} { - cleanup /tmp + {xdev notRoot} { + cleanup $tmpspace file mkdir td1 - file rename td1 /tmp - glob -nocomplain td* /tmp/td* -} {/tmp/td1} + file rename td1 $tmpspace + glob -nocomplain td* [file join $tmpspace td*] +} [file join $tmpspace td1] test fCmd-6.22 {CopyRenameOneFile: copy/rename: !S_ISDIR(source)} \ - {unix notRoot} { - cleanup /tmp + {xdev notRoot} { + cleanup $tmpspace createfile tf1 - file rename tf1 /tmp - glob -nocomplain tf* /tmp/tf* -} {/tmp/tf1} + file rename tf1 $tmpspace + glob -nocomplain tf* [file join $tmpspace tf*] +} [file join $tmpspace tf1] test fCmd-6.23 {CopyRenameOneFile: TclpCopyDirectory failed} -setup { - cleanup /tmp -} -constraints {unix notRoot xdev} -body { + cleanup $tmpspace +} -constraints {notRoot xdev} -body { file mkdir td1/td2/td3 file attributes td1 -permissions 0000 - file rename td1 /tmp + file rename td1 $tmpspace } -returnCodes error -cleanup { file attributes td1 -permissions 0755 -} -match regexp -result {^error renaming "td1"( to "/tmp/td1")?: permission denied$} + cleanup +} -match regexp -result {^error renaming "td1"( to "/tmp/tcl\d+/td1")?: permission denied$} test fCmd-6.24 {CopyRenameOneFile: error uses original name} -setup { cleanup } -constraints {unix notRoot} -body { @@ -626,54 +631,54 @@ test fCmd-6.26 {CopyRenameOneFile: doesn't use original name} -setup { file delete -force ~/td1 } -result "error copying \"~/td1\" to \"td1\": \"[file join $::env(HOME) td1 td2]\": permission denied" test fCmd-6.27 {CopyRenameOneFile: TclpCopyDirectory failed} -setup { - cleanup /tmp -} -constraints {unix notRoot xdev} -returnCodes error -body { + cleanup $tmpspace +} -constraints {notRoot xdev} -returnCodes error -body { file mkdir td1/td2/td3 - file mkdir /tmp/td1 - createfile /tmp/td1/tf1 - file rename -force td1 /tmp -} -result {error renaming "td1" to "/tmp/td1": file already exists} + file mkdir [file join $tmpspace td1] + createfile [file join $tmpspace td1 tf1] + file rename -force td1 $tmpspace +} -match glob -result {error renaming "td1" to "/tmp/tcl*/td1": file already exists} test fCmd-6.28 {CopyRenameOneFile: TclpCopyDirectory failed} -setup { - cleanup /tmp -} -constraints {unix notRoot xdev} -body { + cleanup $tmpspace +} -constraints {notRoot xdev} -body { file mkdir td1/td2/td3 file attributes td1/td2/td3 -permissions 0000 - file rename td1 /tmp + file rename td1 $tmpspace } -returnCodes error -cleanup { file attributes td1/td2/td3 -permissions 0755 -} -result {error renaming "td1" to "/tmp/td1": "td1/td2/td3": permission denied} + cleanup $tmpspace +} -match glob -result {error renaming "td1" to "/tmp/tcl*/td1": "td1/td2/td3": permission denied} test fCmd-6.29 {CopyRenameOneFile: TclpCopyDirectory passed} -setup { - cleanup /tmp -} -constraints {unix notRoot xdev} -body { + cleanup $tmpspace +} -constraints {notRoot xdev} -body { file mkdir td1/td2/td3 - file rename td1 /tmp - glob td* /tmp/td1/t* -} -result {/tmp/td1/td2} + file rename td1 $tmpspace + glob td* [file join $tmpspace td1 t*] +} -result [file join $tmpspace td1 td2] test fCmd-6.30 {CopyRenameOneFile: TclpRemoveDirectory failed} -setup { - cleanup -} -constraints {unix notRoot} -body { + cleanup $tmpspace +} -constraints {xdev notRoot} -body { file mkdir foo/bar file attr foo -perm 040555 - file rename foo/bar /tmp + file rename foo/bar $tmpspace } -returnCodes error -cleanup { - catch {file delete /tmp/bar} + catch {file delete [file join $tmpspace bar]} catch {file attr foo -perm 040777} catch {file delete -force foo} } -match glob -result {*: permission denied} test fCmd-6.31 {CopyRenameOneFile: TclpDeleteFile passed} -setup { - catch {cleanup /tmp} -} -constraints {unix notRoot xdev} -body { - file mkdir /tmp/td1 - createfile /tmp/td1/tf1 - file rename /tmp/td1/tf1 tf1 - list [file exists /tmp/td1/tf1] [file exists tf1] + cleanup $tmpspace +} -constraints {notRoot xdev} -body { + file mkdir [file join $tmpspace td1] + createfile [file join $tmpspace td1 tf1] + file rename [file join $tmpspace td1 tf1] tf1 + list [file exists [file join $tmpspace td1 tf1]] [file exists tf1] } -result {0 1} test fCmd-6.32 {CopyRenameOneFile: copy} -constraints {notRoot} -setup { cleanup } -returnCodes error -body { file copy tf1 tf2 } -result {error copying "tf1": no such file or directory} -catch {cleanup /tmp} test fCmd-7.1 {FileForceOption: none} -constraints {notRoot} -setup { cleanup @@ -1305,23 +1310,23 @@ test fCmd-12.8 {renamefile: generic error} -setup { file delete -force tfa } -result {1} test fCmd-12.9 {renamefile: moving a file across volumes} -setup { - catch {file delete -force -- tfa /tmp/tfa} -} -constraints {unix notRoot} -body { + cleanup $tmpspace +} -constraints {xdev notRoot} -body { set s [createfile tfa] - file rename tfa /tmp - list [checkcontent /tmp/tfa $s] [file exists tfa] + file rename tfa $tmpspace + list [checkcontent [file join $tmpspace tfa] $s] [file exists tfa] } -cleanup { - file delete /tmp/tfa + cleanup $tmpspace } -result {1 0} test fCmd-12.10 {renamefile: moving a directory across volumes} -setup { - catch {file delete -force -- tfad /tmp/tfad} -} -constraints {unix notRoot} -body { + cleanup $tmpspace +} -constraints {xdev notRoot} -body { file mkdir tfad set s [createfile tfad/a] - file rename tfad /tmp - list [checkcontent /tmp/tfad/a $s] [file exists tfad] + file rename tfad $tmpspace + list [checkcontent [file join $tmpspace tfad a] $s] [file exists tfad] } -cleanup { - file delete -force /tmp/tfad + cleanup $tmpspace } -result {1 0} # @@ -2551,5 +2556,8 @@ test fCmd-30.2 {file readable on 'NTUSER.DAT'} -constraints {win 2000orNewer kno # cleanup cleanup +if {[testConstraint unix]} { + removeDirectory tcl[pid] /tmp +} ::tcltest::cleanupTests return diff --git a/tests/safe.test b/tests/safe.test index 7b83cc6..4bd8509 100644 --- a/tests/safe.test +++ b/tests/safe.test @@ -690,6 +690,52 @@ test safe-14.1 {Check that module path is the same as in the master interpreter } -cleanup { safe::interpDelete $i } -result [::tcl::tm::path list] + +### ~ should have no special meaning in paths in safe interpreters +test safe-15.1 {Bug 2913625: defang ~ in paths} -setup { + set savedHOME $env(HOME) + set env(HOME) /foo/bar + set i [safe::interpCreate] +} -constraints knownBug -body { + $i eval { + set d [format %c 126] + list [file dirname $d] [file tail $d] \ + [file join [file dirname $d] [file tail $d]] + } +} -cleanup { + safe::interpDelete $i + set env(HOME) $savedHOME +} -result {~} +test safe-15.2 {Bug 2913625: defang ~user in paths} -setup { + set i [safe::interpCreate] + set user $tcl_platform(user) +} -constraints knownBug -body { + string map [list $user USER] [$i eval \ + "file join \[file dirname ~$user\] \[file tail ~$user\]"] +} -cleanup { + safe::interpDelete $i +} -result {~USER} +test safe-15.3 {Bug 2913625: defang ~ in globs} -setup { + set savedHOME $env(HOME) + set env(HOME) / + set i [safe::interpCreate] +} -constraints knownBug -body { + $i expose glob realglob + $i eval {realglob -nocomplain [join {~ / *} ""]} +} -cleanup { + safe::interpDelete $i + set env(HOME) $savedHOME +} -result {~} +test safe-15.4 {Bug 2913625: defang ~user in globs} -setup { + set i [safe::interpCreate] + set user $tcl_platform(user) +} -constraints knownBug -body { + $i expose glob realglob + string map [list $user USER] [$i eval [list\ + realglob -directory ~$user *]] +} -cleanup { + safe::interpDelete $i +} -result {~USER} set ::auto_path $saveAutoPath # cleanup |