diff --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h --- a/clang-tools-extra/clangd/Config.h +++ b/clang-tools-extra/clangd/Config.h @@ -109,7 +109,7 @@ bool AllowStalePreamble = false; IncludesPolicy UnusedIncludes = IncludesPolicy::Strict; - IncludesPolicy MissingIncludes = IncludesPolicy::None; + IncludesPolicy MissingIncludes = IncludesPolicy::Strict; /// IncludeCleaner will not diagnose usages of these headers matched by /// these regexes. diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -11,6 +11,7 @@ #include "CodeComplete.h" #include "CompileCommands.h" #include "ConfigFragment.h" +#include "Diagnostics.h" #include "GlobalCompilationDatabase.h" #include "Matchers.h" #include "SyncAPI.h" @@ -1205,8 +1206,13 @@ public: void onDiagnosticsReady(PathRef File, llvm::StringRef Version, std::vector Diagnostics) override { + bool HasTidyDiags = false; + for (auto &D : Diagnostics) { + if (D.Source == Diag::ClangTidy) + HasTidyDiags = true; + } std::lock_guard Lock(Mutex); - HadDiagsInLastCallback = !Diagnostics.empty(); + HadDiagsInLastCallback = HasTidyDiags; } std::mutex Mutex; diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "/usr/local/google/home/kadircet/repos/llvm/clang-tools-extra/clang-tidy/ClangTidyOptions.h" +#include "../clang-tidy/ClangTidyOptions.h" #include "Annotations.h" #include "Config.h" #include "Diagnostics.h" @@ -38,6 +38,7 @@ #include "gtest/gtest.h" #include #include +#include #include #include #include @@ -150,7 +151,17 @@ return M; } -TEST(DiagnosticsTest, DiagnosticRanges) { +class DiagnosticsTest : public ::testing::Test { + std::optional Ctx; + void SetUp() override { + Config Cfg; + Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::None; + Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::None; + Ctx.emplace(Config::Key, std::move(Cfg)); + } +}; + +TEST_F(DiagnosticsTest, DiagnosticRanges) { // Check we report correct ranges, including various edge-cases. Annotations Test(R"cpp( // error-ok @@ -214,7 +225,7 @@ // fires for the full expression range (see tweaks/PopulateSwitchTests.cpp). // The quickfix flow only works end-to-end if the tweak can be triggered on // the diagnostic's range. -TEST(DiagnosticsTest, WSwitch) { +TEST_F(DiagnosticsTest, WSwitch) { Annotations Test(R"cpp( enum A { X }; struct B { A a; }; @@ -229,7 +240,7 @@ "enumeration value 'X' not handled in switch"))); } -TEST(DiagnosticsTest, FlagsMatter) { +TEST_F(DiagnosticsTest, FlagsMatter) { Annotations Test("[[void]] main() {} // error-ok"); auto TU = TestTU::withCode(Test.code()); EXPECT_THAT(*TU.build().getDiagnostics(), @@ -245,7 +256,7 @@ withFix(Fix(Test.range(), "int", "change return type to 'int'"))))); } -TEST(DiagnosticsTest, DiagnosticPreamble) { +TEST_F(DiagnosticsTest, DiagnosticPreamble) { Annotations Test(R"cpp( #include $[["not-found.h"]] // error-ok )cpp"); @@ -257,7 +268,7 @@ diagSource(Diag::Clang), diagName("pp_file_not_found")))); } -TEST(DiagnosticsTest, DeduplicatedClangTidyDiagnostics) { +TEST_F(DiagnosticsTest, DeduplicatedClangTidyDiagnostics) { Annotations Test(R"cpp( float foo = [[0.1f]]; )cpp"); @@ -295,7 +306,7 @@ diagSource(Diag::ClangTidy))))); } -TEST(DiagnosticsTest, ClangTidy) { +TEST_F(DiagnosticsTest, ClangTidy) { Annotations Test(R"cpp( #include $deprecated[["assert.h"]] @@ -356,7 +367,7 @@ "function 'bar' is within a recursive call chain")))); } -TEST(DiagnosticsTest, ClangTidyEOF) { +TEST_F(DiagnosticsTest, ClangTidyEOF) { // clang-format off Annotations Test(R"cpp( [[#]]include @@ -373,7 +384,7 @@ diagSource(Diag::ClangTidy), diagName("llvm-include-order"))))); } -TEST(DiagnosticTest, TemplatesInHeaders) { +TEST_F(DiagnosticsTest, TemplatesInHeaders) { // Diagnostics from templates defined in headers are placed at the expansion. Annotations Main(R"cpp( Derived [[y]]; // error-ok @@ -393,7 +404,7 @@ "'Derived' requested here"))))); } -TEST(DiagnosticTest, MakeUnique) { +TEST_F(DiagnosticsTest, MakeUnique) { // We usually miss diagnostics from header functions as we don't parse them. // std::make_unique is an exception. Annotations Main(R"cpp( @@ -418,7 +429,7 @@ "no matching constructor for initialization of 'S'"))); } -TEST(DiagnosticTest, MakeShared) { +TEST_F(DiagnosticsTest, MakeShared) { // We usually miss diagnostics from header functions as we don't parse them. // std::make_shared is only parsed when --parse-forwarding-functions is set Annotations Main(R"cpp( @@ -444,7 +455,7 @@ "no matching constructor for initialization of 'S'"))); } -TEST(DiagnosticTest, NoMultipleDiagnosticInFlight) { +TEST_F(DiagnosticsTest, NoMultipleDiagnosticInFlight) { Annotations Main(R"cpp( template struct Foo { T *begin(); @@ -471,7 +482,7 @@ diagSource(Diag::ClangTidy), diagName("modernize-loop-convert"))))); } -TEST(DiagnosticTest, RespectsDiagnosticConfig) { +TEST_F(DiagnosticsTest, RespectsDiagnosticConfig) { Annotations Main(R"cpp( // error-ok void x() { @@ -493,7 +504,7 @@ "use of undeclared identifier 'unknown'"))); } -TEST(DiagnosticTest, RespectsDiagnosticConfigInHeader) { +TEST_F(DiagnosticsTest, RespectsDiagnosticConfigInHeader) { Annotations Header(R"cpp( int x = "42"; // error-ok )cpp"); @@ -508,7 +519,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } -TEST(DiagnosticTest, ClangTidySuppressionComment) { +TEST_F(DiagnosticsTest, ClangTidySuppressionComment) { Annotations Main(R"cpp( int main() { int i = 3; @@ -540,7 +551,7 @@ diagName("bugprone-integer-division"))))); } -TEST(DiagnosticTest, ClangTidySystemMacro) { +TEST_F(DiagnosticsTest, ClangTidySystemMacro) { Annotations Main(R"cpp( #include "user.h" #include "system.h" @@ -571,7 +582,7 @@ Diag(Main.range("user"), BadDivision)))); } -TEST(DiagnosticTest, ClangTidyWarningAsError) { +TEST_F(DiagnosticsTest, ClangTidyWarningAsError) { Annotations Main(R"cpp( int main() { int i = 3; @@ -603,7 +614,7 @@ }; } -TEST(DiagnosticTest, ClangTidyEnablesClangWarning) { +TEST_F(DiagnosticsTest, ClangTidyEnablesClangWarning) { Annotations Main(R"cpp( // error-ok static void [[foo]]() {} )cpp"); @@ -692,7 +703,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } -TEST(DiagnosticTest, LongFixMessages) { +TEST_F(DiagnosticsTest, LongFixMessages) { // We limit the size of printed code. Annotations Source(R"cpp( int main() { @@ -724,7 +735,7 @@ Fix(Source.range(), "ident", "change 'ide\\…' to 'ident'")))); } -TEST(DiagnosticTest, NewLineFixMessage) { +TEST_F(DiagnosticsTest, NewLineFixMessage) { Annotations Source("int a;[[]]"); TestTU TU = TestTU::withCode(Source.code()); TU.ExtraArgs = {"-Wnewline-eof"}; @@ -733,7 +744,7 @@ ElementsAre(withFix((Fix(Source.range(), "\n", "insert '\\n'"))))); } -TEST(DiagnosticTest, ClangTidySuppressionCommentTrumpsWarningAsError) { +TEST_F(DiagnosticsTest, ClangTidySuppressionCommentTrumpsWarningAsError) { Annotations Main(R"cpp( int main() { int i = 3; @@ -746,7 +757,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), UnorderedElementsAre()); } -TEST(DiagnosticTest, ClangTidyNoLiteralDataInMacroToken) { +TEST_F(DiagnosticsTest, ClangTidyNoLiteralDataInMacroToken) { Annotations Main(R"cpp( #define SIGTERM 15 using pthread_t = int; @@ -761,7 +772,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), UnorderedElementsAre()); // no-crash } -TEST(DiagnosticTest, ElseAfterReturnRange) { +TEST_F(DiagnosticsTest, ElseAfterReturnRange) { Annotations Main(R"cpp( int foo(int cond) { if (cond == 1) { @@ -779,7 +790,7 @@ Diag(Main.range(), "do not use 'else' after 'return'")))); } -TEST(DiagnosticTest, ClangTidySelfContainedDiags) { +TEST_F(DiagnosticsTest, ClangTidySelfContainedDiags) { Annotations Main(R"cpp($MathHeader[[]] struct Foo{ int A, B; @@ -840,7 +851,7 @@ withFix(equalToFix(ExpectedDFix)))))); } -TEST(DiagnosticsTest, Preprocessor) { +TEST_F(DiagnosticsTest, Preprocessor) { // This looks like a preamble, but there's an #else in the middle! // Check that: // - the #else doesn't generate diagnostics (we had this bug) @@ -859,7 +870,7 @@ ElementsAre(Diag(Test.range(), "use of undeclared identifier 'b'"))); } -TEST(DiagnosticsTest, IgnoreVerify) { +TEST_F(DiagnosticsTest, IgnoreVerify) { auto TU = TestTU::withCode(R"cpp( int a; // expected-error {{}} )cpp"); @@ -868,7 +879,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } -TEST(DiagnosticTest, IgnoreBEFilelistOptions) { +TEST_F(DiagnosticsTest, IgnoreBEFilelistOptions) { auto TU = TestTU::withCode(""); TU.ExtraArgs.push_back("-Xclang"); for (const auto *DisableOption : @@ -882,7 +893,7 @@ } // Recursive main-file include is diagnosed, and doesn't crash. -TEST(DiagnosticsTest, RecursivePreamble) { +TEST_F(DiagnosticsTest, RecursivePreamble) { auto TU = TestTU::withCode(R"cpp( #include "foo.h" // error-ok int symbol; @@ -894,7 +905,7 @@ } // Recursive main-file include with #pragma once guard is OK. -TEST(DiagnosticsTest, RecursivePreamblePragmaOnce) { +TEST_F(DiagnosticsTest, RecursivePreamblePragmaOnce) { auto TU = TestTU::withCode(R"cpp( #pragma once #include "foo.h" @@ -908,7 +919,7 @@ // Recursive main-file include with #ifndef guard should be OK. // However, it's not yet recognized (incomplete at end of preamble). -TEST(DiagnosticsTest, RecursivePreambleIfndefGuard) { +TEST_F(DiagnosticsTest, RecursivePreambleIfndefGuard) { auto TU = TestTU::withCode(R"cpp( #ifndef FOO #define FOO @@ -923,7 +934,7 @@ EXPECT_THAT(TU.build().getLocalTopLevelDecls(), SizeIs(1)); } -TEST(DiagnosticsTest, PreambleWithPragmaAssumeNonnull) { +TEST_F(DiagnosticsTest, PreambleWithPragmaAssumeNonnull) { auto TU = TestTU::withCode(R"cpp( #pragma clang assume_nonnull begin void foo(int *x); @@ -936,7 +947,7 @@ NullabilityKind::NonNull); } -TEST(DiagnosticsTest, PreambleHeaderWithBadPragmaAssumeNonnull) { +TEST_F(DiagnosticsTest, PreambleHeaderWithBadPragmaAssumeNonnull) { Annotations Header(R"cpp( #pragma clang assume_nonnull begin // error-ok void foo(int *X); @@ -956,7 +967,7 @@ ASSERT_FALSE(Y->getOriginalType()->getNullability()); } -TEST(DiagnosticsTest, InsideMacros) { +TEST_F(DiagnosticsTest, InsideMacros) { Annotations Test(R"cpp( #define TEN 10 #define RET(x) return x + 10 @@ -977,7 +988,7 @@ "'int *' with an rvalue of type 'int'"))); } -TEST(DiagnosticsTest, NoFixItInMacro) { +TEST_F(DiagnosticsTest, NoFixItInMacro) { Annotations Test(R"cpp( #define Define(name) void name() {} @@ -989,7 +1000,7 @@ Not(withFix(_))))); } -TEST(DiagnosticsTest, PragmaSystemHeader) { +TEST_F(DiagnosticsTest, PragmaSystemHeader) { Annotations Test("#pragma clang [[system_header]]\n"); auto TU = TestTU::withCode(Test.code()); EXPECT_THAT( @@ -1000,7 +1011,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } -TEST(ClangdTest, MSAsm) { +TEST_F(DiagnosticsTest, MSAsm) { // Parsing MS assembly tries to use the target MCAsmInfo, which we don't link. // We used to crash here. Now clang emits a diagnostic, which we filter out. llvm::InitializeAllTargetInfos(); // As in ClangdMain @@ -1009,7 +1020,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } -TEST(DiagnosticsTest, ToLSP) { +TEST_F(DiagnosticsTest, ToLSP) { URIForFile MainFile = URIForFile::canonicalize(testPath("foo/bar/main.cpp"), ""); URIForFile HeaderFile = @@ -1137,7 +1148,7 @@ return MemIndex::build(std::move(Slab).build(), RefSlab(), RelationSlab()); } -TEST(IncludeFixerTest, IncompleteType) { +TEST_F(DiagnosticsTest, IncludeFixerIncompleteType) { auto TU = TestTU::withHeaderCode("namespace ns { class X; } ns::X *x;"); TU.ExtraArgs.push_back("-std=c++20"); auto Index = buildIndexWithSymbol( @@ -1185,7 +1196,7 @@ } } -TEST(IncludeFixerTest, IncompleteEnum) { +TEST_F(DiagnosticsTest, IncludeFixerIncompleteEnum) { Symbol Sym = enm("X"); Sym.Flags |= Symbol::IndexedForCodeCompletion; Sym.CanonicalDeclaration.FileURI = Sym.Definition.FileURI = "unittest:///x.h"; @@ -1216,7 +1227,7 @@ } } -TEST(IncludeFixerTest, NoSuggestIncludeWhenNoDefinitionInHeader) { +TEST_F(DiagnosticsTest, IncludeFixerNoSuggestIncludeWhenNoDefinitionInHeader) { Annotations Test(R"cpp(// error-ok $insert[[]]namespace ns { class X; @@ -1247,7 +1258,7 @@ "member access into incomplete type 'ns::X'"))); } -TEST(IncludeFixerTest, Typo) { +TEST_F(DiagnosticsTest, IncludeFixerTypo) { Annotations Test(R"cpp(// error-ok $insert[[]]namespace ns { void foo() { @@ -1307,7 +1318,7 @@ "Include \"x.h\" for symbol ns::X"))))); } -TEST(IncludeFixerTest, TypoInMacro) { +TEST_F(DiagnosticsTest, IncludeFixerTypoInMacro) { auto TU = TestTU::withCode(R"cpp(// error-ok #define ID(T) T X a1; @@ -1328,7 +1339,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), Each(withFix(_))); } -TEST(IncludeFixerTest, MultipleMatchedSymbols) { +TEST_F(DiagnosticsTest, IncludeFixerMultipleMatchedSymbols) { Annotations Test(R"cpp(// error-ok $insert[[]]namespace na { namespace nb { @@ -1354,7 +1365,7 @@ "Include \"b.h\" for symbol na::nb::X"))))); } -TEST(IncludeFixerTest, NoCrashMemberAccess) { +TEST_F(DiagnosticsTest, IncludeFixerNoCrashMemberAccess) { Annotations Test(R"cpp(// error-ok struct X { int xyz; }; void g() { X x; x.$[[xy]]; } @@ -1369,7 +1380,7 @@ UnorderedElementsAre(Diag(Test.range(), "no member named 'xy' in 'X'"))); } -TEST(IncludeFixerTest, UseCachedIndexResults) { +TEST_F(DiagnosticsTest, IncludeFixerUseCachedIndexResults) { // As index results for the identical request are cached, more than 5 fixes // are generated. Annotations Test(R"cpp(// error-ok @@ -1409,7 +1420,7 @@ } } -TEST(IncludeFixerTest, UnresolvedNameAsSpecifier) { +TEST_F(DiagnosticsTest, IncludeFixerUnresolvedNameAsSpecifier) { Annotations Test(R"cpp(// error-ok $insert[[]]namespace ns { } @@ -1432,7 +1443,7 @@ "Include \"x.h\" for symbol ns::scope::X_Y"))))); } -TEST(IncludeFixerTest, UnresolvedSpecifierWithSemaCorrection) { +TEST_F(DiagnosticsTest, IncludeFixerUnresolvedSpecifierWithSemaCorrection) { Annotations Test(R"cpp(// error-ok $insert[[]]namespace clang { void f() { @@ -1479,7 +1490,7 @@ "Include \"y.h\" for symbol clang::clangd::ns::Y"))))); } -TEST(IncludeFixerTest, SpecifiedScopeIsNamespaceAlias) { +TEST_F(DiagnosticsTest, IncludeFixerSpecifiedScopeIsNamespaceAlias) { Annotations Test(R"cpp(// error-ok $insert[[]]namespace a {} namespace b = a; @@ -1500,7 +1511,7 @@ "Include \"x.h\" for symbol a::X"))))); } -TEST(IncludeFixerTest, NoCrashOnTemplateInstantiations) { +TEST_F(DiagnosticsTest, IncludeFixerNoCrashOnTemplateInstantiations) { Annotations Test(R"cpp( template struct Templ { template @@ -1522,7 +1533,7 @@ ElementsAre(Diag(Test.range(), "use of undeclared identifier 'a'"))); } -TEST(IncludeFixerTest, HeaderNamedInDiag) { +TEST_F(DiagnosticsTest, IncludeFixerHeaderNamedInDiag) { Annotations Test(R"cpp( $insert[[]]int main() { [[printf]](""); @@ -1554,7 +1565,7 @@ "Include for symbol printf"))))); } -TEST(IncludeFixerTest, CImplicitFunctionDecl) { +TEST_F(DiagnosticsTest, IncludeFixerCImplicitFunctionDecl) { Annotations Test("void x() { [[foo]](); }"); auto TU = TestTU::withCode(Test.code()); TU.Filename = "test.c"; @@ -1588,7 +1599,7 @@ "Include \"foo.h\" for symbol foo"))))); } -TEST(DiagsInHeaders, DiagInsideHeader) { +TEST_F(DiagnosticsTest, DiagInsideHeader) { Annotations Main(R"cpp( #include [["a.h"]] void foo() {})cpp"); @@ -1602,7 +1613,7 @@ withNote(Diag(Header.range(), "error occurred here"))))); } -TEST(DiagsInHeaders, DiagInTransitiveInclude) { +TEST_F(DiagnosticsTest, DiagInTransitiveInclude) { Annotations Main(R"cpp( #include [["a.h"]] void foo() {})cpp"); @@ -1615,7 +1626,7 @@ "required for all declarations"))); } -TEST(DiagsInHeaders, DiagInMultipleHeaders) { +TEST_F(DiagnosticsTest, DiagInMultipleHeaders) { Annotations Main(R"cpp( #include $a[["a.h"]] #include $b[["b.h"]] @@ -1631,7 +1642,7 @@ "required for all declarations"))); } -TEST(DiagsInHeaders, PreferExpansionLocation) { +TEST_F(DiagnosticsTest, PreferExpansionLocation) { Annotations Main(R"cpp( #include [["a.h"]] #include "b.h" @@ -1645,7 +1656,7 @@ "is required for all declarations"))); } -TEST(DiagsInHeaders, PreferExpansionLocationMacros) { +TEST_F(DiagnosticsTest, PreferExpansionLocationMacros) { Annotations Main(R"cpp( #define X #include "a.h" @@ -1663,7 +1674,7 @@ "required for all declarations"))); } -TEST(DiagsInHeaders, LimitDiagsOutsideMainFile) { +TEST_F(DiagnosticsTest, LimitDiagsOutsideMainFile) { Annotations Main(R"cpp( #include [["a.h"]] #include "b.h" @@ -1692,7 +1703,7 @@ "required for all declarations"))); } -TEST(DiagsInHeaders, OnlyErrorOrFatal) { +TEST_F(DiagnosticsTest, OnlyErrorOrFatal) { Annotations Main(R"cpp( #include [["a.h"]] void foo() {})cpp"); @@ -1708,7 +1719,7 @@ withNote(Diag(Header.range(), "error occurred here"))))); } -TEST(DiagsInHeaders, OnlyDefaultErrorOrFatal) { +TEST_F(DiagnosticsTest, OnlyDefaultErrorOrFatal) { Annotations Main(R"cpp( #include [["a.h"]] // get unused "foo" warning when building preamble. )cpp"); @@ -1722,7 +1733,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } -TEST(DiagsInHeaders, FromNonWrittenSources) { +TEST_F(DiagnosticsTest, FromNonWrittenSources) { Annotations Main(R"cpp( #include [["a.h"]] void foo() {})cpp"); @@ -1739,7 +1750,7 @@ withNote(Diag(Header.range(), "error occurred here"))))); } -TEST(DiagsInHeaders, ErrorFromMacroExpansion) { +TEST_F(DiagnosticsTest, ErrorFromMacroExpansion) { Annotations Main(R"cpp( void bar() { int fo; // error-ok @@ -1756,7 +1767,7 @@ "identifier 'foo'; did you mean 'fo'?"))); } -TEST(DiagsInHeaders, ErrorFromMacroArgument) { +TEST_F(DiagnosticsTest, ErrorFromMacroArgument) { Annotations Main(R"cpp( void bar() { int fo; // error-ok @@ -1773,7 +1784,7 @@ "identifier 'foo'; did you mean 'fo'?"))); } -TEST(IgnoreDiags, FromNonWrittenInclude) { +TEST_F(DiagnosticsTest, FromNonWrittenInclude) { TestTU TU; TU.ExtraArgs.push_back("--include=a.h"); TU.AdditionalFiles = {{"a.h", "void main();"}}; @@ -1782,7 +1793,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), UnorderedElementsAre()); } -TEST(ToLSPDiag, RangeIsInMain) { +TEST_F(DiagnosticsTest, RangeIsInMain) { ClangdDiagnosticOptions Opts; clangd::Diag D; D.Range = {pos(1, 2), pos(3, 4)}; @@ -1805,7 +1816,7 @@ }); } -TEST(ParsedASTTest, ModuleSawDiag) { +TEST_F(DiagnosticsTest, ModuleSawDiag) { static constexpr const llvm::StringLiteral KDiagMsg = "StampedDiag"; struct DiagModifierModule final : public FeatureModule { struct Listener : public FeatureModule::ASTListener { @@ -1831,7 +1842,7 @@ testing::Contains(Diag(Code.range(), KDiagMsg.str()))); } -TEST(Preamble, EndsOnNonEmptyLine) { +TEST_F(DiagnosticsTest, EndsOnNonEmptyLine) { TestTU TU; TU.ExtraArgs = {"-Wnewline-eof"}; @@ -1850,7 +1861,7 @@ } } -TEST(Diagnostics, Tags) { +TEST_F(DiagnosticsTest, Tags) { TestTU TU; TU.ExtraArgs = {"-Wunused", "-Wdeprecated"}; Annotations Test(R"cpp( @@ -1879,7 +1890,7 @@ withTag(DiagnosticTag::Deprecated))))); } -TEST(DiagnosticsTest, IncludeCleaner) { +TEST_F(DiagnosticsTest, IncludeCleaner) { Annotations Test(R"cpp( $fix[[ $diag[[#include "unused.h"]] ]] @@ -1935,7 +1946,7 @@ EXPECT_THAT(*TU.build().getDiagnostics(), IsEmpty()); } -TEST(DiagnosticsTest, FixItFromHeader) { +TEST_F(DiagnosticsTest, FixItFromHeader) { llvm::StringLiteral Header(R"cpp( void foo(int *); void foo(int *, int);)cpp"); @@ -1958,7 +1969,7 @@ "the argument with &"))))); } -TEST(DiagnosticsTest, UnusedInHeader) { +TEST_F(DiagnosticsTest, UnusedInHeader) { // Clang diagnoses unused static inline functions outside headers. auto TU = TestTU::withCode("static inline void foo(void) {}"); TU.ExtraArgs.push_back("-Wunused-function");