File: tests.tcl

package info (click to toggle)
tclreadline 2.3.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,848 kB
  • sloc: tcl: 5,697; sh: 4,217; ansic: 720; makefile: 80
file content (329 lines) | stat: -rwxr-xr-x 7,256 bytes parent folder | download
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#! /usr/bin/env tclsh
# -*- tclsh -*-
# FILE: tests.tcl
# $Id: e31caa736f35d8fc2643c5067e8a67d22a220614 $
# ---
# tclreadline -- gnu readline for tcl
# https://github.com/flightaware/tclreadline/
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# Copyright (c) 2016, dbohdan <dbohdan@dbohdan.com>
# This software is copyright under the BSD license.
# ---

package require Expect
package require tcltest

::tcltest::configure {*}$::argv

::tcltest::testConstraint itcl3 [expr {
    ![catch { package require Itcl 3.0 }]
}]
::tcltest::testConstraint itcl4 [expr {
    ![catch { package require itcl 4.0 }]
}]
::tcltest::testConstraint itcl [expr {
    [::tcltest::testConstraint itcl3] || [::tcltest::testConstraint itcl4]
}]
::tcltest::testConstraint tcloo [expr {
    ![catch { package require TclOO 1.0 }]
}]

set prompt {% }
set tclshrc [file join $::env(HOME) .tclshrc]

proc setup {} {
    match_max 100000
    set ::timeout 2
    expect_before {
        timeout {
            error {timed out}
        }
        invalid {
            error {invalid command}
        }
    }

    if {[file exists $::tclshrc]} {
        file rename $::tclshrc ${::tclshrc}.renamed
    }

    trap {
        send \x03
        cleanup
        exit 1
    } {SIGINT SIGHUP}

    puts \n----
    uplevel #0 spawn [info nameofexecutable]
    send "package require tclreadline\r"
    expect -exact $::prompt
    send "::tclreadline::Loop\r"
    expect -exact \]
}

proc cleanup {} {
    send \rexit\r

    if {![file exists $::tclshrc] && [file exists $::tclshrc.renamed]} {
        file rename $::tclshrc.renamed ${::tclshrc}
    }
}

proc send_nl args {
    send [join $args \r]\r
}

tcltest::test basic-1.1 {::tclreadline::Loop} \
        -setup setup \
        -cleanup cleanup \
        -body {}

tcltest::test namespace-1.1 {namespace path completion} \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl \
            {namespace eval ::foo {}} \
            {namespace eval ::foo::bar {}}
    expect -exact \]
    send "namespace eval ::foo\t"
    expect -exact ::bar
}

tcltest::test variable-1.1 {variable namespace path completion} \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl \
            {namespace eval ::bar {}} \
            {set ::bar::baz value1}
    expect -exact \]
    send "set ::bar\t"
    expect -exact ::baz
}

tcltest::test variable-1.2 {partial variable name completion after '$'} \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl {set foo 5}
    expect -exact \]
    send "lindex \$f\t"
    expect -exact foo
    send \r
    expect 5
}

tcltest::test variable-1.3 {empty variable name completion after '$'} \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl {set bar 5}
    expect -exact \]
    send "puts \$\t"
    sleep 0.2
    send \t
    expect -exact bar
}

tcltest::test itcl-1.1 {itcl method name completion} \
        -constraints itcl \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl {
        # Prefer [incr Tcl] 4.
        if {[catch {package require itcl}]} {
            package require Itcl
        }
    }
    send_nl {
        ::itcl::class cls {
            public variable opt
            method aleph {} {}
            method beth {} {}
        }
    }
    expect -exact \]
    send_nl {cls obj}
    expect -exact \]
    send "obj a\t"
    sleep 0.2
    send \t
    expect -exact aleph
}

tcltest::test itcl-2.1 {itcl method argument hints} \
        -constraints itcl \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl {
        # Prefer [incr Tcl] 4.
        if {[catch {package require itcl}]} {
            package require Itcl
        }
    }
    send_nl {
        ::itcl::class cls {
            method foo {bar baz quux asdf} {}
        }
    }
    expect -exact \]
    send_nl {cls obj}
    expect -exact \]
    send "obj foo \t"
    sleep 0.2
    send \t
    expect -exact <bar>
    send "arg1 \t"
    sleep 0.2
    send \t
    expect -exact <baz>
    send "arg2 \t"
    sleep 0.2
    send \t
    expect -exact <quux>
    send "arg3 \t"
    sleep 0.2
    send \t
    expect -exact <asdf>
}

tcltest::test itcl-3.1 {itcl option name completion for cget and configure} \
        -constraints itcl \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl {
        # Prefer [incr Tcl] 4.
        if {[catch {package require itcl}]} {
            package require Itcl
        }
    }
    send_nl {
        ::itcl::class cls {
            public variable opt
            method aleph {} {}
            method beth {} {}
        }
    }
    expect -exact \]
    send_nl {cls obj}
    expect -exact \]
    send "obj cget -o\t"
    sleep 0.2
    send \t
    expect -exact -opt
    send \r
    send "obj configure -o\t"
    expect -exact -opt
}

tcltest::test itcl-4.1 {itcl wrong method name} \
        -constraints itcl \
        -setup setup \
        -cleanup cleanup \
        -body {
    set ::timeout 1
    send_nl {
        # Prefer [incr Tcl] 4.
        if {[catch {package require itcl}]} {
            package require Itcl
        }
    }
    send_nl {
        ::itcl::class cls {
            method foo {} {}
        }
    }
    expect -exact \]
    send_nl {cls obj}
    expect -exact \]
    send "obj nope \t"
    expect {
        {error during evaluation} {
            error {error during evaluation}
        }
    }
} -returnCodes 1 -result {timed out}

tcltest::test tcloo-1.1 {TclOO method name completion} \
        -constraints tcloo \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl {package require TclOO}
    send_nl {::oo::class create cls { method bar {} {}; method baz {} {} }}
    expect -exact \]
    send_nl {set quux [cls new]}
    expect -exact \]
    send "\$quux \t"
    sleep 0.2
    send \t\r
    expect -glob "*bar*baz*"
}

tcltest::test tcloo-2.1 {TclOO method argument hints} \
        -constraints tcloo \
        -setup setup \
        -cleanup cleanup \
        -body {
    send_nl {
        ::oo::class create ::cls {
            method foo {bar baz quux asdf} {}
        }
    }
    expect -exact \]
    send_nl {set obj [::cls new]}
    expect -exact \]
    send "\$obj foo \t"
    sleep 0.2
    send \t
    expect -exact <bar>
    send "arg1 \t"
    sleep 0.2
    send \t
    expect -exact <baz>
    send "arg2 \t"
    sleep 0.2
    send \t
    expect -exact <quux>
    send "arg3 \t"
    sleep 0.2
    send \t
    expect -exact <asdf>
}

tcltest::test tcloo-3.1 {TclOO wrong method name} \
        -constraints tcloo \
        -setup setup \
        -cleanup cleanup \
        -body {
    set ::timeout 1
    send_nl {
        ::oo::class create cls {
            method foo {} {}
        }
    }
    expect -exact \]
    send_nl {set obj [cls new]}
    expect -exact \]
    send "\$obj nope \t"
    sleep 0.2
    send \t

    expect {
        {error during evaluation} {
            error {error during evaluation}
        }
    }
} -returnCodes 1 -result {timed out}

# Exit with a nonzero status if there are failed tests.
set failed [expr {$tcltest::numTests(Failed) > 0}]

tcltest::cleanupTests
if {$failed} {
    exit 1
}