Commit 55069192 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools/Editor: Make sure test code is free of diagnostic messages

...where applicable.

Change-Id: Ie42e1012598adf124e5f66b6a53eda01724dfb71
Reviewed-by: default avatarPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 8560036d
...@@ -272,8 +272,10 @@ F2TestCase::F2TestCase(CppEditorAction action, ...@@ -272,8 +272,10 @@ F2TestCase::F2TestCase(CppEditorAction action,
// that is the function bodies are processed. // that is the function bodies are processed.
forever { forever {
const Document::Ptr document = waitForFileInGlobalSnapshot(testFile->filePath()); const Document::Ptr document = waitForFileInGlobalSnapshot(testFile->filePath());
if (document->checkMode() == Document::FullCheck) if (document->checkMode() == Document::FullCheck) {
QVERIFY(document->diagnosticMessages().isEmpty());
break; break;
}
} }
// Rehighlight // Rehighlight
...@@ -1132,7 +1134,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_data() ...@@ -1132,7 +1134,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_data()
"void CD2::virt() {}\n" "void CD2::virt() {}\n"
"\n" "\n"
"int f(A *o) { o->$@virt(); }\n" "int f(A *o) { o->$@virt(); }\n"
"}\n") "\n")
<< (OverrideItemList() << (OverrideItemList()
<< OverrideItem(QLatin1String("A::virt = 0"), 2) << OverrideItem(QLatin1String("A::virt = 0"), 2)
<< OverrideItem(QLatin1String("B::virt"), 5) << OverrideItem(QLatin1String("B::virt"), 5)
...@@ -1158,7 +1160,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_data() ...@@ -1158,7 +1160,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_data()
"void CD2::virt() {}\n" "void CD2::virt() {}\n"
"\n" "\n"
"int f(B *o) { o->$@virt(); }\n" "int f(B *o) { o->$@virt(); }\n"
"}\n") "\n")
<< (OverrideItemList() << (OverrideItemList()
<< OverrideItem(QLatin1String("B::virt"), 5) << OverrideItem(QLatin1String("B::virt"), 5)
<< OverrideItem(QLatin1String("C::virt"), 8) << OverrideItem(QLatin1String("C::virt"), 8)
......
...@@ -87,6 +87,8 @@ public: ...@@ -87,6 +87,8 @@ public:
// Get Document // Get Document
waitForFileInGlobalSnapshot(fileName); waitForFileInGlobalSnapshot(fileName);
const Document::Ptr document = globalSnapshot().document(fileName); const Document::Ptr document = globalSnapshot().document(fileName);
QVERIFY(document);
QVERIFY(document->diagnosticMessages().isEmpty());
m_snapshot.insert(document); m_snapshot.insert(document);
...@@ -344,7 +346,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -344,7 +346,7 @@ void CppToolsPlugin::test_completion_data()
"{\n" "{\n"
" Base *b = new Derived;\n" " Base *b = new Derived;\n"
" if (1)\n" " if (1)\n"
" @\n" " @;\n"
"}\n" "}\n"
) << _("((Derived *)b)->") << (QStringList() ) << _("((Derived *)b)->") << (QStringList()
<< QLatin1String("Derived") << QLatin1String("Derived")
...@@ -367,7 +369,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -367,7 +369,7 @@ void CppToolsPlugin::test_completion_data()
"{\n" "{\n"
" Base *b = new Derived;\n" " Base *b = new Derived;\n"
" if (1)\n" " if (1)\n"
" @\n" " @;\n"
"}\n" "}\n"
) << _("(static_cast<Derived *>(b))->") << (QStringList() ) << _("(static_cast<Derived *>(b))->") << (QStringList()
<< QLatin1String("Derived") << QLatin1String("Derived")
...@@ -1522,7 +1524,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -1522,7 +1524,7 @@ void CppToolsPlugin::test_completion_data()
" int foo2;\n" " int foo2;\n"
" };\n" " };\n"
" @\n" " @\n"
"};\n" "}\n"
) << _("foo") << (QStringList() ) << _("foo") << (QStringList()
<< QLatin1String("foo1") << QLatin1String("foo1")
<< QLatin1String("foo2")); << QLatin1String("foo2"));
...@@ -1704,6 +1706,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -1704,6 +1706,7 @@ void CppToolsPlugin::test_completion_data()
" int m;\n" " int m;\n"
" };\n" " };\n"
"}\n" "}\n"
"}\n"
"void foo()\n" "void foo()\n"
"{\n" "{\n"
" namespace NS = NS1::NS2;\n" " namespace NS = NS1::NS2;\n"
...@@ -1725,6 +1728,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -1725,6 +1728,7 @@ void CppToolsPlugin::test_completion_data()
" int m;\n" " int m;\n"
" };\n" " };\n"
"}\n" "}\n"
"}\n"
"void foo()\n" "void foo()\n"
"{\n" "{\n"
" {\n" " {\n"
...@@ -1823,7 +1827,6 @@ void CppToolsPlugin::test_completion_data() ...@@ -1823,7 +1827,6 @@ void CppToolsPlugin::test_completion_data()
" enum E { val1, val2, val3 };\n" " enum E { val1, val2, val3 };\n"
" @\n" " @\n"
"};\n" "};\n"
"@\n"
) << _("Foo::v") << (QStringList() ) << _("Foo::v") << (QStringList()
<< QLatin1String("val1") << QLatin1String("val1")
<< QLatin1String("val2") << QLatin1String("val2")
...@@ -1835,7 +1838,6 @@ void CppToolsPlugin::test_completion_data() ...@@ -1835,7 +1838,6 @@ void CppToolsPlugin::test_completion_data()
" enum E { val1, val2, val3 };\n" " enum E { val1, val2, val3 };\n"
" @\n" " @\n"
"};\n" "};\n"
"@\n"
) << _("Foo::E::") << (QStringList() ) << _("Foo::E::") << (QStringList()
<< QLatin1String("E") << QLatin1String("E")
<< QLatin1String("val1") << QLatin1String("val1")
...@@ -1848,7 +1850,6 @@ void CppToolsPlugin::test_completion_data() ...@@ -1848,7 +1850,6 @@ void CppToolsPlugin::test_completion_data()
" enum { val1, val2, val3 };\n" " enum { val1, val2, val3 };\n"
" @\n" " @\n"
"};\n" "};\n"
"@\n"
) << _("Foo::v") << (QStringList() ) << _("Foo::v") << (QStringList()
<< QLatin1String("val1") << QLatin1String("val1")
<< QLatin1String("val2") << QLatin1String("val2")
...@@ -1859,8 +1860,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -1859,8 +1860,7 @@ void CppToolsPlugin::test_completion_data()
"{\n" "{\n"
" enum E { val1, val2, val3 };\n" " enum E { val1, val2, val3 };\n"
" @\n" " @\n"
"};\n" "}\n"
"@\n"
) << _("Ns::v") << (QStringList() ) << _("Ns::v") << (QStringList()
<< QLatin1String("val1") << QLatin1String("val1")
<< QLatin1String("val2") << QLatin1String("val2")
...@@ -1871,8 +1871,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -1871,8 +1871,7 @@ void CppToolsPlugin::test_completion_data()
"{\n" "{\n"
" enum E { val1, val2, val3 };\n" " enum E { val1, val2, val3 };\n"
" @\n" " @\n"
"};\n" "}\n"
"@\n"
) << _("Ns::E::") << (QStringList() ) << _("Ns::E::") << (QStringList()
<< QLatin1String("E") << QLatin1String("E")
<< QLatin1String("val1") << QLatin1String("val1")
...@@ -1884,8 +1883,7 @@ void CppToolsPlugin::test_completion_data() ...@@ -1884,8 +1883,7 @@ void CppToolsPlugin::test_completion_data()
"{\n" "{\n"
" enum { val1, val2, val3 };\n" " enum { val1, val2, val3 };\n"
" @\n" " @\n"
"};\n" "}\n"
"@\n"
) << _("Ns::v") << (QStringList() ) << _("Ns::v") << (QStringList()
<< QLatin1String("val1") << QLatin1String("val1")
<< QLatin1String("val2") << QLatin1String("val2")
...@@ -2186,9 +2184,9 @@ void CppToolsPlugin::test_completion_data() ...@@ -2186,9 +2184,9 @@ void CppToolsPlugin::test_completion_data()
"void client()\n" "void client()\n"
"{\n" "{\n"
" Timer *timer = new Timer;\n" " Timer *timer = new Timer;\n"
" connect(timer, SIGNAL(@\n" " @\n"
"}\n" "}\n"
) << _() << (QStringList() ) << _("connect(timer, SIGNAL(") << (QStringList()
<< QLatin1String("timeout()")); << QLatin1String("timeout()"));
QTest::newRow("member_of_class_accessed_by_using_QTCREATORBUG9037_1") << _( QTest::newRow("member_of_class_accessed_by_using_QTCREATORBUG9037_1") << _(
...@@ -2230,9 +2228,9 @@ void CppToolsPlugin::test_completion_data() ...@@ -2230,9 +2228,9 @@ void CppToolsPlugin::test_completion_data()
"\n" "\n"
"double getValue(const QVector<V>& d) const {\n" "double getValue(const QVector<V>& d) const {\n"
" typedef QVector<V>::ConstIterator Iter;\n" " typedef QVector<V>::ConstIterator Iter;\n"
" double val = @\n" " @\n"
"}\n" "}\n"
) << _("d.constBegin()->") << (QStringList()); ) << _("double val = d.constBegin()->") << (QStringList());
} }
void CppToolsPlugin::test_completion_member_access_operator() void CppToolsPlugin::test_completion_member_access_operator()
...@@ -2277,7 +2275,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2277,7 +2275,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"typedef S SType;\n" "typedef S SType;\n"
"SType p;\n" "SType p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList() ) << _("p.") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
...@@ -2288,7 +2285,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2288,7 +2285,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"typedef S *SType;\n" "typedef S *SType;\n"
"SType *p;\n" "SType *p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList()) ) << _("p.") << (QStringList())
<< false; << false;
...@@ -2297,7 +2293,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2297,7 +2293,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"typedef S SType;\n" "typedef S SType;\n"
"SType *p;\n" "SType *p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList() ) << _("p.") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
...@@ -2308,7 +2303,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2308,7 +2303,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"typedef S* SPtr;\n" "typedef S* SPtr;\n"
"SPtr p;\n" "SPtr p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList() ) << _("p.") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
...@@ -2319,7 +2313,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2319,7 +2313,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"struct S { int m; };\n" "struct S { int m; };\n"
"SType *p;\n" "SType *p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList() ) << _("p.") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
...@@ -2330,7 +2323,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2330,7 +2323,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"struct S { int m; };\n" "struct S { int m; };\n"
"SType p;\n" "SType p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList() ) << _("p.") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
...@@ -2341,7 +2333,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2341,7 +2333,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"struct S { int m; };\n" "struct S { int m; };\n"
"SType *p;\n" "SType *p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList()) ) << _("p.") << (QStringList())
<< false; << false;
...@@ -2350,7 +2341,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2350,7 +2341,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"struct S { int m; };\n" "struct S { int m; };\n"
"SType p;\n" "SType p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList() ) << _("p.") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
...@@ -2362,7 +2352,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2362,7 +2352,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"typedef struct SType *STypePtr;\n" "typedef struct SType *STypePtr;\n"
"STypePtr p;\n" "STypePtr p;\n"
"@\n" "@\n"
"}\n"
) << _("p.") << (QStringList() ) << _("p.") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
...@@ -2374,7 +2363,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data() ...@@ -2374,7 +2363,6 @@ void CppToolsPlugin::test_completion_member_access_operator_data()
"typedef struct SType *STypePtr;\n" "typedef struct SType *STypePtr;\n"
"STypePtr p;\n" "STypePtr p;\n"
"@\n" "@\n"
"}\n"
) << _("p->") << (QStringList() ) << _("p->") << (QStringList()
<< QLatin1String("S") << QLatin1String("S")
<< QLatin1String("m")) << QLatin1String("m"))
......
...@@ -99,6 +99,7 @@ public: ...@@ -99,6 +99,7 @@ public:
document->setUtf8Source(preprocessedSource); document->setUtf8Source(preprocessedSource);
document->parse(parseMode); document->parse(parseMode);
document->check(); document->check();
QVERIFY(document->diagnosticMessages().isEmpty());
AST *ast = document->translationUnit()->ast(); AST *ast = document->translationUnit()->ast();
QVERIFY(ast); QVERIFY(ast);
...@@ -614,25 +615,25 @@ void CppToolsPlugin::test_format_pointerdeclaration_macros_data() ...@@ -614,25 +615,25 @@ void CppToolsPlugin::test_format_pointerdeclaration_macros_data()
source = QLatin1String( source = QLatin1String(
"#define FOO int*\n" "#define FOO int*\n"
"FOO @f() {};\n"); "FOO @f() {}\n");
QTest::newRow("macro-in-function-definition-returntype") QTest::newRow("macro-in-function-definition-returntype")
<< source << stripCursor(source); << source << stripCursor(source);
source = QLatin1String( source = QLatin1String(
"#define FOO int*\n" "#define FOO int*\n"
"int f(FOO @a) {};\n"); "int f(FOO @a) {}\n");
QTest::newRow("macro-in-function-definition-param") QTest::newRow("macro-in-function-definition-param")
<< source << stripCursor(source); << source << stripCursor(source);
source = QLatin1String( source = QLatin1String(
"#define FOO int*\n" "#define FOO int*\n"
"while (FOO @s = 0);\n"); "void f() { while (FOO @s = 0) {} }\n");
QTest::newRow("macro-in-if-while-for") QTest::newRow("macro-in-if-while-for")
<< source << stripCursor(source); << source << stripCursor(source);
source = QLatin1String( source = QLatin1String(
"#define FOO int*\n" "#define FOO int*\n"
"foreach (FOO @s, list);\n"); "void f() { foreach (FOO @s, list) {} }\n");
QTest::newRow("macro-in-foreach") QTest::newRow("macro-in-foreach")
<< source << stripCursor(source); << source << stripCursor(source);
......
...@@ -117,6 +117,8 @@ public: ...@@ -117,6 +117,8 @@ public:
// Get class for which to generate the hierarchy // Get class for which to generate the hierarchy
const Document::Ptr firstDocument = snapshot.document(filePaths.first()); const Document::Ptr firstDocument = snapshot.document(filePaths.first());
QVERIFY(firstDocument);
QVERIFY(firstDocument->diagnosticMessages().isEmpty());
Class *clazz = FindFirstClassInDocument()(firstDocument); Class *clazz = FindFirstClassInDocument()(firstDocument);
QVERIFY(clazz); QVERIFY(clazz);
......
...@@ -196,13 +196,35 @@ public: ...@@ -196,13 +196,35 @@ public:
// Compare // Compare
const Document::Ptr cppDocument const Document::Ptr cppDocument
= m_modelManager->cppEditorSupport(cppFileEditor)->snapshotUpdater()->document(); = m_modelManager->cppEditorSupport(cppFileEditor)->snapshotUpdater()->document();
QVERIFY(checkDiagsnosticMessages(cppDocument));
const Document::Ptr hDocument const Document::Ptr hDocument
= m_modelManager->cppEditorSupport(hFileEditor)->snapshotUpdater()->document(); = m_modelManager->cppEditorSupport(hFileEditor)->snapshotUpdater()->document();
QVERIFY(checkDiagsnosticMessages(hDocument));
QVERIFY(documentContainsFunctionDefinition(cppDocument, QVERIFY(documentContainsFunctionDefinition(cppDocument,
QLatin1String("Form::on_pushButton_clicked"))); QLatin1String("Form::on_pushButton_clicked")));
QVERIFY(documentContainsMemberFunctionDeclaration(hDocument, QVERIFY(documentContainsMemberFunctionDeclaration(hDocument,
QLatin1String("Form::on_pushButton_clicked"))); QLatin1String("Form::on_pushButton_clicked")));
} }
static bool checkDiagsnosticMessages(const Document::Ptr &document)
{
if (!document)
return false;
// Since no project is opened and the ui_*.h is not generated,
// the following diagnostic messages will be ignored.
const QStringList ignoreList = QStringList()
<< QLatin1String("ui_form.h: No such file or directory")
<< QLatin1String("QWidget: No such file or directory");
QList<Document::DiagnosticMessage> cleanedDiagnosticMessages;
foreach (const Document::DiagnosticMessage &message, document->diagnosticMessages()) {
if (!ignoreList.contains(message.text()))
cleanedDiagnosticMessages << message;
}
return cleanedDiagnosticMessages.isEmpty();
}
}; };
} // anonymous namespace } // anonymous namespace
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment