File indexing completed on 2024-05-12 04:39:28
0001 /* 0002 SPDX-FileCopyrightText: 2012 Miha Čančula <miha@noughmad.eu> 0003 0004 CTestTestfile.cmake parsing uses code from the xUnit plugin 0005 SPDX-FileCopyrightText: 2008 Manuel Breugelmans <mbr.nxi@gmail.com> 0006 SPDX-FileCopyrightText: 2010 Daniel Calviño Sánchez <danxuliu@gmail.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "ctestutils.h" 0012 #include "ctestsuite.h" 0013 #include "ctestfindjob.h" 0014 #include <debug_testing.h> 0015 0016 #include <interfaces/iproject.h> 0017 #include <project/interfaces/ibuildsystemmanager.h> 0018 #include <project/projectmodel.h> 0019 #include <util/path.h> 0020 #include <QDir> 0021 0022 using namespace KDevelop; 0023 0024 static CMakeTarget targetByName(const QHash< KDevelop::Path, QVector<CMakeTarget>>& targets, const QString& name) 0025 { 0026 for (const auto& subdir: targets) { 0027 for (const auto &target: subdir) { 0028 if (target.name == name) 0029 return target; 0030 } 0031 } 0032 0033 return {}; 0034 } 0035 0036 static CMakeTarget targetByExe(const QHash< KDevelop::Path, QVector<CMakeTarget>>& targets, const KDevelop::Path& exe) 0037 { 0038 for (const auto& subdir: targets) { 0039 for (const auto &target: subdir) { 0040 if (target.artifacts.contains(exe)) 0041 return target; 0042 } 0043 } 0044 0045 return {}; 0046 } 0047 0048 std::vector<std::unique_ptr<CTestSuite>> 0049 CTestUtils::createTestSuites(const QVector<CMakeTest>& testSuites, 0050 const QHash<KDevelop::Path, QVector<CMakeTarget>>& targets, KDevelop::IProject* project) 0051 { 0052 std::vector<std::unique_ptr<CTestSuite>> suites; 0053 suites.reserve(testSuites.size()); 0054 for (const CMakeTest& test : testSuites) { 0055 KDevelop::Path executablePath; 0056 CMakeTarget target; 0057 0058 if (QDir::isAbsolutePath(test.executable)) { 0059 executablePath = KDevelop::Path(test.executable); 0060 target = targetByExe(targets, executablePath); 0061 } else { 0062 target = targetByName(targets, test.executable); 0063 if (target.artifacts.isEmpty()) { 0064 continue; 0065 } 0066 executablePath = target.artifacts.first(); 0067 } 0068 0069 qCDebug(CMAKE_TESTING) << "looking for tests in test" << test.name << "target" << target.name << "with sources" 0070 << target.sources; 0071 0072 suites.push_back(std::make_unique<CTestSuite>(test.name, executablePath, target.sources.toList(), project, 0073 test.arguments, test.properties)); 0074 } 0075 return suites; 0076 }