#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/Utils.h"
#include "llvm/ADT/ScopeExit.h"
-#include "gtest/gtest.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
+#include <cstdlib>
namespace clang {
namespace clangd {
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::errs() << "Failed to create temp directory for module-cache";
+ std::abort();
+ }
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::errs() << "Failed to delete temp directory for module-cache";
+ std::abort();
+ }
}
}
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_unreachable("Failed to build TestTU!");
- }
- if (!AST->getDiagnostics()) {
- ADD_FAILURE() << "TestTU should always build an AST with a fresh Preamble"
- << Code;
- return std::move(*AST);
+ llvm::errs() << "Failed to build code:\n" << Code;
+ std::abort();
}
+ assert(AST->getDiagnostics() &&
+ "TestTU should always build an AST with a fresh Preamble");
// Check for error diagnostics and report gtest failures (unless expected).
// This guards against accidental syntax errors silently subverting tests.
// error-ok is awfully primitive - using clang -verify would be nicer.
// 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;
- break; // Just report first error for simplicity.
+ std::abort(); // Stop after first error for simplicity.
}
}
return std::move(*AST);
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;
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();