cmdgroup parsing: parse cmdlist surrounded by parentheses

This commit is contained in:
Khaïs COLIN 2025-03-20 12:17:54 +01:00
parent 185a069044
commit 0fbfee7d78
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
7 changed files with 169 additions and 5 deletions

71
test.sh
View file

@ -192,4 +192,75 @@ expecting <<EOF
╰─ (no redirections)
EOF
when_run <<EOF "a single command in parentheses is has the parenthesis implicitly removed"
(echo hi)
EOF
# this is how it is handled in bash:
# doing a `ps uf` on bash running `sleep 10`
# \_ bash --norc
# \_ sleep 10
# and `(sleep 10)`
# \_ bash --norc
# \_ sleep 10
# this is exactly the same process graph
expecting <<EOF
╰─ t_cmdgroup
├─ t_cmdlist
│ ├─ num_cmds = 1
│ ╰─ cmd[0]
│ ├─ t_cmdlist_item
│ │ ╰─ t_pipeline
│ │ ├─ num_cmd = 1
│ │ ╰─ cmd[0]
│ │ ╰─ t_simple_cmd
│ │ ├─ words = [echo][hi]
│ │ ╰─ (no redirections)
│ ╰─ t_operator = END
╰─ (no redirections)
EOF
when_run <<EOF "a single cmdlist in parenthesis has the parenthesis implicitly removed"
(echo hi >> append | echo < infile bye && echo hello > outfile)
EOF
expecting <<EOF
╰─ t_cmdgroup
├─ t_cmdlist
│ ├─ num_cmds = 2
│ ├─ cmd[0]
│ │ ├─ t_cmdlist_item
│ │ │ ╰─ t_pipeline
│ │ │ ├─ num_cmd = 2
│ │ │ ├─ cmd[0]
│ │ │ │ ╰─ t_simple_cmd
│ │ │ │ ├─ words = [echo][hi]
│ │ │ │ ╰─ t_redir_list
│ │ │ │ ╰─ redirection[0]
│ │ │ │ ╰─ t_redirection
│ │ │ │ ├─ t_redir_type = REDIR_APPEND
│ │ │ │ ╰─ marker = [append]
│ │ │ ╰─ cmd[1]
│ │ │ ╰─ t_simple_cmd
│ │ │ ├─ words = [echo][bye]
│ │ │ ╰─ t_redir_list
│ │ │ ╰─ redirection[0]
│ │ │ ╰─ t_redirection
│ │ │ ├─ t_redir_type = REDIR_INPUT
│ │ │ ╰─ marker = [infile]
│ │ ╰─ t_operator = AND
│ ╰─ cmd[1]
│ ├─ t_cmdlist_item
│ │ ╰─ t_pipeline
│ │ ├─ num_cmd = 1
│ │ ╰─ cmd[0]
│ │ ╰─ t_simple_cmd
│ │ ├─ words = [echo][hello]
│ │ ╰─ t_redir_list
│ │ ╰─ redirection[0]
│ │ ╰─ t_redirection
│ │ ├─ t_redir_type = REDIR_OUTPUT
│ │ ╰─ marker = [outfile]
│ ╰─ t_operator = END
╰─ (no redirections)
EOF
finalize