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
|
# -*- tcl -*- Commands covered: cat (UNIX), expect
#
# 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.
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
# do this in a way that is backward compatible for Tcl 8.3
namespace import ::tcltest::test ::tcltest::cleanupTests
}
package require Expect
catch {unset x}
log_user 0
exp_spawn cat -u
exp_stty -echo < $spawn_out(slave,name)
test expect-1.1 {exact pattern} {
expect "*"
exp_send "a\r"
set timeout 10
set x 0
expect -ex a {set x 1}
set x
} {1}
test expect-1.2 {exact pattern buffering} {
expect "*"
exp_send "hiahi\r"
set timeout 10
set x 0
expect -ex hi
expect -ex hi {set x 1}
set x
} {1}
# if only this test fails, then configure has guessed incorrectly and
# stty accesses the control terminal from stdout. The quick fix is
# to edit expect_cf.h and define STTY_READS_STDOUT to 1. (It should
# be commented out.) If you figure out a way to fix the configure test,
# let me know. Else, let me know a way to test for your particular
# machine and os version so it can be hardwired.
test expect-1.3 {exact pattern failure} {
expect "*"
exp_send "hiahi\r"
set timeout 10
set x 0
expect -ex hi {set x 1}
expect -ex hi {set x 2}
expect -ex hi {set x 3}
set x
} {2}
test expect-1.4 {glob pattern} {
expect "*"
exp_send "a\r"
set timeout 10
set x 0
expect "a" {set x 1}
set x
} {1}
test expect-1.5 {glob pattern buffering} {
expect "*"
exp_send "a\r"
set timeout 10
set x 0
expect "*" {set x 1}
set x
} {1}
test expect-1.6 {glob buffer} {
expect "*"
exp_send "philosophic\r"
set timeout 10
set x 0
expect "hi"
set x [string match *phi $expect_out(buffer)]
} {1}
test expect-1.7 {glob string} {
expect "*"
exp_send "philosophic\r"
set timeout 10
set x 0
expect "hi"
set expect_out(0,string)
} {hi}
test expect-1.10 {re pattern, gate keeping} {
expect "*"
exp_stty raw < $spawn_out(slave,name)
exp_send "\rats-sw-8>show clock"
#exp_internal 1
set timeout 10
set x 0
expect -re {(.*)show clock$} {set x 1}
#exp_internal 0
exp_stty -raw < $spawn_out(slave,name)
set x
} {1}
test expect-1.11 {re pattern, gate keeping} {
exp_stty raw < $spawn_out(slave,name)
expect "*"
exp_send "enable"
#exp_internal 1
set timeout 10
set x 0
expect -re {(.*)enable$} {set x 1}
exp_stty -raw < $spawn_out(slave,name)
#exp_internal 0
set x
} {1}
test expect-1.12 {re pattern, gate keeping} {
exp_stty raw < $spawn_out(slave,name)
expect "*"
exp_send "sh clock"
#exp_internal 1
set timeout 10
set x 0
expect -re {(.*)sh clock$} {set x 1}
exp_stty -raw < $spawn_out(slave,name)
#exp_internal 0
set x
} {1}
test expect-1.13 {re pattern, gate keeping} {
exp_stty raw < $spawn_out(slave,name)
expect "*"
exp_send "Password: "
#exp_internal 1
set timeout 10
set x 0
expect -re {^.*Password: ?$} {set x 1}
exp_stty -raw < $spawn_out(slave,name)
#exp_internal 0
set x
} {1}
close
wait
set filename /tmp/null.[pid]
set fid [open $filename w]
fconfigure $fid -encoding iso8859-1
puts $fid "a\u0000b"
close $fid
test expect-1.8 {default remove null behavior} {
spawn cat $filename
expect a\u0000b
set rc [regexp $expect_out(buffer) "ab"]
wait
set rc
} {0}
test expect-1.8b {default remove null behavior} {
spawn cat $filename
expect ab
set rc [regexp $expect_out(buffer) "ab"]
wait
set rc
} {1}
test expect-1.9 {match null inline} {
spawn cat $filename
remove_nulls 0
expect a\u0000b
set rc [regexp $expect_out(buffer) "a\u0000b"]
close
wait
set rc
} {1}
file delete -force $filename
cleanupTests
return
|