From 6ea56953d0db6b547cead08b460b64048ed8f30b Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Fri, 28 Oct 2022 10:32:14 -0400 Subject: [PATCH] Create temporary files with ResourceHelper so they get cleanedup Part of #117 --- .../tests/text/selection/BaseSelectionTestsIndexer.java | 6 +++--- .../tests/text/selection/CPPSelectionNoIndexerTests.java | 3 ++- .../ui/tests/text/selection/CSelectionNoIndexerTests.java | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java index ee1000f2de1..dd974ef3360 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java @@ -21,6 +21,7 @@ import java.io.InputStream; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.FileManager; +import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds; import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; @@ -54,7 +55,7 @@ import org.eclipse.ui.texteditor.AbstractTextEditor; * * @author dsteffle */ -public class BaseSelectionTestsIndexer extends BaseSelectionTests { +public abstract class BaseSelectionTestsIndexer extends BaseSelectionTests { protected ICProject fCProject; static FileManager fileManager = new FileManager(); IProgressMonitor monitor = new NullProgressMonitor(); @@ -109,8 +110,7 @@ public class BaseSelectionTestsIndexer extends BaseSelectionTests { //Obtain file handle IFile file = fCProject.getProject().getFile(fileName); - IPath location = new Path( - fCProject.getProject().getLocation().removeLastSegments(1).toOSString() + File.separator + fileName); + IPath location = ResourceHelper.createTemporaryFolder().append(fileName); File linkFile = new File(location.toOSString()); if (linkFile.exists()) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionNoIndexerTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionNoIndexerTests.java index 1a680fec893..e1fd71660a2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionNoIndexerTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionNoIndexerTests.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; +import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase; import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; @@ -137,7 +138,7 @@ public class CPPSelectionNoIndexerTests extends BaseSelectionTests { //Obtain file handle IFile file = project.getProject().getFile(fileName); - IPath location = new Path(project.getLocation().removeLastSegments(1).toOSString() + File.separator + fileName); + IPath location = ResourceHelper.createTemporaryFolder().append(fileName); File linkFile = new File(location.toOSString()); if (!linkFile.exists()) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionNoIndexerTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionNoIndexerTests.java index d7de59d7337..3aae00459b1 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionNoIndexerTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionNoIndexerTests.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; +import org.eclipse.cdt.core.testplugin.ResourceHelper; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; import org.eclipse.core.resources.IFile; @@ -118,12 +119,11 @@ public class CSelectionNoIndexerTests extends BaseSelectionTests { //Obtain file handle IFile file = project.getProject().getFile(fileName); - IPath location = new Path(project.getLocation().removeLastSegments(1).toOSString() + File.separator + fileName); + IPath location = ResourceHelper.createTemporaryFolder().append(fileName); File linkFile = new File(location.toOSString()); - if (!linkFile.exists()) { - linkFile.createNewFile(); - } + assertFalse(linkFile.exists()); + linkFile.createNewFile(); file.createLink(location, IResource.ALLOW_MISSING_LOCAL, null);