From 68aeff4b9f7c576e62153337f6acf5df1bf05eb1 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 17 Aug 2016 14:18:55 +0200 Subject: [PATCH] UnitTest: Break the dependency to LLVM If you have no LLVM installed it was impossible to compile the unit test. But some unit test don't depend on LLVM. With this change it is now possible to compile them. Change-Id: Iac0c1b3cdf6c317e6ba4755acd5f8458db5a7451 Reviewed-by: David Schulz --- tests/unit/unittest/clang_dependency.pri | 3 + tests/unit/unittest/cplusplus.pri | 1 - tests/unit/unittest/creator_dependency.pri | 29 +++++---- tests/unit/unittest/gtest-qt-printing.h | 4 ++ .../unittest/readandwritemessageblocktest.cpp | 1 - tests/unit/unittest/unittest.pro | 60 ++++++++++++------- 6 files changed, 62 insertions(+), 36 deletions(-) diff --git a/tests/unit/unittest/clang_dependency.pri b/tests/unit/unittest/clang_dependency.pri index c49abb26f6f..4cb39b1e40e 100644 --- a/tests/unit/unittest/clang_dependency.pri +++ b/tests/unit/unittest/clang_dependency.pri @@ -1,5 +1,8 @@ +!isEmpty(LLVM_INSTALL_DIR) { include(../../../src/shared/clang/clang_installation.pri) requires(!isEmpty(LIBCLANG_LIBS)) +DEFINES += CLANG_UNIT_TESTS INCLUDEPATH += $$LLVM_INCLUDEPATH LIBS += $$LIBTOOLING_LIBS $$LIBCLANG_LIBS +} diff --git a/tests/unit/unittest/cplusplus.pri b/tests/unit/unittest/cplusplus.pri index d0eb17e6fdb..51909b717f9 100644 --- a/tests/unit/unittest/cplusplus.pri +++ b/tests/unit/unittest/cplusplus.pri @@ -1,4 +1,3 @@ INCLUDEPATH += $$PWD -include($$PWD/../../../src/libs/utils/utils-lib.pri) include($$PWD/../../../src/libs/cplusplus/cplusplus-lib.pri) diff --git a/tests/unit/unittest/creator_dependency.pri b/tests/unit/unittest/creator_dependency.pri index a03c322ca3e..ef8101f2f9a 100644 --- a/tests/unit/unittest/creator_dependency.pri +++ b/tests/unit/unittest/creator_dependency.pri @@ -1,18 +1,23 @@ -include(../../../src/libs/sqlite/sqlite-lib.pri) -include(../../../src/libs/clangbackendipc/clangbackendipc-lib.pri) -include(../../../src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri) -include(../../../src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri) -include(../../../src/plugins/coreplugin/corepluginunittestfiles.pri) -include(../../../src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri) -include(../../../src/plugins/cpptools/cpptoolsunittestfiles.pri) -include(../../../src/plugins/clangrefactoring/clangrefactoring-source.pri) +include($$PWD/../../../src/libs/utils/utils-lib.pri) +include($$PWD/../../../src/libs/sqlite/sqlite-lib.pri) +include($$PWD/../../../src/libs/clangbackendipc/clangbackendipc-lib.pri) +include($$PWD/../../../src/plugins/coreplugin/corepluginunittestfiles.pri) + +!isEmpty(LLVM_INSTALL_DIR) { +include($$PWD/../../../src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri) +include($$PWD/../../../src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri) +include($$PWD/../../../src/plugins/clangcodemodel/clangcodemodelunittestfiles.pri) +include($$PWD/../../../src/plugins/cpptools/cpptoolsunittestfiles.pri) +include($$PWD/../../../src/plugins/clangrefactoring/clangrefactoring-source.pri) include(cplusplus.pri) +DEFINES += CLANG_VERSION=\\\"$${LLVM_VERSION}\\\" +DEFINES += "\"CLANG_RESOURCE_DIR=\\\"$${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include\\\"\"" +} + +DEFINES += QTC_REL_TOOLS_PATH=$$shell_quote(\"$$relative_path($$IDE_LIBEXEC_PATH, $$IDE_BIN_PATH)\") + INCLUDEPATH += \ $$PWD/../../../src/libs \ $$PWD/../../../src/libs/3rdparty \ $$PWD/../../../src/plugins - -DEFINES += QTC_REL_TOOLS_PATH=$$shell_quote(\"$$relative_path($$IDE_LIBEXEC_PATH, $$IDE_BIN_PATH)\") -DEFINES += CLANG_VERSION=\\\"$${LLVM_VERSION}\\\" -DEFINES += "\"CLANG_RESOURCE_DIR=\\\"$${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include\\\"\"" diff --git a/tests/unit/unittest/gtest-qt-printing.h b/tests/unit/unittest/gtest-qt-printing.h index 9bf363a770b..54c79569aeb 100644 --- a/tests/unit/unittest/gtest-qt-printing.h +++ b/tests/unit/unittest/gtest-qt-printing.h @@ -31,8 +31,10 @@ #pragma GCC diagnostic ignored "-Wunused-parameter" #endif +#ifdef CLANG_UNIT_TESTS #include #include +#endif #if defined(__GNUC__) #pragma GCC diagnostic pop @@ -64,6 +66,7 @@ inline void PrintTo(const QString &text, ::std::ostream *os) QT_END_NAMESPACE +#ifdef CLANG_UNIT_TESTS namespace clang { inline void PrintTo(const clang::FullSourceLoc &sourceLocation, ::std::ostream *os) @@ -78,6 +81,7 @@ inline void PrintTo(const clang::FullSourceLoc &sourceLocation, ::std::ostream * } } +#endif //namespace testing { //namespace internal { diff --git a/tests/unit/unittest/readandwritemessageblocktest.cpp b/tests/unit/unittest/readandwritemessageblocktest.cpp index 05cae6f4cb9..90fcc56926d 100644 --- a/tests/unit/unittest/readandwritemessageblocktest.cpp +++ b/tests/unit/unittest/readandwritemessageblocktest.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index 06b08dd2907..3180604fbff 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -24,6 +24,19 @@ msvc: QMAKE_CXXFLAGS_WARN_ON -= -w34100 # 'unreferenced formal parameter' in MAT win32:DEFINES += ECHOSERVER=\"R\\\"xxx($$OUT_PWD/../echo)xxx\\\"\" unix: DEFINES += ECHOSERVER=\"R\\\"xxx($$OUT_PWD/../echoserver/echo)xxx\\\"\" +SOURCES += \ + clientserverinprocesstest.cpp \ + clientserveroutsideprocess.cpp \ + lineprefixertest.cpp \ + main.cpp \ + readandwritemessageblocktest.cpp \ + sizedarraytest.cpp \ + spydummy.cpp \ + smallstringtest.cpp \ + testutils.cpp \ + utf8test.cpp + +!isEmpty($$LIBCLANG_LIBS) { SOURCES += \ activationsequencecontextprocessortest.cpp \ activationsequenceprocessortest.cpp \ @@ -33,8 +46,6 @@ SOURCES += \ clangfixitoperationtest.cpp \ clangipcservertest.cpp \ clangstringtest.cpp \ - clientserverinprocesstest.cpp \ - clientserveroutsideprocess.cpp \ codecompletionsextractortest.cpp \ codecompletiontest.cpp \ completionchunkstotextconvertertest.cpp \ @@ -42,13 +53,9 @@ SOURCES += \ diagnosticsettest.cpp \ diagnostictest.cpp \ fixittest.cpp \ - lineprefixertest.cpp \ - main.cpp \ projecttest.cpp \ - readandwritemessageblocktest.cpp \ sourcelocationtest.cpp \ sourcerangetest.cpp \ - spydummy.cpp \ sqlitecolumntest.cpp \ sqlitedatabasebackendtest.cpp \ sqlitedatabasetest.cpp \ @@ -58,7 +65,6 @@ SOURCES += \ translationunitstest.cpp \ translationunittest.cpp \ unsavedfilestest.cpp \ - utf8test.cpp \ senddocumenttrackertest.cpp \ cursortest.cpp \ skippedsourcerangestest.cpp \ @@ -66,25 +72,27 @@ SOURCES += \ chunksreportedmonitor.cpp \ unsavedfiletest.cpp \ clangisdiagnosticrelatedtolocationtest.cpp \ - smallstringtest.cpp \ highlightingmarkstest.cpp \ - sizedarraytest.cpp \ utf8positionfromlinecolumntest.cpp \ translationunitupdatertest.cpp \ - testutils.cpp \ clangasyncjobtest.cpp \ clangcompletecodejobtest.cpp \ clangcreateinitialdocumentpreamblejobtest.cpp \ clangjobqueuetest.cpp \ - refactoringcompilationdatabasetest.cpp \ - symbolfindertest.cpp \ - refactoringclientserverinprocesstest.cpp \ - refactoringservertest.cpp \ - refactoringenginetest.cpp \ - refactoringclienttest.cpp \ clangjobstest.cpp \ clangrequestdocumentannotationsjobtest.cpp \ clangupdatedocumentannotationsjobtest.cpp +} + +!isEmpty($$LIBTOOLING_LIBS) { +SOURCES += \ + refactoringclientserverinprocesstest.cpp \ + refactoringcompilationdatabasetest.cpp \ + refactoringservertest.cpp \ + refactoringenginetest.cpp \ + refactoringclienttest.cpp \ + symbolfindertest.cpp +} exists($$GOOGLEBENCHMARK_DIR) { SOURCES += \ @@ -93,17 +101,25 @@ SOURCES += \ HEADERS += \ gtest-qt-printing.h \ + spydummy.h \ + dummyclangipcclient.h \ + testutils.h \ mockclangcodemodelclient.h \ mockclangcodemodelserver.h \ mockrefactoringclient.h \ mockrefactoringserver.h \ - spydummy.h \ - dummyclangipcclient.h \ - matcher-diagnosticcontainer.h \ - chunksreportedmonitor.h \ - testutils.h \ + refactoringclientcallbackmock.h + +!isEmpty($$LIBCLANG_LIBS) { +HEADERS += \ clangasyncjobtest.h \ - refactoringclientcallbackmock.h \ + chunksreportedmonitor.h \ + matcher-diagnosticcontainer.h +} + +!isEmpty($$LIBTOOLING_LIBS) { +HEADERS += \ filesystemutilities.h +} OTHER_FILES += $$files(data/*)