forked from qt-creator/qt-creator
Squish: Fix removing a test case
The action has been present but forgotten to get implemented. Change-Id: I7979f852e5b8f89a8014cc05748fb97d35be27e4 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "suiteconf.h"
|
||||
#include "squishtr.h"
|
||||
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
@@ -308,6 +309,47 @@ void SquishFileHandler::closeAllTestSuites()
|
||||
ProjectExplorer::SessionManager::setValue(SK_OpenSuites, suitePathsAsStringList());
|
||||
}
|
||||
|
||||
static void closeOpenedEditorsFor(const Utils::FilePath &filePath)
|
||||
{
|
||||
const QList<Core::IDocument *> openDocuments = Utils::filtered(
|
||||
Core::DocumentModel::openedDocuments(), [filePath](Core::IDocument *doc) {
|
||||
return doc->filePath().isChildOf(filePath);
|
||||
});
|
||||
// for now just ignore modifications - files will be removed completely
|
||||
Core::EditorManager::closeDocuments(openDocuments, false);
|
||||
}
|
||||
|
||||
void SquishFileHandler::deleteTestCase(const QString &suiteName, const QString &testCaseName)
|
||||
{
|
||||
if (!m_suites.contains(suiteName))
|
||||
return;
|
||||
|
||||
if (SquishMessages::simpleQuestion(Tr::tr("Confirm Delete"),
|
||||
Tr::tr("Are you sure you want to delete Test Case \"%1\" "
|
||||
"from the file system?").arg(testCaseName))
|
||||
!= QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Utils::FilePath suiteConfPath = m_suites.value(suiteName);
|
||||
SuiteConf suiteConf = SuiteConf::readSuiteConf(suiteConfPath);
|
||||
const Utils::FilePath testCaseDirectory = suiteConfPath.parentDir().pathAppended(testCaseName);
|
||||
closeOpenedEditorsFor(testCaseDirectory);
|
||||
QString error;
|
||||
if (!testCaseDirectory.removeRecursively(&error)) {
|
||||
QString detail = Tr::tr("Deletion of Test Case failed.");
|
||||
if (!error.isEmpty())
|
||||
detail.append('\n').append(error);
|
||||
SquishMessages::criticalMessage(detail);
|
||||
} else {
|
||||
Core::DocumentManager::expectFileChange(suiteConfPath);
|
||||
suiteConf.removeTestCase(testCaseName);
|
||||
bool ok = suiteConf.write();
|
||||
QTC_CHECK(ok);
|
||||
emit testCaseRemoved(suiteName, testCaseName);
|
||||
}
|
||||
}
|
||||
|
||||
void SquishFileHandler::closeAllInternal()
|
||||
{
|
||||
// TODO close respective editors if there are any
|
||||
|
@@ -25,6 +25,7 @@ public:
|
||||
void openTestSuite(const Utils::FilePath &suiteConfPath, bool isReopen = false);
|
||||
void closeTestSuite(const QString &suiteName);
|
||||
void closeAllTestSuites();
|
||||
void deleteTestCase(const QString &suiteName, const QString &testCaseName);
|
||||
void runTestCase(const QString &suiteName, const QString &testCaseName);
|
||||
void runTestSuite(const QString &suiteName);
|
||||
void recordTestCase(const QString &suiteName, const QString &testCaseName);
|
||||
@@ -39,6 +40,7 @@ signals:
|
||||
void testTreeItemCreated(SquishTestTreeItem *item);
|
||||
void suiteTreeItemRemoved(const QString &suiteName);
|
||||
void suiteTreeItemModified(SquishTestTreeItem *item, const QString &displayName);
|
||||
void testCaseRemoved(const QString &suiteName, const QString &testCaseName);
|
||||
void suitesOpened();
|
||||
|
||||
private:
|
||||
|
@@ -106,6 +106,9 @@ void SquishNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||
connect(runThisTestCase, &QAction::triggered, [suiteName, caseName] {
|
||||
SquishFileHandler::instance()->runTestCase(suiteName, caseName);
|
||||
});
|
||||
connect(deleteTestCase, &QAction::triggered, [suiteName, caseName] {
|
||||
SquishFileHandler::instance()->deleteTestCase(suiteName, caseName);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case SquishTestTreeItem::SquishSuite: {
|
||||
|
@@ -180,6 +180,8 @@ SquishTestTreeModel::SquishTestTreeModel(QObject *parent)
|
||||
this, &SquishTestTreeModel::onSuiteTreeItemModified);
|
||||
connect(m_squishFileHandler, &SquishFileHandler::suiteTreeItemRemoved,
|
||||
this, &SquishTestTreeModel::onSuiteTreeItemRemoved);
|
||||
connect(m_squishFileHandler, &SquishFileHandler::testCaseRemoved,
|
||||
this, &SquishTestTreeModel::onTestCaseRemoved);
|
||||
connect(m_squishFileHandler, &SquishFileHandler::clearedSharedFolders,
|
||||
this, [this] { m_squishSharedFolders->removeChildren(); });
|
||||
|
||||
@@ -450,6 +452,18 @@ void SquishTestTreeModel::onSuiteTreeItemModified(SquishTestTreeItem *item, cons
|
||||
delete item;
|
||||
}
|
||||
|
||||
void SquishTestTreeModel::onTestCaseRemoved(const QString &suiteName, const QString &testCase)
|
||||
{
|
||||
if (SquishTestTreeItem *suite = findSuite(suiteName)) {
|
||||
auto item = suite->findChildAtLevel(1, [this, testCase](const Utils::TreeItem *it) {
|
||||
return data(it->index(), Qt::DisplayRole).toString() == testCase;
|
||||
});
|
||||
QTC_ASSERT(item, return);
|
||||
const QModelIndex idx = item->index();
|
||||
removeTreeItem(idx.row(), idx.parent());
|
||||
}
|
||||
}
|
||||
|
||||
/************************************** SquishTestTreeSortModel **********************************/
|
||||
|
||||
SquishTestTreeSortModel::SquishTestTreeSortModel(SquishTestTreeModel *sourceModel, QObject *parent)
|
||||
|
@@ -81,6 +81,7 @@ private:
|
||||
SquishTestTreeItem *findSuite(const QString &displayName) const;
|
||||
void onSuiteTreeItemRemoved(const QString &suiteName);
|
||||
void onSuiteTreeItemModified(SquishTestTreeItem *item, const QString &display);
|
||||
void onTestCaseRemoved(const QString &suiteName, const QString &testCase);
|
||||
Utils::TreeItem *m_squishSharedFolders;
|
||||
Utils::TreeItem *m_squishSuitesRoot;
|
||||
SquishFileHandler *m_squishFileHandler;
|
||||
|
@@ -242,6 +242,17 @@ void SuiteConf::addTestCase(const QString &name)
|
||||
m_testcases = joinItems(current);
|
||||
}
|
||||
|
||||
void SuiteConf::removeTestCase(const QString &name)
|
||||
{
|
||||
QStringList current = testCases();
|
||||
int position = current.indexOf(name);
|
||||
if (position == -1) // it had been an unlisted test case
|
||||
return;
|
||||
|
||||
current.remove(position);
|
||||
m_testcases = joinItems(current);
|
||||
}
|
||||
|
||||
void SuiteConf::setLanguage(const QString &language)
|
||||
{
|
||||
if (language == "Python")
|
||||
|
@@ -35,6 +35,7 @@ public:
|
||||
QString scriptExtension() const;
|
||||
QStringList testCases() const;
|
||||
void addTestCase(const QString &testCase);
|
||||
void removeTestCase(const QString &testCase);
|
||||
|
||||
QStringList usedTestCases() const;
|
||||
|
||||
|
Reference in New Issue
Block a user