Skip to content

Commit

Permalink
Scripted test for fg built-in
Browse files Browse the repository at this point in the history
  • Loading branch information
magicant committed Jan 8, 2024
1 parent 617c2ec commit 4773aa4
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions yash/tests/scripted_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ fn export_builtin() {
run("export-p.sh")
}

#[test]
fn fg_builtin() {
run_with_pty("fg-p.sh")
}

#[test]
fn fnmatch() {
run("fnmatch-p.sh")
Expand Down
78 changes: 78 additions & 0 deletions yash/tests/scripted_test/fg-p.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# fg-p.sh: test of the fg built-in for any POSIX-compliant shell

posix="true"

cat >job1 <<\__END__
exec sh -c 'echo 1; kill -s STOP $$; echo 2'
__END__

cat >job2 <<\__END__
exec sh -c 'echo a; kill -s STOP $$; echo b'
__END__

chmod a+x job1
chmod a+x job2

mkfifo fifo

test_O -d -e n 'fg cannot be used when job control is disabled' +m
:&
fg
__IN__

test_oE 'default operand chooses most recently suspended job' -m
:&
sh -c 'kill -s STOP $$; echo 1'
fg >/dev/null
__IN__
1
__OUT__

: TODO Needs to find a way to test this <<\__IN__
test_oE 'resumed job is in foreground' -m
sh -c 'kill -s STOP $$; ...'
fg >/dev/null
__IN__

: TODO Needs the kill built-in <<\__IN__
test_x -e 127 'resumed job is disowned unless suspended again' -m
cat fifo >/dev/null &
exec 3>fifo
kill -s STOP %
exec 3>&-
fg >/dev/null
wait $!
__IN__

test_oE 'specifying job ID' -m
./job1
./job2
fg %./job1 >/dev/null
fg %./job2 >/dev/null
__IN__
1
a
2
b
__OUT__

test_oE 'fg prints resumed job' -m
./job1
fg
__IN__
1
./job1
2
__OUT__

test_O -d -e n 'no existing job' -m
fg
__IN__

test_O -d -e n 'no such job' -m
sh -c 'kill -s STOP $$'
fg %_no_such_job_
exit_status=$?
fg >/dev/null
exit $exit_status
__IN__

0 comments on commit 4773aa4

Please sign in to comment.