forked from qt-creator/qt-creator
ClangcodeModel: Move test creation closer to tested code
Change-Id: Ifb6771673aa8639d2ee23d1f34b1ff821000e348 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -86,16 +86,16 @@ void ClangCodeModelPlugin::initialize()
|
|||||||
updateStaleIndexEntries.addToContainer(CppEditor::Constants::M_CONTEXT);
|
updateStaleIndexEntries.addToContainer(CppEditor::Constants::M_CONTEXT);
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
addTest<Tests::ActivationSequenceProcessorTest>();
|
addTestCreator(createActivationSequenceProcessorTest);
|
||||||
addTest<Tests::ClangdTestCompletion>();
|
addTestCreator(createClangdTestCompletion);
|
||||||
addTest<Tests::ClangdTestExternalChanges>();
|
addTestCreator(createClangdTestExternalChanges);
|
||||||
addTest<Tests::ClangdTestFindReferences>();
|
addTestCreator(createClangdTestFindReferences);
|
||||||
addTest<Tests::ClangdTestFollowSymbol>();
|
addTestCreator(createClangdTestFollowSymbol);
|
||||||
addTest<Tests::ClangdTestHighlighting>();
|
addTestCreator(createClangdTestHighlighting);
|
||||||
addTest<Tests::ClangdTestIndirectChanges>();
|
addTestCreator(createClangdTestIndirectChanges);
|
||||||
addTest<Tests::ClangdTestLocalReferences>();
|
addTestCreator(createClangdTestLocalReferences);
|
||||||
addTest<Tests::ClangdTestTooltips>();
|
addTestCreator(createClangdTestTooltips);
|
||||||
addTest<Tests::ClangFixItTest>();
|
addTestCreator(createClangFixItTest);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
namespace ClangCodeModel::Internal::Tests {
|
namespace ClangCodeModel::Internal {
|
||||||
|
|
||||||
static bool resultIs(const ActivationSequenceProcessor &processor, Kind expectedKind,
|
static bool resultIs(const ActivationSequenceProcessor &processor, Kind expectedKind,
|
||||||
int expectedOffset, int expectedNewPos)
|
int expectedOffset, int expectedNewPos)
|
||||||
@@ -21,6 +21,33 @@ static bool resultIs(const ActivationSequenceProcessor &processor, Kind expected
|
|||||||
&& processor.operatorStartPosition() == expectedNewPos;
|
&& processor.operatorStartPosition() == expectedNewPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ActivationSequenceProcessorTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void testCouldNotProcesseRandomCharacters();
|
||||||
|
void testCouldNotProcesseEmptyString();
|
||||||
|
void testDot();
|
||||||
|
void testComma();
|
||||||
|
void testLeftParenAsFunctionCall();
|
||||||
|
void testLeftParenNotAsFunctionCall();
|
||||||
|
void testColonColon();
|
||||||
|
void testArrow();
|
||||||
|
void testDotStar();
|
||||||
|
void testArrowStar();
|
||||||
|
void testDoxyGenCommentBackSlash();
|
||||||
|
void testDoxyGenCommentAt();
|
||||||
|
void testAngleStringLiteral();
|
||||||
|
void testStringLiteral();
|
||||||
|
void testSlash();
|
||||||
|
void testPound();
|
||||||
|
void testPositionIsOne();
|
||||||
|
void testPositionIsTwo();
|
||||||
|
void testPositionIsTwoWithASingleSign();
|
||||||
|
void testPositionIsThree();
|
||||||
|
};
|
||||||
|
|
||||||
void ActivationSequenceProcessorTest::testCouldNotProcesseRandomCharacters()
|
void ActivationSequenceProcessorTest::testCouldNotProcesseRandomCharacters()
|
||||||
{
|
{
|
||||||
ActivationSequenceProcessor processor(QStringLiteral("xxx"), 3, false);
|
ActivationSequenceProcessor processor(QStringLiteral("xxx"), 3, false);
|
||||||
@@ -155,4 +182,11 @@ void ActivationSequenceProcessorTest::testPositionIsThree()
|
|||||||
QVERIFY(resultIs(processor, T_ANGLE_STRING_LITERAL, 1, 2));
|
QVERIFY(resultIs(processor, T_ANGLE_STRING_LITERAL, 1, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ClangCodeModel::Internal::Tests
|
QObject *createActivationSequenceProcessorTest()
|
||||||
|
{
|
||||||
|
return new ActivationSequenceProcessorTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ClangCodeModel::Internal
|
||||||
|
|
||||||
|
#include "activationsequenceprocessortest.moc"
|
||||||
|
@@ -5,33 +5,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace ClangCodeModel::Internal::Tests {
|
namespace ClangCodeModel::Internal {
|
||||||
|
|
||||||
class ActivationSequenceProcessorTest : public QObject
|
QObject *createActivationSequenceProcessorTest();
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private slots:
|
} // ClangCodeModel::Internal
|
||||||
void testCouldNotProcesseRandomCharacters();
|
|
||||||
void testCouldNotProcesseEmptyString();
|
|
||||||
void testDot();
|
|
||||||
void testComma();
|
|
||||||
void testLeftParenAsFunctionCall();
|
|
||||||
void testLeftParenNotAsFunctionCall();
|
|
||||||
void testColonColon();
|
|
||||||
void testArrow();
|
|
||||||
void testDotStar();
|
|
||||||
void testArrowStar();
|
|
||||||
void testDoxyGenCommentBackSlash();
|
|
||||||
void testDoxyGenCommentAt();
|
|
||||||
void testAngleStringLiteral();
|
|
||||||
void testStringLiteral();
|
|
||||||
void testSlash();
|
|
||||||
void testPound();
|
|
||||||
void testPositionIsOne();
|
|
||||||
void testPositionIsTwo();
|
|
||||||
void testPositionIsTwoWithASingleSign();
|
|
||||||
void testPositionIsThree();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ClangCodeModel::Internal::Tests
|
|
||||||
|
@@ -8,25 +8,37 @@
|
|||||||
#include "../clangmodelmanagersupport.h"
|
#include "../clangmodelmanagersupport.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
|
||||||
#include <cplusplus/FindUsages.h>
|
#include <cplusplus/FindUsages.h>
|
||||||
|
|
||||||
#include <cppeditor/cppcodemodelsettings.h>
|
#include <cppeditor/cppcodemodelsettings.h>
|
||||||
#include <cppeditor/cppeditorwidget.h>
|
#include <cppeditor/cppeditorwidget.h>
|
||||||
#include <cppeditor/cpptoolsreuse.h>
|
#include <cppeditor/cpptoolsreuse.h>
|
||||||
#include <cppeditor/cpptoolstestcase.h>
|
#include <cppeditor/cpptoolstestcase.h>
|
||||||
#include <cppeditor/semantichighlighter.h>
|
#include <cppeditor/semantichighlighter.h>
|
||||||
|
|
||||||
#include <languageclient/languageclientmanager.h>
|
#include <languageclient/languageclientmanager.h>
|
||||||
|
|
||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
|
#include <qtsupport/qtkitaspect.h>
|
||||||
|
|
||||||
|
#include <texteditor/blockrange.h>
|
||||||
#include <texteditor/codeassist/assistproposaliteminterface.h>
|
#include <texteditor/codeassist/assistproposaliteminterface.h>
|
||||||
|
#include <texteditor/codeassist/genericproposal.h>
|
||||||
#include <texteditor/codeassist/textdocumentmanipulatorinterface.h>
|
#include <texteditor/codeassist/textdocumentmanipulatorinterface.h>
|
||||||
|
#include <texteditor/semantichighlighter.h>
|
||||||
#include <texteditor/textmark.h>
|
#include <texteditor/textmark.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/searchresultitem.h>
|
||||||
#include <utils/textutils.h>
|
#include <utils/textutils.h>
|
||||||
#include <qtsupport/qtkitaspect.h>
|
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
@@ -47,22 +59,16 @@ using namespace ProjectExplorer;
|
|||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel::Internal {
|
||||||
namespace Internal {
|
|
||||||
namespace Tests {
|
|
||||||
|
|
||||||
using Range = std::tuple<int, int, int>;
|
using Range = std::tuple<int, int, int>;
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace ClangCodeModel::Internal
|
||||||
} // namespace Internal
|
|
||||||
} // namespace ClangCodeModel
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ClangCodeModel::Internal::Tests::Range)
|
Q_DECLARE_METATYPE(ClangCodeModel::Internal::Range)
|
||||||
Q_DECLARE_METATYPE(IAssistProposal *)
|
Q_DECLARE_METATYPE(IAssistProposal *)
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel::Internal {
|
||||||
namespace Internal {
|
|
||||||
namespace Tests {
|
|
||||||
|
|
||||||
const Usage::Tags Initialization{Usage::Tag::Declaration, Usage::Tag::Write};
|
const Usage::Tags Initialization{Usage::Tag::Declaration, Usage::Tag::Write};
|
||||||
|
|
||||||
@@ -92,6 +98,42 @@ int timeOutInMs()
|
|||||||
return timeOut;
|
return timeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClangdTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
~ClangdTest();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Convention: base bame == name of parent dir
|
||||||
|
void setProjectFileName(const QString &fileName) { m_projectFileName = fileName; }
|
||||||
|
|
||||||
|
void setSourceFileNames(const QStringList &fileNames) { m_sourceFileNames = fileNames; }
|
||||||
|
void setMinimumVersion(int version) { m_minVersion = version; }
|
||||||
|
|
||||||
|
ClangdClient *client() const { return m_client; }
|
||||||
|
Utils::FilePath filePath(const QString &fileName) const;
|
||||||
|
TextEditor::TextDocument *document(const QString &fileName) const {
|
||||||
|
return m_sourceDocuments.value(fileName);
|
||||||
|
}
|
||||||
|
ProjectExplorer::Project *project() const { return m_project; }
|
||||||
|
void waitForNewClient(bool withIndex = true);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
virtual void initTestCase();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CppEditor::Tests::TemporaryCopiedDir *m_projectDir = nullptr;
|
||||||
|
QString m_projectFileName;
|
||||||
|
QStringList m_sourceFileNames;
|
||||||
|
QHash<QString, TextEditor::TextDocument *> m_sourceDocuments;
|
||||||
|
ProjectExplorer::Kit *m_kit = nullptr;
|
||||||
|
ProjectExplorer::Project *m_project = nullptr;
|
||||||
|
ClangdClient *m_client = nullptr;
|
||||||
|
int m_minVersion = -1;
|
||||||
|
};
|
||||||
|
|
||||||
ClangdTest::~ClangdTest()
|
ClangdTest::~ClangdTest()
|
||||||
{
|
{
|
||||||
EditorManager::closeAllEditors(false);
|
EditorManager::closeAllEditors(false);
|
||||||
@@ -182,12 +224,27 @@ void ClangdTest::initTestCase()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangdTestFindReferences::ClangdTestFindReferences()
|
class ClangdTestFindReferences final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestFindReferences()
|
||||||
{
|
{
|
||||||
setProjectFileName("find-usages.pro");
|
setProjectFileName("find-usages.pro");
|
||||||
setSourceFileNames({"defs.h", "main.cpp"});
|
setSourceFileNames({"defs.h", "main.cpp"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void initTestCase() override;
|
||||||
|
void init() { m_actualResults.clear(); }
|
||||||
|
void test_data();
|
||||||
|
void test();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Utils::SearchResultItems m_actualResults;
|
||||||
|
};
|
||||||
|
|
||||||
void ClangdTestFindReferences::initTestCase()
|
void ClangdTestFindReferences::initTestCase()
|
||||||
{
|
{
|
||||||
ClangdTest::initTestCase();
|
ClangdTest::initTestCase();
|
||||||
@@ -333,12 +390,23 @@ void ClangdTestFindReferences::test()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ClangdTestFollowSymbol::ClangdTestFollowSymbol()
|
class ClangdTestFollowSymbol final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestFollowSymbol()
|
||||||
{
|
{
|
||||||
setProjectFileName("follow-symbol.pro");
|
setProjectFileName("follow-symbol.pro");
|
||||||
setSourceFileNames({"main.cpp", "header.h"});
|
setSourceFileNames({"main.cpp", "header.h"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void test_data();
|
||||||
|
void test();
|
||||||
|
void testFollowSymbolInHandler();
|
||||||
|
};
|
||||||
|
|
||||||
void ClangdTestFollowSymbol::test_data()
|
void ClangdTestFollowSymbol::test_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("sourceFile");
|
QTest::addColumn<QString>("sourceFile");
|
||||||
@@ -462,12 +530,22 @@ void ClangdTestFollowSymbol::testFollowSymbolInHandler()
|
|||||||
timer.stop();
|
timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangdTestLocalReferences::ClangdTestLocalReferences()
|
class ClangdTestLocalReferences final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestLocalReferences()
|
||||||
{
|
{
|
||||||
setProjectFileName("local-references.pro");
|
setProjectFileName("local-references.pro");
|
||||||
setSourceFileNames({"references.cpp"});
|
setSourceFileNames({"references.cpp"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void test_data();
|
||||||
|
void test();
|
||||||
|
};
|
||||||
|
|
||||||
// We currently only support local variables, but if and when clangd implements
|
// We currently only support local variables, but if and when clangd implements
|
||||||
// the linkedEditingRange request, we can change the expected values for
|
// the linkedEditingRange request, we can change the expected values for
|
||||||
// the file-scope test cases from empty ranges to the actual locations.
|
// the file-scope test cases from empty ranges to the actual locations.
|
||||||
@@ -583,12 +661,23 @@ void ClangdTestLocalReferences::test()
|
|||||||
|
|
||||||
// This tests our help item construction, not the actual tooltip contents. Those come
|
// This tests our help item construction, not the actual tooltip contents. Those come
|
||||||
// pre-formatted from clangd.
|
// pre-formatted from clangd.
|
||||||
ClangdTestTooltips::ClangdTestTooltips()
|
|
||||||
|
class ClangdTestTooltips final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestTooltips()
|
||||||
{
|
{
|
||||||
setProjectFileName("tooltips.pro");
|
setProjectFileName("tooltips.pro");
|
||||||
setSourceFileNames({"tooltips.cpp"});
|
setSourceFileNames({"tooltips.cpp"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void test_data();
|
||||||
|
void test();
|
||||||
|
};
|
||||||
|
|
||||||
void ClangdTestTooltips::test_data()
|
void ClangdTestTooltips::test_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<int>("line");
|
QTest::addColumn<int>("line");
|
||||||
@@ -718,12 +807,29 @@ void ClangdTestTooltips::test()
|
|||||||
QCOMPARE(helpItem.docMark(), expectedMark);
|
QCOMPARE(helpItem.docMark(), expectedMark);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClangdTestHighlighting::ClangdTestHighlighting()
|
|
||||||
|
class ClangdTestHighlighting final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestHighlighting()
|
||||||
{
|
{
|
||||||
setProjectFileName("highlighting.pro");
|
setProjectFileName("highlighting.pro");
|
||||||
setSourceFileNames({"highlighting.cpp"});
|
setSourceFileNames({"highlighting.cpp"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void initTestCase() override;
|
||||||
|
void test_data();
|
||||||
|
void test();
|
||||||
|
void testIfdefedOutBlocks();
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextEditor::HighlightingResults m_results;
|
||||||
|
QList<TextEditor::BlockRange> m_ifdefedOutBlocks;
|
||||||
|
};
|
||||||
|
|
||||||
void ClangdTestHighlighting::initTestCase()
|
void ClangdTestHighlighting::initTestCase()
|
||||||
{
|
{
|
||||||
ClangdTest::initTestCase();
|
ClangdTest::initTestCase();
|
||||||
@@ -1428,7 +1534,7 @@ void ClangdTestHighlighting::testIfdefedOutBlocks()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Manipulator : public TextDocumentManipulatorInterface
|
class Manipulator final : public TextDocumentManipulatorInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Manipulator()
|
Manipulator()
|
||||||
@@ -1497,6 +1603,56 @@ private:
|
|||||||
int m_skipPos = -1;
|
int m_skipPos = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ClangdTestCompletion final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestCompletion();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void initTestCase() override;
|
||||||
|
|
||||||
|
void testCompletePreprocessorKeywords();
|
||||||
|
void testCompleteIncludeDirective();
|
||||||
|
|
||||||
|
void testCompleteGlobals();
|
||||||
|
void testCompleteMembers();
|
||||||
|
void testCompleteMembersFromInside();
|
||||||
|
void testCompleteMembersFromOutside();
|
||||||
|
void testCompleteMembersFromFriend();
|
||||||
|
void testFunctionAddress();
|
||||||
|
void testFunctionHints();
|
||||||
|
void testFunctionHintsFiltered();
|
||||||
|
void testFunctionHintConstructor();
|
||||||
|
void testCompleteClassAndConstructor();
|
||||||
|
void testCompletePrivateFunctionDefinition();
|
||||||
|
|
||||||
|
void testCompleteWithDotToArrowCorrection();
|
||||||
|
void testDontCompleteWithDotToArrowCorrectionForFloats();
|
||||||
|
|
||||||
|
void testCompleteCodeInGeneratedUiFile();
|
||||||
|
|
||||||
|
void testSignalCompletion_data();
|
||||||
|
void testSignalCompletion();
|
||||||
|
|
||||||
|
void testCompleteAfterProjectChange();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void startCollectingHighlightingInfo();
|
||||||
|
void getProposal(const QString &fileName, TextEditor::ProposalModelPtr &proposalModel,
|
||||||
|
const QString &insertString = {}, int *cursorPos = nullptr);
|
||||||
|
static bool hasItem(TextEditor::ProposalModelPtr model, const QString &text,
|
||||||
|
const QString &detail = {});
|
||||||
|
static bool hasSnippet(TextEditor::ProposalModelPtr model, const QString &text);
|
||||||
|
static int itemsWithText(TextEditor::ProposalModelPtr model, const QString &text);
|
||||||
|
static TextEditor::AssistProposalItemInterface *getItem(
|
||||||
|
TextEditor::ProposalModelPtr model, const QString &text, const QString &detail = {});
|
||||||
|
|
||||||
|
QSet<Utils::FilePath> m_documentsWithHighlighting;
|
||||||
|
};
|
||||||
|
|
||||||
ClangdTestCompletion::ClangdTestCompletion()
|
ClangdTestCompletion::ClangdTestCompletion()
|
||||||
{
|
{
|
||||||
setProjectFileName("completion.pro");
|
setProjectFileName("completion.pro");
|
||||||
@@ -2006,12 +2162,21 @@ AssistProposalItemInterface *ClangdTestCompletion::getItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ClangdTestExternalChanges::ClangdTestExternalChanges()
|
class ClangdTestExternalChanges final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestExternalChanges()
|
||||||
{
|
{
|
||||||
setProjectFileName("completion.pro");
|
setProjectFileName("completion.pro");
|
||||||
setSourceFileNames({"mainwindow.cpp", "main.cpp"});
|
setSourceFileNames({"mainwindow.cpp", "main.cpp"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void test();
|
||||||
|
};
|
||||||
|
|
||||||
void ClangdTestExternalChanges::test()
|
void ClangdTestExternalChanges::test()
|
||||||
{
|
{
|
||||||
ClangdClient * const oldClient = client();
|
ClangdClient * const oldClient = client();
|
||||||
@@ -2053,6 +2218,18 @@ void ClangdTestExternalChanges::test()
|
|||||||
QVERIFY(waitForSignalOrTimeout(client(), &ClangdClient::textMarkCreated, timeOutInMs()));
|
QVERIFY(waitForSignalOrTimeout(client(), &ClangdClient::textMarkCreated, timeOutInMs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ClangdTestIndirectChanges final : public ClangdTest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClangdTestIndirectChanges();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void test();
|
||||||
|
};
|
||||||
|
|
||||||
ClangdTestIndirectChanges::ClangdTestIndirectChanges()
|
ClangdTestIndirectChanges::ClangdTestIndirectChanges()
|
||||||
{
|
{
|
||||||
setProjectFileName("indirect-changes.pro");
|
setProjectFileName("indirect-changes.pro");
|
||||||
@@ -2094,6 +2271,46 @@ void ClangdTestIndirectChanges::test()
|
|||||||
QVERIFY(src->marks().isEmpty());
|
QVERIFY(src->marks().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Tests
|
QObject *createClangdTestCompletion()
|
||||||
} // namespace Internal
|
{
|
||||||
} // namespace ClangCodeModel
|
return new ClangdTestCompletion;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *createClangdTestExternalChanges()
|
||||||
|
{
|
||||||
|
return new ClangdTestExternalChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *createClangdTestFindReferences()
|
||||||
|
{
|
||||||
|
return new ClangdTestFindReferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *createClangdTestFollowSymbol()
|
||||||
|
{
|
||||||
|
return new ClangdTestFollowSymbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *createClangdTestHighlighting()
|
||||||
|
{
|
||||||
|
return new ClangdTestHighlighting;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *createClangdTestIndirectChanges()
|
||||||
|
{
|
||||||
|
return new ClangdTestIndirectChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *createClangdTestLocalReferences()
|
||||||
|
{
|
||||||
|
return new ClangdTestLocalReferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *createClangdTestTooltips()
|
||||||
|
{
|
||||||
|
return new ClangdTestTooltips;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ClangCodeModel::Internal
|
||||||
|
|
||||||
|
#include "clangdtests.moc"
|
||||||
|
@@ -3,202 +3,18 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cppeditor/cpptoolstestcase.h>
|
|
||||||
#include <texteditor/blockrange.h>
|
|
||||||
#include <texteditor/codeassist/genericproposal.h>
|
|
||||||
#include <texteditor/semantichighlighter.h>
|
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/searchresultitem.h>
|
|
||||||
|
|
||||||
#include <QHash>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ClangCodeModel::Internal {
|
||||||
class Kit;
|
|
||||||
class Project;
|
|
||||||
}
|
|
||||||
namespace TextEditor { class TextDocument; }
|
|
||||||
|
|
||||||
namespace ClangCodeModel {
|
QObject *createClangdTestCompletion();
|
||||||
namespace Internal {
|
QObject *createClangdTestExternalChanges();
|
||||||
class ClangdClient;
|
QObject *createClangdTestFindReferences();
|
||||||
namespace Tests {
|
QObject *createClangdTestFollowSymbol();
|
||||||
|
QObject *createClangdTestHighlighting();
|
||||||
|
QObject *createClangdTestIndirectChanges();
|
||||||
|
QObject *createClangdTestLocalReferences();
|
||||||
|
QObject *createClangdTestTooltips();
|
||||||
|
|
||||||
class ClangdTest : public QObject
|
} // ClangCodeModel::Internal
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
~ClangdTest();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// Convention: base bame == name of parent dir
|
|
||||||
void setProjectFileName(const QString &fileName) { m_projectFileName = fileName; }
|
|
||||||
|
|
||||||
void setSourceFileNames(const QStringList &fileNames) { m_sourceFileNames = fileNames; }
|
|
||||||
void setMinimumVersion(int version) { m_minVersion = version; }
|
|
||||||
|
|
||||||
ClangdClient *client() const { return m_client; }
|
|
||||||
Utils::FilePath filePath(const QString &fileName) const;
|
|
||||||
TextEditor::TextDocument *document(const QString &fileName) const {
|
|
||||||
return m_sourceDocuments.value(fileName);
|
|
||||||
}
|
|
||||||
ProjectExplorer::Project *project() const { return m_project; }
|
|
||||||
void waitForNewClient(bool withIndex = true);
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
virtual void initTestCase();
|
|
||||||
|
|
||||||
private:
|
|
||||||
CppEditor::Tests::TemporaryCopiedDir *m_projectDir = nullptr;
|
|
||||||
QString m_projectFileName;
|
|
||||||
QStringList m_sourceFileNames;
|
|
||||||
QHash<QString, TextEditor::TextDocument *> m_sourceDocuments;
|
|
||||||
ProjectExplorer::Kit *m_kit = nullptr;
|
|
||||||
ProjectExplorer::Project *m_project = nullptr;
|
|
||||||
ClangdClient *m_client = nullptr;
|
|
||||||
int m_minVersion = -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestFindReferences : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ClangdTestFindReferences();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void initTestCase() override;
|
|
||||||
void init() { m_actualResults.clear(); }
|
|
||||||
void test_data();
|
|
||||||
void test();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Utils::SearchResultItems m_actualResults;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestFollowSymbol : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ClangdTestFollowSymbol();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void test_data();
|
|
||||||
void test();
|
|
||||||
void testFollowSymbolInHandler();
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestLocalReferences : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ClangdTestLocalReferences();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void test_data();
|
|
||||||
void test();
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestTooltips : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ClangdTestTooltips();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void test_data();
|
|
||||||
void test();
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestHighlighting : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ClangdTestHighlighting();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void initTestCase() override;
|
|
||||||
void test_data();
|
|
||||||
void test();
|
|
||||||
void testIfdefedOutBlocks();
|
|
||||||
|
|
||||||
private:
|
|
||||||
TextEditor::HighlightingResults m_results;
|
|
||||||
QList<TextEditor::BlockRange> m_ifdefedOutBlocks;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestCompletion : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ClangdTestCompletion();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void initTestCase() override;
|
|
||||||
|
|
||||||
void testCompletePreprocessorKeywords();
|
|
||||||
void testCompleteIncludeDirective();
|
|
||||||
|
|
||||||
void testCompleteGlobals();
|
|
||||||
void testCompleteMembers();
|
|
||||||
void testCompleteMembersFromInside();
|
|
||||||
void testCompleteMembersFromOutside();
|
|
||||||
void testCompleteMembersFromFriend();
|
|
||||||
void testFunctionAddress();
|
|
||||||
void testFunctionHints();
|
|
||||||
void testFunctionHintsFiltered();
|
|
||||||
void testFunctionHintConstructor();
|
|
||||||
void testCompleteClassAndConstructor();
|
|
||||||
void testCompletePrivateFunctionDefinition();
|
|
||||||
|
|
||||||
void testCompleteWithDotToArrowCorrection();
|
|
||||||
void testDontCompleteWithDotToArrowCorrectionForFloats();
|
|
||||||
|
|
||||||
void testCompleteCodeInGeneratedUiFile();
|
|
||||||
|
|
||||||
void testSignalCompletion_data();
|
|
||||||
void testSignalCompletion();
|
|
||||||
|
|
||||||
void testCompleteAfterProjectChange();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void startCollectingHighlightingInfo();
|
|
||||||
void getProposal(const QString &fileName, TextEditor::ProposalModelPtr &proposalModel,
|
|
||||||
const QString &insertString = {}, int *cursorPos = nullptr);
|
|
||||||
static bool hasItem(TextEditor::ProposalModelPtr model, const QString &text,
|
|
||||||
const QString &detail = {});
|
|
||||||
static bool hasSnippet(TextEditor::ProposalModelPtr model, const QString &text);
|
|
||||||
static int itemsWithText(TextEditor::ProposalModelPtr model, const QString &text);
|
|
||||||
static TextEditor::AssistProposalItemInterface *getItem(
|
|
||||||
TextEditor::ProposalModelPtr model, const QString &text, const QString &detail = {});
|
|
||||||
|
|
||||||
QSet<Utils::FilePath> m_documentsWithHighlighting;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestExternalChanges : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
ClangdTestExternalChanges();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void test();
|
|
||||||
};
|
|
||||||
|
|
||||||
class ClangdTestIndirectChanges : public ClangdTest
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
ClangdTestIndirectChanges();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void test();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Tests
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace ClangCodeModel
|
|
||||||
|
|
||||||
|
@@ -5,13 +5,38 @@
|
|||||||
|
|
||||||
#include "../clangfixitoperation.h"
|
#include "../clangfixitoperation.h"
|
||||||
|
|
||||||
|
#include <cppeditor/cpptoolstestcase.h>
|
||||||
|
|
||||||
#include <utils/changeset.h>
|
#include <utils/changeset.h>
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QScopedPointer>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
namespace ClangCodeModel::Internal::Tests {
|
namespace ClangCodeModel::Internal {
|
||||||
|
|
||||||
|
class ClangFixItTest final : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void init();
|
||||||
|
void testAppendSemicolon();
|
||||||
|
void testComparisonVersusAssignmentChooseComparison();
|
||||||
|
void testComparisonVersusAssignmentChooseParentheses();
|
||||||
|
void testDescription();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Utils::FilePath semicolonFilePath() const;
|
||||||
|
Utils::FilePath compareFilePath() const;
|
||||||
|
QString fileContent(const QString &relFilePath) const;
|
||||||
|
|
||||||
|
ClangFixIt semicolonFixIt() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScopedPointer<CppEditor::Tests::TemporaryCopiedDir> m_dataDir;
|
||||||
|
};
|
||||||
|
|
||||||
static QString qrcPath(const QString &relativeFilePath)
|
static QString qrcPath(const QString &relativeFilePath)
|
||||||
{
|
{
|
||||||
@@ -86,4 +111,11 @@ void ClangFixItTest::testComparisonVersusAssignmentChooseParentheses()
|
|||||||
fileContent("diagnostic_comparison_fixit_expected2.cpp"));
|
fileContent("diagnostic_comparison_fixit_expected2.cpp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ClangCodeModel::Internal::Tests
|
QObject *createClangFixItTest()
|
||||||
|
{
|
||||||
|
return new ClangFixItTest;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // ClangCodeModel::Internal
|
||||||
|
|
||||||
|
#include "clangfixittest.moc"
|
||||||
|
@@ -3,40 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cppeditor/cpptoolstestcase.h>
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace Utils { class FilePath; }
|
|
||||||
|
|
||||||
namespace ClangCodeModel::Internal {
|
namespace ClangCodeModel::Internal {
|
||||||
class ClangFixIt;
|
|
||||||
|
|
||||||
namespace Tests {
|
QObject *createClangFixItTest();
|
||||||
|
|
||||||
class ClangFixItTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void init();
|
|
||||||
void testAppendSemicolon();
|
|
||||||
void testComparisonVersusAssignmentChooseComparison();
|
|
||||||
void testComparisonVersusAssignmentChooseParentheses();
|
|
||||||
void testDescription();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Utils::FilePath semicolonFilePath() const;
|
|
||||||
Utils::FilePath compareFilePath() const;
|
|
||||||
QString fileContent(const QString &relFilePath) const;
|
|
||||||
|
|
||||||
ClangFixIt semicolonFixIt() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QScopedPointer<CppEditor::Tests::TemporaryCopiedDir> m_dataDir;
|
|
||||||
};
|
|
||||||
|
|
||||||
} //namespace Tests
|
|
||||||
} // namespace ClangCodeModel::Internal
|
} // namespace ClangCodeModel::Internal
|
||||||
|
Reference in New Issue
Block a user