mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Remove projects from workspace at test startup
Various tests are not cleaning up properly after themselves, causing test failures on subsequent tests. Therefore start each test by deleting all projects. In addition, some tests were creating their test projects in their constructor. As all the constructors run before all the tests as part of test discovery it means that projects were being created in constructor and interfering with other tests later. With the deleting of all projects in @AfterEach these tests would have started failing. Therefore, change these tests to create their projects and do other initialize tasks in the setUp method. For older JUnit3 style tests: This substantially slows down tests as many tests rely on sharing the project between multiple tests and recreating those projects on each run is slow. Therefore this is not applied universally to all JUnit3 tests. For tests that are affected, those tests are moved to JUnit5 base test. Part of #117
This commit is contained in:
parent
ad478cecc1
commit
306708f5cb
5 changed files with 77 additions and 40 deletions
|
@ -33,7 +33,7 @@ public class AllLanguageSettingsProvidersCoreTestSuite {
|
|||
suite.addTest(LanguageSettingsManagerTests.suite());
|
||||
suite.addTest(LanguageSettingsSerializableProviderTests.suite());
|
||||
// Test converted to JUnit5: suite.addTest(LanguageSettingsPersistenceProjectTests.suite());
|
||||
suite.addTest(LanguageSettingsListenersTests.suite());
|
||||
// Test converted to JUnit5: suite.addTest(LanguageSettingsListenersTests.suite());
|
||||
suite.addTest(LanguageSettingsScannerInfoProviderTests.suite());
|
||||
suite.addTest(LanguageSettingsProviderReferencedProjectsTests.suite());
|
||||
return suite;
|
||||
|
|
|
@ -14,6 +14,13 @@
|
|||
|
||||
package org.eclipse.cdt.core.language.settings.providers;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -25,7 +32,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
|||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -35,13 +42,13 @@ import org.eclipse.core.resources.IResource;
|
|||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test cases to cover {@link ILanguageSettingsChangeListener} capabilities.
|
||||
*/
|
||||
public class LanguageSettingsListenersTests extends BaseTestCase {
|
||||
public class LanguageSettingsListenersTests extends BaseTestCase5 {
|
||||
// These should match corresponding entries defined in plugin.xml
|
||||
private static final String EXTENSION_REGISTERER_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_REGISTERER_PROVIDER_ID;
|
||||
private static final String EXTENSION_EDITABLE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_EDITABLE_PROVIDER_ID;
|
||||
|
@ -82,22 +89,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
|
||||
private MockLanguageSettingsChangeListener mockLseListener = new MockLanguageSettingsChangeListener();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param name - name of the test.
|
||||
*/
|
||||
public LanguageSettingsListenersTests(String name) {
|
||||
super(name);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
protected void afterEachCleanup() throws Exception {
|
||||
LanguageSettingsManager.unregisterLanguageSettingsChangeListener(mockLseListener);
|
||||
LanguageSettingsManager.setWorkspaceProviders(null);
|
||||
try {
|
||||
|
@ -108,28 +101,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
super.tearDown(); // includes ResourceHelper cleanup
|
||||
}
|
||||
|
||||
/**
|
||||
* @return - new TestSuite.
|
||||
*/
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(LanguageSettingsListenersTests.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* main function of the class.
|
||||
*
|
||||
* @param args - arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that global provider does not get unnecessarily registered on start.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_CheckExtensionProvider() throws Exception {
|
||||
// check if extension provider exists
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager
|
||||
|
@ -143,6 +120,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for non-shared configuration owned provider.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_OneOwnedByCfg() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -192,6 +170,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for non-shared configuration owned multiple providers.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_TwoOwnedByCfgs() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProject(this.getName(), null, new String[] {
|
||||
|
@ -256,6 +235,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for shared provider.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_OneGlobal() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -306,6 +286,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for multiple shared providers.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_TwoGlobal() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProject(this.getName(), null, new String[] {
|
||||
|
@ -369,6 +350,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for shared provider when the provider removed from the list.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_TwoGlobalMinusOne() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProject(this.getName(), null, new String[] {
|
||||
|
@ -449,6 +431,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for shared provider define in multiple projects.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_GlobalProviderTwoProjects() throws Exception {
|
||||
// create project 1
|
||||
IProject project_1 = ResourceHelper.createCDTProjectWithConfig(this.getName() + ".1");
|
||||
|
@ -522,6 +505,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for shared global providers not included in any configuration.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_GlobalProviderNotInUse() throws Exception {
|
||||
// create project
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager
|
||||
|
@ -553,6 +537,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered for shared global provider replacing another one in global list.
|
||||
*/
|
||||
@Test
|
||||
public void testListenerRegisterer_GlobalProviderAddRemoveOutsideTheProject() throws Exception {
|
||||
// create project
|
||||
ILanguageSettingsProvider workspaceProvider = LanguageSettingsManager
|
||||
|
@ -620,6 +605,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered when empty provider added and the resulting list of entries does not change.
|
||||
*/
|
||||
@Test
|
||||
public void testNotification_cfgProvider_AddEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -684,6 +670,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered where non-empty provider added.
|
||||
*/
|
||||
@Test
|
||||
public void testNotification_cfgProvider_AddNonEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -757,6 +744,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered during serialization.
|
||||
*/
|
||||
@Test
|
||||
public void testNotification_cfgProvider_SerializeEntries() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -831,6 +819,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered when providers are being added by 2 independent parties in parallel.
|
||||
*/
|
||||
@Test
|
||||
public void testNotification_cfgProvider_SerializeEntriesConcurrent() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -941,6 +930,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered during adding global empty provider.
|
||||
*/
|
||||
@Test
|
||||
public void testNotification_globalProvider_AddEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -1012,6 +1002,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered during adding global non-empty provider.
|
||||
*/
|
||||
@Test
|
||||
public void testNotification_globalProvider_AddNonEmptyProvider() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -1094,6 +1085,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test events triggered during serialization of global shared providers.
|
||||
*/
|
||||
@Test
|
||||
public void testNotification_globalProvider_SerializeEntries() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -1268,6 +1260,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test case when a project is present in the list of resources in delta.
|
||||
*/
|
||||
@Test
|
||||
public void testDelta_AffectedResources_Project() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -1344,6 +1337,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test case when a default resource (null) is represented in the list of resources in delta.
|
||||
*/
|
||||
@Test
|
||||
public void testDelta_AffectedResources_DefaultResource() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -1420,6 +1414,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test case when a folder is present in the list of resources in delta.
|
||||
*/
|
||||
@Test
|
||||
public void testDelta_AffectedResources_Folder() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -1497,6 +1492,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test case when a file is present in the list of resources in delta.
|
||||
*/
|
||||
@Test
|
||||
public void testDelta_AffectedResources_File() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
@ -1574,6 +1570,7 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
/**
|
||||
* Test case when a mix of files and folders is present in the list of resources in delta.
|
||||
*/
|
||||
@Test
|
||||
public void testDelta_AffectedResources_Mix() throws Exception {
|
||||
// create project
|
||||
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||
|
|
|
@ -43,6 +43,7 @@ public abstract class FileBasePluginTestCase extends TestCase {
|
|||
static int numProjects;
|
||||
static Class className;
|
||||
static ICProject cPrj;
|
||||
private Class className2;
|
||||
|
||||
public FileBasePluginTestCase() {
|
||||
}
|
||||
|
@ -80,7 +81,13 @@ public abstract class FileBasePluginTestCase extends TestCase {
|
|||
|
||||
public FileBasePluginTestCase(String name, Class className) {
|
||||
super(name);
|
||||
initialize(className);
|
||||
className2 = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initialize(className2);
|
||||
}
|
||||
|
||||
public void cleanupProject() throws Exception {
|
||||
|
|
|
@ -47,6 +47,7 @@ public abstract class DOMFileBasePluginTest extends TestCase {
|
|||
static int numProjects = 0;
|
||||
static Class className;
|
||||
static ICProject cPrj;
|
||||
private Class className2;
|
||||
|
||||
public DOMFileBasePluginTest() {
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ public abstract class DOMFileBasePluginTest extends TestCase {
|
|||
|
||||
public DOMFileBasePluginTest(String name, Class className) {
|
||||
super(name);
|
||||
initialize(className);
|
||||
className2 = className;
|
||||
}
|
||||
|
||||
public void cleanupProject() throws Exception {
|
||||
|
@ -100,6 +101,12 @@ public abstract class DOMFileBasePluginTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
initialize(className2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (project == null || !project.exists())
|
||||
|
|
|
@ -37,9 +37,13 @@ import org.eclipse.cdt.internal.core.CCoreInternals;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
|
||||
import org.eclipse.cdt.internal.core.pdom.CModelListener;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -115,6 +119,7 @@ public abstract class BaseTestCase5 {
|
|||
this.testInfo = testInfo;
|
||||
|
||||
logMonitoring.start();
|
||||
removeLeftOverProjects();
|
||||
|
||||
CPPASTNameBase.sAllowRecursionBindings = false;
|
||||
CPPASTNameBase.sAllowNameComputation = false;
|
||||
|
@ -130,6 +135,7 @@ public abstract class BaseTestCase5 {
|
|||
TestScannerProvider.clear();
|
||||
|
||||
logMonitoring.stop(fExpectedLoggedNonOK);
|
||||
BaseTestCase5.removeLeftOverProjects();
|
||||
}
|
||||
|
||||
protected void deleteOnTearDown(File file) {
|
||||
|
@ -160,6 +166,26 @@ public abstract class BaseTestCase5 {
|
|||
fExpectedLoggedNonOK = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some tests don't cleanup after themselves well and leave projects
|
||||
* in the workspace. Therefore run this code before each test
|
||||
* to make sure all left over projects are deleted.
|
||||
*/
|
||||
public static void removeLeftOverProjects() throws CoreException {
|
||||
MultiStatus multiStatus = new MultiStatus(BaseTestCase5.class, 0,
|
||||
"Failed to remove left over projects from previous tests");
|
||||
for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
|
||||
try {
|
||||
p.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new NullProgressMonitor());
|
||||
} catch (CoreException e) {
|
||||
multiStatus.add(Status.error("failed to delete " + p.toString(), e));
|
||||
}
|
||||
}
|
||||
if (multiStatus.getChildren().length > 0) {
|
||||
throw new CoreException(multiStatus);
|
||||
}
|
||||
}
|
||||
|
||||
public static void waitForIndexer(ICProject project) throws InterruptedException {
|
||||
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, null);
|
||||
assertTrue(CCoreInternals.getPDOMManager().joinIndexer(INDEXER_TIMEOUT_SEC * 1000, npm()));
|
||||
|
|
Loading…
Add table
Reference in a new issue