Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jan 28, 2024
1 parent f962673 commit ace4372
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,10 +1159,21 @@ Deno.test("subshells", async () => {
assertEquals(result, "1\n2\n4");
}
// shouldn't change the environment either
{
assertEquals(await $`export VAR=5 && echo $VAR`.text(), "5"); // for reference
const result = await $`(export VAR=5) && echo $VAR`.text();
assertEquals(result, "");
}
{
const result = await $`echo 1 && (echo 2 && export VAR=5 && echo $VAR) && echo $VAR`.text();
assertEquals(result, "1\n2\n5\n");
}
await withTempDir(async (tempDir) => {
const subDir = tempDir.join("subDir");
subDir.mkdirSync();
const result = await $`(cd subDir && pwd) && pwd`.text();
assertEquals(result, `${subDir}\n${tempDir}`);
});
});

Deno.test("output redirects", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ async function executeCommandArgs(commandArgs: string[], context: Context): Prom
async function executeSubshell(subshell: Subshell, context: Context): Promise<ExecuteResult> {
const result = await executeSequentialList(subshell, context);
// sub shells do not change the environment or cause an exit
return { code: result.code, changes: [] };
return { code: result.code };
}

async function pipeReaderToWritable(reader: Reader, writable: WritableStream<Uint8Array>, signal: AbortSignal) {
Expand Down

0 comments on commit ace4372

Please sign in to comment.