os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/unixFCmd.test
Update contrib.
1 # This file tests the tclUnixFCmd.c file.
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1996 Sun Microsystems, Inc.
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 # RCS: @(#) $Id: unixFCmd.test,v 1.17.2.1 2003/04/14 15:45:57 vincentdarley Exp $
14 if {[lsearch [namespace children] ::tcltest] == -1} {
15 package require tcltest
16 namespace import -force ::tcltest::*
19 # These tests really need to be run from a writable directory, which
20 # it is assumed [temporaryDirectory] is.
22 cd [temporaryDirectory]
24 # Several tests require need to match results against the unix username
26 if {$tcl_platform(platform) == "unix"} {
27 catch {set user [exec whoami]}
29 catch {regexp {^[^(]*\(([^)]*)\)} [exec id] dummy user}
38 if {[file isdirectory $path]} {
40 foreach p [glob -directory $path *] {
51 set x [glob -directory $p tf* td*]
54 if {[catch {file delete -force -- $file}]} {
56 file delete -force -- $file
62 test unixFCmd-1.1 {TclpRenameFile: EACCES} {unixOnly notRoot} {
64 file mkdir td1/td2/td3
65 file attributes td1/td2 -permissions 0000
66 set msg [list [catch {file rename td1/td2/td3 td2} msg] $msg]
67 file attributes td1/td2 -permissions 0755
69 } {1 {error renaming "td1/td2/td3": permission denied}}
70 test unixFCmd-1.2 {TclpRenameFile: EEXIST} {unixOnly notRoot} {
74 list [catch {file rename td2 td1} msg] $msg
75 } {1 {error renaming "td2" to "td1/td2": file already exists}}
76 test unixFCmd-1.3 {TclpRenameFile: EINVAL} {unixOnly notRoot} {
79 list [catch {file rename td1 td1} msg] $msg
80 } {1 {error renaming "td1" to "td1/td1": trying to rename a volume or move a directory into itself}}
81 test unixFCmd-1.4 {TclpRenameFile: EISDIR} {emptyTest unixOnly notRoot} {
82 # can't make it happen
84 test unixFCmd-1.5 {TclpRenameFile: ENOENT} {unixOnly notRoot} {
87 list [catch {file rename td2 td1} msg] $msg
88 } {1 {error renaming "td2": no such file or directory}}
89 test unixFCmd-1.6 {TclpRenameFile: ENOTDIR} {emptyTest unixOnly notRoot} {
90 # can't make it happen
92 test unixFCmd-1.7 {TclpRenameFile: EXDEV} {unixOnly notRoot} {
95 file attr foo -perm 040555
96 set catchResult [catch {file rename foo/bar /tmp} msg]
97 set msg [lindex [split $msg :] end]
98 catch {file delete /tmp/bar}
99 catch {file attr foo -perm 040777}
100 catch {file delete -force foo}
101 list $catchResult $msg
102 } {1 { permission denied}}
103 test unixFCmd-1.8 {Checking EINTR Bug} {unixOnly notRoot nonPortable} {
106 list [testgotsig] [testgotsig]
108 test unixFCmd-1.9 {Checking EINTR Bug} {unixOnly notRoot nonPortable} {
110 set f [open tfalarm w]
118 set pipe [open "|[info nameofexecutable] tfalarm" r+]
119 set line [read $pipe 1]
121 list $line [testgotsig]
123 test unixFCmd-2.1 {TclpCopyFile: target exists: lstat(dst) == 0} \
128 file copy -force tf1 tf2
130 test unixFCmd-2.2.1 {TclpCopyFile: src is symlink} {unixOnly notRoot dontCopyLinks} {
131 # copying links should end up with real files
134 file link -symbolic tf2 tf1
138 test unixFCmd-2.2.2 {TclpCopyFile: src is symlink} {unixOnly notRoot} {
139 # copying links should end up with the links copied
142 file link -symbolic tf2 tf1
146 test unixFCmd-2.3 {TclpCopyFile: src is block} {unixOnly notRoot} {
149 while {[file type $null] != "characterSpecial"} {
150 set null [file join [file dirname $null] [file readlink $null]]
152 # file copy $null tf1
154 test unixFCmd-2.4 {TclpCopyFile: src is fifo} {unixOnly notRoot} {
156 if [catch {exec mknod tf1 p}] {
160 expr {"[file type tf1]" == "[file type tf2]"}
163 test unixFCmd-2.5 {TclpCopyFile: copy attributes} {unixOnly notRoot} {
166 file attributes tf1 -permissions 0472
168 file attributes tf2 -permissions
169 } 00472 ;# i.e. perms field of [exec ls -l tf2] is -r--rwx-w-
171 test unixFCmd-3.1 {CopyFile not done} {emptyTest unixOnly notRoot} {
174 test unixFCmd-4.1 {TclpDeleteFile not done} {emptyTest unixOnly notRoot} {
177 test unixFCmd-5.1 {TclpCreateDirectory not done} {emptyTest unixOnly notRoot} {
180 test unixFCmd-6.1 {TclpCopyDirectory not done} {emptyTest unixOnly notRoot} {
183 test unixFCmd-7.1 {TclpRemoveDirectory not done} {emptyTest unixOnly notRoot} {
186 test unixFCmd-8.1 {TraverseUnixTree not done} {emptyTest unixOnly notRoot} {
189 test unixFCmd-9.1 {TraversalCopy not done} {emptyTest unixOnly notRoot} {
192 test unixFCmd-10.1 {TraversalDelete not done} {emptyTest unixOnly notRoot} {
195 test unixFCmd-11.1 {CopyFileAttrs not done} {emptyTest unixOnly notRoot} {
198 test unixFCmd-12.1 {GetGroupAttribute - file not found} {unixOnly notRoot} {
199 catch {file delete -force -- foo.test}
200 list [catch {file attributes foo.test -group} msg] $msg
201 } {1 {could not read "foo.test": no such file or directory}}
202 test unixFCmd-12.2 {GetGroupAttribute - file found} {unixOnly notRoot} {
203 catch {file delete -force -- foo.test}
204 close [open foo.test w]
205 list [catch {file attributes foo.test -group}] [file delete -force -- foo.test]
208 test unixFCmd-13.1 {GetOwnerAttribute - file not found} {unixOnly notRoot} {
209 catch {file delete -force -- foo.test}
210 list [catch {file attributes foo.test -group} msg] $msg
211 } {1 {could not read "foo.test": no such file or directory}}
212 test unixFCmd-13.2 {GetOwnerAttribute} {unixOnly notRoot} {
213 catch {file delete -force -- foo.test}
214 close [open foo.test w]
215 list [catch {file attributes foo.test -owner} msg] \
216 [string compare $msg $user] [file delete -force -- foo.test]
219 test unixFCmd-14.1 {GetPermissionsAttribute - file not found} {unixOnly notRoot} {
220 catch {file delete -force -- foo.test}
221 list [catch {file attributes foo.test -permissions} msg] $msg
222 } {1 {could not read "foo.test": no such file or directory}}
223 test unixFCmd-14.2 {GetPermissionsAttribute} {unixOnly notRoot} {
224 catch {file delete -force -- foo.test}
225 close [open foo.test w]
226 list [catch {file attribute foo.test -permissions}] \
227 [file delete -force -- foo.test]
230 # Find a group that exists on this system, or else skip tests that require
232 set ::tcltest::testConstraints(foundGroup) 0
233 if {$tcl_platform(platform) == "unix"} {
235 set groupList [exec groups]
236 set group [lindex $groupList 0]
237 set ::tcltest::testConstraints(foundGroup) 1
242 test unixFCmd-15.1 {SetGroupAttribute - invalid group} {unixOnly notRoot} {
243 catch {file delete -force -- foo.test}
244 list [catch {file attributes foo.test -group foozzz} msg] \
245 $msg [file delete -force -- foo.test]
246 } {1 {could not set group for file "foo.test": group "foozzz" does not exist} {}}
247 test unixFCmd-15.2 {SetGroupAttribute - invalid file} \
248 {unixOnly notRoot foundGroup} {
249 catch {file delete -force -- foo.test}
250 list [catch {file attributes foo.test -group $group} msg] $msg
251 } {1 {could not set group for file "foo.test": no such file or directory}}
253 #changing owners hard to do
254 test unixFCmd-16.1 {SetOwnerAttribute - current owner} {unixOnly notRoot} {
255 catch {file delete -force -- foo.test}
256 close [open foo.test w]
257 list [catch {file attributes foo.test -owner $user} msg] \
258 $msg [string compare [file attributes foo.test -owner] $user] \
259 [file delete -force -- foo.test]
261 test unixFCmd-16.2 {SetOwnerAttribute - invalid file} {unixOnly notRoot} {
262 catch {file delete -force -- foo.test}
263 list [catch {file attributes foo.test -owner $user} msg] $msg
264 } {1 {could not set owner for file "foo.test": no such file or directory}}
265 test unixFCmd-16.3 {SetOwnerAttribute - invalid owner} {unixOnly notRoot} {
266 catch {file delete -force -- foo.test}
267 list [catch {file attributes foo.test -owner foozzz} msg] $msg
268 } {1 {could not set owner for file "foo.test": user "foozzz" does not exist}}
271 test unixFCmd-17.1 {SetPermissionsAttribute} {unixOnly notRoot} {
272 catch {file delete -force -- foo.test}
273 close [open foo.test w]
274 list [catch {file attributes foo.test -permissions 0000} msg] \
275 $msg [file attributes foo.test -permissions] \
276 [file delete -force -- foo.test]
278 test unixFCmd-17.2 {SetPermissionsAttribute} {unixOnly notRoot} {
279 catch {file delete -force -- foo.test}
280 list [catch {file attributes foo.test -permissions 0000} msg] $msg
281 } {1 {could not set permissions for file "foo.test": no such file or directory}}
282 test unixFCmd-17.3 {SetPermissionsAttribute} {unixOnly notRoot} {
283 catch {file delete -force -- foo.test}
284 close [open foo.test w]
285 list [catch {file attributes foo.test -permissions foo} msg] $msg \
286 [file delete -force -- foo.test]
287 } {1 {unknown permission string format "foo"} {}}
288 test unixFCmd-17.4 {SetPermissionsAttribute} {unixOnly notRoot} {
289 catch {file delete -force -- foo.test}
290 close [open foo.test w]
291 list [catch {file attributes foo.test -permissions ---rwx} msg] $msg \
292 [file delete -force -- foo.test]
293 } {1 {unknown permission string format "---rwx"} {}}
295 close [open foo.test w]
297 proc permcheck {testnum permstr expected} {
298 test $testnum {SetPermissionsAttribute} {unixOnly notRoot} {
299 file attributes foo.test -permissions $permstr
300 file attributes foo.test -permissions
303 permcheck unixFCmd-17.5 rwxrwxrwx 00777
304 permcheck unixFCmd-17.6 r--r---w- 00442
305 permcheck unixFCmd-17.7 0 00000
306 permcheck unixFCmd-17.8 u+rwx,g+r 00740
307 permcheck unixFCmd-17.9 u-w 00540
308 permcheck unixFCmd-17.10 o+rwx 00547
309 permcheck unixFCmd-17.11 --x--x--x 00111
310 permcheck unixFCmd-17.12 a+rwx 00777
311 file delete -force -- foo.test
313 test unixFCmd-18.1 {Unix pwd} {nonPortable unixOnly notRoot} {
314 # This test is nonportable because SunOS generates a weird error
315 # message when the current directory isn't readable.
320 file attributes $nd -permissions 0000
321 set r [list [catch {pwd} res] [string range $res 0 36]];
323 file attributes $nd -permissions 0755
326 } {1 {error getting working directory name:}}
331 ::tcltest::cleanupTests