kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: usaxena95, arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
TestTU now prints errors to llvm::errs and aborts on failures via
llvm_unreachable, rather than executing ASSERT_FALSE.
We'd like to make use of these testing libraries in different test suits that
might be compiling with a different gtest version than LLVM has.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103685
Files:
clang-tools-extra/clangd/index/Symbol.cpp
clang-tools-extra/clangd/index/Symbol.h
clang-tools-extra/clangd/unittests/TestTU.cpp
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -17,7 +17,9 @@
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/Utils.h"
#include "llvm/ADT/ScopeExit.h"
-#include "gtest/gtest.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
namespace clang {
namespace clangd {
@@ -69,14 +71,15 @@
void initializeModuleCache(CompilerInvocation &CI) {
llvm::SmallString<128> ModuleCachePath;
- ASSERT_FALSE(
- llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath));
+ if (llvm::sys::fs::createUniqueDirectory("module-cache", ModuleCachePath))
+ llvm_unreachable("Failed to create temp directory for module-cache");
CI.getHeaderSearchOpts().ModuleCachePath = ModuleCachePath.c_str();
}
void deleteModuleCache(const std::string ModuleCachePath) {
if (!ModuleCachePath.empty()) {
- ASSERT_FALSE(llvm::sys::fs::remove_directories(ModuleCachePath));
+ if (llvm::sys::fs::remove_directories(ModuleCachePath))
+ llvm_unreachable("Failed to delete temp directory for module-cache");
}
}
@@ -112,12 +115,12 @@
auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
Diags.take(), Preamble);
if (!AST.hasValue()) {
- ADD_FAILURE() << "Failed to build code:\n" << Code;
+ llvm::errs() << "Failed to build code:\n" << Code;
llvm_unreachable("Failed to build TestTU!");
}
if (!AST->getDiagnostics()) {
- ADD_FAILURE() << "TestTU should always build an AST with a fresh Preamble"
- << Code;
+ llvm::errs() << "TestTU should always build an AST with a fresh Preamble"
+ << Code;
return std::move(*AST);
}
// Check for error diagnostics and report gtest failures (unless expected).
@@ -138,7 +141,7 @@
// We always build AST with a fresh preamble in TestTU.
for (const auto &D : *AST->getDiagnostics())
if (D.Severity >= DiagnosticsEngine::Error) {
- ADD_FAILURE()
+ llvm::errs()
<< "TestTU failed to build (suppress with /*error-ok*/): \n"
<< D << "\n\nFor code:\n"
<< Code;
@@ -176,16 +179,16 @@
if (QName != (S.Scope + S.Name).str())
continue;
if (Result) {
- ADD_FAILURE() << "Multiple symbols named " << QName << ":\n"
- << *Result << "\n---\n"
- << S;
+ llvm::errs() << "Multiple symbols named " << QName << ":\n"
+ << *Result << "\n---\n"
+ << S;
assert(false && "QName is not unique");
}
Result = &S;
}
if (!Result) {
- ADD_FAILURE() << "No symbol named " << QName << " in "
- << ::testing::PrintToString(Slab);
+ llvm::errs() << "No symbol named " << QName << " in "
+ << llvm::to_string(Slab);
assert(false && "No symbol with QName");
}
return *Result;
@@ -225,7 +228,7 @@
Visitor.F = Filter;
Visitor.TraverseDecl(AST.getASTContext().getTranslationUnitDecl());
if (Visitor.Decls.size() != 1) {
- ADD_FAILURE() << Visitor.Decls.size() << " symbols matched.";
+ llvm::errs() << Visitor.Decls.size() << " symbols matched.";
assert(Visitor.Decls.size() == 1);
}
return *Visitor.Decls.front();
Index: clang-tools-extra/clangd/index/Symbol.h
===================================================================
--- clang-tools-extra/clangd/index/Symbol.h
+++ clang-tools-extra/clangd/index/Symbol.h
@@ -233,6 +233,8 @@
std::vector<Symbol> Symbols; // Sorted by SymbolID to allow lookup.
};
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolSlab &Slab);
+
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/index/Symbol.cpp
===================================================================
--- clang-tools-extra/clangd/index/Symbol.cpp
+++ clang-tools-extra/clangd/index/Symbol.cpp
@@ -67,5 +67,15 @@
return SymbolSlab(std::move(NewArena), std::move(SortedSymbols));
}
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolSlab &Slab) {
+ OS << "{";
+ llvm::StringRef Sep = "";
+ for (const auto &S : Slab) {
+ OS << Sep << S;
+ Sep = ", ";
+ }
+ OS << "}";
+ return OS;
+}
} // namespace clangd
} // namespace clang
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits