Changeset View
Changeset View
Standalone View
Standalone View
projectmanagers/cmake/testing/ctestrunjob.cpp
Show All 30 Lines | |||||
31 | #include <interfaces/ilaunchmode.h> | 31 | #include <interfaces/ilaunchmode.h> | ||
32 | #include <util/executecompositejob.h> | 32 | #include <util/executecompositejob.h> | ||
33 | 33 | | |||
34 | #include <KConfigGroup> | 34 | #include <KConfigGroup> | ||
35 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
36 | 36 | | |||
37 | using namespace KDevelop; | 37 | using namespace KDevelop; | ||
38 | 38 | | |||
39 | CTestRunJob::CTestRunJob(CTestSuite* suite, const QStringList& cases, OutputJob::OutputJobVerbosity verbosity, bool expectFail, QObject* parent) | 39 | CTestRunJob::CTestRunJob(CTestSuite* suite, const QStringList& cases, OutputJob::OutputJobVerbosity verbosity, QObject* parent) | ||
40 | : KJob(parent) | 40 | : KJob(parent) | ||
41 | , m_suite(suite) | 41 | , m_suite(suite) | ||
42 | , m_cases(cases) | 42 | , m_cases(cases) | ||
43 | , m_job(nullptr) | 43 | , m_job(nullptr) | ||
44 | , m_outputJob(nullptr) | 44 | , m_outputJob(nullptr) | ||
45 | , m_verbosity(verbosity) | 45 | , m_verbosity(verbosity) | ||
46 | , m_expectFail(expectFail) | | |||
47 | { | 46 | { | ||
48 | foreach (const QString& testCase, cases) | 47 | foreach (const QString& testCase, cases) | ||
49 | { | 48 | { | ||
50 | m_caseResults[testCase] = TestResult::NotRun; | 49 | m_caseResults[testCase] = TestResult::NotRun; | ||
51 | } | 50 | } | ||
52 | 51 | | |||
53 | setCapabilities(Killable); | 52 | setCapabilities(Killable); | ||
54 | } | 53 | } | ||
55 | 54 | | |||
56 | 55 | | |||
57 | KJob* createTestJob(const QString& launchModeId, const QStringList& arguments ) | 56 | static KJob* createTestJob(const QString& launchModeId, const QStringList& arguments, const QString &workingDirectory) | ||
58 | { | 57 | { | ||
59 | LaunchConfigurationType* type = ICore::self()->runController()->launchConfigurationTypeForId( QStringLiteral("Native Application") ); | 58 | LaunchConfigurationType* type = ICore::self()->runController()->launchConfigurationTypeForId( QStringLiteral("Native Application") ); | ||
60 | ILaunchMode* mode = ICore::self()->runController()->launchModeForId( launchModeId ); | 59 | ILaunchMode* mode = ICore::self()->runController()->launchModeForId( launchModeId ); | ||
61 | 60 | | |||
62 | qCDebug(CMAKE) << "got mode and type:" << type << type->id() << mode << mode->id(); | 61 | qCDebug(CMAKE) << "got mode and type:" << type << type->id() << mode << mode->id(); | ||
63 | Q_ASSERT(type && mode); | 62 | Q_ASSERT(type && mode); | ||
64 | 63 | | |||
65 | ILauncher* launcher = nullptr; | 64 | ILauncher* launcher = nullptr; | ||
Show All 20 Lines | 84 | ilaunch = ICore::self()->runController()->createLaunchConfiguration( type, | |||
86 | qMakePair( mode->id(), launcher->id() ), | 85 | qMakePair( mode->id(), launcher->id() ), | ||
87 | nullptr, //TODO add project | 86 | nullptr, //TODO add project | ||
88 | i18n("CTest") ); | 87 | i18n("CTest") ); | ||
89 | ilaunch->config().writeEntry("ConfiguredByCTest", true); | 88 | ilaunch->config().writeEntry("ConfiguredByCTest", true); | ||
90 | //qCDebug(CMAKE) << "created config, launching"; | 89 | //qCDebug(CMAKE) << "created config, launching"; | ||
91 | } else { | 90 | } else { | ||
92 | //qCDebug(CMAKE) << "reusing generated config, launching"; | 91 | //qCDebug(CMAKE) << "reusing generated config, launching"; | ||
93 | } | 92 | } | ||
93 | if (!workingDirectory.isEmpty()) | ||||
94 | ilaunch->config().writeEntry( "Working Directory", QUrl::fromLocalFile( workingDirectory ) ); | ||||
94 | type->configureLaunchFromCmdLineArguments( ilaunch->config(), arguments ); | 95 | type->configureLaunchFromCmdLineArguments( ilaunch->config(), arguments ); | ||
95 | return ICore::self()->runController()->execute(launchModeId, ilaunch); | 96 | return ICore::self()->runController()->execute(launchModeId, ilaunch); | ||
96 | } | 97 | } | ||
97 | 98 | | |||
98 | void CTestRunJob::start() | 99 | void CTestRunJob::start() | ||
99 | { | 100 | { | ||
100 | // if (!m_suite->cases().isEmpty()) | 101 | // if (!m_suite->cases().isEmpty()) | ||
101 | // { | 102 | // { | ||
102 | // TODO: Find a better way of determining whether QTestLib is used by this test | 103 | // TODO: Find a better way of determining whether QTestLib is used by this test | ||
103 | // qCDebug(CMAKE) << "Setting a QtTestDelegate"; | 104 | // qCDebug(CMAKE) << "Setting a QtTestDelegate"; | ||
104 | // setDelegate(new QtTestDelegate); | 105 | // setDelegate(new QtTestDelegate); | ||
105 | // } | 106 | // } | ||
106 | // setStandardToolView(IOutputView::RunView); | 107 | // setStandardToolView(IOutputView::RunView); | ||
107 | 108 | | |||
108 | QStringList arguments = m_cases; | 109 | QStringList arguments = m_cases; | ||
109 | if (m_cases.isEmpty() && !m_suite->arguments().isEmpty()) | 110 | if (m_cases.isEmpty() && !m_suite->arguments().isEmpty()) | ||
110 | { | 111 | { | ||
111 | arguments = m_suite->arguments(); | 112 | arguments = m_suite->arguments(); | ||
112 | } | 113 | } | ||
113 | 114 | | |||
114 | QStringList cases_selected = arguments; | 115 | QStringList cases_selected = arguments; | ||
115 | arguments.prepend(m_suite->executable().toLocalFile()); | 116 | arguments.prepend(m_suite->executable().toLocalFile()); | ||
116 | m_job = createTestJob(QStringLiteral("execute"), arguments); | 117 | const QString workingDirectory = m_suite->properties().value(QLatin1String("WORKING_DIRECTORY"), QString()); | ||
118 | | ||||
119 | m_job = createTestJob(QStringLiteral("execute"), arguments, workingDirectory); | ||||
117 | 120 | | |||
118 | if (ExecuteCompositeJob* cjob = qobject_cast<ExecuteCompositeJob*>(m_job)) { | 121 | if (ExecuteCompositeJob* cjob = qobject_cast<ExecuteCompositeJob*>(m_job)) { | ||
119 | m_outputJob = cjob->findChild<OutputJob*>(); | 122 | m_outputJob = cjob->findChild<OutputJob*>(); | ||
120 | Q_ASSERT(m_outputJob); | 123 | Q_ASSERT(m_outputJob); | ||
121 | m_outputJob->setVerbosity(m_verbosity); | 124 | m_outputJob->setVerbosity(m_verbosity); | ||
122 | 125 | | |||
123 | QString testName = arguments.value(0).split('/').last(); | 126 | QString testName = m_suite->name(); | ||
124 | QString title; | 127 | QString title; | ||
125 | if (cases_selected.count() == 1) | 128 | if (cases_selected.count() == 1) | ||
126 | title = i18nc("running test %1, %2 test case", "CTest %1: %2", testName, cases_selected.value(0)); | 129 | title = i18nc("running test %1, %2 test case", "CTest %1: %2", testName, cases_selected.value(0)); | ||
127 | else | 130 | else | ||
128 | title = i18ncp("running test %1, %2 number of test cases", "CTest %2 (%1)", "CTest %2 (%1)", cases_selected.count(), testName); | 131 | title = i18ncp("running test %1, %2 number of test cases", "CTest %2 (%1)", "CTest %2 (%1)", cases_selected.count(), testName); | ||
129 | 132 | | |||
130 | m_outputJob->setTitle(title); | 133 | m_outputJob->setTitle(title); | ||
131 | 134 | | |||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 182 | { | |||
183 | if (caseRx.indexIn(line) >= 0) { | 186 | if (caseRx.indexIn(line) >= 0) { | ||
184 | testCase = caseRx.cap(1); | 187 | testCase = caseRx.cap(1); | ||
185 | } | 188 | } | ||
186 | 189 | | |||
187 | TestResult::TestCaseResult prevResult = m_caseResults.value(testCase, TestResult::NotRun); | 190 | TestResult::TestCaseResult prevResult = m_caseResults.value(testCase, TestResult::NotRun); | ||
188 | if (prevResult == TestResult::Passed || prevResult == TestResult::NotRun) | 191 | if (prevResult == TestResult::Passed || prevResult == TestResult::NotRun) | ||
189 | { | 192 | { | ||
190 | TestResult::TestCaseResult result = TestResult::NotRun; | 193 | TestResult::TestCaseResult result = TestResult::NotRun; | ||
194 | const bool expectFail = m_suite->properties().value(QStringLiteral("WILL_FAIL"), QStringLiteral("FALSE")) == QLatin1String("TRUE"); | ||||
191 | if (line.startsWith(QLatin1String("PASS :"))) | 195 | if (line.startsWith(QLatin1String("PASS :"))) | ||
192 | { | 196 | { | ||
193 | result = m_expectFail ? TestResult::UnexpectedPass : TestResult::Passed; | 197 | result = expectFail ? TestResult::UnexpectedPass : TestResult::Passed; | ||
194 | } | 198 | } | ||
195 | else if (line.startsWith(QLatin1String("FAIL! :"))) | 199 | else if (line.startsWith(QLatin1String("FAIL! :"))) | ||
196 | { | 200 | { | ||
197 | result = m_expectFail ? TestResult::ExpectedFail : TestResult::Failed; | 201 | result = expectFail ? TestResult::ExpectedFail : TestResult::Failed; | ||
198 | } | 202 | } | ||
199 | else if (line.startsWith(QLatin1String("XFAIL :"))) | 203 | else if (line.startsWith(QLatin1String("XFAIL :"))) | ||
200 | { | 204 | { | ||
201 | result = TestResult::ExpectedFail; | 205 | result = TestResult::ExpectedFail; | ||
202 | } | 206 | } | ||
203 | else if (line.startsWith(QLatin1String("XPASS :"))) | 207 | else if (line.startsWith(QLatin1String("XPASS :"))) | ||
204 | { | 208 | { | ||
205 | result = TestResult::UnexpectedPass; | 209 | result = TestResult::UnexpectedPass; | ||
Show All 13 Lines |