From 37d3c4ed7854833ae87254a4e2b46f277d07772c Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 17 Jan 2024 17:12:13 +0100 Subject: [PATCH] CppEditor: Fix ModelManagerTest Amends 69571427a303fea5c417206555df17572d12b001. Change-Id: I07fa0acb34b8277a6790bbd529a7d39190ce846f Reviewed-by: Reviewed-by: David Schulz --- src/plugins/cppeditor/cppmodelmanager_test.cpp | 13 ++++--------- src/plugins/projectexplorer/projectexplorer.cpp | 10 ++++++++++ src/plugins/projectexplorer/projectexplorer.h | 4 ++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index c2a9189fd63..9e72a224b9f 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -1000,9 +1000,7 @@ void ModelManagerTest::testRenameIncludes() } // Renaming the header - QVERIFY(Core::FileUtils::renameFile(oldHeader, - newHeader, - Core::HandleIncludeGuards::Yes)); + QVERIFY(ProjectExplorerPlugin::renameFile(oldHeader, newHeader)); // Update the c++ model manager again and check for the new includes CppModelManager::updateSourceFiles(sourceFiles).waitForFinished(); @@ -1070,15 +1068,12 @@ void ModelManagerTest::testRenameIncludesInEditor() QVERIFY(CppModelManager::workingCopy().get(mainFile)); // Test the renaming of a header file where a pragma once guard is present - QVERIFY(Core::FileUtils::renameFile(headerWithPragmaOnce, - renamedHeaderWithPragmaOnce, - Core::HandleIncludeGuards::Yes)); + QVERIFY(ProjectExplorerPlugin::renameFile(headerWithPragmaOnce, renamedHeaderWithPragmaOnce)); // Test the renaming the header with include guard: // The contents should match the foobar2000.h in the testdata_project2 project - QVERIFY(Core::FileUtils::renameFile(Utils::FilePath::fromString(headerWithNormalGuard), - Utils::FilePath::fromString(renamedHeaderWithNormalGuard), - Core::HandleIncludeGuards::Yes)); + QVERIFY(ProjectExplorerPlugin::renameFile(FilePath::fromString(headerWithNormalGuard), + FilePath::fromString(renamedHeaderWithNormalGuard))); const MyTestDataDir testDir2(_("testdata_project2")); QFile foobar2000Header(testDir2.file("foobar2000.h")); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 4cf5c55e79d..27390bf884c 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -2484,6 +2484,16 @@ QList> ProjectExplorerPlugin::renameFiles( return renamedFiles; } +#ifdef WITH_TESTS +bool ProjectExplorerPlugin::renameFile(const Utils::FilePath &source, const Utils::FilePath &target) +{ + const bool success = Core::FileUtils::renameFile(source, target, HandleIncludeGuards::Yes); + if (success) + emit instance()->filesRenamed({std::make_pair(source, target)}); + return success; +} +#endif // WITH_TESTS + void ProjectExplorerPluginPrivate::startRunControl(RunControl *runControl) { m_outputPane.createNewOutputWindow(runControl); diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index 12432cafafa..d7e04f3fd1b 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -129,6 +129,10 @@ public: static QList> renameFiles(const QList> &nodesAndNewFilePaths); +#ifdef WITH_TESTS + static bool renameFile(const Utils::FilePath &source, const Utils::FilePath &target); +#endif + static QStringList projectFilePatterns(); static bool isProjectFile(const Utils::FilePath &filePath); static RecentProjectsEntries recentProjects();