@@ -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
156172TYPED_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