summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/unittest/builddependenciesprovider-test.cpp12
-rw-r--r--tests/unit/unittest/builddependenciesstorage-test.cpp4
-rw-r--r--tests/unit/unittest/builddependencycollector-test.cpp635
-rw-r--r--tests/unit/unittest/data/builddependencycollector/external/external1.h (renamed from tests/unit/unittest/data/includecollector/external/external1.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/external/external2.h (renamed from tests/unit/unittest/data/includecollector/external/external2.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/external/external3.h (renamed from tests/unit/unittest/data/includecollector/external/external3.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/external/indirect_external.h (renamed from tests/unit/unittest/data/includecollector/external/indirect_external.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/external/indirect_external2.h (renamed from tests/unit/unittest/data/includecollector/external/indirect_external2.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/false.h (renamed from tests/unit/unittest/data/includecollector/project/false.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/faulty.cpp (renamed from tests/unit/unittest/data/includecollector/project/faulty.cpp)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/faulty.h (renamed from tests/unit/unittest/data/includecollector/project/faulty.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/header1.h (renamed from tests/unit/unittest/data/includecollector/project/header1.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/header2.h (renamed from tests/unit/unittest/data/includecollector/project/header2.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/if.cpp (renamed from tests/unit/unittest/data/includecollector/project/if.cpp)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/macros.h11
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/main.cpp (renamed from tests/unit/unittest/data/includecollector/project/main.cpp)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/main2.cpp (renamed from tests/unit/unittest/data/includecollector/project/main2.cpp)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/main3.cpp (renamed from tests/unit/unittest/data/includecollector/project/main3.cpp)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/main4.cpp9
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/missingfile.cpp (renamed from tests/unit/unittest/data/includecollector/project/missingfile.cpp)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/missingfile.h8
-rw-r--r--tests/unit/unittest/data/builddependencycollector/project/true.h (renamed from tests/unit/unittest/data/includecollector/project/true.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/system/indirect_system.h (renamed from tests/unit/unittest/data/includecollector/system/indirect_system.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/system/indirect_system2.h (renamed from tests/unit/unittest/data/includecollector/system/indirect_system2.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/system/system1.h (renamed from tests/unit/unittest/data/includecollector/system/system1.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/system/system2.h (renamed from tests/unit/unittest/data/includecollector/system/system2.h)0
-rw-r--r--tests/unit/unittest/data/builddependencycollector/system/system3.h (renamed from tests/unit/unittest/data/includecollector/system/system3.h)0
-rw-r--r--tests/unit/unittest/gtest-creator-printing.cpp36
-rw-r--r--tests/unit/unittest/gtest-creator-printing.h3
-rw-r--r--tests/unit/unittest/includecollector-test.cpp422
-rw-r--r--tests/unit/unittest/mockbuilddependencygenerator.h (renamed from tests/unit/unittest/mockbuilddependenciesgenerator.h)4
-rw-r--r--tests/unit/unittest/pchcreator-test.cpp105
-rw-r--r--tests/unit/unittest/pchmanagerserver-test.cpp8
-rw-r--r--tests/unit/unittest/pchtaskgenerator-test.cpp4
-rw-r--r--tests/unit/unittest/symbolindexer-test.cpp2
-rw-r--r--tests/unit/unittest/unittest.pro8
36 files changed, 777 insertions, 494 deletions
diff --git a/tests/unit/unittest/builddependenciesprovider-test.cpp b/tests/unit/unittest/builddependenciesprovider-test.cpp
index 24d4b10465..e829b52d60 100644
--- a/tests/unit/unittest/builddependenciesprovider-test.cpp
+++ b/tests/unit/unittest/builddependenciesprovider-test.cpp
@@ -27,7 +27,7 @@
#include "mockbuilddependenciesstorage.h"
#include "mockmodifiedtimechecker.h"
-#include "mockbuilddependenciesgenerator.h"
+#include "mockbuilddependencygenerator.h"
#include <builddependenciesprovider.h>
@@ -56,7 +56,7 @@ class BuildDependenciesProvider : public testing::Test
protected:
NiceMock<MockBuildDependenciesStorage> mockBuildDependenciesStorage;
NiceMock<MockModifiedTimeChecker> mockModifiedTimeChecker;
- NiceMock<MockBuildDependenciesGenerator> mockBuildDependenciesGenerator;
+ NiceMock<MockBuildDependencyGenerator> mockBuildDependenciesGenerator;
ClangBackEnd::BuildDependenciesProvider provider{mockBuildDependenciesStorage, mockModifiedTimeChecker, mockBuildDependenciesGenerator};
ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1",
{"--yi"},
@@ -70,13 +70,13 @@ protected:
{"/er"},
{1},
{2, 3, 4}};
- SourceEntries firstSources{{1, SourceType::Any, 1}, {2, SourceType::Any, 1}, {10, SourceType::Any, 1}};
- SourceEntries secondSources{{1, SourceType::Any, 1}, {3, SourceType::Any, 1}, {8, SourceType::Any, 1}};
- SourceEntries thirdSources{{4, SourceType::Any, 1}, {8, SourceType::Any, 1}, {10, SourceType::Any, 1}};
+ SourceEntries firstSources{{1, SourceType::UserInclude, 1}, {2, SourceType::UserInclude, 1}, {10, SourceType::UserInclude, 1}};
+ SourceEntries secondSources{{1, SourceType::UserInclude, 1}, {3, SourceType::UserInclude, 1}, {8, SourceType::UserInclude, 1}};
+ SourceEntries thirdSources{{4, SourceType::UserInclude, 1}, {8, SourceType::UserInclude, 1}, {10, SourceType::UserInclude, 1}};
UsedMacros firstUsedMacros{{"YI", 1}};
UsedMacros secondUsedMacros{{"LIANG", 2}, {"ER", 2}};
UsedMacros thirdUsedMacros{{"SAN", 10}};
- BuildDependency buildDependency{secondSources, {}, {}, {}};
+ BuildDependency buildDependency{secondSources, {}};
};
TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTimeStampsAreUpToDate)
diff --git a/tests/unit/unittest/builddependenciesstorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp
index 05d3d70887..1100f1a634 100644
--- a/tests/unit/unittest/builddependenciesstorage-test.cpp
+++ b/tests/unit/unittest/builddependenciesstorage-test.cpp
@@ -171,9 +171,9 @@ TEST_F(BuildDependenciesStorage, UpdateSources)
SourceEntries entries{{1, SourceType::TopInclude, 10}, {2, SourceType::TopSystemInclude, 20}};
EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(10), TypedEq<int>(1)));
- EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(1), TypedEq<int>(1)));
+ EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(0), TypedEq<int>(1)));
EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(20), TypedEq<int>(2)));
- EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(2), TypedEq<int>(2)));
+ EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(1), TypedEq<int>(2)));
storage.updateSources(entries);
}
diff --git a/tests/unit/unittest/builddependencycollector-test.cpp b/tests/unit/unittest/builddependencycollector-test.cpp
new file mode 100644
index 0000000000..ba94a276d4
--- /dev/null
+++ b/tests/unit/unittest/builddependencycollector-test.cpp
@@ -0,0 +1,635 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "googletest.h"
+
+#include <refactoringdatabaseinitializer.h>
+#include <filepathcaching.h>
+#include <builddependencycollector.h>
+
+#include <sqlitedatabase.h>
+
+#include <QDateTime>
+#include <QDir>
+
+using testing::AllOf;
+using testing::Contains;
+using testing::Not;
+using testing::ElementsAre;
+using testing::UnorderedElementsAre;
+
+using ClangBackEnd::BuildDependency;
+using ClangBackEnd::FilePathId;
+using ClangBackEnd::FilePathIds;
+using ClangBackEnd::FilePathView;
+using ClangBackEnd::SourceDependency;
+using ClangBackEnd::SourceType;
+using ClangBackEnd::UsedMacro;
+
+namespace {
+
+MATCHER_P2(HasInclude, sourceId, sourceType,
+ std::string(negation ? "hasn't " : "has ")
+ + PrintToString(ClangBackEnd::SourceEntry(sourceId, sourceType, -1)))
+{
+ const ClangBackEnd::SourceEntry &entry = arg;
+
+ return entry.sourceId == sourceId && entry.sourceType == sourceType;
+}
+
+class BuildDependencyCollector : public ::testing::Test
+{
+protected:
+ BuildDependencyCollector()
+ {
+ setFilePathCache(&filePathCache);
+
+ collector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+ collector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ collector.addUnsavedFiles({{{TESTDATA_DIR, "BuildDependencyCollector/project/generated_file.h"}, "#pragma once", {}}});
+
+ collector.setExcludedFilePaths(Utils::clone(excludePaths));
+ emptyCollector.setExcludedFilePaths(Utils::clone(excludePaths));
+ }
+
+ ~BuildDependencyCollector()
+ {
+ setFilePathCache(nullptr);
+ }
+
+ FilePathId id(const Utils::SmallStringView &path) const
+ {
+ return filePathCache.filePathId(FilePathView{path});
+ }
+
+ static off_t fileSize(Utils::SmallStringView filePath)
+ {
+ return QFileInfo(QString(filePath)).size();
+ }
+
+ static std::time_t lastModified(Utils::SmallStringView filePath)
+ {
+ return QFileInfo(QString(filePath)).lastModified().toTime_t();
+ }
+
+ ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const
+ {
+ return {id(filePath), fileSize(filePath), lastModified(filePath), false};
+ }
+
+ static
+ FilePathIds filteredIncludes(const ClangBackEnd::SourceEntries &includes,
+ ClangBackEnd::SourceType includeType)
+ {
+ FilePathIds filteredIncludes;
+
+ for (const ClangBackEnd::SourceEntry &include : includes) {
+ if (include.sourceType == includeType)
+ filteredIncludes.push_back(include.sourceId);
+ }
+
+ return filteredIncludes;
+ }
+
+ static
+ FilePathIds topIncludes(const ClangBackEnd::SourceEntries &includes)
+ {
+ return filteredIncludes(includes, ClangBackEnd::SourceType::TopInclude);
+ }
+
+ static
+ FilePathIds systemTopIncludes(const ClangBackEnd::SourceEntries &includes)
+ {
+ return filteredIncludes(includes, ClangBackEnd::SourceType::TopSystemInclude);
+ }
+
+ static
+ FilePathIds userIncludes(const ClangBackEnd::SourceEntries &includes)
+ {
+ return filteredIncludes(includes, ClangBackEnd::SourceType::UserInclude);
+ }
+
+ static
+ FilePathIds allIncludes(const ClangBackEnd::SourceEntries &includes)
+ {
+ FilePathIds filteredIncludes;
+
+ for (const ClangBackEnd::SourceEntry &include : includes)
+ filteredIncludes.push_back(include.sourceId);
+
+ return filteredIncludes;
+ }
+
+protected:
+ Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
+ ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
+ ClangBackEnd::FilePathCaching filePathCache{database};
+ ClangBackEnd::BuildDependencyCollector collector{filePathCache};
+ ClangBackEnd::BuildDependencyCollector emptyCollector{filePathCache};
+ ClangBackEnd::FilePaths excludePaths = {TESTDATA_DIR "/builddependencycollector/project/main.cpp",
+ TESTDATA_DIR "/builddependencycollector/project/main2.cpp",
+ TESTDATA_DIR "/builddependencycollector/project/header1.h",
+ TESTDATA_DIR "/builddependencycollector/project/header2.h",
+ TESTDATA_DIR "/builddependencycollector/project/generated_file.h"};
+};
+
+TEST_F(BuildDependencyCollector, IncludesExternalHeader)
+{
+ collector.collect();
+
+ ASSERT_THAT(allIncludes(collector.includeIds()),
+ AllOf(Contains(id(TESTDATA_DIR "/builddependencycollector/external/external1.h")),
+ Contains(id(TESTDATA_DIR "/builddependencycollector/external/external2.h")),
+ Contains(id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h")),
+ Contains(id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"))));
+}
+
+TEST_F(BuildDependencyCollector, InternalHeaderAreUserIncludes)
+{
+ collector.collect();
+
+ ASSERT_THAT(userIncludes(collector.includeIds()), Contains(id(TESTDATA_DIR "/builddependencycollector/project/header1.h")));
+}
+
+TEST_F(BuildDependencyCollector, NoDuplicate)
+{
+ collector.collect();
+
+ ASSERT_THAT(allIncludes(collector.includeIds()),
+ UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h")));
+}
+
+TEST_F(BuildDependencyCollector, IncludesAreSorted)
+{
+ collector.collect();
+
+ ASSERT_THAT(allIncludes(collector.includeIds()),
+ ElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h")));
+}
+
+TEST_F(BuildDependencyCollector, If)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/if.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(allIncludes(emptyCollector.includeIds()),
+ ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/true.h")));
+}
+
+TEST_F(BuildDependencyCollector, LocalPath)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(allIncludes(emptyCollector.includeIds()),
+ UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h")));
+}
+
+TEST_F(BuildDependencyCollector, IgnoreMissingFile)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(allIncludes(emptyCollector.includeIds()),
+ UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h")));
+}
+
+TEST_F(BuildDependencyCollector, IncludesOnlyTopExternalHeader)
+{
+ collector.collect();
+
+ ASSERT_THAT(topIncludes(collector.includeIds()),
+ UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h")));
+}
+
+TEST_F(BuildDependencyCollector, TopIncludeInIfMacro)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/if.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+ emptyCollector.setExcludedFilePaths({TESTDATA_DIR "/builddependencycollector/project/if.cpp"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(topIncludes(emptyCollector.includeIds()),
+ ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/true.h")));
+}
+
+TEST_F(BuildDependencyCollector, TopIncludeWithLocalPath)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(topIncludes(emptyCollector.includeIds()),
+ UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h")));
+}
+
+TEST_F(BuildDependencyCollector, TopIncludesIgnoreMissingFile)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+ emptyCollector.setExcludedFilePaths({TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(topIncludes(emptyCollector.includeIds()),
+ UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h")));
+}
+
+TEST_F(BuildDependencyCollector, SourceFiles)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.sourceFiles(),
+ UnorderedElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp"),
+ id(TESTDATA_DIR "/symbolscollector_header1.h"),
+ id(TESTDATA_DIR "/symbolscollector_header2.h")));
+}
+
+TEST_F(BuildDependencyCollector, MainFileInSourceFiles)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ ASSERT_THAT(emptyCollector.sourceFiles(),
+ ElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp")));
+}
+
+TEST_F(BuildDependencyCollector, ResetMainFileInSourceFiles)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ ASSERT_THAT(emptyCollector.sourceFiles(),
+ ElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp")));
+}
+
+TEST_F(BuildDependencyCollector, DontDuplicateSourceFiles)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+ emptyCollector.collect();
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.sourceFiles(),
+ UnorderedElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp"),
+ id(TESTDATA_DIR "/symbolscollector_header1.h"),
+ id(TESTDATA_DIR "/symbolscollector_header2.h")));
+}
+
+TEST_F(BuildDependencyCollector, ClearSourceFiles)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.clear();
+
+ ASSERT_THAT(emptyCollector.sourceFiles(), IsEmpty());
+}
+
+TEST_F(BuildDependencyCollector, ClearFileStatus)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+ emptyCollector.collect();
+
+ emptyCollector.clear();
+
+ ASSERT_THAT(emptyCollector.fileStatuses(), IsEmpty());
+}
+
+TEST_F(BuildDependencyCollector, ClearUsedMacros)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_defines.h"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+ emptyCollector.collect();
+
+ emptyCollector.clear();
+
+ ASSERT_THAT(emptyCollector.usedMacros(), IsEmpty());
+}
+
+TEST_F(BuildDependencyCollector, ClearSourceDependencies)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main2.cpp"), {"cc", "-I" TESTDATA_DIR});
+ emptyCollector.collect();
+
+ emptyCollector.clear();
+
+ ASSERT_THAT(emptyCollector.sourceDependencies(), IsEmpty());
+}
+
+TEST_F(BuildDependencyCollector, DontCollectSourceFilesAfterFilesAreCleared)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.clear();
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.sourceFiles(), IsEmpty());
+}
+
+TEST_F(BuildDependencyCollector, DontCollectFileStatusAfterFilesAreCleared)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.clear();
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.fileStatuses(), IsEmpty());
+}
+
+TEST_F(BuildDependencyCollector, DontCollectUsedMacrosAfterFilesAreCleared)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.clear();
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.usedMacros(), IsEmpty());
+}
+
+
+TEST_F(BuildDependencyCollector, DontCollectSourceDependenciesAfterFilesAreCleared)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.clear();
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.sourceDependencies(), IsEmpty());
+}
+
+TEST_F(BuildDependencyCollector, CollectUsedMacrosWithExternalDefine)
+{
+ auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
+ emptyCollector.addFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.usedMacros(),
+ ElementsAre(Eq(UsedMacro{"DEFINED", fileId}),
+ Eq(UsedMacro{"IF_DEFINE", fileId}),
+ Eq(UsedMacro{"__clang__", fileId}),
+ Eq(UsedMacro{"CLASS_EXPORT", fileId}),
+ Eq(UsedMacro{"IF_NOT_DEFINE", fileId}),
+ Eq(UsedMacro{"MACRO_EXPANSION", fileId}),
+ Eq(UsedMacro{"COMPILER_ARGUMENT", fileId})));
+}
+
+TEST_F(BuildDependencyCollector, CollectUsedMacrosWithoutExternalDefine)
+{
+ auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
+ emptyCollector.addFile(fileId, {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.usedMacros(),
+ ElementsAre(Eq(UsedMacro{"DEFINED", fileId}),
+ Eq(UsedMacro{"IF_DEFINE", fileId}),
+ Eq(UsedMacro{"__clang__", fileId}),
+ Eq(UsedMacro{"CLASS_EXPORT", fileId}),
+ Eq(UsedMacro{"IF_NOT_DEFINE", fileId}),
+ Eq(UsedMacro{"MACRO_EXPANSION", fileId}),
+ Eq(UsedMacro{"COMPILER_ARGUMENT", fileId})));
+}
+
+TEST_F(BuildDependencyCollector, DontCollectHeaderGuards)
+{
+ auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
+ emptyCollector.addFile(fileId, {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.usedMacros(),
+ Not(Contains(Eq(UsedMacro{"SYMBOLSCOLLECTOR_DEFINES_H", fileId}))));
+}
+
+TEST_F(BuildDependencyCollector, DISABLED_DontCollectDynamicLibraryExports)
+{
+ auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
+ emptyCollector.addFile(fileId, {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.usedMacros(),
+ Not(Contains(Eq(UsedMacro{"CLASS_EXPORT", fileId}))));
+}
+
+TEST_F(BuildDependencyCollector, CollectFileStatuses)
+{
+ emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system"});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.fileStatuses(),
+ ElementsAre(
+ fileStatus(TESTDATA_DIR "/symbolscollector_main.cpp"),
+ fileStatus(TESTDATA_DIR "/symbolscollector_header1.h"),
+ fileStatus(TESTDATA_DIR "/symbolscollector_header2.h")));
+}
+
+TEST_F(BuildDependencyCollector, CollectSourceDependencies)
+{
+ auto mainFileId = id(TESTDATA_DIR "/symbolscollector_main2.cpp");
+ auto header1FileId = id(TESTDATA_DIR "/symbolscollector_header1.h");
+ auto header2FileId = id(TESTDATA_DIR "/symbolscollector_header2.h");
+ auto header3FileId = id(TESTDATA_DIR "/symbolscollector_header3.h");
+ emptyCollector.addFile(mainFileId, {"cc", "-I" TESTDATA_DIR});
+
+ emptyCollector.collect();
+
+ ASSERT_THAT(emptyCollector.sourceDependencies(),
+ UnorderedElementsAre(SourceDependency(mainFileId, header1FileId),
+ SourceDependency(mainFileId, header3FileId),
+ SourceDependency(header3FileId, header2FileId),
+ SourceDependency(header1FileId, header2FileId)));
+}
+
+TEST_F(BuildDependencyCollector, Create)
+{
+ ClangBackEnd::BuildDependencyCollector collector{filePathCache};
+ ClangBackEnd::V2::ProjectPartContainer
+ projectPart{"project1",
+ {"cc",
+ "-I",
+ TESTDATA_DIR "/builddependencycollector/external",
+ "-I",
+ TESTDATA_DIR "/builddependencycollector/project",
+ "-isystem",
+ TESTDATA_DIR "/builddependencycollector/system"},
+ {},
+ {},
+ {id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/macros.h"),},
+ {id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp")}};
+
+ auto buildDependency = collector.create(projectPart);
+
+ ASSERT_THAT(
+ buildDependency,
+ AllOf(
+ Field(&BuildDependency::fileStatuses,
+ UnorderedElementsAre(
+ fileStatus(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ fileStatus(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external.h"),
+ fileStatus(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external2.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/system/indirect_system2.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
+ fileStatus(TESTDATA_DIR "/builddependencycollector/project/macros.h"))),
+ Field(&BuildDependency::includes,
+ UnorderedElementsAre(
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ SourceType::UserInclude),
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ SourceType::UserInclude),
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ SourceType::TopInclude),
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ SourceType::TopInclude),
+ HasInclude(id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external.h"),
+ SourceType::UserInclude),
+ HasInclude(id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external2.h"),
+ SourceType::UserInclude),
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ SourceType::TopInclude),
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
+ SourceType::TopSystemInclude),
+ HasInclude(id(TESTDATA_DIR
+ "/builddependencycollector/system/indirect_system.h"),
+ SourceType::SystemInclude),
+ HasInclude(id(TESTDATA_DIR
+ "/builddependencycollector/system/indirect_system2.h"),
+ SourceType::SystemInclude),
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
+ SourceType::UserInclude),
+ HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/macros.h"),
+ SourceType::UserInclude))),
+ Field(&BuildDependency::usedMacros,
+ UnorderedElementsAre(
+ UsedMacro{"DEFINE",
+ id(TESTDATA_DIR "/builddependencycollector/project/macros.h")},
+ UsedMacro{"IFDEF",
+ id(TESTDATA_DIR "/builddependencycollector/project/macros.h")},
+ UsedMacro{"DEFINED",
+ id(TESTDATA_DIR "/builddependencycollector/project/macros.h")})),
+ Field(&BuildDependency::sourceFiles,
+ UnorderedElementsAre(
+ id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external3.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
+ id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"),
+ id(TESTDATA_DIR "/builddependencycollector/system/indirect_system2.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
+ id(TESTDATA_DIR "/builddependencycollector/project/macros.h"))),
+ Field(
+ &BuildDependency::sourceDependencies,
+ UnorderedElementsAre(
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header1.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/project/missingfile.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/external1.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/external2.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/system/system1.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
+ id(TESTDATA_DIR "/builddependencycollector/project/macros.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/external3.h")),
+ SourceDependency(id(TESTDATA_DIR
+ "/builddependencycollector/project/missingfile.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/external1.h")),
+ SourceDependency(id(TESTDATA_DIR
+ "/builddependencycollector/external/external1.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external.h")),
+ SourceDependency(id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/indirect_external2.h")),
+ SourceDependency(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/system/indirect_system.h")),
+ SourceDependency(id(TESTDATA_DIR
+ "/builddependencycollector/system/indirect_system.h"),
+ id(TESTDATA_DIR
+ "/builddependencycollector/system/indirect_system2.h"))))));
+}
+} // namespace
diff --git a/tests/unit/unittest/data/includecollector/external/external1.h b/tests/unit/unittest/data/builddependencycollector/external/external1.h
index 6bc9da6c80..6bc9da6c80 100644
--- a/tests/unit/unittest/data/includecollector/external/external1.h
+++ b/tests/unit/unittest/data/builddependencycollector/external/external1.h
diff --git a/tests/unit/unittest/data/includecollector/external/external2.h b/tests/unit/unittest/data/builddependencycollector/external/external2.h
index 6f70f09bee..6f70f09bee 100644
--- a/tests/unit/unittest/data/includecollector/external/external2.h
+++ b/tests/unit/unittest/data/builddependencycollector/external/external2.h
diff --git a/tests/unit/unittest/data/includecollector/external/external3.h b/tests/unit/unittest/data/builddependencycollector/external/external3.h
index 6f70f09bee..6f70f09bee 100644
--- a/tests/unit/unittest/data/includecollector/external/external3.h
+++ b/tests/unit/unittest/data/builddependencycollector/external/external3.h
diff --git a/tests/unit/unittest/data/includecollector/external/indirect_external.h b/tests/unit/unittest/data/builddependencycollector/external/indirect_external.h
index 33e9663b63..33e9663b63 100644
--- a/tests/unit/unittest/data/includecollector/external/indirect_external.h
+++ b/tests/unit/unittest/data/builddependencycollector/external/indirect_external.h
diff --git a/tests/unit/unittest/data/includecollector/external/indirect_external2.h b/tests/unit/unittest/data/builddependencycollector/external/indirect_external2.h
index 3f59c932d3..3f59c932d3 100644
--- a/tests/unit/unittest/data/includecollector/external/indirect_external2.h
+++ b/tests/unit/unittest/data/builddependencycollector/external/indirect_external2.h
diff --git a/tests/unit/unittest/data/includecollector/project/false.h b/tests/unit/unittest/data/builddependencycollector/project/false.h
index 3f59c932d3..3f59c932d3 100644
--- a/tests/unit/unittest/data/includecollector/project/false.h
+++ b/tests/unit/unittest/data/builddependencycollector/project/false.h
diff --git a/tests/unit/unittest/data/includecollector/project/faulty.cpp b/tests/unit/unittest/data/builddependencycollector/project/faulty.cpp
index e6697eb5d9..e6697eb5d9 100644
--- a/tests/unit/unittest/data/includecollector/project/faulty.cpp
+++ b/tests/unit/unittest/data/builddependencycollector/project/faulty.cpp
diff --git a/tests/unit/unittest/data/includecollector/project/faulty.h b/tests/unit/unittest/data/builddependencycollector/project/faulty.h
index 4a0601f95b..4a0601f95b 100644
--- a/tests/unit/unittest/data/includecollector/project/faulty.h
+++ b/tests/unit/unittest/data/builddependencycollector/project/faulty.h
diff --git a/tests/unit/unittest/data/includecollector/project/header1.h b/tests/unit/unittest/data/builddependencycollector/project/header1.h
index 3f59c932d3..3f59c932d3 100644
--- a/tests/unit/unittest/data/includecollector/project/header1.h
+++ b/tests/unit/unittest/data/builddependencycollector/project/header1.h
diff --git a/tests/unit/unittest/data/includecollector/project/header2.h b/tests/unit/unittest/data/builddependencycollector/project/header2.h
index 851c723be5..851c723be5 100644
--- a/tests/unit/unittest/data/includecollector/project/header2.h
+++ b/tests/unit/unittest/data/builddependencycollector/project/header2.h
diff --git a/tests/unit/unittest/data/includecollector/project/if.cpp b/tests/unit/unittest/data/builddependencycollector/project/if.cpp
index f148f0bd9c..f148f0bd9c 100644
--- a/tests/unit/unittest/data/includecollector/project/if.cpp
+++ b/tests/unit/unittest/data/builddependencycollector/project/if.cpp
diff --git a/tests/unit/unittest/data/builddependencycollector/project/macros.h b/tests/unit/unittest/data/builddependencycollector/project/macros.h
new file mode 100644
index 0000000000..3b7d254ad8
--- /dev/null
+++ b/tests/unit/unittest/data/builddependencycollector/project/macros.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#define DEFINE
+
+#ifdef IFDEF
+#endif
+
+#if defined(DEFINED)
+#endif
+DEFINE
+
diff --git a/tests/unit/unittest/data/includecollector/project/main.cpp b/tests/unit/unittest/data/builddependencycollector/project/main.cpp
index caa808606c..caa808606c 100644
--- a/tests/unit/unittest/data/includecollector/project/main.cpp
+++ b/tests/unit/unittest/data/builddependencycollector/project/main.cpp
diff --git a/tests/unit/unittest/data/includecollector/project/main2.cpp b/tests/unit/unittest/data/builddependencycollector/project/main2.cpp
index fb7d23d972..fb7d23d972 100644
--- a/tests/unit/unittest/data/includecollector/project/main2.cpp
+++ b/tests/unit/unittest/data/builddependencycollector/project/main2.cpp
diff --git a/tests/unit/unittest/data/includecollector/project/main3.cpp b/tests/unit/unittest/data/builddependencycollector/project/main3.cpp
index 7f206d44f7..7f206d44f7 100644
--- a/tests/unit/unittest/data/includecollector/project/main3.cpp
+++ b/tests/unit/unittest/data/builddependencycollector/project/main3.cpp
diff --git a/tests/unit/unittest/data/builddependencycollector/project/main4.cpp b/tests/unit/unittest/data/builddependencycollector/project/main4.cpp
new file mode 100644
index 0000000000..ff215f43d7
--- /dev/null
+++ b/tests/unit/unittest/data/builddependencycollector/project/main4.cpp
@@ -0,0 +1,9 @@
+#include <header1.h>
+#include <header2.h>
+#include "missingfile.h"
+#include "missingfile.h"
+#include <external1.h>
+#include <../external/external1.h>
+#include <../external/external2.h>
+#include <system1.h>
+#include "macros.h"
diff --git a/tests/unit/unittest/data/includecollector/project/missingfile.cpp b/tests/unit/unittest/data/builddependencycollector/project/missingfile.cpp
index 6f3a7ea58c..6f3a7ea58c 100644
--- a/tests/unit/unittest/data/includecollector/project/missingfile.cpp
+++ b/tests/unit/unittest/data/builddependencycollector/project/missingfile.cpp
diff --git a/tests/unit/unittest/data/builddependencycollector/project/missingfile.h b/tests/unit/unittest/data/builddependencycollector/project/missingfile.h
new file mode 100644
index 0000000000..1ac1ed43d7
--- /dev/null
+++ b/tests/unit/unittest/data/builddependencycollector/project/missingfile.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "missing_file.moc"
+#include "foo/missing_file.moc"
+#include <missing_file2.moc>
+#include <foo2/missing_file2.moc>
+
+#include "external1.h"
diff --git a/tests/unit/unittest/data/includecollector/project/true.h b/tests/unit/unittest/data/builddependencycollector/project/true.h
index 3f59c932d3..3f59c932d3 100644
--- a/tests/unit/unittest/data/includecollector/project/true.h
+++ b/tests/unit/unittest/data/builddependencycollector/project/true.h
diff --git a/tests/unit/unittest/data/includecollector/system/indirect_system.h b/tests/unit/unittest/data/builddependencycollector/system/indirect_system.h
index e0fa22c9d9..e0fa22c9d9 100644
--- a/tests/unit/unittest/data/includecollector/system/indirect_system.h
+++ b/tests/unit/unittest/data/builddependencycollector/system/indirect_system.h
diff --git a/tests/unit/unittest/data/includecollector/system/indirect_system2.h b/tests/unit/unittest/data/builddependencycollector/system/indirect_system2.h
index 3f59c932d3..3f59c932d3 100644
--- a/tests/unit/unittest/data/includecollector/system/indirect_system2.h
+++ b/tests/unit/unittest/data/builddependencycollector/system/indirect_system2.h
diff --git a/tests/unit/unittest/data/includecollector/system/system1.h b/tests/unit/unittest/data/builddependencycollector/system/system1.h
index 98e09cd083..98e09cd083 100644
--- a/tests/unit/unittest/data/includecollector/system/system1.h
+++ b/tests/unit/unittest/data/builddependencycollector/system/system1.h
diff --git a/tests/unit/unittest/data/includecollector/system/system2.h b/tests/unit/unittest/data/builddependencycollector/system/system2.h
index 6f70f09bee..6f70f09bee 100644
--- a/tests/unit/unittest/data/includecollector/system/system2.h
+++ b/tests/unit/unittest/data/builddependencycollector/system/system2.h
diff --git a/tests/unit/unittest/data/includecollector/system/system3.h b/tests/unit/unittest/data/builddependencycollector/system/system3.h
index 6f70f09bee..6f70f09bee 100644
--- a/tests/unit/unittest/data/includecollector/system/system3.h
+++ b/tests/unit/unittest/data/builddependencycollector/system/system3.h
diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp
index 186858dc86..be0018ef3d 100644
--- a/tests/unit/unittest/gtest-creator-printing.cpp
+++ b/tests/unit/unittest/gtest-creator-printing.cpp
@@ -66,6 +66,10 @@
#include <coreplugin/find/searchresultitem.h>
#include <coreplugin/locator/ilocatorfilter.h>
+namespace {
+ClangBackEnd::FilePathCaching *filePathCache = nullptr;
+}
+
void PrintTo(const Utf8String &text, ::std::ostream *os)
{
*os << text;
@@ -171,7 +175,10 @@ namespace ClangBackEnd {
std::ostream &operator<<(std::ostream &out, const FilePathId &id)
{
- return out << "(" << id.filePathId << ")";
+ if (filePathCache)
+ return out << "(" << id.filePathId << ", " << filePathCache->filePath(id) << ")";
+
+ return out << id.filePathId;
}
std::ostream &operator<<(std::ostream &out, const FilePathView &filePathView)
@@ -1014,10 +1021,13 @@ std::ostream &operator<<(std::ostream &out, const PchTask &task)
std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency)
{
- return out << "("
- << dependency.includes << ", "
- << dependency.topsSystemIncludeIds << ", "
- << dependency.topIncludeIds << ")";
+ return out << "(\n"
+ << "includes: " << dependency.includes << ",\n"
+ << "usedMacros: " << dependency.usedMacros << ",\n"
+ << "fileStatuses: " << dependency.fileStatuses << ",\n"
+ << "sourceFiles: " << dependency.sourceFiles << ",\n"
+ << "sourceDependencies: " << dependency.sourceDependencies << ",\n"
+ << ")";
}
const char *sourceTypeString(SourceType sourceType)
@@ -1025,9 +1035,14 @@ const char *sourceTypeString(SourceType sourceType)
using ClangBackEnd::SymbolTag;
switch (sourceType) {
- case SourceType::Any: return "Any";
- case SourceType::TopInclude: return "TopInclude";
- case SourceType::TopSystemInclude: return "TopSystemInclude";
+ case SourceType::TopInclude:
+ return "TopInclude";
+ case SourceType::TopSystemInclude:
+ return "TopSystemInclude";
+ case SourceType::SystemInclude:
+ return "SystemInclude";
+ case SourceType::UserInclude:
+ return "UserInclude";
}
return "";
@@ -1131,3 +1146,8 @@ std::ostream &operator<<(std::ostream &out, const Usage &usage)
return out << "(" << usage.path << ", " << usage.line << ", " << usage.column <<")";
}
} // namespace CppTools
+
+void setFilePathCache(ClangBackEnd::FilePathCaching *cache)
+{
+ filePathCache = cache;
+}
diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h
index 7eca6cf9a1..fe7e4e3405 100644
--- a/tests/unit/unittest/gtest-creator-printing.h
+++ b/tests/unit/unittest/gtest-creator-printing.h
@@ -173,6 +173,7 @@ class PchCreatorIncludes;
class PchTask;
class BuildDependency;
class SourceEntry;
+class FilePathCaching;
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
@@ -289,3 +290,5 @@ class Usage;
std::ostream &operator<<(std::ostream &out, const Usage &usage);
} // namespace CppTools
+
+void setFilePathCache(ClangBackEnd::FilePathCaching *filePathCache);
diff --git a/tests/unit/unittest/includecollector-test.cpp b/tests/unit/unittest/includecollector-test.cpp
deleted file mode 100644
index 8fff80c0b1..0000000000
--- a/tests/unit/unittest/includecollector-test.cpp
+++ /dev/null
@@ -1,422 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-****************************************************************************/
-
-#include "googletest.h"
-
-#include <refactoringdatabaseinitializer.h>
-#include <filepathcaching.h>
-#include <includecollector.h>
-
-#include <sqlitedatabase.h>
-
-#include <QDateTime>
-#include <QDir>
-
-using testing::AllOf;
-using testing::Contains;
-using testing::Not;
-using testing::ElementsAre;
-using testing::UnorderedElementsAre;
-
-using ClangBackEnd::FilePathId;
-using ClangBackEnd::FilePathIds;
-using ClangBackEnd::FilePathView;
-using ClangBackEnd::SourceDependency;
-using ClangBackEnd::UsedMacro;
-
-namespace {
-
-class IncludeCollector : public ::testing::Test
-{
-protected:
- void SetUp()
- {
- collector.addFile(id(TESTDATA_DIR "/includecollector/project/main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
- collector.addFile(id(TESTDATA_DIR "/includecollector/project/main2.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- collector.addUnsavedFiles({{{TESTDATA_DIR, "includecollector/project/generated_file.h"}, "#pragma once", {}}});
-
- collector.setExcludedIncludes(excludePaths.clone());
- emptyCollector.setExcludedIncludes(excludePaths.clone());
- }
-
- FilePathId id(const Utils::SmallStringView &path) const
- {
- return filePathCache.filePathId(FilePathView{path});
- }
-
- static off_t fileSize(Utils::SmallStringView filePath)
- {
- return QFileInfo(QString(filePath)).size();
- }
-
- static std::time_t lastModified(Utils::SmallStringView filePath)
- {
- return QFileInfo(QString(filePath)).lastModified().toTime_t();
- }
-
- ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const
- {
- return {id(filePath), fileSize(filePath), lastModified(filePath), false};
- }
-protected:
- Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
- ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
- ClangBackEnd::FilePathCaching filePathCache{database};
- ClangBackEnd::IncludeCollector collector{filePathCache};
- ClangBackEnd::IncludeCollector emptyCollector{filePathCache};
- Utils::PathStringVector excludePaths = {TESTDATA_DIR "/includecollector/project/main.cpp",
- TESTDATA_DIR "/includecollector/project/main2.cpp",
- TESTDATA_DIR "/includecollector/project/header1.h",
- TESTDATA_DIR "/includecollector/project/header2.h",
- TESTDATA_DIR "/includecollector/project/generated_file.h"};
-};
-
-TEST_F(IncludeCollector, IncludesExternalHeader)
-{
- collector.collect();
-
- ASSERT_THAT(collector.takeIncludeIds(),
- AllOf(Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")),
- Contains(id(TESTDATA_DIR "/includecollector/external/external2.h")),
- Contains(id(TESTDATA_DIR "/includecollector/external/indirect_external.h")),
- Contains(id(TESTDATA_DIR "/includecollector/external/indirect_external2.h"))));
-}
-
-TEST_F(IncludeCollector, DoesNotIncludesInternalHeader)
-{
- collector.collect();
-
- ASSERT_THAT(collector.takeIncludeIds(), Not(Contains(id(TESTDATA_DIR "/includecollector/project/header1.h"))));
-}
-
-TEST_F(IncludeCollector, NoDuplicate)
-{
- collector.collect();
-
- ASSERT_THAT(collector.takeIncludeIds(),
- UnorderedElementsAre(id(TESTDATA_DIR "/includecollector/external/external1.h"),
- id(TESTDATA_DIR "/includecollector/external/external2.h"),
- id(TESTDATA_DIR "/includecollector/external/external3.h"),
- id(TESTDATA_DIR "/includecollector/external/indirect_external.h"),
- id(TESTDATA_DIR "/includecollector/external/indirect_external2.h")));
-}
-
-TEST_F(IncludeCollector, IncludesAreSorted)
-{
- collector.collect();
-
- ASSERT_THAT(collector.takeIncludeIds(),
- SizeIs(5));
-}
-
-TEST_F(IncludeCollector, If)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/includecollector/project/if.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.takeIncludeIds(),
- ElementsAre(id(TESTDATA_DIR "/includecollector/project/true.h")));
-}
-
-TEST_F(IncludeCollector, LocalPath)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/includecollector/project/main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.takeIncludeIds(),
- UnorderedElementsAre(id(TESTDATA_DIR "/includecollector/external/external1.h"),
- id(TESTDATA_DIR "/includecollector/external/external2.h"),
- id(TESTDATA_DIR "/includecollector/external/external3.h"),
- id(TESTDATA_DIR "/includecollector/external/indirect_external.h"),
- id(TESTDATA_DIR "/includecollector/external/indirect_external2.h")));
-}
-
-TEST_F(IncludeCollector, IgnoreMissingFile)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/includecollector/project/missingfile.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.takeIncludeIds(),
- UnorderedElementsAre(id(TESTDATA_DIR "/includecollector/external/external1.h"),
- id(TESTDATA_DIR "/includecollector/external/indirect_external.h"),
- id(TESTDATA_DIR "/includecollector/external/indirect_external2.h")));
-}
-
-TEST_F(IncludeCollector, IncludesOnlyTopExternalHeader)
-{
- collector.collect();
-
- ASSERT_THAT(collector.takeTopIncludeIds(),
- UnorderedElementsAre(id(TESTDATA_DIR "/includecollector/external/external1.h"),
- id(TESTDATA_DIR "/includecollector/external/external2.h"),
- id(TESTDATA_DIR "/includecollector/external/external3.h")));
-}
-
-TEST_F(IncludeCollector, TopIncludeInIfMacro)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/includecollector/project/if.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
- emptyCollector.setExcludedIncludes({TESTDATA_DIR "/includecollector/project/if.cpp"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.takeTopIncludeIds(),
- ElementsAre(id(TESTDATA_DIR "/includecollector/project/true.h")));
-}
-
-TEST_F(IncludeCollector, TopIncludeWithLocalPath)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/includecollector/project/main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.takeTopIncludeIds(),
- UnorderedElementsAre(id(TESTDATA_DIR "/includecollector/external/external1.h"),
- id(TESTDATA_DIR "/includecollector/external/external2.h"),
- id(TESTDATA_DIR "/includecollector/external/external3.h")));
-}
-
-TEST_F(IncludeCollector, TopIncludesIgnoreMissingFile)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/includecollector/project/missingfile.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
- emptyCollector.setExcludedIncludes({TESTDATA_DIR "/includecollector/project/missingfile.cpp"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.takeTopIncludeIds(),
- UnorderedElementsAre(id(TESTDATA_DIR "/includecollector/external/external1.h")));
-}
-
-TEST_F(IncludeCollector, SourceFiles)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.sourceFiles(),
- UnorderedElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp"),
- id(TESTDATA_DIR "/symbolscollector_header1.h"),
- id(TESTDATA_DIR "/symbolscollector_header2.h")));
-}
-
-TEST_F(IncludeCollector, MainFileInSourceFiles)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- ASSERT_THAT(emptyCollector.sourceFiles(),
- ElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp")));
-}
-
-TEST_F(IncludeCollector, ResetMainFileInSourceFiles)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- ASSERT_THAT(emptyCollector.sourceFiles(),
- ElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp")));
-}
-
-TEST_F(IncludeCollector, DontDuplicateSourceFiles)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
- emptyCollector.collect();
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.sourceFiles(),
- UnorderedElementsAre(id(TESTDATA_DIR "/symbolscollector_main.cpp"),
- id(TESTDATA_DIR "/symbolscollector_header1.h"),
- id(TESTDATA_DIR "/symbolscollector_header2.h")));
-}
-
-TEST_F(IncludeCollector, ClearSourceFiles)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.clear();
-
- ASSERT_THAT(emptyCollector.sourceFiles(), IsEmpty());
-}
-
-TEST_F(IncludeCollector, ClearFileStatus)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
- emptyCollector.collect();
-
- emptyCollector.clear();
-
- ASSERT_THAT(emptyCollector.fileStatuses(), IsEmpty());
-}
-
-TEST_F(IncludeCollector, ClearUsedMacros)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_defines.h"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
- emptyCollector.collect();
-
- emptyCollector.clear();
-
- ASSERT_THAT(emptyCollector.usedMacros(), IsEmpty());
-}
-
-TEST_F(IncludeCollector, ClearSourceDependencies)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main2.cpp"), {"cc", "-I" TESTDATA_DIR});
- emptyCollector.collect();
-
- emptyCollector.clear();
-
- ASSERT_THAT(emptyCollector.sourceDependencies(), IsEmpty());
-}
-
-TEST_F(IncludeCollector, DontCollectSourceFilesAfterFilesAreCleared)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.clear();
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.sourceFiles(), IsEmpty());
-}
-
-TEST_F(IncludeCollector, DontCollectFileStatusAfterFilesAreCleared)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.clear();
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.fileStatuses(), IsEmpty());
-}
-
-TEST_F(IncludeCollector, DontCollectUsedMacrosAfterFilesAreCleared)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.clear();
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.usedMacros(), IsEmpty());
-}
-
-
-TEST_F(IncludeCollector, DontCollectSourceDependenciesAfterFilesAreCleared)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.clear();
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.sourceDependencies(), IsEmpty());
-}
-
-TEST_F(IncludeCollector, CollectUsedMacrosWithExternalDefine)
-{
- auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
- emptyCollector.addFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.usedMacros(),
- ElementsAre(Eq(UsedMacro{"DEFINED", fileId}),
- Eq(UsedMacro{"IF_DEFINE", fileId}),
- Eq(UsedMacro{"__clang__", fileId}),
- Eq(UsedMacro{"CLASS_EXPORT", fileId}),
- Eq(UsedMacro{"IF_NOT_DEFINE", fileId}),
- Eq(UsedMacro{"MACRO_EXPANSION", fileId}),
- Eq(UsedMacro{"COMPILER_ARGUMENT", fileId})));
-}
-
-TEST_F(IncludeCollector, CollectUsedMacrosWithoutExternalDefine)
-{
- auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
- emptyCollector.addFile(fileId, {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.usedMacros(),
- ElementsAre(Eq(UsedMacro{"DEFINED", fileId}),
- Eq(UsedMacro{"IF_DEFINE", fileId}),
- Eq(UsedMacro{"__clang__", fileId}),
- Eq(UsedMacro{"CLASS_EXPORT", fileId}),
- Eq(UsedMacro{"IF_NOT_DEFINE", fileId}),
- Eq(UsedMacro{"MACRO_EXPANSION", fileId}),
- Eq(UsedMacro{"COMPILER_ARGUMENT", fileId})));
-}
-
-TEST_F(IncludeCollector, DontCollectHeaderGuards)
-{
- auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
- emptyCollector.addFile(fileId, {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.usedMacros(),
- Not(Contains(Eq(UsedMacro{"SYMBOLSCOLLECTOR_DEFINES_H", fileId}))));
-}
-
-TEST_F(IncludeCollector, DISABLED_DontCollectDynamicLibraryExports)
-{
- auto fileId = id(TESTDATA_DIR "/symbolscollector_defines.h");
- emptyCollector.addFile(fileId, {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.usedMacros(),
- Not(Contains(Eq(UsedMacro{"CLASS_EXPORT", fileId}))));
-}
-
-TEST_F(IncludeCollector, CollectFileStatuses)
-{
- emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector_main.cpp"), {"cc", "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system"});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.fileStatuses(),
- ElementsAre(
- fileStatus(TESTDATA_DIR "/symbolscollector_main.cpp"),
- fileStatus(TESTDATA_DIR "/symbolscollector_header1.h"),
- fileStatus(TESTDATA_DIR "/symbolscollector_header2.h")));
-}
-
-TEST_F(IncludeCollector, CollectSourceDependencies)
-{
- auto mainFileId = id(TESTDATA_DIR "/symbolscollector_main2.cpp");
- auto header1FileId = id(TESTDATA_DIR "/symbolscollector_header1.h");
- auto header2FileId = id(TESTDATA_DIR "/symbolscollector_header2.h");
- auto header3FileId = id(TESTDATA_DIR "/symbolscollector_header3.h");
- emptyCollector.addFile(mainFileId, {"cc", "-I" TESTDATA_DIR});
-
- emptyCollector.collect();
-
- ASSERT_THAT(emptyCollector.sourceDependencies(),
- UnorderedElementsAre(SourceDependency(mainFileId, header1FileId),
- SourceDependency(mainFileId, header3FileId),
- SourceDependency(header3FileId, header2FileId),
- SourceDependency(header1FileId, header2FileId)));
-}
-
-}
diff --git a/tests/unit/unittest/mockbuilddependenciesgenerator.h b/tests/unit/unittest/mockbuilddependencygenerator.h
index 832c37f0bf..91b8a1422d 100644
--- a/tests/unit/unittest/mockbuilddependenciesgenerator.h
+++ b/tests/unit/unittest/mockbuilddependencygenerator.h
@@ -27,9 +27,9 @@
#include "googletest.h"
-#include <builddependenciesgeneratorinterface.h>
+#include <builddependencygeneratorinterface.h>
-class MockBuildDependenciesGenerator : public ClangBackEnd::BuildDependenciesGeneratorInterface
+class MockBuildDependencyGenerator : public ClangBackEnd::BuildDependencyGeneratorInterface
{
public:
MOCK_METHOD1(create,
diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp
index 29056203e3..2929f2e394 100644
--- a/tests/unit/unittest/pchcreator-test.cpp
+++ b/tests/unit/unittest/pchcreator-test.cpp
@@ -43,21 +43,33 @@
namespace {
+using ClangBackEnd::FilePath;
using ClangBackEnd::FilePathId;
+using ClangBackEnd::FilePathIds;
+using ClangBackEnd::FilePathView;
using ClangBackEnd::GeneratedFiles;
using ClangBackEnd::IdPaths;
using ClangBackEnd::ProjectPartPch;
-using ClangBackEnd::V2::ProjectPartContainer;
+using ClangBackEnd::SourceEntries;
+using ClangBackEnd::SourceEntry;
+using ClangBackEnd::SourceType;
using ClangBackEnd::V2::FileContainer;
-using ClangBackEnd::FilePath;
-using ClangBackEnd::FilePathIds;
-using ClangBackEnd::FilePathView;
+using ClangBackEnd::V2::ProjectPartContainer;
using Utils::PathString;
using Utils::SmallString;
using UnitTests::EndsWith;
+MATCHER_P2(HasIdAndType, sourceId, sourceType,
+ std::string(negation ? "hasn't" : "has") +
+ PrintToString(ClangBackEnd::SourceEntry(sourceId, sourceType,
+ -1)))
+{
+ const ClangBackEnd::SourceEntry &entry = arg;
+ return entry.sourceId == sourceId && entry.sourceType == sourceType;
+}
+
class PchCreator: public ::testing::Test
{
protected:
@@ -74,27 +86,27 @@ protected:
protected:
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
- FilePath main1Path = TESTDATA_DIR "/includecollector/project/main3.cpp";
- FilePath main2Path = TESTDATA_DIR "/includecollector/project/main2.cpp";
- FilePath header1Path = TESTDATA_DIR "/includecollector/project/header1.h";
- FilePath header2Path = TESTDATA_DIR "/includecollector/project/header2.h";
- Utils::SmallStringView generatedFileName = "includecollector/project/generated_file.h";
- FilePath generatedFilePath = TESTDATA_DIR "/includecollector/project/generated_file.h";
+ FilePath main1Path = TESTDATA_DIR "/builddependencycollector/project/main3.cpp";
+ FilePath main2Path = TESTDATA_DIR "/builddependencycollector/project/main2.cpp";
+ FilePath header1Path = TESTDATA_DIR "/builddependencycollector/project/header1.h";
+ FilePath header2Path = TESTDATA_DIR "/builddependencycollector/project/header2.h";
+ Utils::SmallStringView generatedFileName = "builddependencycollector/project/generated_file.h";
+ FilePath generatedFilePath = TESTDATA_DIR "/builddependencycollector/project/generated_file.h";
TestEnvironment environment;
FileContainer generatedFile{{TESTDATA_DIR, generatedFileName}, "#pragma once", {}};
NiceMock<MockPchManagerClient> mockPchManagerClient;
NiceMock<MockClangPathWatcher> mockClangPathWatcher;
ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher};
ProjectPartContainer projectPart1{"project1",
- {"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system", "-Wno-pragma-once-outside-header"},
+ {"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system", "-Wno-pragma-once-outside-header"},
{{"DEFINE", "1"}},
- {TESTDATA_DIR "/includecollector/external", TESTDATA_DIR "/includecollector/project"},
+ {TESTDATA_DIR "/builddependencycollector/external", TESTDATA_DIR "/builddependencycollector/project"},
{id(header1Path)},
{id(main1Path)}};
ProjectPartContainer projectPart2{"project2",
- {"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-x", "c++-header", "-Wno-pragma-once-outside-header"},
+ {"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-x", "c++-header", "-Wno-pragma-once-outside-header"},
{{"DEFINE", "1"}},
- {TESTDATA_DIR "/includecollector/external", TESTDATA_DIR "/includecollector/project"},
+ {TESTDATA_DIR "/builddependencycollector/external", TESTDATA_DIR "/builddependencycollector/project"},
{id(header2Path)},
{id(main2Path)}};
};
@@ -112,7 +124,7 @@ TEST_F(PchCreator, CreateProjectPartCommandLine)
{
auto commandLine = creator.generateProjectPartCommandLine(projectPart1);
- ASSERT_THAT(commandLine, ElementsAre(environment.clangCompilerPath(), "-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system", "-Wno-pragma-once-outside-header"));
+ ASSERT_THAT(commandLine, ElementsAre(environment.clangCompilerPath(), "-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/builddependencycollector/external", "-I", TESTDATA_DIR "/builddependencycollector/project", "-isystem", TESTDATA_DIR "/builddependencycollector/system", "-Wno-pragma-once-outside-header"));
}
TEST_F(PchCreator, CreateProjectPartHeaders)
@@ -135,37 +147,45 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes)
auto includeIds = creator.generateProjectPartPchIncludes(projectPart1);
- ASSERT_THAT(includeIds,
- AllOf(
- Field(&PchCreatorIncludes::includeIds,
- AllOf(Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")),
- Contains(id(TESTDATA_DIR "/includecollector/external/external2.h")),
- Contains(id(TESTDATA_DIR "/includecollector/project/header2.h")),
- Contains(id(TESTDATA_DIR "/includecollector/system/system1.h")))),
- Field(&PchCreatorIncludes::topSystemIncludeIds,
- AllOf(Contains(id(TESTDATA_DIR "/includecollector/system/system1.h")),
- Not(Contains(id(TESTDATA_DIR "/includecollector/system/indirect_system.h"))))),
- Field(&PchCreatorIncludes::topIncludeIds,
- AllOf(Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")),
- Contains(id(TESTDATA_DIR "/includecollector/external/external2.h"))))));
+ ASSERT_THAT(
+ includeIds,
+ AllOf(
+ Contains(HasIdAndType(
+ id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
+ SourceType::TopInclude)),
+ Contains(HasIdAndType(
+ id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
+ SourceType::TopSystemInclude)),
+ Contains(HasIdAndType(
+ id(TESTDATA_DIR
+ "/builddependencycollector/system/indirect_system.h"),
+ SourceType::SystemInclude)),
+ Contains(HasIdAndType(
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/external1.h"),
+ SourceType::TopInclude)),
+ Contains(HasIdAndType(
+ id(TESTDATA_DIR
+ "/builddependencycollector/external/external2.h"),
+ SourceType::TopInclude))));
}
TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent)
{
auto includes = creator.generateProjectPartPchIncludes(projectPart1);
- auto content = creator.generatePchIncludeFileContent(includes.topIncludeIds);
+ auto content = creator.generatePchIncludeFileContent(creator.topIncludeIds(includes));
ASSERT_THAT(std::string(content),
- AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector/project/header2.h\"\n"),
- HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external1.h\"\n"),
- HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external2.h\"\n")));
+ AllOf(HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/project/header2.h\"\n"),
+ HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external1.h\"\n"),
+ HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external2.h\"\n")));
}
TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile)
{
auto includes = creator.generateProjectPartPchIncludes(projectPart1);
- auto content = creator.generatePchIncludeFileContent(includes.topIncludeIds);
+ auto content = creator.generatePchIncludeFileContent(creator.topIncludeIds(includes));
auto pchIncludeFilePath = creator.generateProjectPathPchHeaderFilePath(projectPart1);
auto file = creator.generateFileWithContent(pchIncludeFilePath, content);
file->open(QIODevice::ReadOnly);
@@ -173,9 +193,9 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile)
auto fileContent = file->readAll();
ASSERT_THAT(fileContent.toStdString(),
- AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector/project/header2.h\"\n"),
- HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external1.h\"\n"),
- HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external2.h\"\n")));
+ AllOf(HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/project/header2.h\"\n"),
+ HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external1.h\"\n"),
+ HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external2.h\"\n")));
}
TEST_F(PchCreator, CreateProjectPartPchCompilerArguments)
@@ -235,9 +255,9 @@ TEST_F(PchCreatorVerySlowTest, IdPathsForCreatePchsForProjectParts)
ASSERT_THAT(creator.takeProjectIncludes(),
AllOf(Field(&IdPaths::id, "project1"),
- Field(&IdPaths::filePathIds, AllOf(Contains(id(TESTDATA_DIR "/includecollector/project/header2.h")),
- Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")),
- Contains(id(TESTDATA_DIR "/includecollector/external/external2.h"))))));
+ Field(&IdPaths::filePathIds, AllOf(Contains(id(TESTDATA_DIR "/builddependencycollector/project/header2.h")),
+ Contains(id(TESTDATA_DIR "/builddependencycollector/external/external1.h")),
+ Contains(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"))))));
}
TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForProjectPart)
@@ -276,7 +296,7 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesNoPchForProjectPart
{{"DEFINE", "1"}},
{"/includes"},
{},
- {id(TESTDATA_DIR "/includecollector/project/faulty.cpp")}};
+ {id(TESTDATA_DIR "/builddependencycollector/project/faulty.cpp")}};
creator.generatePch(faultyProjectPart);
@@ -290,15 +310,14 @@ TEST_F(PchCreator, CreateProjectPartSourcesContent)
{
auto content = creator.generateProjectPartSourcesContent(projectPart1);
- ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector/project/main3.cpp\"\n"));
+ ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/builddependencycollector/project/main3.cpp\"\n"));
}
TEST_F(PchCreator, Call)
{
auto content = creator.generateProjectPartSourcesContent(projectPart1);
- ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector/project/main3.cpp\"\n"));
+ ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/builddependencycollector/project/main3.cpp\"\n"));
}
-
}
diff --git a/tests/unit/unittest/pchmanagerserver-test.cpp b/tests/unit/unittest/pchmanagerserver-test.cpp
index 443d6a37b2..153c71b510 100644
--- a/tests/unit/unittest/pchmanagerserver-test.cpp
+++ b/tests/unit/unittest/pchmanagerserver-test.cpp
@@ -74,10 +74,10 @@ protected:
NiceMock<MockPchManagerClient> mockPchManagerClient;
SmallString projectPartId1 = "project1";
SmallString projectPartId2 = "project2";
- PathString main1Path = TESTDATA_DIR "/includecollector_main3.cpp";
- PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp";
- PathString header1Path = TESTDATA_DIR "/includecollector_header1.h";
- PathString header2Path = TESTDATA_DIR "/includecollector_header2.h";
+ PathString main1Path = TESTDATA_DIR "/BuildDependencyCollector_main3.cpp";
+ PathString main2Path = TESTDATA_DIR "/BuildDependencyCollector_main2.cpp";
+ PathString header1Path = TESTDATA_DIR "/BuildDependencyCollector_header1.h";
+ PathString header2Path = TESTDATA_DIR "/BuildDependencyCollector_header2.h";
ClangBackEnd::IdPaths idPath{projectPartId1, {1, 2}};
ProjectPartContainer projectPart1{projectPartId1.clone(),
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp
index 248803cc4b..dcc0e6207e 100644
--- a/tests/unit/unittest/pchtaskgenerator-test.cpp
+++ b/tests/unit/unittest/pchtaskgenerator-test.cpp
@@ -49,8 +49,8 @@ protected:
{"/yi"},
{{1, 1}},
{{1, 2}}};
- SourceEntries firstSources{{1, SourceType::Any, 1}, {2, SourceType::Any, 1}, {10, SourceType::Any, 1}};
- BuildDependency buildDependency{firstSources, {}, {}, {}};
+ SourceEntries firstSources{{1, SourceType::UserInclude, 1}, {2, SourceType::UserInclude, 1}, {10, SourceType::UserInclude, 1}};
+ BuildDependency buildDependency{firstSources, {}};
};
TEST_F(PchTaskGenerator, Create)
diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp
index fef72b47e4..8cd1ab8ef3 100644
--- a/tests/unit/unittest/symbolindexer-test.cpp
+++ b/tests/unit/unittest/symbolindexer-test.cpp
@@ -162,7 +162,7 @@ protected:
ClangBackEnd::FilePathId main2PathId{filePathId(TESTDATA_DIR "/symbolindexer_main2.cpp")};
ClangBackEnd::FilePathId header2PathId{filePathId(TESTDATA_DIR "/symbolindexer_header1.h")};
ClangBackEnd::FilePathId header1PathId{filePathId(TESTDATA_DIR "/symbolindexer_header2.h")};
- PathString generatedFileName = "includecollector_generated_file.h";
+ PathString generatedFileName = "BuildDependencyCollector_generated_file.h";
ClangBackEnd::FilePathId generatedFilePathId21;
ProjectPartContainer projectPart1{"project1",
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro
index c8ecdb66e5..3c17ef126a 100644
--- a/tests/unit/unittest/unittest.pro
+++ b/tests/unit/unittest/unittest.pro
@@ -106,7 +106,8 @@ SOURCES += \
pchtaskgenerator-test.cpp \
compilationdatabaseutils-test.cpp \
builddependenciesprovider-test.cpp \
- builddependenciesstorage-test.cpp
+ builddependenciesstorage-test.cpp \
+ builddependencycollector-test.cpp
!isEmpty(LIBCLANG_LIBS) {
SOURCES += \
@@ -172,7 +173,6 @@ SOURCES += \
clangqueryprojectfindfilter-test.cpp \
clangquery-test.cpp \
gtest-clang-printing.cpp \
- includecollector-test.cpp \
pchcreator-test.cpp \
refactoringclientserverinprocess-test.cpp \
refactoringclient-test.cpp \
@@ -252,8 +252,8 @@ HEADERS += \
mocktaskscheduler.h \
mockbuilddependenciesprovider.h \
mockmodifiedtimechecker.h \
- mockbuilddependenciesgenerator.h \
- mockbuilddependenciesstorage.h
+ mockbuilddependenciesstorage.h \
+ mockbuilddependencygenerator.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \