Clang: Remove project tracking on clangbackend side

...as it is not needed. Just provide the compilation arguments as part
of the Document.

As a side effect, re-initializing the backend after a crash is cheaper
and will not freeze the UI anymore (referenced bug).

Task-number: QTCREATORBUG-21097
Change-Id: I866e25ef1fd5e4d318df16612a7564469e6baa11
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-09-25 09:41:32 +02:00
parent 25ea9a4d24
commit aa290912b8
102 changed files with 394 additions and 2388 deletions

View File

@@ -25,9 +25,7 @@
#include "googletest.h"
#include <projectpart.h>
#include <clangexceptions.h>
#include <projects.h>
#include <clangdocument.h>
#include <clangdocuments.h>
#include <unsavedfiles.h>
@@ -37,8 +35,6 @@
using ClangBackEnd::Document;
using ClangBackEnd::UnsavedFiles;
using ClangBackEnd::ProjectPart;
using ClangBackEnd::ProjectPartContainer;
using testing::IsNull;
using testing::NotNull;
@@ -51,15 +47,13 @@ namespace {
using ::testing::PrintToString;
MATCHER_P3(IsDocument, filePath, projectPartId, documentRevision,
MATCHER_P2(IsDocument, filePath, documentRevision,
std::string(negation ? "isn't" : "is")
+ " document with file path "+ PrintToString(filePath)
+ " and project " + PrintToString(projectPartId)
+ " and document revision " + PrintToString(documentRevision)
)
{
return arg.filePath() == filePath
&& arg.projectPart().id() == projectPartId
&& arg.documentRevision() == documentRevision;
}
@@ -69,39 +63,28 @@ protected:
void SetUp() override;
protected:
ClangBackEnd::ProjectParts projects;
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{projects, unsavedFiles};
ClangBackEnd::Documents documents{unsavedFiles};
const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp");
const Utf8String otherFilePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h");
const Utf8String headerPath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h");
const Utf8String nonExistingFilePath = Utf8StringLiteral("foo.cpp");
const Utf8String projectPartId = Utf8StringLiteral("projectPartId");
const Utf8String otherProjectPartId = Utf8StringLiteral("otherProjectPartId");
const Utf8String nonExistingProjectPartId = Utf8StringLiteral("nonExistingProjectPartId");
const ClangBackEnd::FileContainer fileContainer{filePath, projectPartId};
const ClangBackEnd::FileContainer headerContainer{headerPath, projectPartId};
const ClangBackEnd::FileContainer fileContainer{filePath};
const ClangBackEnd::FileContainer headerContainer{headerPath};
};
using DocumentsSlowTest = Documents;
TEST_F(Documents, ThrowForGettingWithWrongFilePath)
{
ASSERT_THROW(documents.document(nonExistingFilePath, projectPartId),
ASSERT_THROW(documents.document(nonExistingFilePath),
ClangBackEnd::DocumentDoesNotExistException);
}
TEST_F(Documents, ThrowForGettingWithWrongProjectPartFilePath)
{
ASSERT_THROW(documents.document(filePath, nonExistingProjectPartId),
ClangBackEnd::ProjectPartDoNotExistException);
}
TEST_F(Documents, ThrowForAddingNonExistingFile)
{
ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId);
ClangBackEnd::FileContainer fileContainer(nonExistingFilePath);
ASSERT_THROW(documents.create({fileContainer}),
ClangBackEnd::DocumentFileDoesNotExistException);
@@ -109,25 +92,25 @@ TEST_F(Documents, ThrowForAddingNonExistingFile)
TEST_F(Documents, DoNotThrowForAddingNonExistingFileWithUnsavedContent)
{
ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId, Utf8String(), true);
ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, Utf8String(), true);
ASSERT_NO_THROW(documents.create({fileContainer}));
}
TEST_F(Documents, Add)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
documents.create({fileContainer});
ASSERT_THAT(documents.document(filePath, projectPartId),
IsDocument(filePath, projectPartId, 74u));
ASSERT_THAT(documents.document(filePath),
IsDocument(filePath, 74u));
}
TEST_F(Documents, CreateWithUnsavedContentSetsDependenciesDirty)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainerWithUnsavedContent(otherFilePath, projectPartId, Utf8StringVector(), Utf8String(), true, 2u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainerWithUnsavedContent(otherFilePath, Utf8StringVector(), Utf8String(), true, 2u);
auto dependentDocument = documents.create({fileContainer}).at(0);
dependentDocument.setDependedFilePaths(QSet<Utf8String>() << filePath << otherFilePath);
@@ -138,46 +121,43 @@ TEST_F(Documents, CreateWithUnsavedContentSetsDependenciesDirty)
TEST_F(Documents, AddAndTestCreatedTranslationUnit)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
auto createdDocuments = documents.create({fileContainer});
ASSERT_THAT(createdDocuments.front(),
IsDocument(filePath, projectPartId, 74u));
ASSERT_THAT(createdDocuments.front(), IsDocument(filePath, 74u));
}
TEST_F(Documents, ThrowForCreatingAnExistingDocument)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
documents.create({fileContainer});
ASSERT_THROW(documents.create({fileContainer}),
ClangBackEnd::DocumentAlreadyExistsException);
ASSERT_THROW(documents.create({fileContainer}), ClangBackEnd::DocumentAlreadyExistsException);
}
TEST_F(Documents, ThrowForUpdatingANonExistingDocument)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
ASSERT_THROW(documents.update({fileContainer}),
ClangBackEnd::DocumentDoesNotExistException);
}
TEST_F(Documents, UpdateSingle)
{
ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u);
ClangBackEnd::FileContainer createFileContainer(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8StringVector(), 75u);
documents.create({createFileContainer});
documents.update({updateFileContainer});
ASSERT_THAT(documents.document(filePath, projectPartId),
IsDocument(filePath, projectPartId, 75u));
ASSERT_THAT(documents.document(filePath), IsDocument(filePath, 75u));
}
TEST_F(Documents, UpdateReturnsUpdatedDocument)
{
ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u);
ClangBackEnd::FileContainer createFileContainer(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8StringVector(), 75u);
documents.create({createFileContainer});
const std::vector<Document> updatedDocuments = documents.update({updateFileContainer});
@@ -186,52 +166,50 @@ TEST_F(Documents, UpdateReturnsUpdatedDocument)
ASSERT_THAT(updatedDocuments.front().documentRevision(), Eq(75u));
}
// TODO: Does this test still makes sense?
TEST_F(Documents, UpdateMultiple)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainerWithOtherProject(filePath, otherProjectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer updatedFileContainer(filePath, Utf8String(), Utf8StringVector(), 75u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainerWithOtherProject(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer updatedFileContainer(filePath, Utf8StringVector(), 75u);
documents.create({fileContainer, fileContainerWithOtherProject});
documents.update({updatedFileContainer});
ASSERT_THAT(documents.document(filePath, projectPartId),
IsDocument(filePath, projectPartId, 75u));
ASSERT_THAT(documents.document(filePath, otherProjectPartId),
IsDocument(filePath, otherProjectPartId, 75u));
ASSERT_THAT(documents.document(filePath), IsDocument(filePath, 75u));
}
TEST_F(DocumentsSlowTest, UpdateUnsavedFileAndCheckForReparse)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, Utf8String(), true, 75u);
documents.create({fileContainer, headerContainer});
Document document = documents.document(filePath, projectPartId);
Document document = documents.document(filePath);
document.parse();
documents.update({headerContainerWithUnsavedContent});
ASSERT_TRUE(documents.document(filePath, projectPartId).isDirty());
ASSERT_TRUE(documents.document(filePath).isDirty());
}
TEST_F(DocumentsSlowTest, RemoveFileAndCheckForReparse)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainer(headerPath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, Utf8String(), true, 75u);
documents.create({fileContainer, headerContainer});
Document document = documents.document(filePath, projectPartId);
Document document = documents.document(filePath);
document.parse();
documents.remove({headerContainerWithUnsavedContent});
ASSERT_TRUE(documents.document(filePath, projectPartId).isDirty());
ASSERT_TRUE(documents.document(filePath).isDirty());
}
TEST_F(Documents, DontGetNewerFileContainerIfRevisionIsTheSame)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
documents.create({fileContainer});
auto newerFileContainers = documents.newerFileContainers({fileContainer});
@@ -241,8 +219,8 @@ TEST_F(Documents, DontGetNewerFileContainerIfRevisionIsTheSame)
TEST_F(Documents, GetNewerFileContainerIfRevisionIsDifferent)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer newerContainer(filePath, projectPartId, Utf8StringVector(), 75u);
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringVector(), 74u);
ClangBackEnd::FileContainer newerContainer(filePath, Utf8StringVector(), 75u);
documents.create({fileContainer});
auto newerFileContainers = documents.newerFileContainers({newerContainer});
@@ -252,61 +230,50 @@ TEST_F(Documents, GetNewerFileContainerIfRevisionIsDifferent)
TEST_F(Documents, ThrowForRemovingWithWrongFilePath)
{
ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId);
ClangBackEnd::FileContainer fileContainer(nonExistingFilePath);
ASSERT_THROW(documents.remove({fileContainer}),
ClangBackEnd::DocumentDoesNotExistException);
}
TEST_F(Documents, ThrowForRemovingWithWrongProjectPartFilePath)
{
ClangBackEnd::FileContainer fileContainer(filePath, nonExistingProjectPartId);
ASSERT_THROW(documents.remove({fileContainer}),
ClangBackEnd::ProjectPartDoNotExistException);
}
TEST_F(Documents, Remove)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId);
ClangBackEnd::FileContainer fileContainer(filePath);
documents.create({fileContainer});
documents.remove({fileContainer});
ASSERT_THROW(documents.document(filePath, projectPartId),
ASSERT_THROW(documents.document(filePath),
ClangBackEnd::DocumentDoesNotExistException);
}
TEST_F(Documents, RemoveAllValidIfExceptionIsThrown)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId);
ClangBackEnd::FileContainer fileContainer(filePath);
documents.create({fileContainer});
ASSERT_THROW(documents.remove({ClangBackEnd::FileContainer(Utf8StringLiteral("dontextist.pro"), projectPartId), fileContainer}),
ASSERT_THROW(documents.remove({ClangBackEnd::FileContainer(Utf8StringLiteral("dontextist.pro")), fileContainer}),
ClangBackEnd::DocumentDoesNotExistException);
ASSERT_THAT(documents.documents(),
Not(Contains(Document(filePath,
projects.project(projectPartId),
Utf8StringVector(),
documents))));
Not(Contains(Document(filePath, Utf8StringVector(), documents))));
}
TEST_F(Documents, HasDocument)
{
documents.create({{filePath, projectPartId}});
documents.create({{filePath}});
ASSERT_TRUE(documents.hasDocument(filePath, projectPartId));
ASSERT_TRUE(documents.hasDocument(filePath));
}
TEST_F(Documents, HasNotDocument)
{
ASSERT_FALSE(documents.hasDocument(filePath, projectPartId));
ASSERT_FALSE(documents.hasDocument(filePath));
}
TEST_F(Documents, FilteredPositive)
{
documents.create({{filePath, projectPartId}});
documents.create({{filePath}});
const auto isMatchingFilePath = [this](const Document &document) {
return document.filePath() == filePath;
};
@@ -318,7 +285,7 @@ TEST_F(Documents, FilteredPositive)
TEST_F(Documents, FilteredNegative)
{
documents.create({{filePath, projectPartId}});
documents.create({{filePath}});
const auto isMatchingNothing = [](const Document &) {
return false;
};
@@ -330,7 +297,7 @@ TEST_F(Documents, FilteredNegative)
TEST_F(Documents, DirtyAndVisibleButNotCurrentDocuments)
{
documents.create({{filePath, projectPartId}});
documents.create({{filePath}});
documents.updateDocumentsWithChangedDependency(filePath);
documents.setVisibleInEditors({filePath});
documents.setUsedByCurrentEditor(Utf8String());
@@ -402,45 +369,9 @@ TEST_F(Documents, IsNotVisibleEditorAfterBeingVisible)
ASSERT_FALSE(document.isVisibleInEditor());
}
TEST_F(Documents, SetDocumentsDirtyIfProjectPartChanged)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
const auto createdDocuments = documents.create({fileContainer});
ClangBackEnd::FileContainer fileContainerWithOtherProject(filePath, otherProjectPartId, Utf8StringVector(), 74u);
documents.create({fileContainerWithOtherProject});
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
const auto affectedDocuments = documents.setDocumentsDirtyIfProjectPartChanged();
ASSERT_THAT(affectedDocuments, createdDocuments);
}
TEST_F(Documents, SetDocumentsDirtyIfProjectPartChanged_EvenIfAlreadyDirty)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
auto createdDocuments = documents.create({fileContainer});
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
documents.setDocumentsDirtyIfProjectPartChanged(); // Make already dirty
const auto affectedDocuments = documents.setDocumentsDirtyIfProjectPartChanged();
ASSERT_THAT(affectedDocuments, createdDocuments);
}
TEST_F(Documents, SetDocumentsDirtyIfProjectPartChanged_ReturnsEmpty)
{
ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, Utf8StringVector(), 74u);
documents.create({fileContainer});
const auto affectedDocuments = documents.setDocumentsDirtyIfProjectPartChanged();
ASSERT_TRUE(affectedDocuments.empty());
}
// TODO: Remove?
void Documents::SetUp()
{
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
projects.createOrUpdate({ProjectPartContainer(otherProjectPartId)});
}
}