diff --git a/llvm/test/tools/llvm-ar/invalid-object-file.test b/llvm/test/tools/llvm-ar/invalid-object-file.test index d967d8763a921..f7cdc626662d6 100644 --- a/llvm/test/tools/llvm-ar/invalid-object-file.test +++ b/llvm/test/tools/llvm-ar/invalid-object-file.test @@ -6,3 +6,6 @@ # CHECK: error: unable to load '[[FILE]]': file too small to be an archive # CHECK-NOT: {{.}} + +## Also test that errors like this (e.g. invlid input files) don't generate a usage message +# CHECK-NOT: USAGE: llvm-ar diff --git a/llvm/test/tools/llvm-ranlib/bad-usage.test b/llvm/test/tools/llvm-ranlib/bad-usage.test new file mode 100644 index 0000000000000..dd5e2e9e501e7 --- /dev/null +++ b/llvm/test/tools/llvm-ranlib/bad-usage.test @@ -0,0 +1,7 @@ +## Test that useage message is shown when no input file is given +## And that we return non-zero. + +# RUN: not llvm-ranlib 2>&1 | FileCheck %s + +# CHECK: error: an archive name must be specified +# CHECK: USAGE: llvm-ranlib diff --git a/llvm/test/tools/llvm-ranlib/help-message.test b/llvm/test/tools/llvm-ranlib/help-message.test new file mode 100644 index 0000000000000..885638a53fcda --- /dev/null +++ b/llvm/test/tools/llvm-ranlib/help-message.test @@ -0,0 +1,8 @@ +## Show that the help message for llvm-ranlib can be printed with either the +## long flag -help. + +# RUN: llvm-ranlib -h | FileCheck %s +# RUN: llvm-ranlib -help | FileCheck %s +# RUN: llvm-ranlib --help | FileCheck %s + +# CHECK: USAGE: llvm-ranlib diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp index 18cad21f9644b..1fdc433047f71 100644 --- a/llvm/tools/llvm-ar/llvm-ar.cpp +++ b/llvm/tools/llvm-ar/llvm-ar.cpp @@ -56,20 +56,18 @@ static StringRef ToolName; // The basename of this program. static StringRef Stem; -const char RanlibHelp[] = R"( -OVERVIEW: LLVM Ranlib (llvm-ranlib) +const char RanlibHelp[] = R"(OVERVIEW: LLVM Ranlib (llvm-ranlib) This program generates an index to speed access to archives USAGE: llvm-ranlib OPTIONS: - -help - Display available options - -version - Display the version of this program + -h --help - Display available options + --version - Display the version of this program )"; -const char ArHelp[] = R"( -OVERVIEW: LLVM Archiver +const char ArHelp[] = R"(OVERVIEW: LLVM Archiver USAGE: llvm-ar [options] [-][modifiers] [relpos] [count] [files] llvm-ar -M [ 1) - fail("only one operation may be specified"); + badUsage("only one operation may be specified"); if (NumPositional > 1) - fail("you may only specify one of 'a', 'b', and 'i' modifiers"); + badUsage("you may only specify one of 'a', 'b', and 'i' modifiers"); if (AddAfter || AddBefore) if (Operation != Move && Operation != ReplaceOrInsert) - fail("the 'a', 'b' and 'i' modifiers can only be specified with " - "the 'm' or 'r' operations"); + badUsage("the 'a', 'b' and 'i' modifiers can only be specified with " + "the 'm' or 'r' operations"); if (CountParam) if (Operation != Extract && Operation != Delete) - fail("the 'N' modifier can only be specified with the 'x' or 'd' " - "operations"); + badUsage("the 'N' modifier can only be specified with the 'x' or 'd' " + "operations"); if (OriginalDates && Operation != Extract) - fail("the 'o' modifier is only applicable to the 'x' operation"); + badUsage("the 'o' modifier is only applicable to the 'x' operation"); if (OnlyUpdate && Operation != ReplaceOrInsert) - fail("the 'u' modifier is only applicable to the 'r' operation"); + badUsage("the 'u' modifier is only applicable to the 'r' operation"); if (AddLibrary && Operation != QuickAppend) - fail("the 'L' modifier is only applicable to the 'q' operation"); + badUsage("the 'L' modifier is only applicable to the 'q' operation"); // Return the parsed operation to the caller return Operation; @@ -1079,7 +1082,7 @@ static void runMRIScript() { } static bool handleGenericOption(StringRef arg) { - if (arg == "-help" || arg == "--help") { + if (arg == "-help" || arg == "--help" || arg == "-h") { printHelpMessage(); return true; } @@ -1161,6 +1164,9 @@ static int ranlib_main(int argc, char **argv) { ArchiveName = argv[i]; } } + if (!ArchiveSpecified) { + badUsage("an archive name must be specified"); + } return performOperation(CreateSymTab, nullptr); }