Skip to content

Commit

Permalink
Fix merge problems
Browse files Browse the repository at this point in the history
  • Loading branch information
zackradisic committed Apr 16, 2024
1 parent c0daac0 commit 52fecf9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
65 changes: 47 additions & 18 deletions test/js/bun/shell/bunshell-default.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
import { $ } from "bun";
import { bunExe, createTestBuilder } from "./test_builder";
import { bunEnv } from "harness";
const TestBuilder = createTestBuilder(import.meta.path);

test("default throw on command failure", async () => {
try {
await $`echo hi; ls oogabooga`.quiet();
expect.unreachable();
} catch (e: any) {
expect(e).toBeInstanceOf(Error);
expect(e.exitCode).toBe(1);
expect(e.message).toBe("Failed with exit code 1");
expect(e.stdout.toString("utf-8")).toBe("hi\n");
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\n");
}
// Run in a subproc because other tests may change the value of $.throws
const code = /* ts */ `
import { $ } from "bun";
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
test('test', async () => {
try {
await $\`echo hi; ls oogabooga\`.quiet();
expect.unreachable();
} catch (e: any) {
expect(e).toBeInstanceOf(Error);
expect(e.exitCode).toBe(1);
expect(e.message).toBe("Failed with exit code 1");
expect(e.stdout.toString("utf-8")).toBe("hi\\n");
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\\n");
}
})
`;

await TestBuilder.command`echo ${code} > index.test.ts; ${bunExe()} test index.test.ts`
.ensureTempDir()
.stderr(s => s.includes("1 pass"))
.env(bunEnv)
.run();
});

test("ShellError has .text()", async () => {
try {
await $`ls oogabooga`.quiet();
expect.unreachable();
} catch (e: any) {
expect(e).toBeInstanceOf(Error);
expect(e.exitCode).toBe(1);
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\n");
}
// Run in a subproc because other tests may change the value of $.throws
const code = /* ts */ `
import { $ } from "bun";
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
test('test', async () => {
try {
await $\`ls oogabooga\`.quiet();
expect.unreachable();
} catch (e: any) {
expect(e).toBeInstanceOf(Error);
expect(e.exitCode).toBe(1);
expect(e.stderr.toString("utf-8")).toBe("ls: oogabooga: No such file or directory\\n");
}
})
`;

await TestBuilder.command`echo ${code} > index.test.ts; ${bunExe()} test index.test.ts`
.ensureTempDir()
.stderr(s => s.includes("1 pass"))
.env(bunEnv)
.run();
});
4 changes: 3 additions & 1 deletion test/js/bun/shell/commands/cp.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { $ } from "bun";
import { TestBuilder } from "../test_builder";
import { createTestBuilder } from "../test_builder";
import { beforeAll, describe, test, expect, beforeEach } from "bun:test";
import { sortedShellOutput } from "../util";
import { tempDirWithFiles } from "harness";
import fs from "fs";
import { shellInternals } from "bun:internal-for-testing";
const { builtinDisabled } = shellInternals;

const TestBuilder = createTestBuilder(import.meta.path);

const p = process.platform === "win32" ? (s: string) => s.replaceAll("/", "\\") : (s: string) => s;

$.nothrow();
Expand Down
2 changes: 2 additions & 0 deletions test/js/bun/shell/test_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ export function createTestBuilder(path: string) {
}
}
}

return TestBuilder;
}

function generateRandomString(length: number): string {
Expand Down

0 comments on commit 52fecf9

Please sign in to comment.