diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2016-07-01 15:07:32 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2016-07-04 13:08:03 +0000 |
commit | 36e7f4541f071a1cce21c8ad12cf6e580f026674 (patch) | |
tree | 20d15cae73238bb106e7cdaeed7d4f82f3e66f66 /tests | |
parent | a12184ea32752fc002965d27a513d3e4df47ca83 (diff) | |
download | qt-creator-36e7f4541f071a1cce21c8ad12cf6e580f026674.tar.gz |
Clang: Pass on file paths with native separators
libclang 3.8 seems to be sensitive to file paths separators [1]. On Windows,
this led to not updated document annotations and/or crashes after reparsing.
When passing file paths to libclang, convert to native separators.
When getting file paths from libclang, convert back.
This handles:
* main file path
* file paths of the unsaved files
* -I<DIR> arguments, the resource path (for builtins) and the paths to the
wrapped qt headers
* included header files from libclang
* source locations from libclang
Also, minimize the conversion in SourceLocation to a minimum by making
filePath() lazy.
[1] https://llvm.org/bugs/show_bug.cgi?id=28381
Change-Id: If5866f34a6fdc6b34b16c022d3988e8e6eae2a0a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/unittest/clangcodecompleteresultstest.cpp | 8 | ||||
-rw-r--r-- | tests/unit/unittest/codecompletionsextractortest.cpp | 6 | ||||
-rw-r--r-- | tests/unit/unittest/translationunittest.cpp | 5 | ||||
-rw-r--r-- | tests/unit/unittest/unsavedfiletest.cpp | 19 |
4 files changed, 34 insertions, 4 deletions
diff --git a/tests/unit/unittest/clangcodecompleteresultstest.cpp b/tests/unit/unittest/clangcodecompleteresultstest.cpp index 8a27c0c801..b16c2266ed 100644 --- a/tests/unit/unittest/clangcodecompleteresultstest.cpp +++ b/tests/unit/unittest/clangcodecompleteresultstest.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include <clangcodecompleteresults.h> +#include <clangfilepath.h> #include <projectpart.h> #include <projects.h> #include <clangtranslationunit.h> @@ -41,6 +42,7 @@ namespace { using ClangBackEnd::ClangCodeCompleteResults; +using ClangBackEnd::FilePath; using ClangBackEnd::TranslationUnit; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::ProjectPart; @@ -55,7 +57,8 @@ TEST(ClangCodeCompleteResults, GetData) projectPart, Utf8StringVector(), translationUnits); - CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0); + Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath()); + CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), nativeFilePath.constData(), 49, 1, 0, 0, 0); ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); @@ -81,7 +84,8 @@ TEST(ClangCodeCompleteResults, MoveClangCodeCompleteResults) projectPart, Utf8StringVector(), translationUnits); - CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), translationUnit.filePath().constData(), 49, 1, 0, 0, 0); + Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath()); + CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(translationUnit.cxTranslationUnit(), nativeFilePath.constData(), 49, 1, 0, 0, 0); ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults); diff --git a/tests/unit/unittest/codecompletionsextractortest.cpp b/tests/unit/unittest/codecompletionsextractortest.cpp index 1b3d0eb567..10180c289f 100644 --- a/tests/unit/unittest/codecompletionsextractortest.cpp +++ b/tests/unit/unittest/codecompletionsextractortest.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include <clangcodecompleteresults.h> +#include <clangfilepath.h> #include <codecompletionsextractor.h> #include <filecontainer.h> #include <projectpart.h> @@ -44,6 +45,7 @@ using ClangBackEnd::CodeCompletionsExtractor; using ClangBackEnd::ClangCodeCompleteResults; +using ClangBackEnd::FilePath; using ClangBackEnd::TranslationUnit; using ClangBackEnd::CodeCompletion; using ClangBackEnd::UnsavedFiles; @@ -139,8 +141,10 @@ const ClangBackEnd::FileContainer unsavedDataFileContainer(const char *filePath, ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit, uint line, uint column = 1) { + Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath()); + return ClangCodeCompleteResults(clang_codeCompleteAt(translationUnit.cxTranslationUnit(), - translationUnit.filePath().constData(), + nativeFilePath.constData(), line, column, translationUnit.cxUnsavedFiles(), diff --git a/tests/unit/unittest/translationunittest.cpp b/tests/unit/unittest/translationunittest.cpp index 9d6cc83a0a..2d4486021a 100644 --- a/tests/unit/unittest/translationunittest.cpp +++ b/tests/unit/unittest/translationunittest.cpp @@ -23,6 +23,7 @@ ** ****************************************************************************/ +#include <clangfilepath.h> #include <commandlinearguments.h> #include <diagnosticset.h> #include <highlightingmarks.h> @@ -52,6 +53,7 @@ #include <thread> using ClangBackEnd::FileContainer; +using ClangBackEnd::FilePath; using ClangBackEnd::TranslationUnit; using ClangBackEnd::UnsavedFiles; using ClangBackEnd::ProjectPart; @@ -156,9 +158,10 @@ TEST_F(TranslationUnit, ResetedTranslationUnitIsNull) TEST_F(TranslationUnit, LastCommandLineArgumentIsFilePath) { + const Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnitFilePath); const auto arguments = translationUnit.commandLineArguments(); - ASSERT_THAT(arguments.at(arguments.count() - 1), Eq(translationUnitFilePath)); + ASSERT_THAT(arguments.at(arguments.count() - 1), Eq(nativeFilePath)); } TEST_F(TranslationUnit, TimeStampForProjectPartChangeIsUpdatedAsNewCxTranslationUnitIsGenerated) diff --git a/tests/unit/unittest/unsavedfiletest.cpp b/tests/unit/unittest/unsavedfiletest.cpp index 463c29be8b..13afb99c51 100644 --- a/tests/unit/unittest/unsavedfiletest.cpp +++ b/tests/unit/unittest/unsavedfiletest.cpp @@ -28,9 +28,11 @@ #include "gmock/gmock.h" #include "gtest-qt-printing.h" +#include <clangfilepath.h> #include <unsavedfile.h> #include <unsavedfiles.h> +using ClangBackEnd::FilePath; using ClangBackEnd::UnsavedFile; using ClangBackEnd::UnsavedFiles; @@ -61,6 +63,8 @@ protected: Utf8String otherFilePath = Utf8StringLiteral("otherpath"); Utf8String otherFileContent = Utf8StringLiteral("othercontent"); + Utf8String absoluteFilePath = Utf8StringLiteral(TESTDATA_DIR"/file.cpp"); + uint aLength = 2; Utf8String aReplacement = Utf8StringLiteral("replacement"); }; @@ -126,6 +130,21 @@ TEST_F(UnsavedFile, AssignMoveFromIsSwapped) otherFileContent.byteSize())); } +TEST_F(UnsavedFile, FilePath) +{ + ::UnsavedFile unsavedFile(absoluteFilePath, QStringLiteral("")); + + ASSERT_THAT(unsavedFile.filePath(), Eq(absoluteFilePath)); +} + +TEST_F(UnsavedFile, NativeFilePath) +{ + ::UnsavedFile unsavedFile(absoluteFilePath, QStringLiteral("")); + const Utf8String nativeFilePath = FilePath::toNativeSeparators(absoluteFilePath); + + ASSERT_THAT(unsavedFile.nativeFilePath(), Eq(nativeFilePath)); +} + TEST_F(UnsavedFile, DoNotReplaceWithOffsetZeroInEmptyContent) { ::UnsavedFile unsavedFile(filePath, QStringLiteral("")); |