diff options
author | Keno Fischer <keno@alumni.harvard.edu> | 2018-05-14 23:26:06 +0000 |
---|---|---|
committer | Keno Fischer <keno@alumni.harvard.edu> | 2018-05-14 23:26:06 +0000 |
commit | 8248d7c6616fd5b612d991adcff59ed288eaef5e (patch) | |
tree | c660f216925effc2436264cee02156eba4185b96 /llvm/unittests/Support/CommandLineTest.cpp | |
parent | a2b8fe660404a9594363e7b9721c1df4f27fd500 (diff) | |
download | llvm-8248d7c6616fd5b612d991adcff59ed288eaef5e.zip llvm-8248d7c6616fd5b612d991adcff59ed288eaef5e.tar.gz llvm-8248d7c6616fd5b612d991adcff59ed288eaef5e.tar.bz2 |
[CommandLine] Error message for incorrect PositionalEatArgs usage
Summary:
bugpoint has several options specified as `PositionalEatArgs` to pass
options through to the underlying tool, e.g. `-tool-args`. The `-help`
message suggests the usage is: `-tool-args=<string>`. However, this is
misleading, because that's not how these arguments work. Rather than taking
a value, the option consumes all positional arguments until the next
recognized option (or all arguments if `--` is specified at some point).
To make this slightly clearer, instead print the help as:
```
-tool-args <string>... - <tool arguments>...
```
Additionally, add an error if the user attempts to use a `PositionalEatArgs`
argument with a value, instead of silently ignoring it. Example:
```
./bin/bugpoint -tool-args=-mpcu=skylake-avx512
bugpoint: for the -tool-args option: This argument does not take a value.
Instead, it consumes any positional arguments until the next recognized option.
```
Reviewed By: aprantl
Differential Revision: https://reviews.llvm.org/D46787
llvm-svn: 332311
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r-- | llvm/unittests/Support/CommandLineTest.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index 8657504..a52420f 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -816,4 +816,23 @@ TEST(CommandLineTest, ReadConfigFile) { llvm::sys::fs::remove(TestDir); } +TEST(CommandLineTest, PositionalEatArgsError) { + static cl::list<std::string> PosEatArgs("positional-eat-args", cl::Positional, + cl::desc("<arguments>..."), cl::ZeroOrMore, + cl::PositionalEatsArgs); + + const char *args[] = {"prog", "-positional-eat-args=XXXX"}; + const char *args2[] = {"prog", "-positional-eat-args=XXXX", "-foo"}; + const char *args3[] = {"prog", "-positional-eat-args", "-foo"}; + + std::string Errs; + raw_string_ostream OS(Errs); + EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS)); OS.flush(); + EXPECT_FALSE(Errs.empty()); Errs.clear(); + EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, StringRef(), &OS)); OS.flush(); + EXPECT_FALSE(Errs.empty()); Errs.clear(); + EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), &OS)); OS.flush(); + EXPECT_TRUE(Errs.empty()); +} + } // anonymous namespace |