mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Alistair Smith <hi@alistair.sh> Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com>
94 lines
2.8 KiB
TypeScript
94 lines
2.8 KiB
TypeScript
import { $, spawn } from "bun";
|
|
import { describe, expect, test } from "bun:test";
|
|
import { bunEnv, bunExe } from "harness";
|
|
import * as path from "node:path";
|
|
import { createTestBuilder } from "./test_builder";
|
|
const TestBuilder = createTestBuilder(import.meta.path);
|
|
|
|
$.nothrow();
|
|
describe("$ argv", async () => {
|
|
for (let i = 0; i < process.argv.length; i++) {
|
|
const element = process.argv[i];
|
|
TestBuilder.command`echo $${{ raw: i }}`
|
|
.exitCode(0)
|
|
.stdout(process.argv[i] + "\n")
|
|
.runAsTest(`$${i} should equal process.argv[${i}]`);
|
|
}
|
|
});
|
|
|
|
test("$ argv: standalone", async () => {
|
|
const script = path.join(import.meta.dir, "fixtures", "positionals.bun.sh");
|
|
const { stdout, stderr, exited } = spawn({
|
|
cmd: [bunExe(), "run", script, "a", "b", "c"],
|
|
stdout: "pipe",
|
|
stdin: "ignore",
|
|
stderr: "pipe",
|
|
env: bunEnv,
|
|
});
|
|
|
|
expect(stderr).toBeDefined();
|
|
const err = await stderr.text();
|
|
expect(err).toBeEmpty();
|
|
|
|
expect(stdout).toBeDefined();
|
|
const out = await stdout.text();
|
|
expect(out.split("\n")).toEqual([script, "a", "bb", ""]);
|
|
});
|
|
|
|
test("$ argv: standalone: not enough args", async () => {
|
|
const script = path.join(import.meta.dir, "fixtures", "positionals.bun.sh");
|
|
const { stdout, stderr, exited } = spawn({
|
|
cmd: [bunExe(), "run", script],
|
|
stdout: "pipe",
|
|
stdin: "ignore",
|
|
stderr: "pipe",
|
|
env: bunEnv,
|
|
});
|
|
|
|
expect(stderr).toBeDefined();
|
|
const err = await stderr.text();
|
|
expect(err).toBeEmpty();
|
|
|
|
expect(stdout).toBeDefined();
|
|
const out = await stdout.text();
|
|
expect(out.split("\n")).toEqual([script, "", "", ""]);
|
|
});
|
|
|
|
test("$ argv: standalone: only 10", async () => {
|
|
const script = path.join(import.meta.dir, "fixtures", "positionals2.bun.sh");
|
|
const { stdout, stderr, exited } = spawn({
|
|
cmd: [bunExe(), "run", script, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"],
|
|
stdout: "pipe",
|
|
stdin: "ignore",
|
|
stderr: "pipe",
|
|
env: bunEnv,
|
|
});
|
|
|
|
expect(stderr).toBeDefined();
|
|
const err = await stderr.text();
|
|
expect(err).toBeEmpty();
|
|
|
|
expect(stdout).toBeDefined();
|
|
const out = await stdout.text();
|
|
expect(out.split("\n")).toEqual([script, "a", "bb", "c", "d", "e", "f", "g", "h", "i", "a0", ""]);
|
|
});
|
|
|
|
test("$ argv: standalone: non-ascii", async () => {
|
|
const script = path.join(import.meta.dir, "fixtures", "positionals2.bun.sh");
|
|
const { stdout, stderr, exited } = spawn({
|
|
cmd: [bunExe(), "run", script, "キ", "テ", "ィ", "・", "ホ", "ワ", "イ", "ト"],
|
|
stdout: "pipe",
|
|
stdin: "ignore",
|
|
stderr: "pipe",
|
|
env: bunEnv,
|
|
});
|
|
|
|
expect(stderr).toBeDefined();
|
|
const err = await stderr.text();
|
|
expect(err).toBeEmpty();
|
|
|
|
expect(stdout).toBeDefined();
|
|
const out = await stdout.text();
|
|
expect(out.split("\n")).toEqual([script, "キ", "テテ", "ィ", "・", "ホ", "ワ", "イ", "ト", "", "キ0", ""]);
|
|
});
|