diff options
author | Brian Gesiak <modocache@gmail.com> | 2018-05-14 21:35:00 +0000 |
---|---|---|
committer | Brian Gesiak <modocache@gmail.com> | 2018-05-14 21:35:00 +0000 |
commit | eda977f414fead94b5072dd35d53be2fa71c5f00 (patch) | |
tree | 52d42f9f76d47dca4dbcb13cbaf4c5e0e863a112 /llvm/unittests/Option/OptionParsingTest.cpp | |
parent | ace7ae935ffc181b79d5a22d58589949191b3416 (diff) | |
download | bcm5719-llvm-eda977f414fead94b5072dd35d53be2fa71c5f00.tar.gz bcm5719-llvm-eda977f414fead94b5072dd35d53be2fa71c5f00.zip |
[Option] Fix PR37006 prefix choice in findNearest
Summary:
In https://bugs.llvm.org/show_bug.cgi?id=37006 Nico Weber points out a
flaw in `OptTable::findNearest`: if an option "foo"'s prefixes are "--"
and "-", then the nearest option for "--fob" will be "-foo". This is
incorrect, however, since the function is expected to return "--foo".
The bug is due to a naive loop that attempts to predetermines which
prefix is best. Instead, compute the edit distance for each prefix/name
pair.
Test Plan: `check-llvm`
Reviewers: thakis
Reviewed By: thakis
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D46776
llvm-svn: 332299
Diffstat (limited to 'llvm/unittests/Option/OptionParsingTest.cpp')
-rw-r--r-- | llvm/unittests/Option/OptionParsingTest.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/unittests/Option/OptionParsingTest.cpp b/llvm/unittests/Option/OptionParsingTest.cpp index eef21ab5120..99c1ef32476 100644 --- a/llvm/unittests/Option/OptionParsingTest.cpp +++ b/llvm/unittests/Option/OptionParsingTest.cpp @@ -283,6 +283,10 @@ TEST(Option, FindNearest) { EXPECT_EQ(Nearest, "-blorp"); EXPECT_EQ(1U, T.findNearest("--blorm", Nearest)); EXPECT_EQ(Nearest, "--blorp"); + EXPECT_EQ(1U, T.findNearest("-blarg", Nearest)); + EXPECT_EQ(Nearest, "-blarn"); + EXPECT_EQ(1U, T.findNearest("--blarm", Nearest)); + EXPECT_EQ(Nearest, "--blarn"); EXPECT_EQ(1U, T.findNearest("-fjormp", Nearest)); EXPECT_EQ(Nearest, "--fjormp"); |