1# fg-p.tst: test of the fg built-in for any POSIX-compliant shell
2../checkfg || skip="true" # %REQUIRETTY%
3
4posix="true"
5
6cat >job1 <<\__END__
7exec sh -c 'echo 1; kill -s STOP $$; echo 2'
8__END__
9
10cat >job2 <<\__END__
11exec sh -c 'echo a; kill -s STOP $$; echo b'
12__END__
13
14chmod a+x job1
15chmod a+x job2
16
17mkfifo fifo
18
19test_O -d -e n 'fg cannot be used when job control is disabled' +m
20:&
21fg
22__IN__
23
24test_oE 'default operand chooses most recently suspended job' -m
25:&
26sh -c 'kill -s STOP $$; echo 1'
27fg >/dev/null
28__IN__
291
30__OUT__
31
32test_oE 'resumed job is in foreground' -m
33sh -c 'kill -s STOP $$; ../checkfg && echo fg'
34fg >/dev/null
35__IN__
36fg
37__OUT__
38
39test_x -e 127 'resumed job is disowned unless suspended again' -m
40cat fifo >/dev/null &
41exec 3>fifo
42kill -s STOP %
43exec 3>&-
44fg >/dev/null
45wait $!
46__IN__
47
48test_oE 'specifying job ID' -m
49./job1
50./job2
51fg %./job1 >/dev/null
52fg %./job2 >/dev/null
53__IN__
541
55a
562
57b
58__OUT__
59
60test_oE 'fg prints resumed job' -m
61./job1
62fg
63__IN__
641
65./job1
662
67__OUT__
68
69test_O -d -e n 'no existing job' -m
70fg
71__IN__
72
73test_O -d -e n 'no such job' -m
74sh -c 'kill -s STOP $$'
75fg %_no_such_job_
76exit_status=$?
77fg >/dev/null
78exit $exit_status
79__IN__
80
81# vim: set ft=sh ts=8 sts=4 sw=4 noet:
82