Skip to content

Commit

Permalink
Merge pull request #86 from yassinebenaid/fix-bug-in-command-substitu…
Browse files Browse the repository at this point in the history
…tion

Add missing comand substitution test
  • Loading branch information
yassinebenaid authored Jan 4, 2025
2 parents 6104ebf + c6a13cb commit 186b691
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions generator/tests/07-command-substitution.test
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 186b691

Please sign in to comment.