[llvm] [CommandLine] Better report unknown subcommands (PR #74811)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 22:04:42 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff dd9587795811ba21e6ca6ad52b4531e17e6babd6 c09a851d4685997a28dfda3b64c50ed4678b890e -- llvm/lib/Support/CommandLine.cpp llvm/unittests/Support/CommandLineTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index a25477a134..ae80490a33 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1347,20 +1347,20 @@ struct AutoDeleteFile {
 };
 
 static std::string interceptStdout(std::function<void()> F) {
-    outs().flush();  // flush any output from previous tests
-    AutoDeleteFile File;
-    {
-      OutputRedirector Stdout(fileno(stdout));
-      if (!Stdout.Valid)
-        return "";
-      File.FilePath = Stdout.FilePath;
-    F();
-      outs().flush();
-    }
-    auto Buffer = MemoryBuffer::getFile(File.FilePath);
-    if (!Buffer)
+  outs().flush(); // flush any output from previous tests
+  AutoDeleteFile File;
+  {
+    OutputRedirector Stdout(fileno(stdout));
+    if (!Stdout.Valid)
       return "";
-    return Buffer->get()->getBuffer().str();
+    File.FilePath = Stdout.FilePath;
+    F();
+    outs().flush();
+  }
+  auto Buffer = MemoryBuffer::getFile(File.FilePath);
+  if (!Buffer)
+    return "";
+  return Buffer->get()->getBuffer().str();
 }
 
 template <void (*Func)(const cl::Option &)>
@@ -2271,8 +2271,7 @@ TEST(CommandLineTest, UnknownCommands) {
   const char *Args2[] = {"prog", "faz"};
   EXPECT_FALSE(
       cl::ParseCommandLineOptions(std::size(Args2), Args2, StringRef(), &OS));
-  EXPECT_EQ(Errs,
-            "prog: Unknown subcommand 'faz'.  Try: 'prog --help'\n");
+  EXPECT_EQ(Errs, "prog: Unknown subcommand 'faz'.  Try: 'prog --help'\n");
 }
 
 } // anonymous namespace

``````````

</details>


https://github.com/llvm/llvm-project/pull/74811


More information about the llvm-commits mailing list