Commit d5e3e27b authored by Thibault North's avatar Thibault North Committed by Milian Wolff

CMake: discover more unit tests

Discover unit-tests using bracket arguments and/or listed in
files other than CTestTestFile.cmake:

When using gtest_discover_tests(), add_test() directives are present
in various .cmake files. To date, Kdevelop searches for unit-tests
does not follow include() directives present in the main
CTestTestfile.cmake, leading to no unit-tests being shown.
Additionally, the bracket arguments of CMake is not enabled for
parsing tests arguments.

This patch enables them, and follows include() directives.

Reviewers: apol, kfunk, mwolff
Reviewed By: mwolff
Subscribers: mwolff, kdevelop-devel
Tags: #kdevelop
BUG: 405225
Differential Revision: https://phabricator.kde.org/D19673
parent 9431143f
...@@ -691,15 +691,15 @@ QString defaultGenerator() ...@@ -691,15 +691,15 @@ QString defaultGenerator()
return defGen; return defGen;
} }
QVector<Test> importTestSuites(const Path &buildDir) QVector<Test> importTestSuites(const Path &buildDir, const QString &cmakeTestFileName)
{ {
const auto contents = CMakeListsParser::readCMakeFile(buildDir.toLocalFile() + QLatin1String("/CTestTestfile.cmake")); const auto cmakeTestFile = Path(buildDir, cmakeTestFileName).toLocalFile() ;
const auto contents = CMakeListsParser::readCMakeFile(cmakeTestFile);
QVector<Test> tests; QVector<Test> tests;
for (const auto& entry: contents) { for (const auto& entry: contents) {
if (entry.name == QLatin1String("add_test")) { if (entry.name == QLatin1String("add_test")) {
auto args = entry.arguments; auto args = entry.arguments;
Test test; Test test;
test.name = args.takeFirst().value; test.name = args.takeFirst().value;
test.executable = args.takeFirst().value; test.executable = args.takeFirst().value;
...@@ -707,6 +707,9 @@ QVector<Test> importTestSuites(const Path &buildDir) ...@@ -707,6 +707,9 @@ QVector<Test> importTestSuites(const Path &buildDir)
tests += test; tests += test;
} else if (entry.name == QLatin1String("subdirs")) { } else if (entry.name == QLatin1String("subdirs")) {
tests += importTestSuites(Path(buildDir, entry.arguments.first().value)); tests += importTestSuites(Path(buildDir, entry.arguments.first().value));
} else if (entry.name == QLatin1String("include")) {
// Include directive points directly to a .cmake file hosting the tests
tests += importTestSuites(Path(buildDir, entry.arguments.first().value), QString());
} else if (entry.name == QLatin1String("set_tests_properties")) { } else if (entry.name == QLatin1String("set_tests_properties")) {
if(entry.arguments.count() < 4 || entry.arguments.count() % 2) { if(entry.arguments.count() < 4 || entry.arguments.count() % 2) {
qCWarning(CMAKE) << "found set_tests_properties() with unexpected number of arguments:" qCWarning(CMAKE) << "found set_tests_properties() with unexpected number of arguments:"
...@@ -732,4 +735,8 @@ QVector<Test> importTestSuites(const Path &buildDir) ...@@ -732,4 +735,8 @@ QVector<Test> importTestSuites(const Path &buildDir)
return tests; return tests;
} }
QVector<Test> importTestSuites(const Path &buildDir) {
return importTestSuites(buildDir, QStringLiteral("CTestTestfile.cmake"));
}
} }
...@@ -188,6 +188,7 @@ bool CMakeListsParser::readCMakeFunction(cmListFileLexer *lexer, CMakeFunctionDe ...@@ -188,6 +188,7 @@ bool CMakeListsParser::readCMakeFunction(cmListFileLexer *lexer, CMakeFunctionDe
func.arguments << CMakeFunctionArgument( QString::fromLocal8Bit(token->text, token->length), false, token->line, token->column ); func.arguments << CMakeFunctionArgument( QString::fromLocal8Bit(token->text, token->length), false, token->line, token->column );
break; break;
case cmListFileLexer_Token_Identifier: case cmListFileLexer_Token_Identifier:
case cmListFileLexer_Token_ArgumentBracket:
case cmListFileLexer_Token_ArgumentUnquoted: case cmListFileLexer_Token_ArgumentUnquoted:
func.arguments << CMakeFunctionArgument( QString::fromLocal8Bit(token->text, token->length), false, token->line, token->column ); func.arguments << CMakeFunctionArgument( QString::fromLocal8Bit(token->text, token->length), false, token->line, token->column );
break; break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment