Skip to content
Myr

Fix argument concatenation with `$` (#553)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 6fe7e51 · Browse files · 3 files+97 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+97 added−8 removed

  • tests:+45 added−0 removed
  • other:+52 added−8 removed

3 files+97 added−8 removed

modified:docs/scripts.md+20 added
138 unmodified lines
139const example = await $`echo example`;140await $`echo ${example}`;141```142143### Concatenation144145```sh146# Bash147tmpDir="/tmp"148mkdir "$tmpDir/filename"149```150151```js152// zx153const tmpDir = '/tmp'154await $`mkdir ${tmpDir}/filename`;155```156157```js158// Execa159const tmpDir = '/tmp'160await $`mkdir ${tmpDir}/filename`;161```162163### Parallel commands164165```sh166# Bash
510 unmodified lines
modified:lib/command.js+32 added-8 removed
modified:test/command.js+45 added
111 unmodified lines
112 const {stdout} = await $`echo.js ${['foo', 'bar']}`;113 t.is(stdout, 'foo\nbar');114});115116test('$ allows empty array interpolation', async t => {117 const {stdout} = await $`echo.js foo ${[]} bar`;118 t.is(stdout, 'foo\nbar');119});120121test('$ allows execa return value interpolation', async t => {122 const foo = await $`echo.js foo`;123 const {stdout} = await $`echo.js ${foo} bar`;124 t.is(stdout, 'foo\nbar');
51 unmodified lines
176 const {stdout} = await $`echo.js \u`;177 t.is(stdout, '\\u');178});179180test('$ can concatenate at the end of tokens', async t => {181 const {stdout} = await $`echo.js foo${'bar'}`;182 t.is(stdout, 'foobar');183});184185test('$ does not concatenate at the end of tokens with a space', async t => {186 const {stdout} = await $`echo.js foo ${'bar'}`;187 t.is(stdout, 'foo\nbar');188});189190test('$ can concatenate at the end of tokens followed by an array', async t => {191 const {stdout} = await $`echo.js foo${['bar', 'foo']}`;192 t.is(stdout, 'foobar\nfoo');193});194195test('$ can concatenate at the start of tokens', async t => {196 const {stdout} = await $`echo.js ${'foo'}bar`;197 t.is(stdout, 'foobar');198});199200test('$ does not concatenate at the start of tokens with a space', async t => {201 const {stdout} = await $`echo.js ${'foo'} bar`;202 t.is(stdout, 'foo\nbar');203});204205test('$ can concatenate at the start of tokens followed by an array', async t => {206 const {stdout} = await $`echo.js ${['foo', 'bar']}foo`;207 t.is(stdout, 'foo\nbarfoo');208});209210test('$ can concatenate at the start and end of tokens followed by an array', async t => {211 const {stdout} = await $`echo.js foo${['bar', 'foo']}bar`;212 t.is(stdout, 'foobar\nfoobar');213});214215test('$ can concatenate multiple tokens', async t => {216 const {stdout} = await $`echo.js ${'foo'}bar${'foo'}`;217 t.is(stdout, 'foobarfoo');218});219220test('$ allows escaping spaces in commands with interpolation', async t => {221 const {stdout} = await $`${'command with space.js'} foo bar`;222 t.is(stdout, 'foo\nbar');223});
112 unmodified lines