fish-shell/tests/wait.expect

187 lines
6.4 KiB
Text
Raw Normal View History

2017-10-22 07:10:23 +00:00
# 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 background jobs
set error_msg "three background jobs: Fail"
send_line "sleep 3 &; sleep 1 &; sleep 2 &"
expect_prompt
send_line "wait"
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_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 }
# one job id specified
set error_msg "one job id specified: Fail"
2017-10-22 07:10:23 +00:00
send_line "sleep 3 &; set pid1 \$last_pid; sleep 1 &; set pid2 \$last_pid; sleep 2 &; set pid3 \$last_pid;"
2017-10-22 07:10:23 +00:00
expect_prompt
send_line "wait \$pid3"
expect "Job 3, 'sleep 1 &' has ended" {} timeout { puts stderr $error_msg }
expect_prompt "Job 4, 'sleep 2 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "wait \$pid1"
2017-10-22 07:10:23 +00:00
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 }
# three job ids specified
set error_msg "three job ids specified: Fail"
send_line "sleep 3 &; set pid1 \$last_pid; sleep 1 &; set pid2 \$last_pid; sleep 2 &; set pid3 \$last_pid; sleep 4 &; set pid4 \$last_pid;"
2017-10-22 07:10:23 +00:00
expect_prompt
send_line "wait \$pid1 \$pid3 \$pid4"
expect "Job 3, 'sleep 1 &' has ended" {} timeout { puts stderr $error_msg }
expect "Job 4, 'sleep 2 &' has ended" {} timeout { puts stderr $error_msg }
2017-10-22 07:10:23 +00:00
expect "Job 1, 'sleep 3 &' has ended" {} timeout { puts stderr $error_msg }
expect_prompt "Job 5, 'sleep 4 &' has ended" {} unmatched { puts stderr $error_msg }
2017-10-22 07:10:23 +00:00
send_line "jobs"
expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg }
# wait with -n option
set error_msg "wait with -n option: Fail"
send_line "sleep 3 &; set pid1 \$last_pid; sleep 1 &; set pid2 \$last_pid; sleep 2 &; set pid3 \$last_pid;"
2017-10-22 07:10:23 +00:00
expect_prompt
send_line "wait -n"
expect_prompt "Job 3, 'sleep 1 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "wait --any"
expect_prompt "Job 4, 'sleep 2 &' has ended" {} unmatched { puts stderr $error_msg }
2017-10-22 07:10:23 +00:00
send_line "wait -n"
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 }
# specify job ids with -n option
set error_msg "specify job ids with -n option: Fail"
send_line "sleep 3 &; set pid1 \$last_pid; sleep 1 &; set pid2 \$last_pid; sleep 2 &; set pid3 \$last_pid;"
2017-10-22 07:10:23 +00:00
expect_prompt
send_line "wait -n \$pid1 \$pid3"
expect "Job 3, 'sleep 1 &' has ended" {} timeout { puts stderr $error_msg }
expect_prompt "Job 4, 'sleep 2 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "wait -n \$pid1"
2017-10-22 07:10:23 +00:00
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"
2017-10-22 07:10:23 +00:00
send_line "sleep 3 &"
expect_prompt
send_line "kill -STOP \$last_pid"
2017-10-22 07:10:23 +00:00
expect_prompt
send_line "wait"
expect_prompt
send_line "wait \$last_pid"
2017-10-22 07:10:23 +00:00
expect_prompt
send_line "wait -n"
expect_prompt
send_line "bg \$last_pid"
2017-10-22 07:10:23 +00:00
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"
2017-10-22 07:10:23 +00:00
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
set error_msg "wait for jobs by its process name: Fail"
send_line "for i in (seq 1 10); sleep 2 &; end"
expect_prompt
send_line "wait sleep"
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 }
# complex case 2
set error_msg "complex case 2: Fail"
send_line "for i in (seq 2 4); ls | sleep \$i | cat > /dev/null &; end"
expect_prompt
send_line "sleep 3 | cat &"
expect_prompt
send_line "sleep 1 &"
expect_prompt
send_line "wait -n cat"
expect_prompt
send_line "jobs | wc -l"
expect "3" {} timeout { puts stderr $error_msg }
expect_prompt
send_line "wait"
expect_prompt "Job 4, 'sleep 3 | cat &' 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 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 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 }