Imported Upstream version 5.45
[platform/upstream/expect.git] / tests / spawn.test
1 # Commands covered:  spawn
2 #
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands.  Sourcing this file into Tcl runs the tests and
5 # generates output for errors.  No output means no errors were found.
6
7 if {[lsearch [namespace children] ::tcltest] == -1} {
8     package require tcltest
9     # do this in a way that is backward compatible for Tcl 8.3
10     namespace import ::tcltest::test ::tcltest::cleanupTests
11 }
12 package require Expect
13
14 log_user 0
15
16 #exp_internal -f /dev/ttyp5 0
17
18 test spawn-1.1 {basic spawn operation} {
19         set x [catch {exp_spawn cat}]
20         set first_spawn_id $spawn_id; # save for later test
21         exp_close;exp_wait
22         set x
23 } {0}
24
25 test spawn-1.2 {spawn cat, then simple send/expect sequence} {
26     set cat [exp_spawn -noecho cat -u]
27     exp_send "a\r"
28     expect "a" {set x 1} timeout {set x 0}
29     exp_close;exp_wait
30     set x
31 } {1}
32
33 test spawn-1.3 {spawn two processes simultaneously} {
34     exp_spawn -noecho cat; set cat $spawn_id
35     exp_spawn -noecho cat; set cat2 $spawn_id
36     set x [expr {0!=[string compare [exp_pid -i $cat2] [exp_pid -i $cat]]}]
37     exp_close -i $cat;exp_wait -i $cat;exp_close -i $cat2;exp_wait -i $cat2
38     set x
39 } {1}
40
41 test spawn-1.4 {spawn open file} {
42         set x 0
43         set y 0
44
45         set file [open /tmp/[pid] w]
46         puts $file "testing expect's spawn -open"
47         exp_close $file
48         set pid [exp_spawn -open [open /tmp/[pid]]]
49         expect "testing expect's spawn -open" {set x 1}
50         expect eof {set y 1}
51         exec rm /tmp/[pid]
52         exp_wait
53         list $x $y $pid
54 } {1 1 0}
55
56 test spawn-1.5 {spawn with no fd leak} {
57         exp_spawn cat
58         set x [expr {"$first_spawn_id"=="$spawn_id"}]
59         exp_close; exp_wait
60         set x
61 } {1}   
62
63 # looks to be some control-char problem
64 #ftest spawn-1.6 {spawn with echo} {
65 #       exp_spawn cat
66 #} {spawn cat}
67         
68 #ftest spawn-1.7 {spawn with -noecho} {
69 #       exp_spawn -noecho cat
70 #} {}
71
72 cleanupTests
73 return