diff --git a/generator/tests/07-command-substitution.test b/generator/tests/07-command-substitution.test index 049214d6..6a2b1533 100644 --- a/generator/tests/07-command-substitution.test +++ b/generator/tests/07-command-substitution.test @@ -248,3 +248,95 @@ func Main(shell *runtime.Shell, streamManager *runtime.StreamManager) { } #(ENDTEST) + + + +#(TEST: command as expression in redirection) + +cat <$(echo file.txt) + +#(RESULT) + +package main + +import "bunster-build/runtime" + +func Main(shell *runtime.Shell, streamManager *runtime.StreamManager) { + func() { + var commandName = `cat` + var arguments []string + var command = shell.Command(commandName, arguments...) + streamManager := streamManager.Clone() + defer streamManager.Destroy() + expr4, exitCode := func() (string, int) { + streamManager := streamManager.Clone() + defer streamManager.Destroy() + shell := shell.Clone() + var buffer = runtime.NewBuffer(``, false) + streamManager.Add(`1`, buffer, false) + func() { + var commandName = `echo` + var arguments []string + arguments = append(arguments, `file.txt`) + var command = shell.Command(commandName, arguments...) + streamManager := streamManager.Clone() + defer streamManager.Destroy() + if stream, err := streamManager.Get(`0`); err != nil { + shell.HandleError(err) + } else { + command.Stdin = stream + } + if stream, err := streamManager.Get(`1`); err != nil { + shell.HandleError(err) + } else { + command.Stdout = stream + } + if stream, err := streamManager.Get(`2`); err != nil { + shell.HandleError(err) + } else { + command.Stderr = stream + } + if err := command.Run(); err != nil { + shell.HandleError(err) + return + } + shell.ExitCode = command.ProcessState.ExitCode() + + }() + return buffer.String(true), shell.ExitCode + }() + if exitCode != 0 { + shell.ExitCode = exitCode + return + } + stream0, err := streamManager.OpenStream(expr4, runtime.STREAM_FLAG_READ) + if err != nil { + shell.HandleError(err) + return + } + streamManager.Add(`0`, stream0, false) + if stream, err := streamManager.Get(`0`); err != nil { + shell.HandleError(err) + } else { + command.Stdin = stream + } + if stream, err := streamManager.Get(`1`); err != nil { + shell.HandleError(err) + } else { + command.Stdout = stream + } + if stream, err := streamManager.Get(`2`); err != nil { + shell.HandleError(err) + } else { + command.Stderr = stream + } + if err := command.Run(); err != nil { + shell.HandleError(err) + return + } + shell.ExitCode = command.ProcessState.ExitCode() + + }() +} + +#(ENDTEST)