fish-shell/tests/wait.expect
2017-11-16 10:48:21 -08:00

108 lines
3.6 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"
send_line "sleep 3 &; sleep 1 &; sleep 2 &"
expect_prompt
send_line "wait %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 %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 }
# 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 }
# wait with -n option
set error_msg "wait with -n option: Fail"
send_line "sleep 3 &; sleep 1 &; sleep 2 &"
expect_prompt
send_line "wait -n"
expect_prompt "Job 2, 'sleep 1 &' has ended" {} unmatched { puts stderr $error_msg }
send_line "wait -n"
expect_prompt "Job 3, '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 &; 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 stopped jobs
set error_msg "don't wait 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 "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 }