Commit c88bf19b authored by Milian Wolff's avatar Milian Wolff

clang: add new (partially failing) test file for lambdas

We apparently fail to build uses for lambda captures using
C++14 `identifier initializer` statements. Turns out that the
init-capture isn't visited by libclang, see also:

https://reviews.llvm.org/D60672
parent d8119c13
/// "useCount" : 1
void foo()
{
/// "useCount": 2
auto l1 = []() {
foo();
};
/// "useCount": 1
auto l2 = [l1] {
l1();
};
/// "useCount": 0
auto l3 = [lambda = l2]() {
lambda();
};
}
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <tests/json/declarationvalidator.h> #include <tests/json/declarationvalidator.h>
#include "testfilepaths.h" #include "testfilepaths.h"
#include "testprovider.h"
//Include all used json tests, otherwise "Test not found" //Include all used json tests, otherwise "Test not found"
#include <tests/json/jsondeclarationtests.h> #include <tests/json/jsondeclarationtests.h>
...@@ -55,13 +56,22 @@ void TestFiles::initTestCase() ...@@ -55,13 +56,22 @@ void TestFiles::initTestCase()
DUChain::self()->disablePersistentStorage(); DUChain::self()->disablePersistentStorage();
Core::self()->languageController()->backgroundParser()->setDelay(0); Core::self()->languageController()->backgroundParser()->setDelay(0);
CodeRepresentation::setDiskChangesForbidden(true); CodeRepresentation::setDiskChangesForbidden(true);
m_provider = new TestEnvironmentProvider;
IDefinesAndIncludesManager::manager()->registerBackgroundProvider(m_provider);
} }
void TestFiles::cleanupTestCase() void TestFiles::cleanupTestCase()
{ {
delete m_provider;
TestCore::shutdown(); TestCore::shutdown();
} }
void TestFiles::cleanup()
{
m_provider->clear();
}
void TestFiles::testFiles_data() void TestFiles::testFiles_data()
{ {
QTest::addColumn<QString>("fileName"); QTest::addColumn<QString>("fileName");
...@@ -75,6 +85,11 @@ void TestFiles::testFiles_data() ...@@ -75,6 +85,11 @@ void TestFiles::testFiles_data()
void TestFiles::testFiles() void TestFiles::testFiles()
{ {
QFETCH(QString, fileName); QFETCH(QString, fileName);
if (QTest::currentDataTag() == QLatin1String("lambdas.cpp")) {
m_provider->parserArguments += "-std=c++14";
}
const IndexedString indexedFileName(fileName); const IndexedString indexedFileName(fileName);
ReferencedTopDUContext top = ReferencedTopDUContext top =
DUChain::self()->waitForUpdate(indexedFileName, TopDUContext::AllDeclarationsContextsAndUses); DUChain::self()->waitForUpdate(indexedFileName, TopDUContext::AllDeclarationsContextsAndUses);
...@@ -88,12 +103,14 @@ void TestFiles::testFiles() ...@@ -88,12 +103,14 @@ void TestFiles::testFiles()
DUChainReadLocker lock; DUChainReadLocker lock;
DeclarationValidator validator; DeclarationValidator validator;
top->visit(validator); top->visit(validator);
QVERIFY(validator.testsPassed());
foreach(auto problem, top->problems()) { foreach(auto problem, top->problems()) {
qDebug() << problem; qDebug() << problem;
} }
QEXPECT_FAIL("lambdas.cpp", "capture with identifier and initializer aren't visited apparently", Abort);
QVERIFY(validator.testsPassed());
if (!QTest::currentDataTag() || strcmp("invalid.cpp", QTest::currentDataTag()) != 0) { if (!QTest::currentDataTag() || strcmp("invalid.cpp", QTest::currentDataTag()) != 0) {
QVERIFY(top->problems().isEmpty()); QVERIFY(top->problems().isEmpty());
} }
......
...@@ -22,14 +22,19 @@ ...@@ -22,14 +22,19 @@
#include <QObject> #include <QObject>
class TestEnvironmentProvider;
class TestFiles : public QObject class TestFiles : public QObject
{ {
Q_OBJECT Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void initTestCase(); void initTestCase();
void cleanupTestCase(); void cleanupTestCase();
void cleanup();
void testFiles_data(); void testFiles_data();
void testFiles(); void testFiles();
private:
TestEnvironmentProvider *m_provider;
}; };
#endif // TEST_FILES_H #endif // TEST_FILES_H
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