Changeset View
Changeset View
Standalone View
Standalone View
plugins/cmake/tests/test_ctestfindsuites.cpp
Show All 34 Lines | |||||
35 | #include <testing/ctestsuite.h> | 35 | #include <testing/ctestsuite.h> | ||
36 | #include <tests/autotestshell.h> | 36 | #include <tests/autotestshell.h> | ||
37 | #include <tests/testcore.h> | 37 | #include <tests/testcore.h> | ||
38 | #include <project/projectmodel.h> | 38 | #include <project/projectmodel.h> | ||
39 | 39 | | |||
40 | #include <QDir> | 40 | #include <QDir> | ||
41 | #include <QtTest> | 41 | #include <QtTest> | ||
42 | 42 | | |||
43 | Q_DECLARE_METATYPE(KDevelop::ITestSuite*) | ||||
44 | | ||||
43 | using namespace KDevelop; | 45 | using namespace KDevelop; | ||
44 | 46 | | |||
45 | void waitForSuites(IProject* project, int count, int max) | 47 | void waitForSuites(IProject* project, int count, int max) | ||
46 | { | 48 | { | ||
47 | auto testController = ICore::self()->testController(); | 49 | auto testController = ICore::self()->testController(); | ||
48 | for(int i = 0; testController->testSuitesForProject(project).size() < count && i < max * 10; ++i) { | 50 | for(int i = 0; testController->testSuitesForProject(project).size() < count && i < max * 10; ++i) { | ||
49 | QSignalSpy spy(testController, &ITestController::testSuiteAdded); | 51 | QSignalSpy spy(testController, &ITestController::testSuiteAdded); | ||
50 | QVERIFY(spy.wait(1000)); | 52 | QVERIFY(spy.wait(1000)); | ||
51 | } | 53 | } | ||
52 | } | 54 | } | ||
53 | 55 | | |||
54 | void TestCTestFindSuites::initTestCase() | 56 | void TestCTestFindSuites::initTestCase() | ||
55 | { | 57 | { | ||
56 | AutoTestShell::init({"KDevCMakeManager", "KDevCMakeBuilder", "KDevMakeBuilder", "KDevStandardOutputView"}); | 58 | AutoTestShell::init({"KDevCMakeManager", "KDevCMakeBuilder", "KDevMakeBuilder", "KDevStandardOutputView"}); | ||
57 | TestCore::initialize(); | 59 | TestCore::initialize(); | ||
58 | 60 | | |||
61 | qRegisterMetaType<ITestSuite*>(); | ||||
62 | | ||||
59 | cleanup(); | 63 | cleanup(); | ||
60 | } | 64 | } | ||
61 | 65 | | |||
62 | void TestCTestFindSuites::cleanup() | 66 | void TestCTestFindSuites::cleanup() | ||
63 | { | 67 | { | ||
64 | foreach(IProject* p, ICore::self()->projectController()->projects()) { | 68 | foreach(IProject* p, ICore::self()->projectController()->projects()) { | ||
65 | ICore::self()->projectController()->closeProject(p); | 69 | ICore::self()->projectController()->closeProject(p); | ||
66 | } | 70 | } | ||
Show All 13 Lines | 80 | { | |||
80 | QList<ITestSuite*> suites = ICore::self()->testController()->testSuitesForProject(project); | 84 | QList<ITestSuite*> suites = ICore::self()->testController()->testSuitesForProject(project); | ||
81 | 85 | | |||
82 | QCOMPARE(suites.size(), 5); | 86 | QCOMPARE(suites.size(), 5); | ||
83 | 87 | | |||
84 | DUChainReadLocker locker(DUChain::lock()); | 88 | DUChainReadLocker locker(DUChain::lock()); | ||
85 | 89 | | |||
86 | foreach (auto suite, suites) | 90 | foreach (auto suite, suites) | ||
87 | { | 91 | { | ||
88 | qDebug() << "checking suite" << suite->name(); | | |||
89 | QCOMPARE(suite->cases(), QStringList()); | 92 | QCOMPARE(suite->cases(), QStringList()); | ||
90 | QVERIFY(!suite->declaration().isValid()); | 93 | QVERIFY(!suite->declaration().isValid()); | ||
91 | CTestSuite* ctestSuite = static_cast<CTestSuite*>(suite); | 94 | CTestSuite* ctestSuite = static_cast<CTestSuite*>(suite); | ||
92 | const auto buildDir = Path(CMake::allBuildDirs(project).at(0)); | 95 | const auto buildDir = Path(CMake::allBuildDirs(project).at(0)); | ||
93 | QString exeSubdir = buildDir.relativePath(ctestSuite->executable().parent()); | 96 | QString exeSubdir = buildDir.relativePath(ctestSuite->executable().parent()); | ||
94 | QCOMPARE(exeSubdir, ctestSuite->name() == "fail" ? QStringLiteral("bin") : QString() ); | 97 | QCOMPARE(exeSubdir, ctestSuite->name() == "fail" ? QStringLiteral("bin") : QString() ); | ||
95 | QString willFail; | 98 | QString willFail; | ||
96 | const QString workingDirectory = ctestSuite->properties().value(QLatin1String("WORKING_DIRECTORY"), QString()); | 99 | const QString workingDirectory = ctestSuite->properties().value(QLatin1String("WORKING_DIRECTORY"), QString()); | ||
Show All 11 Lines | |||||
108 | else if (ctestSuite->name() == QLatin1String("test_five")) | 111 | else if (ctestSuite->name() == QLatin1String("test_five")) | ||
109 | QCOMPARE(workingDirectory, QString(buildDir.path() + QLatin1String("/bin"))); | 112 | QCOMPARE(workingDirectory, QString(buildDir.path() + QLatin1String("/bin"))); | ||
110 | else | 113 | else | ||
111 | QCOMPARE(workingDirectory, QString()); | 114 | QCOMPARE(workingDirectory, QString()); | ||
112 | QCOMPARE(ctestSuite->properties().value(QLatin1String("WILL_FAIL")), willFail); | 115 | QCOMPARE(ctestSuite->properties().value(QLatin1String("WILL_FAIL")), willFail); | ||
113 | } | 116 | } | ||
114 | } | 117 | } | ||
115 | 118 | | |||
119 | void TestCTestFindSuites::testQtTestCases() | ||||
120 | { | ||||
121 | IProject* project = loadProject( "unit_tests_kde" ); | ||||
122 | QVERIFY2(project, "Project was not opened"); | ||||
123 | | ||||
124 | QSignalSpy spy(ICore::self()->testController(), &ITestController::testSuiteAdded); | ||||
125 | QVERIFY(spy.isValid()); | ||||
126 | | ||||
127 | // Background parsing can take a long time, so we need a long timeout | ||||
128 | QVERIFY(spy.wait(30 * 1000)); | ||||
129 | | ||||
130 | QList<ITestSuite*> suites = ICore::self()->testController()->testSuitesForProject(project); | ||||
131 | QCOMPARE(suites.size(), 1); | ||||
132 | | ||||
133 | QStringList cases = { | ||||
134 | QStringLiteral("passingTestCase"), | ||||
135 | QStringLiteral("failingTestCase"), | ||||
136 | QStringLiteral("expectedFailTestCase"), | ||||
137 | QStringLiteral("unexpectedPassTestCase"), | ||||
138 | QStringLiteral("skippedTestCase"), | ||||
139 | }; | ||||
140 | | ||||
141 | DUChainReadLocker locker(DUChain::lock()); | ||||
142 | | ||||
143 | foreach (auto suite, suites) | ||||
144 | { | ||||
145 | QCOMPARE(suite->cases(), cases); | ||||
146 | QVERIFY(suite->declaration().isValid()); | ||||
147 | | ||||
148 | foreach (const auto& caseName, suite->cases()) | ||||
149 | { | ||||
150 | QVERIFY(suite->caseDeclaration(caseName).isValid()); | ||||
151 | } | ||||
152 | } | ||||
153 | } | ||||
154 | | ||||
116 | QTEST_MAIN(TestCTestFindSuites) | 155 | QTEST_MAIN(TestCTestFindSuites) |