diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index 4457c7531fc..3c9fbbcad5b 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -32,7 +32,11 @@ #include #include #include +#include +#include +#include #include +#include #include #include #include @@ -405,10 +409,33 @@ void AutotestPluginPrivate::onRunUnderCursorTriggered(TestRunMode mode) // check whether we have been triggered on a test function definition const int line = currentEditor->currentLine(); const Utils::FilePath &filePath = currentEditor->textDocument()->filePath(); - const QList filteredItems = Utils::filtered(testsItems, [&](ITestTreeItem *it){ + QList filteredItems = Utils::filtered(testsItems, [&](ITestTreeItem *it){ return it->line() == line && it->filePath() == filePath; }); + if (filteredItems.size() == 0 && testsItems.size() > 1) { + const CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::instance()->snapshot(); + const CPlusPlus::Document::Ptr doc = snapshot.document(filePath); + if (!doc.isNull()) { + CPlusPlus::Scope *scope = doc->scopeAt(line, currentEditor->currentColumn()); + if (scope->asClass()) { + const QList fullName + = CPlusPlus::LookupContext::fullyQualifiedName(scope); + const QString className = CPlusPlus::Overview().prettyName(fullName); + + filteredItems = Utils::filtered(testsItems, + [&text, &className](ITestTreeItem *it){ + return it->name() == text + && static_cast(it->parent())->name() == className; + }); + } + } + } + if ((filteredItems.size() != 1 && testsItems.size() > 1) + && (mode == TestRunMode::Debug || mode == TestRunMode::DebugWithoutDeploy)) { + MessageManager::writeFlashing(Tr::tr("Cannot debug multiple tests at once.")); + return; + } const QList testsToRun = testItemsToTestConfigurations( filteredItems.size() == 1 ? filteredItems : testsItems, mode);