Changeset View
Changeset View
Standalone View
Standalone View
plugins/cmake/testing/ctestutils.cpp
Show All 30 Lines | |||||
31 | #include <interfaces/iruncontroller.h> | 31 | #include <interfaces/iruncontroller.h> | ||
32 | #include <project/interfaces/ibuildsystemmanager.h> | 32 | #include <project/interfaces/ibuildsystemmanager.h> | ||
33 | #include <project/projectmodel.h> | 33 | #include <project/projectmodel.h> | ||
34 | #include <util/path.h> | 34 | #include <util/path.h> | ||
35 | #include <QDir> | 35 | #include <QDir> | ||
36 | 36 | | |||
37 | using namespace KDevelop; | 37 | using namespace KDevelop; | ||
38 | 38 | | |||
39 | // TODO: we are lacking introspection into targets, to see what files belong to each target. | | |||
40 | static CMakeTarget targetByName(const QHash< KDevelop::Path, QVector<CMakeTarget>>& targets, const QString& name) | 39 | static CMakeTarget targetByName(const QHash< KDevelop::Path, QVector<CMakeTarget>>& targets, const QString& name) | ||
41 | { | 40 | { | ||
42 | for (const auto &subdir: targets.values()) { | 41 | for (const auto &subdir: targets.values()) { | ||
43 | for (const auto &target: subdir) { | 42 | for (const auto &target: subdir) { | ||
44 | if (target.name == name) | 43 | if (target.name == name) | ||
45 | return target; | 44 | return target; | ||
46 | } | 45 | } | ||
47 | } | 46 | } | ||
47 | | ||||
48 | return {}; | ||||
49 | } | ||||
50 | | ||||
51 | static CMakeTarget targetByExe(const QHash< KDevelop::Path, QVector<CMakeTarget>>& targets, const KDevelop::Path& exe) | ||||
52 | { | ||||
53 | for (const auto &subdir: targets.values()) { | ||||
54 | for (const auto &target: subdir) { | ||||
55 | if (target.artifacts.contains(exe)) | ||||
56 | return target; | ||||
57 | } | ||||
58 | } | ||||
59 | | ||||
48 | return {}; | 60 | return {}; | ||
49 | } | 61 | } | ||
50 | 62 | | |||
51 | void CTestUtils::createTestSuites(const QVector<Test>& testSuites, const QHash< KDevelop::Path, QVector<CMakeTarget>>& targets, KDevelop::IProject* project) | 63 | void CTestUtils::createTestSuites(const QVector<Test>& testSuites, const QHash< KDevelop::Path, QVector<CMakeTarget>>& targets, KDevelop::IProject* project) | ||
52 | { | 64 | { | ||
53 | foreach (const Test& test, testSuites) { | 65 | foreach (const Test& test, testSuites) { | ||
54 | KDevelop::Path executablePath; | 66 | KDevelop::Path executablePath; | ||
67 | CMakeTarget target; | ||||
68 | | ||||
55 | if (QDir::isAbsolutePath(test.executable)) { | 69 | if (QDir::isAbsolutePath(test.executable)) { | ||
56 | executablePath = KDevelop::Path(test.executable); | 70 | executablePath = KDevelop::Path(test.executable); | ||
71 | target = targetByExe(targets, executablePath); | ||||
57 | } else { | 72 | } else { | ||
58 | const auto target = targetByName(targets, test.executable); | 73 | target = targetByName(targets, test.executable); | ||
59 | if (target.artifacts.isEmpty()) { | 74 | if (target.artifacts.isEmpty()) { | ||
60 | continue; | 75 | continue; | ||
61 | } | 76 | } | ||
62 | executablePath = target.artifacts.first(); | 77 | executablePath = target.artifacts.first(); | ||
63 | } | 78 | } | ||
64 | 79 | | |||
65 | CTestSuite* suite = new CTestSuite(test.name, executablePath, {}, project, test.arguments, test.properties); | 80 | qCDebug(CMAKE) << "looking for tests in test" << test.name << "target" << target.name << "with sources" << target.sources; | ||
81 | | ||||
82 | CTestSuite* suite = new CTestSuite(test.name, executablePath, target.sources.toList(), project, test.arguments, test.properties); | ||||
66 | ICore::self()->runController()->registerJob(new CTestFindJob(suite)); | 83 | ICore::self()->runController()->registerJob(new CTestFindJob(suite)); | ||
67 | } | 84 | } | ||
68 | } | 85 | } |