mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:17:36 +00:00
Shell: Fix job control and backgrounding
This patchset makes the shell capable of lazily resolving and executing sequences of commands, to allow for putting logical sequences in the background. In particular, it enables And/Or/Sequence nodes to be run in the background, and consequently unmarks them as `would_execute`. Doing so also fixes job control to an extent, as jobs are now capable of having 'tails', so sequences can be put in the background while preserving their following sequences.
This commit is contained in:
parent
a2a54f459f
commit
715e11f692
10 changed files with 180 additions and 151 deletions
|
@ -1,13 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
setopt --verbose
|
||||
|
||||
if test 1 -eq 1 {
|
||||
# Are comments ok?
|
||||
# Basic 'if' structure, empty block.
|
||||
if true {
|
||||
} else {
|
||||
echo "if true runs false branch"
|
||||
exit 2
|
||||
}
|
||||
if false {
|
||||
echo "if false runs true branch"
|
||||
exit 2
|
||||
} else {
|
||||
}
|
||||
|
|
|
@ -23,69 +23,69 @@ test "$(echo yes)" = yes || exit 2
|
|||
alias fail="echo Failure: "
|
||||
|
||||
# Redirections.
|
||||
test -z "$(echo foo > /dev/null)" || fail direct path redirection
|
||||
test -z "$(echo foo 2> /dev/null 1>&2)" || fail indirect redirection
|
||||
test -n "$(echo foo 2> /dev/null)" || fail fds interfere with each other
|
||||
test -z "$(echo foo > /dev/null)" || fail direct path redirection && exit 2
|
||||
test -z "$(echo foo 2> /dev/null 1>&2)" || fail indirect redirection && exit 2
|
||||
test -n "$(echo foo 2> /dev/null)" || fail fds interfere with each other && exit 2
|
||||
|
||||
# Argument unpack
|
||||
test "$(echo (yes))" = yes || fail arguments inside bare lists
|
||||
test "$(echo (no)() yes)" = yes || fail arguments inside juxtaposition: empty
|
||||
test "$(echo (y)(es))" = yes || fail arguments inside juxtaposition: list
|
||||
test "$(echo "y"es)" = yes || fail arguments inside juxtaposition: string
|
||||
test "$(echo (yes))" = yes || fail arguments inside bare lists && exit 2
|
||||
test "$(echo (no)() yes)" = yes || fail arguments inside juxtaposition: empty && exit 2
|
||||
test "$(echo (y)(es))" = yes || fail arguments inside juxtaposition: list && exit 2
|
||||
test "$(echo "y"es)" = yes || fail arguments inside juxtaposition: string && exit 2
|
||||
|
||||
# String substitution
|
||||
foo=yes
|
||||
test "$(echo $foo)" = yes || fail simple string var lookup
|
||||
test "$(echo "$foo")" = yes || fail stringified string var lookup
|
||||
test "$(echo $foo)" = yes || fail simple string var lookup && exit 2
|
||||
test "$(echo "$foo")" = yes || fail stringified string var lookup && exit 2
|
||||
|
||||
# List substitution
|
||||
foo=(yes)
|
||||
# Static lookup, as list
|
||||
test "$(echo $foo)" = yes || fail simple list var lookup
|
||||
test "$(echo $foo)" = yes || fail simple list var lookup && exit 2
|
||||
# Static lookup, stringified
|
||||
test "$(echo "$foo")" = yes || fail stringified list var lookup
|
||||
test "$(echo "$foo")" = yes || fail stringified list var lookup && exit 2
|
||||
# Dynamic lookup through static expression
|
||||
test "$(echo $'foo')" = yes || fail dynamic lookup through static exp
|
||||
test "$(echo $'foo')" = yes || fail dynamic lookup through static exp && exit 2
|
||||
# Dynamic lookup through dynamic expression
|
||||
ref_to_foo=foo
|
||||
test "$(echo $"$ref_to_foo")" = yes || fail dynamic lookup through dynamic exp
|
||||
test "$(echo $"$ref_to_foo")" = yes || fail dynamic lookup through dynamic exp && exit 2
|
||||
|
||||
# More redirections
|
||||
echo test > /tmp/sh-test
|
||||
test "$(cat /tmp/sh-test)" = test || fail simple path redirect
|
||||
test "$(cat /tmp/sh-test)" = test || fail simple path redirect && exit 2
|
||||
rm /tmp/sh-test
|
||||
|
||||
# 'brace' expansions
|
||||
test "$(echo x(yes no))" = "xyes xno" || fail simple juxtaposition expansion
|
||||
test "$(echo (y n)(es o))" = "yes yo nes no" || fail list-list juxtaposition expansion
|
||||
test "$(echo ()(foo bar baz))" = "" || fail empty expansion
|
||||
test "$(echo x(yes no))" = "xyes xno" || fail simple juxtaposition expansion && exit 2
|
||||
test "$(echo (y n)(es o))" = "yes yo nes no" || fail list-list juxtaposition expansion && exit 2
|
||||
test "$(echo ()(foo bar baz))" = "" || fail empty expansion && exit 2
|
||||
|
||||
# Variables inside commands
|
||||
to_devnull=(>/dev/null)
|
||||
test "$(echo hewwo $to_devnull)" = "" || fail variable containing simple command
|
||||
test "$(echo hewwo $to_devnull)" = "" || fail variable containing simple command && exit 2
|
||||
|
||||
word_count=(() | wc -w)
|
||||
test "$(echo well hello friends $word_count)" -eq 3 || fail variable containing pipeline
|
||||
test "$(echo well hello friends $word_count)" -eq 3 || fail variable containing pipeline && exit 2
|
||||
|
||||
# Globs
|
||||
mkdir sh-test
|
||||
pushd sh-test
|
||||
touch (a b c)(d e f)
|
||||
test "$(echo a*)" = "ad ae af" || fail '*' glob expansion
|
||||
test "$(echo a?)" = "ad ae af" || fail '?' glob expansion
|
||||
test "$(echo a*)" = "ad ae af" || fail '*' glob expansion && exit 2
|
||||
test "$(echo a?)" = "ad ae af" || fail '?' glob expansion && exit 2
|
||||
|
||||
glob_in_var='*'
|
||||
test "$(echo $glob_in_var)" = '*' || fail substituted string acts as glob
|
||||
test "$(echo $glob_in_var)" = '*' || fail substituted string acts as glob && exit 2
|
||||
|
||||
test "$(echo (a*))" = "ad ae af" || fail globs in lists resolve wrong
|
||||
test "$(echo x(a*))" = "xad xae xaf" || fail globs in lists do not resolve to lists
|
||||
test "$(echo "foo"a*)" = "fooad fooae fooaf" || fail globs join to dquoted strings
|
||||
test "$(echo (a*))" = "ad ae af" || fail globs in lists resolve wrong && exit 2
|
||||
test "$(echo x(a*))" = "xad xae xaf" || fail globs in lists do not resolve to lists && exit 2
|
||||
test "$(echo "foo"a*)" = "fooad fooae fooaf" || fail globs join to dquoted strings && exit 2
|
||||
popd
|
||||
rm -fr sh-test
|
||||
|
||||
# Setopt
|
||||
setopt --inline_exec_keep_empty_segments
|
||||
test "$(echo -n "a\n\nb")" = "a b" || fail inline_exec_keep_empty_segments has no effect
|
||||
test "$(echo -n "a\n\nb")" = "a b" || fail inline_exec_keep_empty_segments has no effect && exit 2
|
||||
|
||||
setopt --no_inline_exec_keep_empty_segments
|
||||
test "$(echo -n "a\n\nb")" = "a b" || fail cannot unset inline_exec_keep_empty_segments
|
||||
test "$(echo -n "a\n\nb")" = "a b" || fail cannot unset inline_exec_keep_empty_segments && exit 2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue