| 602 | } |
| 603 | |
| 604 | QVector<CMakeTest> importTestSuites(const Path &buildDir, const QString &cmakeTestFileName) |
| 605 | { |
| 606 | const auto cmakeTestFile = Path(buildDir, cmakeTestFileName).toLocalFile() ; |
| 607 | const auto contents = CMakeListsParser::readCMakeFile(cmakeTestFile); |
| 608 | |
| 609 | QVector<CMakeTest> tests; |
| 610 | for (const auto& entry: contents) { |
| 611 | if (entry.name == QLatin1String("add_test")) { |
| 612 | auto args = entry.arguments; |
| 613 | CMakeTest test; |
| 614 | test.name = args.takeFirst().value; |
| 615 | test.executable = args.takeFirst().value; |
| 616 | test.arguments = kTransform<QStringList>(args, [](const CMakeFunctionArgument& arg) { return arg.value; }); |
| 617 | tests += test; |
| 618 | } else if (entry.name == QLatin1String("subdirs")) { |
| 619 | tests += importTestSuites(Path(buildDir, entry.arguments.first().value)); |
| 620 | } else if (entry.name == QLatin1String("include")) { |
| 621 | // Include directive points directly to a .cmake file hosting the tests |
| 622 | tests += importTestSuites(Path(buildDir, entry.arguments.first().value), QString()); |
| 623 | } else if (entry.name == QLatin1String("set_tests_properties")) { |
| 624 | if(entry.arguments.count() < 4 || entry.arguments.count() % 2) { |
| 625 | qCWarning(CMAKE) << "found set_tests_properties() with unexpected number of arguments:" |
| 626 | << entry.arguments.count(); |
| 627 | continue; |
| 628 | } |
| 629 | if (tests.isEmpty() || entry.arguments.first().value != tests.last().name) { |
| 630 | qCWarning(CMAKE) << "found set_tests_properties(" << entry.arguments.first().value |
| 631 | << " ...), but expected test " << tests.last().name; |
| 632 | continue; |
| 633 | } |
| 634 | if (entry.arguments[1].value != QLatin1String("PROPERTIES")) { |
| 635 | qCWarning(CMAKE) << "found set_tests_properties(" << entry.arguments.first().value |
| 636 | << entry.arguments.at(1).value << "...), but expected PROPERTIES as second argument"; |
| 637 | continue; |
| 638 | } |
| 639 | CMakeTest &test = tests.last(); |
| 640 | for (int i = 2; i < entry.arguments.count(); i += 2) |
| 641 | test.properties[entry.arguments[i].value] = entry.arguments[i + 1].value; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | return tests; |
| 646 | } |
| 647 | |
| 648 | QVector<CMakeTest> importTestSuites(const Path &buildDir) { |
| 649 | return importTestSuites(buildDir, QStringLiteral("CTestTestfile.cmake")); |
no test coverage detected