From ec3c7946af36e539375dc9c0e366d31dfe4ca2b5 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 11 Jul 2019 17:40:46 +0200 Subject: [PATCH] UnitTests: Fix compile without Clang I moved the clang depend code under the condition that it is only compiled if LLVM is present. Change-Id: If1e37f677464ff38833c81dbebdfe8eaa563cdde Reviewed-by: Christian Stenger --- .../source/clangrefactoringbackend-source.pri | 8 +-- tests/unit/unittest/benchmark_dependency.pri | 2 +- .../unittest/conditionally-disabled-tests.h | 3 - tests/unit/unittest/gtest-clang-printing.cpp | 57 ++++++++++++++++++ tests/unit/unittest/gtest-clang-printing.h | 16 +++++ .../unit/unittest/gtest-creator-printing.cpp | 60 ------------------- tests/unit/unittest/unittest.pro | 6 +- 7 files changed, 81 insertions(+), 71 deletions(-) diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri index dd4e51028d2..ce809e9efbd 100644 --- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri +++ b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri @@ -2,7 +2,6 @@ INCLUDEPATH += $$PWD HEADERS += \ $$PWD/clangrefactoringbackend_global.h \ - $$PWD/filestatuspreprocessorcallbacks.h \ $$PWD/sourcerangefilter.h \ $$PWD/symbolindexer.h \ $$PWD/symbolentry.h \ @@ -14,10 +13,8 @@ HEADERS += \ $$PWD/symbolindexinginterface.h \ $$PWD/collectmacrospreprocessorcallbacks.h \ $$PWD/projectpartentry.h \ - $$PWD/symbolsvisitorbase.h \ $$PWD/usedmacro.h \ $$PWD/sourcedependency.h \ - $$PWD/indexdataconsumer.h \ $$PWD/sourcesmanager.h \ $$PWD/symbolindexertaskqueue.h \ $$PWD/symbolindexertaskqueueinterface.h \ @@ -35,6 +32,7 @@ SOURCES += \ $$PWD/collectsymbolsaction.cpp \ $$PWD/collectmacrossourcefilecallbacks.cpp \ $$PWD/symbolscollector.cpp \ + $$PWD/filestatuspreprocessorcallbacks.cpp \ $$PWD/clangquerygatherer.cpp \ $$PWD/symbolindexing.cpp \ $$PWD/indexdataconsumer.cpp @@ -51,10 +49,12 @@ HEADERS += \ $$PWD/collectsymbolsaction.h \ $$PWD/collectmacrossourcefilecallbacks.h \ $$PWD/symbolscollector.h \ + $$PWD/symbolsvisitorbase.h \ + $$PWD/indexdataconsumer.h \ + $$PWD/filestatuspreprocessorcallbacks.h \ $$PWD/clangquerygatherer.h } SOURCES += \ - $$PWD/filestatuspreprocessorcallbacks.cpp \ $$PWD/sourcerangefilter.cpp \ $$PWD/symbolindexer.cpp diff --git a/tests/unit/unittest/benchmark_dependency.pri b/tests/unit/unittest/benchmark_dependency.pri index dd17215e678..e9e0408530a 100644 --- a/tests/unit/unittest/benchmark_dependency.pri +++ b/tests/unit/unittest/benchmark_dependency.pri @@ -1,6 +1,6 @@ GOOGLEBENCHMARK_DIR = $$(GOOGLEBENCHMARK_DIR) -exists($$GOOGLEBENCHMARK_DIR) { +!isEmpty(GOOGLEBENCHMARK_DIR):exists($$GOOGLEBENCHMARK_DIR) { INCLUDEPATH += $$GOOGLEBENCHMARK_DIR/include DEFINES += HAVE_STD_REGEX WITH_BENCHMARKS diff --git a/tests/unit/unittest/conditionally-disabled-tests.h b/tests/unit/unittest/conditionally-disabled-tests.h index c88a844b96a..128520a8817 100644 --- a/tests/unit/unittest/conditionally-disabled-tests.h +++ b/tests/unit/unittest/conditionally-disabled-tests.h @@ -24,9 +24,6 @@ ****************************************************************************/ #include -#include - -#include #ifdef Q_OS_WIN # define DISABLED_ON_WINDOWS(x) DISABLED_##x diff --git a/tests/unit/unittest/gtest-clang-printing.cpp b/tests/unit/unittest/gtest-clang-printing.cpp index d6299f1057f..4c10958f52d 100644 --- a/tests/unit/unittest/gtest-clang-printing.cpp +++ b/tests/unit/unittest/gtest-clang-printing.cpp @@ -23,9 +23,17 @@ ** ****************************************************************************/ +#include "gtest-creator-printing.h" + #ifdef CLANG_UNIT_TESTS #include #include + +#include +#include +#include +#include + #endif #include @@ -77,3 +85,52 @@ void PrintTo(const SourceRange &sourceRange, ::std::ostream *os) } } + +namespace ClangBackEnd { +std::ostream &operator<<(std::ostream &os, const TokenInfo &tokenInfo) +{ + os << "(type: " << tokenInfo.types() << ", " + << " line: " << tokenInfo.line() << ", " + << " column: " << tokenInfo.column() << ", " + << " length: " << tokenInfo.length() << ")"; + + return os; +} + +template +std::ostream &operator<<(std::ostream &out, const TokenProcessor &tokenInfos) +{ + out << "["; + + for (const T &entry : tokenInfos) + out << entry; + + out << "]"; + + return out; +} + +template std::ostream &operator<<(std::ostream &out, const TokenProcessor &tokenInfos); +template std::ostream &operator<<(std::ostream &out, const TokenProcessor &tokenInfos); + +std::ostream &operator<<(std::ostream &out, const SuspendResumeJobsEntry &entry) +{ + return out << "(" << entry.document.filePath() << ", " << entry.jobRequestType << ", " + << entry.preferredTranslationUnit << ")"; +} + +std::ostream &operator<<(std::ostream &os, const ReferencesResult &value) +{ + os << "ReferencesResult("; + os << value.isLocalVariable << ", {"; + for (const SourceRangeContainer &r : value.references) { + os << r.start.line << ","; + os << r.start.column << ","; + os << r.end.column - r.start.column << ","; + } + os << "})"; + + return os; +} + +} // namespace ClangBackEnd diff --git a/tests/unit/unittest/gtest-clang-printing.h b/tests/unit/unittest/gtest-clang-printing.h index 7ed5a8b9605..b0c0a93afba 100644 --- a/tests/unit/unittest/gtest-clang-printing.h +++ b/tests/unit/unittest/gtest-clang-printing.h @@ -27,6 +27,8 @@ #include +#include + namespace llvm { class StringRef; @@ -48,3 +50,17 @@ namespace TestGlobal { void setSourceManager(const clang::SourceManager *sourceManager); } +namespace ClangBackEnd { +class TokenInfo; +template +class TokenProcessor; +class SuspendResumeJobsEntry; +class ReferencesResult; + +std::ostream &operator<<(std::ostream &os, const TokenInfo &tokenInfo); +template +std::ostream &operator<<(std::ostream &out, const TokenProcessor &tokenInfos); +std::ostream &operator<<(std::ostream &out, const SuspendResumeJobsEntry &entry); +std::ostream &operator<<(std::ostream &os, const ReferencesResult &value); + +} // namespace ClangBackEnd diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 773a6321424..141a926d9e4 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -35,15 +35,12 @@ #include #include #include -#include #include #include -#include #include #include #include #include -#include #include #include #include @@ -58,16 +55,12 @@ #include #include #include -#include #include #include #include - #include - #include #include - #include #include @@ -924,35 +917,6 @@ std::ostream &operator<<(std::ostream &os, const DocumentVisibilityChangedMessag return os; } -std::ostream &operator<<(std::ostream &os, const TokenInfo &tokenInfo) -{ - os << "(type: " << tokenInfo.types() << ", " - << " line: " << tokenInfo.line() << ", " - << " column: " << tokenInfo.column() << ", " - << " length: " << tokenInfo.length() - << ")"; - - return os; -} - -template -std::ostream &operator<<(std::ostream &out, const TokenProcessor &tokenInfos) -{ - out << "["; - - for (const T &entry : tokenInfos) - out << entry; - - out << "]"; - - return out; -} - -template -std::ostream &operator<<(std::ostream &out, const TokenProcessor &tokenInfos); -template -std::ostream &operator<<(std::ostream &out, const TokenProcessor &tokenInfos); - std::ostream &operator<<(std::ostream &out, const FilePath &filePath) { return out << "(" << filePath.path() << ", " << filePath.slashIndex() << ")"; @@ -1078,30 +1042,6 @@ std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &m return out << "(" << message.generatedFiles << ")"; } -std::ostream &operator<<(std::ostream &out, const SuspendResumeJobsEntry &entry) -{ - return out << "(" - << entry.document.filePath() << ", " - << entry.jobRequestType << ", " - << entry.preferredTranslationUnit - << ")"; -} - -std::ostream &operator<<(std::ostream &os, const ReferencesResult &value) -{ - os << "ReferencesResult("; - os << value.isLocalVariable << ", {"; - for (const SourceRangeContainer &r : value.references) { - os << r.start.line << ","; - os << r.start.column << ","; - EXPECT_THAT(r.start.line, testing::Eq(r.end.line)); - os << r.end.column - r.start.column << ","; - } - os << "})"; - - return os; -} - std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task) { return out << "(" << task.filePathId << ", " << task.projectPartId << ")"; diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index c64d22925b6..bcd1bae2b07 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -97,10 +97,8 @@ SOURCES += \ nativefilepath-test.cpp \ nativefilepathview-test.cpp \ mocktimer.cpp \ - tokenprocessor-test.cpp \ projectpartartefact-test.cpp \ filestatuscache-test.cpp \ - highlightingresultreporter-test.cpp \ precompiledheaderstorage-test.cpp \ generatedfiles-test.cpp \ sourcesmanager-test.cpp \ @@ -163,6 +161,7 @@ SOURCES += \ diagnosticset-test.cpp \ diagnostic-test.cpp \ fixit-test.cpp \ + highlightingresultreporter-test.cpp \ senddocumenttracker-test.cpp \ skippedsourceranges-test.cpp \ sourcelocation-test.cpp \ @@ -174,6 +173,7 @@ SOURCES += \ sqlitetable-test.cpp \ sqlstatementbuilder-test.cpp \ token-test.cpp \ + tokenprocessor-test.cpp \ translationunitupdater-test.cpp \ unsavedfiles-test.cpp \ unsavedfile-test.cpp \ @@ -205,7 +205,7 @@ SOURCES += \ SOURCES += clangformat-test.cpp } -exists($$GOOGLEBENCHMARK_DIR) { +!isEmpty(GOOGLEBENCHMARK_DIR):exists($$GOOGLEBENCHMARK_DIR) { SOURCES += \ smallstring-benchmark.cpp }