[clangd] Qualify uses of ::testing everywhere. NFC

Add an initial '::' qualifier to all usages of 'testing' namespace that
did not have one.

The goal is to make our code style in tests more consistent.

llvm-svn: 360026
This commit is contained in:
Ilya Biryukov 2019-05-06 10:08:47 +00:00
parent 69f4e8aa8e
commit 3ab77491dd
15 changed files with 109 additions and 112 deletions

View File

@ -7,12 +7,12 @@
#include "gtest/gtest.h"
#include <thread>
using testing::_;
using testing::AllOf;
using testing::Contains;
using testing::ElementsAre;
using testing::Not;
using testing::UnorderedElementsAre;
using ::testing::_;
using ::testing::AllOf;
using ::testing::Contains;
using ::testing::ElementsAre;
using ::testing::Not;
using ::testing::UnorderedElementsAre;
namespace clang {
namespace clangd {
@ -23,9 +23,9 @@ MATCHER(Declared, "") {
}
MATCHER(Defined, "") { return !StringRef(arg.Definition.FileURI).empty(); }
MATCHER_P(FileURI, F, "") { return StringRef(arg.Location.FileURI) == F; }
testing::Matcher<const RefSlab &>
RefsAre(std::vector<testing::Matcher<Ref>> Matchers) {
return ElementsAre(testing::Pair(_, UnorderedElementsAreArray(Matchers)));
::testing::Matcher<const RefSlab &>
RefsAre(std::vector<::testing::Matcher<Ref>> Matchers) {
return ElementsAre(::testing::Pair(_, UnorderedElementsAreArray(Matchers)));
}
// URI cannot be empty since it references keys in the IncludeGraph.
MATCHER(EmptyIncludeNode, "") {

View File

@ -18,7 +18,7 @@ namespace clang {
namespace clangd {
namespace {
using testing::ElementsAre;
using ::testing::ElementsAre;
TEST(ClangdUnitTest, GetBeginningOfIdentifier) {
std::string Preamble = R"cpp(

View File

@ -352,16 +352,16 @@ TEST(DexIterators, Optimizations) {
// Search token tests.
//===----------------------------------------------------------------------===//
testing::Matcher<std::vector<Token>>
::testing::Matcher<std::vector<Token>>
tokensAre(std::initializer_list<std::string> Strings, Token::Kind Kind) {
std::vector<Token> Tokens;
for (const auto &TokenData : Strings) {
Tokens.push_back(Token(Kind, TokenData));
}
return testing::UnorderedElementsAreArray(Tokens);
return ::testing::UnorderedElementsAreArray(Tokens);
}
testing::Matcher<std::vector<Token>>
::testing::Matcher<std::vector<Token>>
trigramsAre(std::initializer_list<std::string> Trigrams) {
return tokensAre(Trigrams, Token::Kind::Trigram);
}

View File

@ -27,23 +27,24 @@ namespace clang {
namespace clangd {
namespace {
using testing::_;
using testing::ElementsAre;
using testing::Field;
using testing::IsEmpty;
using testing::Pair;
using testing::UnorderedElementsAre;
using ::testing::_;
using ::testing::ElementsAre;
using ::testing::Field;
using ::testing::IsEmpty;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
testing::Matcher<const Diag &> WithFix(testing::Matcher<Fix> FixMatcher) {
::testing::Matcher<const Diag &> WithFix(::testing::Matcher<Fix> FixMatcher) {
return Field(&Diag::Fixes, ElementsAre(FixMatcher));
}
testing::Matcher<const Diag &> WithFix(testing::Matcher<Fix> FixMatcher1,
testing::Matcher<Fix> FixMatcher2) {
::testing::Matcher<const Diag &> WithFix(::testing::Matcher<Fix> FixMatcher1,
::testing::Matcher<Fix> FixMatcher2) {
return Field(&Diag::Fixes, UnorderedElementsAre(FixMatcher1, FixMatcher2));
}
testing::Matcher<const Diag &> WithNote(testing::Matcher<Note> NoteMatcher) {
::testing::Matcher<const Diag &>
WithNote(::testing::Matcher<Note> NoteMatcher) {
return Field(&Diag::Notes, ElementsAre(NoteMatcher));
}
@ -54,7 +55,7 @@ MATCHER_P2(Diag, Range, Message,
MATCHER_P3(Fix, Range, Replacement, Message,
"Fix " + llvm::to_string(Range) + " => " +
testing::PrintToString(Replacement) + " = [" + Message + "]") {
::testing::PrintToString(Replacement) + " = [" + Message + "]") {
return arg.Message == Message && arg.Edits.size() == 1 &&
arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
}
@ -159,7 +160,7 @@ TEST(DiagnosticsTest, DiagnosticPreamble) {
auto TU = TestTU::withCode(Test.code());
EXPECT_THAT(TU.build().getDiagnostics(),
ElementsAre(testing::AllOf(
ElementsAre(::testing::AllOf(
Diag(Test.range(), "'not-found.h' file not found"),
DiagSource(Diag::Clang), DiagName("pp_file_not_found"))));
}

View File

@ -23,13 +23,13 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using testing::_;
using testing::AllOf;
using testing::Contains;
using testing::ElementsAre;
using testing::IsEmpty;
using testing::Pair;
using testing::UnorderedElementsAre;
using ::testing::_;
using ::testing::AllOf;
using ::testing::Contains;
using ::testing::ElementsAre;
using ::testing::IsEmpty;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
MATCHER_P(RefRange, Range, "") {
return std::make_tuple(arg.Location.Start.line(), arg.Location.Start.column(),
@ -49,9 +49,9 @@ MATCHER_P(QName, N, "") { return (arg.Scope + arg.Name).str() == N; }
namespace clang {
namespace clangd {
namespace {
testing::Matcher<const RefSlab &>
RefsAre(std::vector<testing::Matcher<Ref>> Matchers) {
return ElementsAre(testing::Pair(_, UnorderedElementsAreArray(Matchers)));
::testing::Matcher<const RefSlab &>
RefsAre(std::vector<::testing::Matcher<Ref>> Matchers) {
return ElementsAre(::testing::Pair(_, UnorderedElementsAreArray(Matchers)));
}
Symbol symbol(llvm::StringRef ID) {

View File

@ -44,7 +44,7 @@ MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
// GMock helpers for matching DocumentSymbol.
MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
template <class... ChildMatchers>
testing::Matcher<DocumentSymbol> Children(ChildMatchers... ChildrenM) {
::testing::Matcher<DocumentSymbol> Children(ChildMatchers... ChildrenM) {
return Field(&DocumentSymbol::children, ElementsAre(ChildrenM...));
}
@ -573,7 +573,7 @@ TEST_F(DocumentSymbolsTest, Namespaces) {
)cpp");
EXPECT_THAT(
getSymbols(FilePath),
ElementsAreArray<testing::Matcher<DocumentSymbol>>(
ElementsAreArray<::testing::Matcher<DocumentSymbol>>(
{AllOf(WithName("ans1"),
Children(AllOf(WithName("ai1"), Children()),
AllOf(WithName("ans2"), Children(WithName("ai2"))))),

View File

@ -15,7 +15,7 @@
namespace clang {
namespace clangd {
namespace {
using testing::Not;
using ::testing::Not;
struct ExpectedMatch {
// Annotations are optional, and will not be asserted if absent.
@ -43,7 +43,7 @@ private:
llvm::Optional<llvm::StringRef> Annotated;
};
struct MatchesMatcher : public testing::MatcherInterface<llvm::StringRef> {
struct MatchesMatcher : public ::testing::MatcherInterface<llvm::StringRef> {
ExpectedMatch Candidate;
llvm::Optional<float> Score;
MatchesMatcher(ExpectedMatch Candidate, llvm::Optional<float> Score)
@ -56,7 +56,7 @@ struct MatchesMatcher : public testing::MatcherInterface<llvm::StringRef> {
}
bool MatchAndExplain(llvm::StringRef Pattern,
testing::MatchResultListener *L) const override {
::testing::MatchResultListener *L) const override {
std::unique_ptr<llvm::raw_ostream> OS(
L->stream()
? (llvm::raw_ostream *)(new llvm::raw_os_ostream(*L->stream()))
@ -65,15 +65,15 @@ struct MatchesMatcher : public testing::MatcherInterface<llvm::StringRef> {
auto Result = Matcher.match(Candidate.Word);
auto AnnotatedMatch = Matcher.dumpLast(*OS << "\n");
return Result && Candidate.accepts(AnnotatedMatch) &&
(!Score || testing::Value(*Result, testing::FloatEq(*Score)));
(!Score || ::testing::Value(*Result, ::testing::FloatEq(*Score)));
}
};
// Accepts patterns that match a given word, optionally requiring a score.
// Dumps the debug tables on match failure.
testing::Matcher<llvm::StringRef> matches(llvm::StringRef M,
llvm::Optional<float> Score = {}) {
return testing::MakeMatcher<llvm::StringRef>(new MatchesMatcher(M, Score));
::testing::Matcher<llvm::StringRef> matches(llvm::StringRef M,
llvm::Optional<float> Score = {}) {
return ::testing::MakeMatcher<llvm::StringRef>(new MatchesMatcher(M, Score));
}
TEST(FuzzyMatch, Matches) {
@ -179,7 +179,7 @@ TEST(FuzzyMatch, Matches) {
EXPECT_THAT("std", Not(matches("pthread_condattr_setpshared")));
}
struct RankMatcher : public testing::MatcherInterface<llvm::StringRef> {
struct RankMatcher : public ::testing::MatcherInterface<llvm::StringRef> {
std::vector<ExpectedMatch> RankedStrings;
RankMatcher(std::initializer_list<ExpectedMatch> RankedStrings)
: RankedStrings(RankedStrings) {}
@ -193,7 +193,7 @@ struct RankMatcher : public testing::MatcherInterface<llvm::StringRef> {
}
bool MatchAndExplain(llvm::StringRef Pattern,
testing::MatchResultListener *L) const override {
::testing::MatchResultListener *L) const override {
std::unique_ptr<llvm::raw_ostream> OS(
L->stream()
? (llvm::raw_ostream *)(new llvm::raw_os_ostream(*L->stream()))
@ -236,8 +236,8 @@ struct RankMatcher : public testing::MatcherInterface<llvm::StringRef> {
// Accepts patterns that match all the strings and rank them in the given order.
// Dumps the debug tables on match failure.
template <typename... T>
testing::Matcher<llvm::StringRef> ranks(T... RankedStrings) {
return testing::MakeMatcher<llvm::StringRef>(
::testing::Matcher<llvm::StringRef> ranks(T... RankedStrings) {
return ::testing::MakeMatcher<llvm::StringRef>(
new RankMatcher{ExpectedMatch(RankedStrings)...});
}

View File

@ -32,12 +32,12 @@ MATCHER_P(HasDigest, Digest, "") { return arg.Digest == Digest; }
MATCHER_P(HasName, Name, "") { return arg.Name == Name; }
MATCHER(HasSameURI, "") {
llvm::StringRef URI = testing::get<0>(arg);
const std::string &Path = testing::get<1>(arg);
llvm::StringRef URI = ::testing::get<0>(arg);
const std::string &Path = ::testing::get<1>(arg);
return toUri(Path) == URI;
}
testing::Matcher<const IncludeGraphNode &>
::testing::Matcher<const IncludeGraphNode &>
IncludesAre(const std::vector<std::string> &Includes) {
return ::testing::Field(&IncludeGraphNode::DirectIncludes,
UnorderedPointwise(HasSameURI(), Includes));

View File

@ -18,14 +18,14 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using testing::_;
using testing::AllOf;
using testing::AnyOf;
using testing::ElementsAre;
using testing::IsEmpty;
using testing::Pair;
using testing::Pointee;
using testing::UnorderedElementsAre;
using ::testing::_;
using ::testing::AllOf;
using ::testing::AnyOf;
using ::testing::ElementsAre;
using ::testing::IsEmpty;
using ::testing::Pair;
using ::testing::Pointee;
using ::testing::UnorderedElementsAre;
namespace clang {
namespace clangd {

View File

@ -21,13 +21,13 @@ namespace clang {
namespace clangd {
namespace {
using testing::ElementsAreArray;
using ::testing::ElementsAreArray;
struct Case {
const char *AnnotatedCode;
std::vector<const char *> Expected;
};
class ASTUtils : public testing::Test,
class ASTUtils : public ::testing::Test,
public ::testing::WithParamInterface<Case> {};
TEST_P(ASTUtils, PrintTemplateArgs) {
@ -55,7 +55,7 @@ TEST_P(ASTUtils, PrintTemplateArgs) {
}
INSTANTIATE_TEST_CASE_P(ASTUtilsTests, ASTUtils,
testing::ValuesIn(std::vector<Case>({
::testing::ValuesIn(std::vector<Case>({
{
R"cpp(
template <class X> class Bar {};

View File

@ -13,11 +13,11 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using testing::_;
using testing::AllOf;
using testing::Pair;
using testing::UnorderedElementsAre;
using testing::UnorderedElementsAreArray;
using ::testing::_;
using ::testing::AllOf;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
using ::testing::UnorderedElementsAreArray;
namespace clang {
namespace clangd {
@ -135,7 +135,7 @@ TEST(SerializationTest, YAMLConversions) {
EXPECT_THAT(
*ParsedYAML->Refs,
UnorderedElementsAre(Pair(cantFail(SymbolID::fromStr("057557CEBF6E6B2D")),
testing::SizeIs(1))));
::testing::SizeIs(1))));
auto Ref1 = ParsedYAML->Refs->begin()->second.front();
EXPECT_EQ(Ref1.Kind, RefKind::Reference);
EXPECT_EQ(StringRef(Ref1.Location.FileURI), "file:///path/foo.cc");

View File

@ -32,16 +32,16 @@ namespace clang {
namespace clangd {
namespace {
using testing::_;
using testing::AllOf;
using testing::Contains;
using testing::Each;
using testing::ElementsAre;
using testing::Field;
using testing::Not;
using testing::Pair;
using testing::UnorderedElementsAre;
using testing::UnorderedElementsAreArray;
using ::testing::_;
using ::testing::AllOf;
using ::testing::Contains;
using ::testing::Each;
using ::testing::ElementsAre;
using ::testing::Field;
using ::testing::Not;
using ::testing::Pair;
using ::testing::UnorderedElementsAre;
using ::testing::UnorderedElementsAreArray;
// GMock helpers for matching Symbol.
MATCHER_P(Labeled, Label, "") {
@ -96,16 +96,16 @@ MATCHER(VisibleOutsideFile, "") {
return static_cast<bool>(arg.Flags & Symbol::VisibleOutsideFile);
}
MATCHER(RefRange, "") {
const Ref &Pos = testing::get<0>(arg);
const Range &Range = testing::get<1>(arg);
const Ref &Pos = ::testing::get<0>(arg);
const Range &Range = ::testing::get<1>(arg);
return std::make_tuple(Pos.Location.Start.line(), Pos.Location.Start.column(),
Pos.Location.End.line(), Pos.Location.End.column()) ==
std::make_tuple(Range.start.line, Range.start.character,
Range.end.line, Range.end.character);
}
testing::Matcher<const std::vector<Ref> &>
::testing::Matcher<const std::vector<Ref> &>
HaveRanges(const std::vector<Range> Ranges) {
return testing::UnorderedPointwise(RefRange(), Ranges);
return ::testing::UnorderedPointwise(RefRange(), Ranges);
}
class ShouldCollectSymbolTest : public ::testing::Test {
@ -121,8 +121,8 @@ public:
// build() must have been called.
bool shouldCollect(llvm::StringRef Name, bool Qualified = true) {
assert(AST.hasValue());
const NamedDecl& ND = Qualified ? findDecl(*AST, Name)
: findUnqualifiedDecl(*AST, Name);
const NamedDecl &ND =
Qualified ? findDecl(*AST, Name) : findUnqualifiedDecl(*AST, Name);
ASTContext& Ctx = AST->getASTContext();
const SourceManager& SM = Ctx.getSourceManager();
bool MainFile = SM.isWrittenInMainFile(SM.getExpansionLoc(ND.getBeginLoc()));
@ -655,19 +655,15 @@ TEST_F(SymbolCollectorTest, References) {
)";
CollectorOpts.CountReferences = true;
runSymbolCollector(Header, Main);
EXPECT_THAT(Symbols,
UnorderedElementsAreArray(
{AllOf(QName("W"), RefCount(1)),
AllOf(QName("X"), RefCount(1)),
AllOf(QName("Y"), RefCount(0)),
AllOf(QName("Z"), RefCount(0)),
AllOf(QName("y"), RefCount(0)),
AllOf(QName("z"), RefCount(0)),
AllOf(QName("x"), RefCount(0)),
AllOf(QName("w"), RefCount(0)),
AllOf(QName("w2"), RefCount(0)),
AllOf(QName("V"), RefCount(1)),
AllOf(QName("v"), RefCount(0))}));
EXPECT_THAT(
Symbols,
UnorderedElementsAreArray(
{AllOf(QName("W"), RefCount(1)), AllOf(QName("X"), RefCount(1)),
AllOf(QName("Y"), RefCount(0)), AllOf(QName("Z"), RefCount(0)),
AllOf(QName("y"), RefCount(0)), AllOf(QName("z"), RefCount(0)),
AllOf(QName("x"), RefCount(0)), AllOf(QName("w"), RefCount(0)),
AllOf(QName("w2"), RefCount(0)), AllOf(QName("V"), RefCount(1)),
AllOf(QName("v"), RefCount(0))}));
}
TEST_F(SymbolCollectorTest, SymbolRelativeNoFallback) {

View File

@ -24,7 +24,7 @@ namespace clang {
namespace clangd {
namespace {
using testing::ElementsAreArray;
using ::testing::ElementsAreArray;
auto CreateExpectedSymbolDetails = [](const std::string &name,
const std::string &container,

View File

@ -27,21 +27,21 @@ namespace clang {
namespace clangd {
namespace {
using testing::AllOf;
using testing::ElementsAre;
using testing::Eq;
using testing::Field;
using testing::IsEmpty;
using testing::Matcher;
using testing::Pointee;
using testing::UnorderedElementsAreArray;
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Field;
using ::testing::IsEmpty;
using ::testing::Matcher;
using ::testing::Pointee;
using ::testing::UnorderedElementsAreArray;
// GMock helpers for matching TypeHierarchyItem.
MATCHER_P(WithName, N, "") { return arg.name == N; }
MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
MATCHER_P(SelectionRangeIs, R, "") { return arg.selectionRange == R; }
template <class... ParentMatchers>
testing::Matcher<TypeHierarchyItem> Parents(ParentMatchers... ParentsM) {
::testing::Matcher<TypeHierarchyItem> Parents(ParentMatchers... ParentsM) {
return Field(&TypeHierarchyItem::parents, HasValue(ElementsAre(ParentsM...)));
}

View File

@ -25,10 +25,10 @@ namespace clang {
namespace clangd {
namespace {
using testing::ElementsAre;
using testing::IsEmpty;
using testing::Matcher;
using testing::UnorderedElementsAreArray;
using ::testing::ElementsAre;
using ::testing::IsEmpty;
using ::testing::Matcher;
using ::testing::UnorderedElementsAreArray;
class IgnoreDiagnostics : public DiagnosticsConsumer {
void onDiagnosticsReady(PathRef File,
@ -120,7 +120,7 @@ MATCHER_P3(Sym, Name, Decl, DefOrNone, "") {
}
return true;
}
testing::Matcher<LocatedSymbol> Sym(std::string Name, Range Decl) {
::testing::Matcher<LocatedSymbol> Sym(std::string Name, Range Decl) {
return Sym(Name, Decl, llvm::None);
}
MATCHER_P(Sym, Name, "") { return arg.Name == Name; }