Skip to content

Commit

Permalink
Allow multiple args for interpreters (#669)
Browse files Browse the repository at this point in the history
This is a bug where we only expect one argument. Downstream, the OS
libraries expect arguments to be passed as an array.

This PR fixes this. Please see the test case.
  • Loading branch information
sourishkrout authored Sep 19, 2024
1 parent ca6efae commit 25d698b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/runner/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func parseFileProgram(programPath string) (program string, args []string) {
}

if len(parts) > 1 {
args = []string{parts[1]}
args = strings.Split(parts[1], " ")
}

return
Expand Down
29 changes: 29 additions & 0 deletions internal/runner/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ func Test_command(t *testing.T) {
assert.Equal(t, "", string(data))
})

t.Run("DenoWithArgs", func(t *testing.T) {
t.Parallel()

stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)

cmd, err := newCommand(
context.Background(),
&commandConfig{
ProgramName: "deno run --allow-all",
LanguageID: "ts",
Stdout: stdout,
Stderr: stderr,
CommandMode: CommandModeTempFile,
Script: "console.log('1'); console.log('2')",
Logger: testCreateLogger(t),
},
)
require.NoError(t, err)
require.NoError(t, cmd.Start(context.Background()))
require.NoError(t, cmd.Wait())
data, err := io.ReadAll(stdout)
assert.NoError(t, err)
assert.Equal(t, "1\n2\n", string(data))
data, err = io.ReadAll(stderr)
assert.NoError(t, err)
assert.Equal(t, "", string(data))
})

t.Run("Nonexec resorts to cat", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 25d698b

Please sign in to comment.