mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Cleanup of temporary files created by tests.
Change-Id: Iaca298c1fd237787ea06cba5307cc473034ad314
This commit is contained in:
parent
2ca45300fe
commit
bfb4854e5d
5 changed files with 75 additions and 45 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2014 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.internal.tests;
|
||||
|
||||
|
@ -16,9 +17,9 @@ import java.io.InputStream;
|
|||
import java.net.URI;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
|
@ -30,7 +31,7 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
public class ResourceLookupTests extends TestCase {
|
||||
public class ResourceLookupTests extends BaseTestCase {
|
||||
public static Test suite() {
|
||||
return new TestSuite(ResourceLookupTests.class);
|
||||
}
|
||||
|
@ -38,7 +39,8 @@ public class ResourceLookupTests extends TestCase {
|
|||
private IProject fProject;
|
||||
|
||||
@Override
|
||||
protected void setUp() {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
fProject= root.getProject("reslookup_" + getName());
|
||||
}
|
||||
|
@ -46,6 +48,7 @@ public class ResourceLookupTests extends TestCase {
|
|||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
fProject.delete(true, new NullProgressMonitor());
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected IFolder createFolder(IProject project, String filename) throws CoreException {
|
||||
|
@ -214,7 +217,7 @@ public class ResourceLookupTests extends TestCase {
|
|||
fProject.create(new NullProgressMonitor());
|
||||
fProject.open(new NullProgressMonitor());
|
||||
createFolder(fProject, "folder1");
|
||||
File f= File.createTempFile("extern", "h");
|
||||
File f= createTempFile("extern", "h");
|
||||
IPath location= Path.fromOSString(f.getAbsolutePath());
|
||||
IFile file1= fProject.getFile("linked1");
|
||||
IFile file2= fProject.getFile("linked2.h");
|
||||
|
|
|
@ -14,10 +14,9 @@ package org.eclipse.cdt.internal.pdom.tests;
|
|||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -64,7 +63,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
private static final String LOC_CYCINC1= "resources/pdomtests/generatePDOMTests/cyclicIncludes1";
|
||||
private static final String LOC_CYCINC2= "resources/pdomtests/generatePDOMTests/cyclicIncludes2";
|
||||
|
||||
private static List toDeleteOnTearDown= new ArrayList();
|
||||
private static Deque<ICProject> projectsToDeleteOnTearDown= new ArrayDeque<>();
|
||||
|
||||
public static Test suite() {
|
||||
return suite(GeneratePDOMApplicationTest.class);
|
||||
|
@ -74,17 +73,17 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
toDeleteOnTearDown.clear();
|
||||
target= File.createTempFile("test", "pdom");
|
||||
target.delete();
|
||||
super.setUp();
|
||||
projectsToDeleteOnTearDown.clear();
|
||||
target = nonExistentTempFile("temp", "pdom");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
for(Iterator i= toDeleteOnTearDown.iterator(); i.hasNext(); ) {
|
||||
ICProject cproject= (ICProject) i.next();
|
||||
for (ICProject cproject; (cproject = projectsToDeleteOnTearDown.pollLast()) != null;) {
|
||||
cproject.getProject().delete(true, new NullProgressMonitor());
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testBrokenExportProjectProvider1() throws Exception {
|
||||
|
@ -232,10 +231,8 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
|
||||
wpdom.acquireReadLock();
|
||||
try {
|
||||
assertEquals(1, wpdom.findBindings(new char[][] { "foo"
|
||||
.toCharArray() }, CLinkage, npm()).length);
|
||||
assertEquals(0, wpdom.findBindings(new char[][] { "foo"
|
||||
.toCharArray() }, CPPLinkage, npm()).length);
|
||||
assertEquals(1, wpdom.findBindings(new char[][] { "foo".toCharArray() }, CLinkage, npm()).length);
|
||||
assertEquals(0, wpdom.findBindings(new char[][] { "foo".toCharArray() }, CPPLinkage, npm()).length);
|
||||
} finally {
|
||||
wpdom.releaseReadLock();
|
||||
}
|
||||
|
@ -296,7 +293,8 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
if (listener!=null) {
|
||||
CCorePlugin.getIndexManager().removeIndexerStateListener(listener);
|
||||
}
|
||||
return new WritablePDOM(target, new URIRelativeLocationConverter(BASEURI), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
return new WritablePDOM(target, new URIRelativeLocationConverter(BASEURI),
|
||||
LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
}
|
||||
|
||||
private void doGenerate(String[] args) throws CoreException {
|
||||
|
@ -330,7 +328,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
@Override
|
||||
public ICProject createProject() throws CoreException {
|
||||
ICProject cproject= CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null, IPDOMManager.ID_NO_INDEXER);
|
||||
toDeleteOnTearDown.add(cproject);
|
||||
projectsToDeleteOnTearDown.add(cproject);
|
||||
CProjectHelper.importSourcesFromPlugin(cproject, CTestPlugin.getDefault().getBundle(), LOC_TSTPRJ1);
|
||||
return cproject;
|
||||
}
|
||||
|
@ -346,7 +344,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
@Override
|
||||
public ICProject createProject() throws CoreException {
|
||||
ICProject cproject= CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null, IPDOMManager.ID_NO_INDEXER);
|
||||
toDeleteOnTearDown.add(cproject);
|
||||
projectsToDeleteOnTearDown.add(cproject);
|
||||
CProjectHelper.importSourcesFromPlugin(cproject, CTestPlugin.getDefault().getBundle(), LOC_TSTPRJ1);
|
||||
return cproject;
|
||||
}
|
||||
|
@ -364,7 +362,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
@Override
|
||||
public ICProject createProject() throws CoreException {
|
||||
ICProject cproject= CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null, IPDOMManager.ID_NO_INDEXER);
|
||||
toDeleteOnTearDown.add(cproject);
|
||||
projectsToDeleteOnTearDown.add(cproject);
|
||||
CProjectHelper.importSourcesFromPlugin(cproject, CTestPlugin.getDefault().getBundle(), LOC_TSTPRJ1);
|
||||
return cproject;
|
||||
}
|
||||
|
@ -387,7 +385,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
@Override
|
||||
public ICProject createProject() throws CoreException {
|
||||
ICProject cproject= CProjectHelper.createCProject("test" + System.currentTimeMillis(), null, IPDOMManager.ID_NO_INDEXER);
|
||||
toDeleteOnTearDown.add(cproject);
|
||||
projectsToDeleteOnTearDown.add(cproject);
|
||||
CProjectHelper.importSourcesFromPlugin(cproject, CTestPlugin.getDefault().getBundle(), LOC_TSTPRJ3);
|
||||
return cproject;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
|
@ -46,7 +47,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* Tests bugs found in the PDOM
|
||||
* Tests bugs found in the PDOM.
|
||||
*/
|
||||
public class PDOMCPPBugsTest extends BaseTestCase {
|
||||
ICProject cproject;
|
||||
|
@ -108,7 +109,7 @@ public class PDOMCPPBugsTest extends BaseTestCase {
|
|||
// this test is currently failing on the cdt test build machine, but
|
||||
// not on my local linux or windows boxes.
|
||||
|
||||
File tmp= new File(System.getProperty("java.io.tmpdir")+"/temp"+System.currentTimeMillis()+".pdom");
|
||||
File tmp = nonExistentTempFile("temp", "pdom");
|
||||
IIndexLocationConverter cvr= new ResourceContainerRelativeLocationConverter(cproject.getProject());
|
||||
final PDOMManager pdomManager = CCoreInternals.getPDOMManager();
|
||||
pdomManager.exportProjectPDOM(cproject, tmp, cvr, null);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.pdom.tests;
|
||||
|
||||
|
@ -52,7 +53,7 @@ public class PDOMProviderTests extends PDOMTestBase {
|
|||
}
|
||||
|
||||
public void testLifeCycle() throws Exception {
|
||||
final File tempPDOM= File.createTempFile("foo", "bar");
|
||||
final File tempPDOM= createTempFile("foo", "bar");
|
||||
|
||||
{
|
||||
ICProject cproject= CProjectHelper.createCCProject("foo" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER);
|
||||
|
@ -124,7 +125,7 @@ public class PDOMProviderTests extends PDOMTestBase {
|
|||
}
|
||||
|
||||
public void testCommonSDK() throws Exception {
|
||||
final File tempPDOM= File.createTempFile("foo", "bar");
|
||||
final File tempPDOM= createTempFile("foo", "bar");
|
||||
|
||||
{
|
||||
ICProject cproject= CProjectHelper.createCCProject("foo" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER);
|
||||
|
@ -242,7 +243,7 @@ public class PDOMProviderTests extends PDOMTestBase {
|
|||
}
|
||||
|
||||
public void testVersionMismatchOfExternalPDOM_178998() throws Exception {
|
||||
final File tempPDOM= File.createTempFile("foo", "bar");
|
||||
final File tempPDOM= createTempFile("foo", "bar");
|
||||
|
||||
{
|
||||
ICProject cproject= CProjectHelper.createCCProject("foo" + System.currentTimeMillis(), null, IPDOMManager.ID_FAST_INDEXER);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2013 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2014 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,10 +12,14 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.testplugin.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -62,6 +66,7 @@ public class BaseTestCase extends TestCase {
|
|||
private boolean fExpectFailure;
|
||||
private int fBugNumber;
|
||||
private int fExpectedLoggedNonOK;
|
||||
private Deque<File> filesToDeleteOnTearDown= new ArrayDeque<>();
|
||||
|
||||
public BaseTestCase() {
|
||||
super();
|
||||
|
@ -77,6 +82,7 @@ public class BaseTestCase extends TestCase {
|
|||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CPPASTNameBase.sAllowRecursionBindings= false;
|
||||
CPPASTNameBase.sAllowNameComputation= false;
|
||||
CModelListener.sSuppressUpdateOfLastRecentlyUsed= true;
|
||||
|
@ -84,8 +90,29 @@ public class BaseTestCase extends TestCase {
|
|||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
for (File file; (file = filesToDeleteOnTearDown.pollLast()) != null;) {
|
||||
file.delete();
|
||||
}
|
||||
ResourceHelper.cleanUp();
|
||||
TestScannerProvider.clear();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void deleteOnTearDown(File file) {
|
||||
filesToDeleteOnTearDown.add(file);
|
||||
}
|
||||
|
||||
protected File createTempFile(String prefix, String suffix) throws IOException {
|
||||
File file = File.createTempFile(prefix, suffix);
|
||||
filesToDeleteOnTearDown.add(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
protected File nonExistentTempFile(String prefix, String suffix) {
|
||||
File file= new File(System.getProperty("java.io.tmpdir"),
|
||||
prefix + System.currentTimeMillis() + '.' + suffix);
|
||||
filesToDeleteOnTearDown.add(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
protected static TestSuite suite(Class clazz) {
|
||||
|
@ -212,7 +239,7 @@ public class BaseTestCase extends TestCase {
|
|||
|
||||
@Override
|
||||
public void run(TestResult result) {
|
||||
if (!fExpectFailure || "true".equals(System.getProperty("SHOW_EXPECTED_FAILURES"))) {
|
||||
if (!fExpectFailure || Boolean.parseBoolean(System.getProperty("SHOW_EXPECTED_FAILURES"))) {
|
||||
super.run(result);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue