Skip to content

Commit

Permalink
Fix short option error (#4796)
Browse files Browse the repository at this point in the history
"unsigned char" prints as an integer, not a char

---------

Co-authored-by: Richard Smith <[email protected]>
  • Loading branch information
jonmeow and zygoloid authored Jan 14, 2025
1 parent 2faff26 commit a3e66d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion common/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,8 @@ auto Parser::ParseShortOptionSeq(llvm::StringRef unparsed_arg)
auto* arg_entry =
(c < short_option_table_.size()) ? short_option_table_[c] : nullptr;
if (!arg_entry) {
return Error(llvm::formatv("unknown short option `{0}`", c));
return Error(
llvm::formatv("unknown short option `-{0}`", static_cast<char>(c)));
}
// Mark this argument as parsed.
arg_entry->setInt(true);
Expand Down
4 changes: 4 additions & 0 deletions common/command_line_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ TEST(ArgParserTest, ShortArgs) {
EXPECT_THAT(integer_option, Eq(123));

TestRawOstream os;

EXPECT_THAT(parse({"-v"}, os), IsError(StrEq("unknown short option `-v`")));
EXPECT_THAT(parse({"-xvx"}, os), IsError(StrEq("unknown short option `-v`")));

EXPECT_THAT(
parse({"-xzf"}, os),
IsError(StrEq("option `-z` (short for `--option2`) requires a value to "
Expand Down

0 comments on commit a3e66d6

Please sign in to comment.