Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/macOSXFCmd.test @ 68

Last change on this file since 68 was 25, checked in by landauf, 16 years ago

added tcl to libs

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