aboutsummaryrefslogtreecommitdiff
path: root/tests/file.test
blob: fb5a555cca7cfb2e75e104bc8d92e1483a5b260c (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
source [file dirname [info script]]/testing.tcl

needs cmd file

test join-1.1 "One name" {
	file join abc
} {abc}

test join-1.2 "One name with trailing slash" {
	file join abc/
} {abc}

test join-1.3 "One name with leading slash" {
	file join /abc
} {/abc}

test join-1.4 "One name with leading and trailing slash" {
	file join /abc/
} {/abc}

test join-1.5 "Two names" {
	file join abc def
} {abc/def}

test join-1.6 "Two names with dir trailing slash" {
	file join abc/ def
} {abc/def}

test join-1.7 "Two names with dir leading slash" {
	file join /abc def
} {/abc/def}

test join-1.8 "Two names with dir leading and trailing slash" {
	file join /abc/ def
} {/abc/def}

test join-1.9 "Two names with file trailing slash" {
	file join abc def/
} {abc/def}

test join-1.10 "Two names with file leading slash" {
	file join abc /def
} {/def}

test join-1.11 "Two names with file leading and trailing slash" {
	file join abc /def/
} {/def}

test join-1.12 "Two names with double slashes" {
	file join abc/ /def
} {/def}

test join-1.13 "Join to root" {
	file join / abc
} {/abc}

test join-1.14 "Join to root" {
	set dir [file join / .]
	# Either / or /. is OK here
	expr {$dir in {/ /.}}
} 1

test join-1.15 "Join to root" {
	file join / /
} {/}

test join-1.16 "Join to root" {
	file join /abc /
} {/}

test join-1.17 "With trailing slash" {
	file join /abc/def/ ghi/jkl
} {/abc/def/ghi/jkl}

test join-2.1 "Dir is empty string" {
	file join "" def
} {def}

test join-2.2 "File is empty string" {
	file join abc ""
} {abc}

test join-2.3 "Path too long" jim {
	set components [string repeat {abcdefghi } 500]
	list [catch [concat file join $components] msg] $msg
} {1 {Path too long}}

test tail-1.1 "One component" {
	file tail abc
} {abc}

test tail-1.2 "Two components" {
	file tail abc/def
} {def}

test tail-1.3 "Absolute one component" {
	file tail /abc
} {abc}

test tail-1.4 "Trailing slash" {
	file tail abc/
} {abc}

test dirname-1.1 "One component" {
	file dirname abc
} {.}

test dirname-1.2 "Two components" {
	file dirname abc/def
} {abc}

test dirname-1.3 "Absolute one component" {
	file dirname /abc
} {/}

test dirname-1.4 "Trailing slash" {
	file dirname abc/
} {.}

# These tests are courtesy of picol

test file.12.1 "picol test" {file dirname /foo/bar/grill.txt}  /foo/bar
test file.12.2 "picol test" {file dirname /foo/bar/baz/}       /foo/bar
test file.12.3 "picol test" {file dirname /foo/bar/baz///}     /foo/bar
test file.12.4 "picol test" {file dirname /foo/bar/baz///qux}  /foo/bar/baz
test file.12.5 "picol test" {file dirname foo/bar/grill.txt}   foo/bar
test file.12.6 "picol test" {file dirname foo/bar/baz/}        foo/bar
test file.12.7 "picol test" {file dirname {}}    .
test file.12.8 "picol test" {file dirname /}     /
test file.12.9 "picol test" {file dirname ///}   /

test file.13.1 "picol test" {file tail /foo/bar/grill.txt}   grill.txt
test file.13.2 "picol test" {file tail /foo/bar/baz/}        baz
test file.13.3 "picol test" {file tail /foo/bar/baz///}      baz
test file.13.4 "picol test" {file dirname /foo/bar/baz///qux}  /foo/bar/baz
test file.13.5 "picol test" {file tail foo/bar/grill.txt}    grill.txt
test file.13.6 "picol test" {file tail foo/bar/baz/}         baz
test file.13.7 "picol test" {file tail {}}    {}
test file.13.8 "picol test" {file tail /}     {}
test file.13.9 "picol test" {file tail ///}   {}

test file.14   "picol test" {file join foo}               foo
test file.15   "picol test" {file join foo bar}           foo/bar
test file.16   "picol test" {file join foo /bar}          /bar

if {$tcl_platform(platform) eq {windows}} {
    test file.17  "picol test" {file join foo C:/bar grill}  C:/bar/grill
}

test file.18   "picol test" {file split {/foo/space station/bar}}  {/ foo {space station} bar}
test file.19   "picol test" {file split {/foo/space station/bar/}}  {/ foo {space station} bar}
test file.20   "picol test" {file split {foo/space station/bar}}  {foo {space station} bar}
test file.21   "picol test" {file split foo///bar}  {foo bar}
test file.22   "picol test" {file split foo}  foo

testreport