From fe9aef05c2dcfbde6e29e2edb2d49e29a54bea4d Mon Sep 17 00:00:00 2001 From: pointhex <1111artem1111@gmail.com> Date: Sun, 16 Jun 2024 22:58:26 +0200 Subject: [clang-format] Add DiagHandler parameter to format::getStyle() (#91317) It allows to control of error output for the function. Closes #94205. --------- Co-authored-by: Owen Pan --- clang/unittests/Format/ConfigParseTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'clang/unittests/Format/ConfigParseTest.cpp') diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index ff3ced3..2513ab39 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -1452,6 +1452,27 @@ TEST(ConfigParseTest, GetStyleOfSpecificFile) { ASSERT_EQ(*Style, getGoogleStyle()); } +TEST(ConfigParseTest, GetStyleOutput) { + llvm::vfs::InMemoryFileSystem FS; + + // Don't suppress output. + testing::internal::CaptureStderr(); + auto Style = getStyle("{invalid_key=invalid_value}", "a.h", "LLVM", "", &FS, + /*AllowUnknownOptions=*/true); + auto Output = testing::internal::GetCapturedStderr(); + ASSERT_TRUE((bool)Style); + ASSERT_FALSE(Output.empty()); + + // Suppress stderr. + testing::internal::CaptureStderr(); + Style = getStyle("{invalid_key=invalid_value}", "a.h", "LLVM", "", &FS, + /*AllowUnknownOptions=*/true, + [](const llvm::SMDiagnostic &, void *) {}); + Output = testing::internal::GetCapturedStderr(); + ASSERT_TRUE((bool)Style); + ASSERT_TRUE(Output.empty()); +} + } // namespace } // namespace format } // namespace clang -- cgit v1.1