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 job ids specified
|
|
|
|
set error_msg "three job ids specified: Fail"
|
|
|
|
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "sleep 0.3 &; sleep 0.1 &; sleep 0.2 &; sleep 0.4 &;"
|
2017-10-22 07:10:23 +00:00
|
|
|
expect_prompt
|
2018-04-15 02:42:57 +00:00
|
|
|
send_line "wait %1 %3 %4"
|
2019-01-01 01:36:08 +00:00
|
|
|
expect "Job 2, 'sleep 0.1 &' has ended" {} timeout { puts stderr $error_msg }
|
|
|
|
expect "Job 3, 'sleep 0.2 &' has ended" {} timeout { puts stderr $error_msg }
|
|
|
|
expect "Job 1, 'sleep 0.3 &' has ended" {} timeout { puts stderr $error_msg }
|
|
|
|
expect_prompt "Job 4, 'sleep 0.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 }
|
|
|
|
|
|
|
|
# specify job ids with -n option
|
|
|
|
set error_msg "specify job ids with -n option: Fail"
|
|
|
|
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "sleep 0.3 &; sleep 0.1 &; sleep 0.2 &"
|
2017-10-22 07:10:23 +00:00
|
|
|
expect_prompt
|
2018-04-15 02:42:57 +00:00
|
|
|
send_line "wait -n %1 %3"
|
2019-01-01 01:36:08 +00:00
|
|
|
expect "Job 2, 'sleep 0.1 &' has ended" {} timeout { puts stderr $error_msg }
|
|
|
|
expect_prompt "Job 3, 'sleep 0.2 &' has ended" {} unmatched { puts stderr $error_msg }
|
2018-04-15 02:42:57 +00:00
|
|
|
send_line "wait -n %1"
|
2019-01-01 01:36:08 +00:00
|
|
|
expect_prompt "Job 1, 'sleep 0.3 &' 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 }
|
|
|
|
|
2018-03-24 17:21:15 +00:00
|
|
|
# don't wait for stopped jobs
|
|
|
|
set error_msg "don't wait for stopped jobs: Fail"
|
2017-10-22 07:10:23 +00:00
|
|
|
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "sleep 0.3 &"
|
2017-10-22 07:10:23 +00:00
|
|
|
expect_prompt
|
2018-04-15 02:42:57 +00:00
|
|
|
send_line "kill -STOP %1"
|
2017-10-22 07:10:23 +00:00
|
|
|
expect_prompt
|
|
|
|
send_line "wait"
|
|
|
|
expect_prompt
|
2018-04-15 02:42:57 +00:00
|
|
|
send_line "wait %1"
|
2017-10-22 07:10:23 +00:00
|
|
|
expect_prompt
|
|
|
|
send_line "wait -n"
|
|
|
|
expect_prompt
|
2018-04-15 02:42:57 +00:00
|
|
|
send_line "bg %1"
|
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
|
2018-03-24 17:21:15 +00:00
|
|
|
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 }
|
2018-03-24 17:21:15 +00:00
|
|
|
|
|
|
|
# wait for jobs by its process name with -n option
|
|
|
|
set error_msg "wait for jobs by its process name with -n option: Fail"
|
|
|
|
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "for i in (seq 1 3); sleep 0.\$i &; end"
|
2018-03-24 17:21:15 +00:00
|
|
|
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"
|
|
|
|
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "for i in (seq 1 10); ls | sleep 0.2 | cat > /dev/null &; end"
|
2018-03-24 17:21:15 +00:00
|
|
|
expect_prompt
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "sleep 0.3 | cat &"
|
2018-03-24 17:21:15 +00:00
|
|
|
expect_prompt
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "sleep 0.1 &"
|
2018-03-24 17:21:15 +00:00
|
|
|
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 }
|
|
|
|
|
2018-03-25 05:22:27 +00:00
|
|
|
# test with fish script
|
2018-03-25 05:24:23 +00:00
|
|
|
set error_msg "test with fish script: Fail"
|
|
|
|
|
2019-01-01 01:36:08 +00:00
|
|
|
send_line "fish -c 'sleep 0.2 &; sleep 0.3 &; sleep 0.1 &; wait -n sleep; jobs | wc -l'"
|
2018-03-25 05:22:27 +00:00
|
|
|
expect "1" {} timeout { puts stderr $error_msg }
|
|
|
|
expect_prompt
|
|
|
|
|
2018-03-24 17:21:15 +00:00
|
|
|
# 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 }
|