File: wait.expect

package info (click to toggle)
fish 3.0.2-2%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,448 kB
  • sloc: ansic: 75,559; cpp: 43,314; sh: 9,096; javascript: 7,710; python: 2,538; makefile: 1,461; objc: 709; perl: 367; xml: 18
file content (125 lines) | stat: -rw-r--r-- 4,036 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
# vim: set filetype=expect:
spawn $fish
expect_prompt

# one background job
set error_msg "one background job: Fail"

send_line "sleep 1 &"
expect_prompt
send_line "wait"
expect_prompt "Job 1, 'sleep 1 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# three job ids specified
set error_msg "three job ids specified: Fail"

send_line "sleep 3 &; sleep 1 &; sleep 2 &; sleep 4 &;"
expect_prompt
send_line "wait %1 %3 %4"
expect "Job 2, 'sleep 1 &' has ended" {} timeout { puts stderr $error_msg }
expect "Job 3, 'sleep 2 &' has ended" {} timeout { puts stderr $error_msg }
expect "Job 1, 'sleep 3 &' has ended" {} timeout { puts stderr $error_msg }
expect_prompt "Job 4, 'sleep 4 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# specify job ids with -n option
set error_msg "specify job ids with -n option: Fail"

send_line "sleep 3 &; sleep 1 &; sleep 2 &"
expect_prompt
send_line "wait -n %1 %3"
expect "Job 2, 'sleep 1 &' has ended" {} timeout { puts stderr $error_msg }
expect_prompt "Job 3, 'sleep 2 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "wait -n %1"
expect_prompt "Job 1, 'sleep 3 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# don't wait for stopped jobs
set error_msg "don't wait for stopped jobs: Fail"

send_line "sleep 3 &"
expect_prompt
send_line "kill -STOP %1"
expect_prompt
send_line "wait"
expect_prompt
send_line "wait %1"
expect_prompt
send_line "wait -n"
expect_prompt
send_line "bg %1"
expect_prompt
send_line "wait"
expect_prompt
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# return immediately when no jobs
set error_msg "return immediately when no jobs: Fail"

send_line "wait"
expect_prompt
send_line "wait -n"
expect_prompt
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# wait for jobs by its process name with -n option
set error_msg "wait for jobs by its process name with -n option: Fail"

send_line "for i in (seq 1 3); sleep \$i &; end"
expect_prompt
send_line "wait -n sleep"
expect_prompt
send_line "jobs | wc -l"
expect "2" {} timeout { puts stderr $error_msg }
expect_prompt
send_line "wait"
expect_prompt
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# complex case
set error_msg "complex case: Fail"

send_line "for i in (seq 1 10); ls | sleep 2 | cat > /dev/null &; end"
expect_prompt
send_line "sleep 3 | cat &"
expect_prompt
send_line "sleep 1 &"
expect_prompt
send_line "wait \$last_pid sleep"
expect_prompt
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# don't wait for itself
set error_msg "don't wait for itself: Fail"

send_line "wait wait"
expect_prompt "wait: Could not find child processes with the name 'wait'" {} unmatched { puts stderr $error_msg }
send_line "wait -n wait"
expect_prompt "wait: Could not find child processes with the name 'wait'" {} unmatched { puts stderr $error_msg }
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }

# test with fish script
set error_msg "test with fish script: Fail"

send_line "fish -c 'sleep 2 &; sleep 3 &; sleep 1 &; wait -n sleep; jobs | wc -l'"
expect "1" {} timeout { puts stderr $error_msg }
expect_prompt

# test error messages
set error_msg "test error messages: Fail"

send_line "wait 0"
expect_prompt "wait: '0' is not a valid process id" {} unmatched { puts stderr $error_msg }
send_line "wait 1"
expect_prompt "wait: Could not find a job with process id '1'" {} unmatched { puts stderr $error_msg }
send_line "wait hoge"
expect_prompt "wait: Could not find child processes with the name 'hoge'" {} unmatched { puts stderr $error_msg }