fish-shell/tests/wait.expect
2018-03-09 10:50:43 -06:00

108 lines
3.9 KiB
Text

# 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"
send_line "sleep 3 &; set pid1 \$last_pid; sleep 1 &; set pid2 \$last_pid; sleep 2 &; set pid3 \$last_pid;"
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"
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;"
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 }
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 }
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;"
expect_prompt
send_line "wait -n"
expect_prompt "Job 3, 'sleep 1 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "wait -n"
expect_prompt "Job 4, 'sleep 2 &' has ended" {} unmatched { puts stderr $error_msg }
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;"
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"
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 stopped jobs
set error_msg "don't wait stopped jobs: Fail"
send_line "sleep 3 &"
expect_prompt
send_line "kill -STOP \$last_pid"
expect_prompt
send_line "wait"
expect_prompt
send_line "wait \$last_pid"
expect_prompt
send_line "wait -n"
expect_prompt
send_line "bg \$last_pid"
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 "don't wait stopped 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 }