summaryrefslogtreecommitdiffstats
path: root/tests/fileSystem.test
blob: eb0a082515b5a32bb2be8bca9d01923fcb31e8b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# This file tests the filesystem and vfs internals.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2002 Vincent Darley.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import -force ::tcltest::*
}

makeFile "test file" gorp.file
makeDirectory dir.file
makeFile "test file in directory" [file join dir.file inside.file]

# It would be good to be able to make these work on MacOS too.
# If we added 'file link from to' we could easily do that.
catch {exec ln -s gorp.file link.file}
catch {exec ln -s inside.file dir.file/linkinside.file}
catch {exec ln -s dir.file dir.link}

test filesystem-1.0 {link normalisation} {unixOnly} {
   string equal [file normalize gorp.file] [file normalize link.file]
} {0}

test filesystem-1.1 {link normalisation} {unixOnly} {
   string equal [file normalize dir.file] [file normalize dir.link]
} {0}

test filesystem-1.2 {link normalisation} {unixOnly} {
   string equal [file normalize gorp.file/foo] [file normalize link.file/foo]
} {1}

test filesystem-1.3 {link normalisation} {unixOnly} {
   string equal [file normalize dir.file/foo] [file normalize dir.link/foo]
} {1}

test filesystem-1.4 {link normalisation} {unixOnly} {
   string equal [file normalize dir.file/inside.file] [file normalize dir.link/inside.file]
} {1}

test filesystem-1.5 {link normalisation} {unixOnly} {
   string equal [file normalize dir.file/linkinside.file] [file normalize dir.file/linkinside.file]
} {1}

test filesystem-1.6 {link normalisation} {unixOnly} {
   string equal [file normalize dir.file/linkinside.file] [file normalize dir.link/inside.file]
} {0}

test filesystem-1.7 {link normalisation} {unixOnly} {
   string equal [file normalize dir.link/linkinside.file/foo] [file normalize dir.file/inside.file/foo]
} {1}

test filesystem-1.8 {link normalisation} {unixOnly} {
   string equal [file normalize dir.file/linkinside.filefoo] [file normalize dir.link/inside.filefoo]
} {0}

file delete -force gorp.file link.file dir.file dir.link

test filesystem-2.0 {new native path} {unixOnly} {
   foreach f [lsort [glob -nocomplain /usr/bin/c*]] {
       catch {file readlink $f}
   }
   # If we reach here we've succeeded. We used to crash above.
   expr 1
} {1}

# Make sure the testfilesystem hasn't been registered.
while {![catch {testfilesystem 0}]} {}

test filesystem-3.0 {Tcl_FSRegister} {
    testfilesystem 1
} {registered}

test filesystem-3.1 {Tcl_FSUnregister} {
    testfilesystem 0
} {unregistered}

test filesystem-3.2 {Tcl_FSUnregister} {
    list [catch {testfilesystem 0} err] $err
} {1 failed}

test filesystem-3.3 {Tcl_FSRegister} {
    testfilesystem 1
    testfilesystem 1
    testfilesystem 0
    testfilesystem 0
} {unregistered}

test filesystem-3.4 {Tcl_FSRegister} {
    testfilesystem 1
    file system bar
} {reporting}

test filesystem-3.5 {Tcl_FSUnregister} {
    testfilesystem 0
    file system bar
} {native}

test filesystem-4.0 {testfilesystem} {
    -match glob
    -body {
	testfilesystem 1
	set filesystemReport {}
	file exists foo
	testfilesystem 0
	set filesystemReport
    }
    -result {* {access foo}}
}

test filesystem-4.1 {testfilesystem} {
    -match glob
    -body {
	testfilesystem 1
	set filesystemReport {}
	catch {file stat foo bar}
	testfilesystem 0
	set filesystemReport
    }
    -result {* {stat foo}}
}

test filesystem-4.2 {testfilesystem} {
    -match glob
    -body {
	testfilesystem 1
	set filesystemReport {}
	catch {file lstat foo bar}
	testfilesystem 0
	set filesystemReport
    }
    -result {* {lstat foo}}
}

test filesystem-4.3 {testfilesystem} {
    -match glob
    -body {
	testfilesystem 1
	set filesystemReport {}
	catch {glob *}
	testfilesystem 0
	set filesystemReport
    }
    -result {* {matchindirectory *}*}
}

test filesystem-5.1 {cache and ~} {
    -body {
	set orig $env(HOME)
	set ::env(HOME) /foo/bar/blah
	set testdir ~
	set res1 "Parent of ~ (/foo/bar/blah) is [file dirname $testdir]"
	set ::env(HOME) /a/b/c
	set res2 "Parent of ~ (/a/b/c) is [file dirname $testdir]"
	list $res1 $res2
    }
    -result {{Parent of ~ (/foo/bar/blah) is /foo/bar} {Parent of ~ (/a/b/c) is /a/b}}
}

	
# cleanup
catch {unset filesystemReport}
# Make sure the testfilesystem hasn't been registered.
while {![catch {testfilesystem 0}]} {}

::tcltest::cleanupTests
return