llvm/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

//===--- DiagnosticsTests.cpp ------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "../clang-tidy/ClangTidyOptions.h"
#include "Annotations.h"
#include "Config.h"
#include "Diagnostics.h"
#include "Feature.h"
#include "FeatureModule.h"
#include "ParsedAST.h"
#include "Protocol.h"
#include "TestFS.h"
#include "TestIndex.h"
#include "TestTU.h"
#include "TidyProvider.h"
#include "index/MemIndex.h"
#include "index/Ref.h"
#include "index/Relation.h"
#include "index/Symbol.h"
#include "support/Context.h"
#include "support/Path.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticSema.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Specifiers.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Testing/Support/SupportHelpers.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

namespace clang {
namespace clangd {
namespace {

_;
AllOf;
Contains;
Each;
ElementsAre;
Field;
IsEmpty;
Not;
Pair;
SizeIs;
UnorderedElementsAre;

::testing::Matcher<const Diag &> withFix(::testing::Matcher<Fix> FixMatcher) {}

::testing::Matcher<const Diag &> withFix(::testing::Matcher<Fix> FixMatcher1,
                                         ::testing::Matcher<Fix> FixMatcher2) {}

::testing::Matcher<const Diag &> withID(unsigned ID) {}
::testing::Matcher<const Diag &>
withNote(::testing::Matcher<Note> NoteMatcher) {}

::testing::Matcher<const Diag &>
withNote(::testing::Matcher<Note> NoteMatcher1,
         ::testing::Matcher<Note> NoteMatcher2) {}

::testing::Matcher<const Diag &>
withTag(::testing::Matcher<DiagnosticTag> TagMatcher) {}

MATCHER_P(hasRange, Range, "") {}

MATCHER_P2(Diag, Range, Message,
           "Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {}

MATCHER_P3(Fix, Range, Replacement, Message,
           "Fix " + llvm::to_string(Range) + " => " +
               ::testing::PrintToString(Replacement) + " = [" + Message + "]") {}

MATCHER_P(fixMessage, Message, "") {}

MATCHER_P(equalToLSPDiag, LSPDiag,
          "LSP diagnostic " + llvm::to_string(LSPDiag)) {}

MATCHER_P(diagSource, S, "") {}
MATCHER_P(diagName, N, "") {}
MATCHER_P(diagSeverity, S, "") {}

MATCHER_P(equalToFix, Fix, "LSP fix " + llvm::to_string(Fix)) {}

// Helper function to make tests shorter.
Position pos(int Line, int Character) {}

// Normally returns the provided diagnostics matcher.
// If clang-tidy checks are not linked in, returns a matcher for no diagnostics!
// This is intended for tests where the diagnostics come from clang-tidy checks.
// We don't #ifdef each individual test as it's intrusive and we want to ensure
// that as much of the test is still compiled an run as possible.
::testing::Matcher<std::vector<clangd::Diag>>
ifTidyChecks(::testing::Matcher<std::vector<clangd::Diag>> M) {}

TEST(DiagnosticsTest, DiagnosticRanges) {}

// Verify that the -Wswitch case-not-covered diagnostic range covers the
// whole expression. This is important because the "populate-switch" tweak
// 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(DiagnosticsTest, FlagsMatter) {}

TEST(DiagnosticsTest, DiagnosticPreamble) {}

TEST(DiagnosticsTest, DeduplicatedClangTidyDiagnostics) {}

TEST(DiagnosticsTest, ClangTidy) {}

TEST(DiagnosticsTest, ClangTidyEOF) {}

TEST(DiagnosticTest, TemplatesInHeaders) {}

TEST(DiagnosticTest, MakeUnique) {}

TEST(DiagnosticTest, CoroutineInHeader) {}

TEST(DiagnosticTest, MakeShared) {}

TEST(DiagnosticTest, NoMultipleDiagnosticInFlight) {}

TEST(DiagnosticTest, RespectsDiagnosticConfig) {}

TEST(DiagnosticTest, RespectsDiagnosticConfigInHeader) {}

TEST(DiagnosticTest, ClangTidySuppressionComment) {}

TEST(DiagnosticTest, ClangTidySystemMacro) {}

TEST(DiagnosticTest, ClangTidyWarningAsError) {}

TidyProvider addClangArgs(std::vector<llvm::StringRef> ExtraArgs,
                          llvm::StringRef Checks) {}

TEST(DiagnosticTest, ClangTidyEnablesClangWarning) {}

TEST(DiagnosticTest, LongFixMessages) {}

TEST(DiagnosticTest, NewLineFixMessage) {}

TEST(DiagnosticTest, ClangTidySuppressionCommentTrumpsWarningAsError) {}

TEST(DiagnosticTest, ClangTidyNoLiteralDataInMacroToken) {}

TEST(DiagnosticTest, ElseAfterReturnRange) {}

TEST(DiagnosticTest, ClangTidySelfContainedDiags) {}

TEST(DiagnosticTest, ClangTidySelfContainedDiagsFormatting) {}

TEST(DiagnosticsTest, ClangTidyCallingIntoPreprocessor) {}

TEST(DiagnosticsTest, Preprocessor) {}

TEST(DiagnosticsTest, IgnoreVerify) {}

TEST(DiagnosticTest, IgnoreBEFilelistOptions) {}

// Recursive main-file include is diagnosed, and doesn't crash.
TEST(DiagnosticsTest, RecursivePreamble) {}

// Recursive main-file include with #pragma once guard is OK.
TEST(DiagnosticsTest, RecursivePreamblePragmaOnce) {}

// 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(DiagnosticsTest, PreambleWithPragmaAssumeNonnull) {}

TEST(DiagnosticsTest, PreambleHeaderWithBadPragmaAssumeNonnull) {}

TEST(DiagnosticsTest, InsideMacros) {}

TEST(DiagnosticsTest, NoFixItInMacro) {}

TEST(DiagnosticsTest, PragmaSystemHeader) {}

TEST(ClangdTest, MSAsm) {}

TEST(DiagnosticsTest, ToLSP) {}

struct SymbolWithHeader {};

std::unique_ptr<SymbolIndex>
buildIndexWithSymbol(llvm::ArrayRef<SymbolWithHeader> Syms) {}

TEST(IncludeFixerTest, IncompleteType) {}

TEST(IncludeFixerTest, IncompleteEnum) {}

TEST(IncludeFixerTest, NoSuggestIncludeWhenNoDefinitionInHeader) {}

TEST(IncludeFixerTest, Typo) {}

TEST(IncludeFixerTest, TypoInMacro) {}

TEST(IncludeFixerTest, MultipleMatchedSymbols) {}

TEST(IncludeFixerTest, NoCrashMemberAccess) {}

TEST(IncludeFixerTest, UseCachedIndexResults) {}

TEST(IncludeFixerTest, UnresolvedNameAsSpecifier) {}

TEST(IncludeFixerTest, UnresolvedSpecifierWithSemaCorrection) {}

TEST(IncludeFixerTest, SpecifiedScopeIsNamespaceAlias) {}

TEST(IncludeFixerTest, NoCrashOnTemplateInstantiations) {}

TEST(IncludeFixerTest, HeaderNamedInDiag) {}

TEST(IncludeFixerTest, CImplicitFunctionDecl) {}

TEST(DiagsInHeaders, DiagInsideHeader) {}

TEST(DiagsInHeaders, DiagInTransitiveInclude) {}

TEST(DiagsInHeaders, DiagInMultipleHeaders) {}

TEST(DiagsInHeaders, PreferExpansionLocation) {}

TEST(DiagsInHeaders, PreferExpansionLocationMacros) {}

TEST(DiagsInHeaders, LimitDiagsOutsideMainFile) {}

TEST(DiagsInHeaders, OnlyErrorOrFatal) {}

TEST(DiagsInHeaders, OnlyDefaultErrorOrFatal) {}

TEST(DiagsInHeaders, FromNonWrittenSources) {}

TEST(DiagsInHeaders, ErrorFromMacroExpansion) {}

TEST(DiagsInHeaders, ErrorFromMacroArgument) {}

TEST(IgnoreDiags, FromNonWrittenInclude) {}

TEST(ToLSPDiag, RangeIsInMain) {}

TEST(ParsedASTTest, ModuleSawDiag) {}

TEST(Preamble, EndsOnNonEmptyLine) {}

TEST(Diagnostics, Tags) {}

TEST(Diagnostics, DeprecatedDiagsAreHints) {}

TEST(DiagnosticsTest, IncludeCleaner) {}

TEST(DiagnosticsTest, FixItFromHeader) {}

TEST(DiagnosticsTest, UnusedInHeader) {}

} // namespace
} // namespace clangd
} // namespace clang