Skip to content

Commit b907a9c

Browse files
committed
More test cases.
1 parent 66af1aa commit b907a9c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

llvm/unittests/Option/OptionSubCommandsTest.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,26 @@ TYPED_TEST(OptSubCommandTableTest, SubCommandParsing) {
147147
EXPECT_TRUE(SC.empty());
148148
// Expect the multiple subcommands error message.
149149
EXPECT_NE(std::string::npos, ErrMsg.find("Multiple subcommands passed"));
150+
EXPECT_NE(std::string::npos, ErrMsg.find("foo"));
151+
EXPECT_NE(std::string::npos, ErrMsg.find("bar"));
150152
// Do not expect the rnregistered subcommands error message.
151153
EXPECT_EQ(std::string::npos,
152154
ErrMsg.find("Unregistered positionals passed"));
153155
}
156+
157+
{
158+
// Test case 5: Check invalid use of passing unregistered subcommands.
159+
const char *Args[] = {"foobar"};
160+
InputArgList AL = T.ParseArgs(Args, MAI, MAC);
161+
StringRef SC = AL.getSubcommand(
162+
T.getSubCommands(), HandleMultipleSubcommands, HandleOtherPositionals);
163+
// No valid subcommand should be returned as this is an invalid invocation.
164+
EXPECT_TRUE(SC.empty());
165+
// Expect the rnregistered subcommands error message.
166+
EXPECT_NE(std::string::npos,
167+
ErrMsg.find("Unregistered positionals passed"));
168+
EXPECT_NE(std::string::npos, ErrMsg.find("foobar"));
169+
}
154170
}
155171

156172
TYPED_TEST(OptSubCommandTableTest, SubCommandHelp) {
@@ -208,4 +224,4 @@ TYPED_TEST(OptSubCommandTableTest, SubCommandHelp) {
208224
// version is a global option and should not be shown.
209225
EXPECT_EQ(std::string::npos, Help.find("-version"));
210226
}
211-
} // end anonymous namespace
227+
} // end anonymous namespace

0 commit comments

Comments
 (0)