| 1 |
# This file tests the tclMacOSXFCmd.c file. |
| 2 |
# |
| 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. |
| 6 |
# |
| 7 |
# Copyright (c) 2003 Tcl Core Team. |
| 8 |
# |
| 9 |
# See the file "license.terms" for information on usage and redistribution |
| 10 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 11 |
|
| 12 |
if {"::tcltest" ni [namespace children]} { |
| 13 |
package require tcltest 2.5 |
| 14 |
namespace import -force ::tcltest::* |
| 15 |
} |
| 16 |
|
| 17 |
# These tests really need to be run from a writable directory, which |
| 18 |
# it is assumed [temporaryDirectory] is. |
| 19 |
set oldcwd [pwd] |
| 20 |
cd [temporaryDirectory] |
| 21 |
|
| 22 |
# check whether macosx file attributes are supported |
| 23 |
testConstraint macosxFileAttr 0 |
| 24 |
if {[testConstraint unix] && $tcl_platform(os) eq "Darwin"} { |
| 25 |
catch {file delete -force -- foo.test} |
| 26 |
close [open foo.test w] |
| 27 |
catch { |
| 28 |
file attributes foo.test -creator |
| 29 |
testConstraint macosxFileAttr 1 |
| 30 |
} |
| 31 |
file delete -force -- foo.test |
| 32 |
} |
| 33 |
|
| 34 |
test macOSXFCmd-1.1 {MacOSXGetFileAttribute - file not found} {macosxFileAttr notRoot} { |
| 35 |
catch {file delete -force -- foo.test} |
| 36 |
list [catch {file attributes foo.test -creator} msg] $msg |
| 37 |
} {1 {could not read "foo.test": no such file or directory}} |
| 38 |
test macOSXFCmd-1.2 {MacOSXGetFileAttribute - creator} {macosxFileAttr notRoot} { |
| 39 |
catch {file delete -force -- foo.test} |
| 40 |
close [open foo.test w] |
| 41 |
list [catch {file attributes foo.test -creator} msg] $msg \ |
| 42 |
[file delete -force -- foo.test] |
| 43 |
} {0 {} {}} |
| 44 |
test macOSXFCmd-1.3 {MacOSXGetFileAttribute - type} {macosxFileAttr notRoot} { |
| 45 |
catch {file delete -force -- foo.test} |
| 46 |
close [open foo.test w] |
| 47 |
list [catch {file attributes foo.test -type} msg] $msg \ |
| 48 |
[file delete -force -- foo.test] |
| 49 |
} {0 {} {}} |
| 50 |
test macOSXFCmd-1.4 {MacOSXGetFileAttribute - hidden} {macosxFileAttr notRoot} { |
| 51 |
catch {file delete -force -- foo.test} |
| 52 |
close [open foo.test w] |
| 53 |
list [catch {file attributes foo.test -hidden} msg] $msg \ |
| 54 |
[file delete -force -- foo.test] |
| 55 |
} {0 0 {}} |
| 56 |
test macOSXFCmd-1.5 {MacOSXGetFileAttribute - rsrclength} {macosxFileAttr notRoot} { |
| 57 |
catch {file delete -force -- foo.test} |
| 58 |
close [open foo.test w] |
| 59 |
list [catch {file attributes foo.test -rsrclength} msg] $msg \ |
| 60 |
[file delete -force -- foo.test] |
| 61 |
} {0 0 {}} |
| 62 |
|
| 63 |
test macOSXFCmd-2.1 {MacOSXSetFileAttribute - file not found} {macosxFileAttr notRoot} { |
| 64 |
catch {file delete -force -- foo.test} |
| 65 |
list [catch {file attributes foo.test -creator FOOC} msg] $msg |
| 66 |
} {1 {could not read "foo.test": no such file or directory}} |
| 67 |
test macOSXFCmd-2.2 {MacOSXSetFileAttribute - creator} {macosxFileAttr notRoot} { |
| 68 |
catch {file delete -force -- foo.test} |
| 69 |
close [open foo.test w] |
| 70 |
list [catch {file attributes foo.test -creator FOOC} msg] $msg \ |
| 71 |
[catch {file attributes foo.test -creator} msg] $msg \ |
| 72 |
[file delete -force -- foo.test] |
| 73 |
} {0 {} 0 FOOC {}} |
| 74 |
test macOSXFCmd-2.3 {MacOSXSetFileAttribute - empty creator} {macosxFileAttr notRoot} { |
| 75 |
catch {file delete -force -- foo.test} |
| 76 |
close [open foo.test w] |
| 77 |
list [catch {file attributes foo.test -creator {}} msg] $msg \ |
| 78 |
[catch {file attributes foo.test -creator} msg] $msg \ |
| 79 |
[file delete -force -- foo.test] |
| 80 |
} {0 {} 0 {} {}} |
| 81 |
test macOSXFCmd-2.4 {MacOSXSetFileAttribute - type} {macosxFileAttr notRoot} { |
| 82 |
catch {file delete -force -- foo.test} |
| 83 |
close [open foo.test w] |
| 84 |
list [catch {file attributes foo.test -type FOOT} msg] $msg \ |
| 85 |
[catch {file attributes foo.test -type} msg] $msg \ |
| 86 |
[file delete -force -- foo.test] |
| 87 |
} {0 {} 0 FOOT {}} |
| 88 |
test macOSXFCmd-2.5 {MacOSXSetFileAttribute - empty type} {macosxFileAttr notRoot} { |
| 89 |
catch {file delete -force -- foo.test} |
| 90 |
close [open foo.test w] |
| 91 |
list [catch {file attributes foo.test -type {}} msg] $msg \ |
| 92 |
[catch {file attributes foo.test -type} msg] $msg \ |
| 93 |
[file delete -force -- foo.test] |
| 94 |
} {0 {} 0 {} {}} |
| 95 |
test macOSXFCmd-2.6 {MacOSXSetFileAttribute - hidden} {macosxFileAttr notRoot} { |
| 96 |
catch {file delete -force -- foo.test} |
| 97 |
close [open foo.test w] |
| 98 |
list [catch {file attributes foo.test -hidden 1} msg] $msg \ |
| 99 |
[catch {file attributes foo.test -hidden} msg] $msg \ |
| 100 |
[file delete -force -- foo.test] |
| 101 |
} {0 {} 0 1 {}} |
| 102 |
test macOSXFCmd-2.7 {MacOSXSetFileAttribute - rsrclength} {macosxFileAttr notRoot nonPortable} { |
| 103 |
catch {file delete -force -- foo.test} |
| 104 |
close [open foo.test w] |
| 105 |
catch { |
| 106 |
set f [open foo.test/..namedfork/rsrc w] |
| 107 |
fconfigure $f -translation lf -eofchar {} |
| 108 |
puts -nonewline $f "foo" |
| 109 |
close $f |
| 110 |
} |
| 111 |
list [catch {file attributes foo.test -rsrclength} msg] $msg \ |
| 112 |
[catch {file attributes foo.test -rsrclength 0} msg] $msg \ |
| 113 |
[catch {file attributes foo.test -rsrclength} msg] $msg \ |
| 114 |
[file delete -force -- foo.test] |
| 115 |
} {0 3 0 {} 0 0 {}} |
| 116 |
|
| 117 |
test macOSXFCmd-3.1 {MacOSXCopyFileAttributes} {macosxFileAttr notRoot} { |
| 118 |
catch {file delete -force -- foo.test} |
| 119 |
catch {file delete -force -- bar.test} |
| 120 |
close [open foo.test w] |
| 121 |
catch { |
| 122 |
file attributes foo.test -creator FOOC -type FOOT -hidden 1 |
| 123 |
set f [open foo.test/..namedfork/rsrc w] |
| 124 |
fconfigure $f -translation lf -eofchar {} |
| 125 |
puts -nonewline $f "foo" |
| 126 |
close $f |
| 127 |
file copy foo.test bar.test |
| 128 |
} |
| 129 |
list [catch {file attributes bar.test -creator} msg] $msg \ |
| 130 |
[catch {file attributes bar.test -type} msg] $msg \ |
| 131 |
[catch {file attributes bar.test -hidden} msg] $msg \ |
| 132 |
[catch {file attributes bar.test -rsrclength} msg] $msg \ |
| 133 |
[file delete -force -- foo.test bar.test] |
| 134 |
} {0 FOOC 0 FOOT 0 1 0 3 {}} |
| 135 |
|
| 136 |
test macOSXFCmd-4.1 {TclMacOSXMatchType} {macosxFileAttr notRoot} { |
| 137 |
file mkdir globtest |
| 138 |
cd globtest |
| 139 |
foreach f {bar baz foo inv inw .nv reg} { |
| 140 |
catch {file delete -force -- $f.test} |
| 141 |
close [open $f.test w] |
| 142 |
} |
| 143 |
catch {file delete -force -- dir.test} |
| 144 |
file mkdir dir.test |
| 145 |
catch { |
| 146 |
file attributes bar.test -type FOOT |
| 147 |
file attributes baz.test -creator FOOC -type FOOT |
| 148 |
file attributes foo.test -creator FOOC |
| 149 |
file attributes inv.test -hidden 1 |
| 150 |
file attributes inw.test -hidden 1 -type FOOT |
| 151 |
file attributes dir.test -hidden 1 |
| 152 |
} |
| 153 |
set res [list \ |
| 154 |
[catch {lsort [glob *.test]} msg] $msg \ |
| 155 |
[catch {lsort [glob -types FOOT *.test]} msg] $msg \ |
| 156 |
[catch {lsort [glob -types {{macintosh type FOOT}} *.test]} msg] $msg \ |
| 157 |
[catch {lsort [glob -types FOOTT *.test]} msg] $msg \ |
| 158 |
[catch {lsort [glob -types {{macintosh type FOOTT}} *.test]} msg] $msg \ |
| 159 |
[catch {lsort [glob -types {{macintosh type {}}} *.test]} msg] $msg \ |
| 160 |
[catch {lsort [glob -types {{macintosh creator FOOC}} *.test]} msg] $msg \ |
| 161 |
[catch {lsort [glob -types {{macintosh creator FOOC} {macintosh type FOOT}} *.test]} msg] $msg \ |
| 162 |
[catch {lsort [glob -types hidden *.test]} msg] $msg \ |
| 163 |
[catch {lsort [glob -types {hidden FOOT} *.test]} msg] $msg \ |
| 164 |
] |
| 165 |
cd .. |
| 166 |
file delete -force globtest |
| 167 |
set res |
| 168 |
} [list \ |
| 169 |
0 {bar.test baz.test dir.test foo.test inv.test inw.test reg.test} \ |
| 170 |
0 {bar.test baz.test inw.test} 0 {bar.test baz.test inw.test} \ |
| 171 |
1 {bad argument to "-types": FOOTT} \ |
| 172 |
1 {expected Macintosh OS type but got "FOOTT": } \ |
| 173 |
0 {foo.test inv.test reg.test} 0 {baz.test foo.test} \ |
| 174 |
0 baz.test 0 {.nv.test dir.test inv.test inw.test} \ |
| 175 |
0 inw.test |
| 176 |
] |
| 177 |
|
| 178 |
# cleanup |
| 179 |
cd $oldcwd |
| 180 |
::tcltest::cleanupTests |
| 181 |
return |