unix.exp 1.41 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
set nl "\r?\n"
set any "\[ -\]"
set deep_any "\\\[ -\\\]"

set stty_init "-echo -onlcr -ocrnl -istrip"

proc l2g_start {} {
    global spawn_id
    global l2g

    spawn $l2g
}

proc l2g_stop {} {
    global spawn_id

    close
}

proc l2g_send {str} {
    unanchored_expect "^l2g> " "prompt before $str"
22
    verbose "sending $str"
Per Cederqvist's avatar
Per Cederqvist committed
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
    send "$str\n"
}

proc simple_expect {regex {testname ""}} {
    global test
    global any
    global nl

    set test $testname
    if {$test == ""} {
	set test "looking for $regex"
    }
    expect {
	-re "^$regex$nl" {pass "$test"}
	timeout 	 {fail "$test (timeout)"}
	eof 		 {fail "$test (eof)"; wait}
	buffer_full 	{fail "$test (buffer_full)"}
	-re "($any*)$nl" {
	    fail "$test (unexpected line '$expect_out(1,string)' waiting for '$regex')"
	}
	-re "($any*)l2g>" {
	    fail "$test (unexpected incomplete line '$expect_out(1,string)' waiting for '$regex')"
	}
    }
    unset test
}

proc unanchored_expect {regex testname} {
    global test
    global any
    global nl

    set test $testname
    expect {
	-re "$regex" 	{pass "$test"}
	timeout 	{fail "$test (timeout)"}
	buffer_full 	{fail "$test (buffer_full)"}
	eof 		{fail "$test (eof)"; wait}
	-re "($any*)$nl" {
	    fail "$test (unexpected line '$expect_out(1,string)' waiting for '$regex')"
	}
	-re "($any*)l2g>" {
	    fail "$test (unexpected incomplete line '$expect_out(1,string)' waiting for '$regex')"
	}
    }
    unset test
}