forked from qt-creator/qt-creator
C++: fix include/framework path handling.
Instead of having two lists of paths, now only one list is used where both include paths and framework paths can be mixed. This reflects the way the compiler is invoked, and retains the (correct) search order. Task-number: QTCREATORBUG-11599 Change-Id: I373953e3e305df5b7a0d10920e12d146584adf9f Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -123,11 +123,11 @@ static QString &removeTrailingWhitespace(QString &input)
|
||||
/// Exactly one TestFile must contain the cursor position marker '@' in the originalSource.
|
||||
QuickFixTestCase::QuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &theTestFiles,
|
||||
CppQuickFixFactory *factory,
|
||||
const QStringList &includePaths,
|
||||
const ProjectPart::HeaderPaths &headerPaths,
|
||||
int resultIndex)
|
||||
: m_testFiles(theTestFiles)
|
||||
, m_cppCodeStylePreferences(0)
|
||||
, m_restoreIncludePaths(false)
|
||||
, m_restoreHeaderPaths(false)
|
||||
{
|
||||
QVERIFY(succeededSoFar());
|
||||
|
||||
@@ -144,10 +144,10 @@ QuickFixTestCase::QuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &theTe
|
||||
testFile->writeToDisk();
|
||||
|
||||
// Set appropriate include paths
|
||||
if (!includePaths.isEmpty()) {
|
||||
m_restoreIncludePaths = true;
|
||||
m_includePathsToRestore = m_modelManager->includePaths();
|
||||
m_modelManager->setIncludePaths(includePaths);
|
||||
if (!headerPaths.isEmpty()) {
|
||||
m_restoreHeaderPaths = true;
|
||||
m_headerPathsToRestore = m_modelManager->headerPaths();
|
||||
m_modelManager->setHeaderPaths(headerPaths);
|
||||
}
|
||||
|
||||
// Update Code Model
|
||||
@@ -213,14 +213,22 @@ QuickFixTestCase::~QuickFixTestCase()
|
||||
m_cppCodeStylePreferences->setCurrentDelegate(m_cppCodeStylePreferencesOriginalDelegateId);
|
||||
|
||||
// Restore include paths
|
||||
if (m_restoreIncludePaths)
|
||||
m_modelManager->setIncludePaths(m_includePathsToRestore);
|
||||
if (m_restoreHeaderPaths)
|
||||
m_modelManager->setHeaderPaths(m_headerPathsToRestore);
|
||||
|
||||
// Remove created files from file system
|
||||
foreach (const QuickFixTestDocument::Ptr &testDocument, m_testFiles)
|
||||
QVERIFY(QFile::remove(testDocument->filePath()));
|
||||
}
|
||||
|
||||
void QuickFixTestCase::run(const QList<QuickFixTestDocument::Ptr> &theTestFiles,
|
||||
CppQuickFixFactory *factory, const QString &incPath)
|
||||
{
|
||||
ProjectPart::HeaderPaths hps;
|
||||
hps += ProjectPart::HeaderPath(incPath, ProjectPart::HeaderPath::IncludePath);
|
||||
QuickFixTestCase(theTestFiles, factory, hps);
|
||||
}
|
||||
|
||||
/// Delegates directly to AddIncludeForUndefinedIdentifierOp for easier testing.
|
||||
class AddIncludeForUndefinedIdentifierTestFactory : public CppQuickFixFactory
|
||||
{
|
||||
@@ -1289,7 +1297,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_afterClass()
|
||||
testFiles << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||
|
||||
InsertDefFromDecl factory;
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(), 1);
|
||||
QuickFixTestCase(testFiles, &factory, ProjectPart::HeaderPaths(), 1);
|
||||
}
|
||||
|
||||
/// Check from header file: If there is a source file, insert the definition in the source file.
|
||||
@@ -1478,7 +1486,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_insideClass()
|
||||
"};";
|
||||
|
||||
InsertDefFromDecl factory;
|
||||
QuickFixTestCase(singleDocument(original, expected), &factory, QStringList(), 1);
|
||||
QuickFixTestCase(singleDocument(original, expected), &factory, ProjectPart::HeaderPaths(), 1);
|
||||
}
|
||||
|
||||
/// Check not triggering when definition exists
|
||||
@@ -1492,7 +1500,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitio
|
||||
const QByteArray expected = original;
|
||||
|
||||
InsertDefFromDecl factory;
|
||||
QuickFixTestCase test(singleDocument(original, expected), &factory, QStringList(), 1);
|
||||
QuickFixTestCase test(singleDocument(original, expected), &factory, ProjectPart::HeaderPaths(),
|
||||
1);
|
||||
}
|
||||
|
||||
/// Find right implementation file.
|
||||
@@ -1910,7 +1919,7 @@ void insertToSectionDeclFromDef(const QByteArray §ion, int sectionIndex)
|
||||
testFiles << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||
|
||||
InsertDeclFromDef factory;
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(), sectionIndex);
|
||||
QuickFixTestCase(testFiles, &factory, ProjectPart::HeaderPaths(), sectionIndex);
|
||||
}
|
||||
|
||||
/// Check from source file: Insert in header file.
|
||||
@@ -1961,7 +1970,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_normal()
|
||||
|
||||
// Do not use the test factory, at least once we want to go through the "full stack".
|
||||
AddIncludeForUndefinedIdentifier factory;
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Ignore *.moc includes
|
||||
@@ -1986,7 +1995,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc()
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert include at top for a sorted group
|
||||
@@ -2012,7 +2021,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop(
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert include in the middle for a sorted group
|
||||
@@ -2038,7 +2047,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingMidd
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert include at bottom for a sorted group
|
||||
@@ -2064,7 +2073,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingBott
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: For an unsorted group the new include is appended
|
||||
@@ -2090,7 +2099,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_appendToUns
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert a local include at front if there are only global includes
|
||||
@@ -2117,7 +2126,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstLocalI
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert a global include at back if there are only local includes
|
||||
@@ -2146,7 +2155,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstGlobal
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<file.h>"));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Prefer group with longest matching prefix
|
||||
@@ -2176,7 +2185,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_preferGroup
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"prefixc.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Create a new include group if there are only include groups with a different include dir
|
||||
@@ -2203,7 +2212,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_newGroupIfO
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Include group with mixed include dirs, sorted --> insert properly
|
||||
@@ -2231,7 +2240,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsSo
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<firstlib/file.h>"));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Include group with mixed include dirs, unsorted --> append
|
||||
@@ -2259,7 +2268,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsUn
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lastlib/file.h>"));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Include group with mixed include types
|
||||
@@ -2285,7 +2294,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"z.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Include group with mixed include types
|
||||
@@ -2311,7 +2320,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"a.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Include group with mixed include types
|
||||
@@ -2337,7 +2346,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"lib/file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Include group with mixed include types
|
||||
@@ -2363,7 +2372,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lib/file.h>"));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert very first include
|
||||
@@ -2386,7 +2395,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_noinclude()
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert very first include if there is a c++ style comment on top
|
||||
@@ -2415,7 +2424,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: Insert very first include if there is a c style comment on top
|
||||
@@ -2448,7 +2457,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalIncludePath());
|
||||
}
|
||||
|
||||
/// Check: If a "Qt Class" was not found by the locator, check the header files in the Qt
|
||||
@@ -2472,8 +2481,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomet
|
||||
+ "/file.cpp", original, expected);
|
||||
|
||||
AddIncludeForUndefinedIdentifier factory;
|
||||
QuickFixTestCase(testFiles,&factory,
|
||||
QStringList(CppTools::Tests::TestIncludePaths::globalQtCoreIncludePath()));
|
||||
QuickFixTestCase::run(testFiles, &factory, TestIncludePaths::globalQtCoreIncludePath());
|
||||
|
||||
}
|
||||
|
||||
/// Check: Move definition from header to cpp.
|
||||
@@ -2638,7 +2647,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside2()
|
||||
testFiles << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||
|
||||
MoveFuncDefOutside factory;
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(), 1);
|
||||
QuickFixTestCase(testFiles, &factory, ProjectPart::HeaderPaths(), 1);
|
||||
}
|
||||
|
||||
/// Check: Move definition from header to cpp (with namespace).
|
||||
@@ -2951,7 +2960,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_afterClass()
|
||||
testFiles << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||
|
||||
MoveFuncDefOutside factory;
|
||||
QuickFixTestCase(testFiles, &factory, QStringList(), 1);
|
||||
QuickFixTestCase(testFiles, &factory, ProjectPart::HeaderPaths(), 1);
|
||||
}
|
||||
|
||||
/// Check if whitespace is respected for operator functions
|
||||
|
||||
Reference in New Issue
Block a user