summaryrefslogtreecommitdiff
path: root/expect/tests/expect.test
blob: 73bfdb2fdaa1c8f7cffca3e1e3a40c977cd11069 (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
# 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 {[string compare test [info procs test]] == 1} then {source defs}

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}

close
wait