Imported from ../bash-3.1.tar.gz.
[platform/upstream/bash.git] / tests / jobs.tests
index cd044f1..5866b0c 100644 (file)
@@ -1,6 +1,34 @@
+# test out %+, jobs -p, and $! agreement in a subshell first
+${THIS_SH} ./jobs1.sub
+
+# test out fg/bg failure in a subshell
+${THIS_SH} ./jobs2.sub
+
+# test out behavior of waiting for background pids -- bug in versions
+# before 2.03
+${THIS_SH} ./jobs3.sub
+
+# test out behavior of using job control notation when job control is not
+# active
+${THIS_SH} ./jobs4.sub
+
 jobs
 echo $?
 
+# a no-such-job error, since we can use job control notation without job control
+wait %1
+
+# make sure we can't fg a job started when job control was not active
+sleep 30 &
+pid=$!
+fg %1
+# make sure the killed processes don't cause a message
+exec 5>&2
+exec 2>/dev/null
+kill -n 9 $pid
+wait    # make sure we reap the processes while stderr is still redirected
+exec 2>&5
+
 echo wait-for-pid
 sleep 10 &
 wait $!
@@ -68,13 +96,17 @@ fg -s %1
 bg -s %1
 wait
 
-# someday this may mean to disown all running jobs, but for now it is
+# someday this may mean to disown all stopped jobs, but for now it is
 # an error
-disown -r
+disown -s
 
-# this is an error
+# this is an error -- the job with the pid that is the value of $! is
+# retained only until a `wait' is performed
 disown %1
 
+# this, however, is an error
+disown %2
+
 echo wait-for-non-child
 wait 1
 echo $?
@@ -93,6 +125,12 @@ jobs -r
 
 # should be an error
 kill -n 1 %4
+# should be an error
+jobs %4
+echo current job:
+jobs %+
+echo previous job:
+jobs %-
 
 kill -STOP %2
 sleep 5        # give time for the shell to get the stop notification