Compare commits

...

3 Commits

Author SHA1 Message Date
Claude Bot
78c1023b97 test: refactor mv illegal option tests to use test.each
Address code review feedback to reduce duplication by using parameterized tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 07:26:57 +00:00
Claude Bot
8bda817ed9 test: add exit code assertions to mv illegal option tests
Address code review feedback to verify exit codes in catch blocks.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 07:17:05 +00:00
Claude Bot
60b2339c19 fix(shell): report correct illegal option character in mv command
The mv command was reporting "-" for all unrecognized flags instead of
the actual flag character. For example, `mv -T` would show
"mv: illegal option -- -" instead of "mv: illegal option -- T".

The bug was in parseFlag() where the else branch returned a hardcoded
"-" instead of the actual unrecognized character from the flag string.

Fixes #26749

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 07:06:54 +00:00
2 changed files with 29 additions and 2 deletions

View File

@@ -447,7 +447,7 @@ pub fn parseFlag(this: *Mv, flag: []const u8) union(enum) { continue_parsing, do
if (flag[0] != '-') return .done;
const small_flags = flag[1..];
for (small_flags) |char| {
for (small_flags, 0..) |char, i| {
switch (char) {
'f' => {
this.opts.force_overwrite = true;
@@ -471,7 +471,7 @@ pub fn parseFlag(this: *Mv, flag: []const u8) union(enum) { continue_parsing, do
this.opts.verbose_output = true;
},
else => {
return .{ .illegal_option = "-" };
return .{ .illegal_option = small_flags[i..][0..1] };
},
}
}

View File

@@ -0,0 +1,27 @@
import { $ } from "bun";
import { expect, test } from "bun:test";
// https://github.com/oven-sh/bun/issues/26749
// mv command should report the correct illegal option character in error messages
const cases: [string, string][] = [
["-T", "T"],
["-X", "X"],
["-fX", "X"],
["-vZ", "Z"],
];
test.each(cases)("mv reports correct illegal option for %s", async (flag, expectedChar) => {
$.throws(true);
try {
await Bun.$`mv ${flag} ./a ./b`;
expect.unreachable("should have thrown");
} catch (e: unknown) {
const err = e as Bun.$.ShellError;
const stderr = new TextDecoder().decode(err.stderr);
expect(stderr).toContain(`mv: illegal option -- ${expectedChar}`);
expect(err.exitCode).not.toBe(0);
} finally {
$.nothrow();
}
});