Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah Graham2020-12-21 20:22:55 +0000
committerJonah Graham2021-02-01 16:32:58 +0000
commit64e21a93c46623fb0f641fd25d0e537cc10f52a7 (patch)
tree1db1772521d78b561a4c670f57fef026793d7805
parent5c82be881d09ca8df67d334934554c4df3b7f199 (diff)
downloadorg.eclipse.cdt-64e21a93c46623fb0f641fd25d0e537cc10f52a7.tar.gz
org.eclipse.cdt-64e21a93c46623fb0f641fd25d0e537cc10f52a7.tar.xz
org.eclipse.cdt-64e21a93c46623fb0f641fd25d0e537cc10f52a7.zip
Bug 499777: Flaky and slow test tags
to exclude flaky and slow tests from gerrit runs and main build tests can be tagged as such. See BTreeExpensiveTests for example of a slow test and Bug_303953Test for an example of a flaky one. The root README.md has a few notes on converting tests to JUnit5 and adding annotations to mark them slow or flaky. Change-Id: I03a4004112e6a500d8ec2771d68f14f7dc5f67fb
-rw-r--r--README.md26
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/AbstractBuilderTest.java32
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AutomatedIntegrationSuite.java5
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_303953Test.java9
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_335476Test.java (renamed from build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_335476.java)24
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/RegressionTestSuite.java2
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildClean.java31
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyLibsTests.java47
-rw-r--r--core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/cdescriptor/tests/CDescriptorTests.java151
-rw-r--r--core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTestSuite.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java97
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeExpensiveTests.java19
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java19
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestSuite.java2
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java3
-rw-r--r--core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java25
16 files changed, 281 insertions, 213 deletions
diff --git a/README.md b/README.md
index bd24783d3ed..29a190f7955 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,16 @@ with `-DskipDoc=true`
Running tests for CDT can be time consuming. For local builds this can be skipped
with `-DskipTests=true`.
+#### excludedGroups to skip slow or flaky tests
+
+Some tests in CDT are fairly slow to run and rarely are exercising actively changing code. Some tests in CDT are fairly flaky to run and rarely are exercising actively changing code. These tests are excluded from the main CDT builds (both master/branch and gerrit verify jobs) and are instead run in a special job. Therefore the Jenkinsfiles for master/branch and gerrit use excludedGroups by default.
+
+To skip slow tests use `-DexcludedGroups=slowTest`
+To skip flaky tests use `-DexcludedGroups=flakyTest`
+To skip both use `-DexcludedGroups=flakyTest,slowTest`
+
+See section below on marking tests for how to annotate a test properly.
+
#### jgit.dirtyWorkingTree-cdtDefault
Running a build with uncommitted changes will normally cause an error. To run a build with
@@ -147,3 +157,19 @@ When the host is Windows, getting docker to behave as encoded in the pom.xml may
See also `jniheaders` profile above.
+### Marking tests as Slow or Flaky
+
+Tests in CDT can be marked as Slow or Flaky to prevent them running as part of the standard test suites. See excludedGroups to skip slow or flaky tests sections above.
+
+The proper way to mark a test as slow or flaky is to add a JUnit5 @Tag on the test with `flakyTest` or `slowTest`. The canonical values for these are in the JUnit5 base test `org.eclipse.cdt.core.testplugin.util.BaseTestCase5`.
+
+These tags can only be applied to JUnit5 (aka Jupiter) tests. If a test needs converting, do that in a separate commit before adding the tags so that the test refactoring can be verified before excluding the test from normal runs.
+
+### Converting tests to JUnit5
+
+To take advantage of new features, such as excluding flaky and slow tests, individual tests need to JUnit5 (aka Jupiter). If a test is currently written in JUnit4 or JUnit3 style it needs to be converted to JUnit5 first. Those tests that currently derive from `org.eclipse.cdt.core.testplugin.util.BaseTestCase` can change to `org.eclipse.cdt.core.testplugin.util.BaseTestCase5` and make further adjustments. Common adjustments are:
+- refactoring `setUp`/`tearDown` methods to use `@BeforeEach` and `@AfterEach` annotations
+- refactor complicated uses of TestSuites in JUnit3 that were workarounds for the lack of JUnit features like `@BeforeAll` and `@AfterAll`.
+- add `@Test` annotation (make sure to use `org.junit.jupiter.api.Test` and not JUnit4's `org.junit.Test`)
+- statically import assert methods from `org.junit.jupiter.api.Assertions` (note that in JUnit5 the message is now last instead of first, this generally leads to an error by changing the imports, except in the case of `assertEquals` where the first and third parameter are `String`)
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/AbstractBuilderTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/AbstractBuilderTest.java
index bc5a5db06c3..0c29dbb14dd 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/AbstractBuilderTest.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/AbstractBuilderTest.java
@@ -14,6 +14,9 @@
package org.eclipse.cdt.managedbuilder.testplugin;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -42,8 +45,9 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.jobs.Job;
-
-import junit.framework.TestCase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestInfo;
/**
* Abstract builder test which provides utility methods for:
@@ -55,7 +59,7 @@ import junit.framework.TestCase;
* <li>Cleaning up the workspace at the end</li>
* </ul>
*/
-public abstract class AbstractBuilderTest extends TestCase {
+public abstract class AbstractBuilderTest {
private static final boolean WINDOWS = java.io.File.separatorChar == '\\';
static final String PATH = "builderTests";
@@ -63,16 +67,14 @@ public abstract class AbstractBuilderTest extends TestCase {
private String workspace;
private List<IProject> projects;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @BeforeEach
+ public void setUp() throws Exception {
setAutoBuilding(false);
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- ResourceHelper.cleanUp(getName());
+ @AfterEach
+ public void tearDown(TestInfo testInfo) throws Exception {
+ ResourceHelper.cleanUp(testInfo.getDisplayName());
// Bug 327126 Stop the indexer before tearing down so we don't deadlock
Job.getJobManager().cancel(CCorePlugin.getPDOMManager());
Job.getJobManager().join(CCorePlugin.getPDOMManager(), null);
@@ -113,7 +115,7 @@ public abstract class AbstractBuilderTest extends TestCase {
};
getWorkspace().run(body, null);
} finally {
- assertTrue(verifier.getMessage(), verifier.isDeltaValid());
+ assertTrue(verifier.isDeltaValid(), verifier.getMessage());
getWorkspace().removeResourceChangeListener(verifier);
printAllMarkers();
}
@@ -240,14 +242,6 @@ public abstract class AbstractBuilderTest extends TestCase {
return resources;
}
- public AbstractBuilderTest() {
- super();
- }
-
- public AbstractBuilderTest(String name) {
- super(name);
- }
-
protected void setWorkspace(String name) {
workspace = name;
projects = new ArrayList<>();
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AutomatedIntegrationSuite.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AutomatedIntegrationSuite.java
index df8a5912c8a..7c2dae81626 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AutomatedIntegrationSuite.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AutomatedIntegrationSuite.java
@@ -22,11 +22,10 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.managedbuilder.core.regressions.RegressionTestSuite;
import org.eclipse.cdt.managedbuilder.core.tests.BuildDescriptionModelTests;
import org.eclipse.cdt.managedbuilder.core.tests.BuildSystem40Tests;
-import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCore20Tests;
+import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCore_SharedToolOptionsTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildDependencyCalculatorTests;
-import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildDependencyLibsTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildEnvironmentTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildMacrosTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildTCSupportedTest;
@@ -74,7 +73,7 @@ public class AutomatedIntegrationSuite {
suite.addTest(AllLanguageSettingsProvidersMBSTestSuite.suite());
// managedbuilder.core.tests
- suite.addTest(ManagedBuildDependencyLibsTests.suite());
+ // Test converted to JUnit5: suite.addTest(ManagedBuildDependencyLibsTests.suite());
suite.addTest(ManagedBuildCore20Tests.suite());
suite.addTest(ManagedBuildCoreTests.suite());
suite.addTest(ManagedProjectUpdateTests.suite());
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_303953Test.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_303953Test.java
index 70f1554f63d..389ede01354 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_303953Test.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_303953Test.java
@@ -13,11 +13,14 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.regressions;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.managedbuilder.testplugin.AbstractBuilderTest;
import org.eclipse.cdt.managedbuilder.testplugin.ResourceDeltaVerifier;
import org.eclipse.core.resources.IFile;
@@ -26,6 +29,8 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests that removing the last source file from a directory
@@ -34,6 +39,8 @@ import org.eclipse.core.runtime.CoreException;
*/
public class Bug_303953Test extends AbstractBuilderTest {
+ @Tag(BaseTestCase5.FLAKY_TEST_TAG)
+ @Test
public void testBuildAfterSourcefileDelete() throws CoreException {
setWorkspace("regressions");
final IProject app = loadProject("helloworldC");
@@ -52,7 +59,7 @@ public class Bug_303953Test extends AbstractBuilderTest {
// Delete helloworldC
IFile srcFile = app.getFile("src/helloworldC.c");
- assertTrue("1.1", srcFile.exists());
+ assertTrue(srcFile.exists(), "1.1");
srcFile.delete(false, null);
// Build again
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_335476.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_335476Test.java
index b2345a0f3a9..0ade26c8aba 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_335476.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_335476Test.java
@@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.regressions;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
@@ -27,22 +30,25 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.Path;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
/**
* This tests that an environment variable, which is part of the build
* (in this case referenced by a -I), makes it through to makefile
* correctly when it changes.
*/
-public class Bug_335476 extends AbstractBuilderTest {
+@Disabled("This is a test for a known failure - see Bug 335476")
+public class Bug_335476Test extends AbstractBuilderTest {
private final String VAR_NAME = "INC";
IProject app;
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
ICdtVariableManager buildMacroManager = CCorePlugin.getDefault().getCdtVariableManager();
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @BeforeEach
+ public void setUpLocal() throws Exception {
setWorkspace("regressions");
app = loadProject("bug_335476");
// Ensure Debug is the active configuration
@@ -94,11 +100,9 @@ public class Bug_335476 extends AbstractBuilderTest {
String value2 = buildMacroManager.resolveValue("${" + VAR_NAME + "}", "", ";",
CCorePlugin.getDefault().getProjectDescription(app, false).getActiveConfiguration());
- assertTrue(i + " EnvManager " + expected + " exepected, but was: " + value, expected.equals(value));
- assertTrue(i + " CdtVarManager " + expected + " exepected, but was: " + value2,
- expected.equals(value2));
- assertTrue(i + " Makefile: " + expected + " exepected, but was: " + buildVar,
- expected.equals(buildVar));
+ assertEquals(expected, value, i + " EnvManager " + expected + " exepected, but was: " + value);
+ assertEquals(expected, value2, i + " CdtVarManager " + expected + " exepected, but was: " + value2);
+ assertEquals(expected, buildVar, i + " Makefile: " + expected + " exepected, but was: " + buildVar);
found = true;
}
// Check that we at least matched
@@ -115,10 +119,12 @@ public class Bug_335476 extends AbstractBuilderTest {
}
}
+ @Test
public void testChangingEnvironmentBuildSystem_FULL_BUILD() throws Exception {
runTest(IncrementalProjectBuilder.FULL_BUILD);
}
+ @Test
public void testChangingEnvironmentBuildSystem_INC_BUILD() throws Exception {
runTest(IncrementalProjectBuilder.INCREMENTAL_BUILD);
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/RegressionTestSuite.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/RegressionTestSuite.java
index 55af3fcb28a..94de1f2a43f 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/RegressionTestSuite.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/RegressionTestSuite.java
@@ -26,7 +26,7 @@ public class RegressionTestSuite extends TestCase {
TestSuite suite = new TestSuite(RegressionTestSuite.class.getName());
// Test that common builder does the correct amount of work.
- suite.addTestSuite(Bug_303953Test.class);
+ // Test converted to JUnit5: suite.addTest(new JUnit4TestAdapter(Bug_303953Test.class));
return suite;
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildClean.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildClean.java
index 40f3dd723a6..f9a91f7cbac 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildClean.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildClean.java
@@ -13,6 +13,10 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.Collection;
import org.eclipse.cdt.managedbuilder.testplugin.AbstractBuilderTest;
@@ -24,34 +28,37 @@ import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public class ManagedBuildClean extends AbstractBuilderTest {
private static final String PROJ_PATH = "testCleanProjects";
private IProject fInternalBuilderProject;
private IProject fExternalBuilderProject;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @BeforeEach
+ public void setUpLocal() throws Exception {
IWorkspaceDescription wsDescription = ResourcesPlugin.getWorkspace().getDescription();
wsDescription.setAutoBuilding(false);
ResourcesPlugin.getWorkspace().setDescription(wsDescription);
- assertNotNull("Cannot create testCleanInternal project",
- fInternalBuilderProject = ManagedBuildTestHelper.loadProject("testCleanInternal", PROJ_PATH));
- assertNotNull("Cannot create testCleanExternal project",
- fExternalBuilderProject = ManagedBuildTestHelper.loadProject("testCleanExternal", PROJ_PATH));
+ assertNotNull(fInternalBuilderProject = ManagedBuildTestHelper.loadProject("testCleanInternal", PROJ_PATH),
+ "Cannot create testCleanInternal project");
+ assertNotNull(fExternalBuilderProject = ManagedBuildTestHelper.loadProject("testCleanExternal", PROJ_PATH),
+ "Cannot create testCleanExternal project");
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @AfterEach
+ public void tearDownLocal() throws Exception {
ManagedBuildTestHelper.removeProject(fInternalBuilderProject.getName());
}
+ @Test
public void testCleanInternal() throws Exception {
helperTestClean(fInternalBuilderProject, false);
}
+ @Test
public void testCleanExternal() throws Exception {
helperTestClean(fExternalBuilderProject, true);
}
@@ -63,7 +70,7 @@ public class ManagedBuildClean extends AbstractBuilderTest {
Collection<IResource> resources = getProjectBuildExeResources(project.getName(), "Debug",
"src/" + project.getName(), externalBuilder);
for (IResource resource : resources) {
- assertTrue("Resource not found: " + resource, resource.exists());
+ assertTrue(resource.exists(), "Resource not found: " + resource);
}
// do a clean and make sure files are gone
@@ -77,7 +84,7 @@ public class ManagedBuildClean extends AbstractBuilderTest {
// makefiles are not removed when cleaning
continue;
}
- assertFalse("Resource not deleted: " + resource, resource.exists());
+ assertFalse(resource.exists(), "Resource not deleted: " + resource);
}
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyLibsTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyLibsTests.java
index 437cbeb2159..a304317667a 100644
--- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyLibsTests.java
+++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedBuildDependencyLibsTests.java
@@ -13,6 +13,10 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.ArrayList;
import java.util.List;
@@ -40,9 +44,9 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
private static final String PROJ_PATH = "depLibsProjects";
@@ -52,19 +56,6 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
private IToolChain[] allToolChains;
- public ManagedBuildDependencyLibsTests(String name) {
- super(name);
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(ManagedBuildDependencyLibsTests.class.getName());
-
- suite.addTest(new ManagedBuildDependencyLibsTests("testDepLibs"));
- suite.addTest(new ManagedBuildDependencyLibsTests("testDepUObjs"));
- suite.addTest(new ManagedBuildDependencyLibsTests("testGetArtifactTimeStampEscapeURI_bug377295"));
- return suite;
- }
-
private void buildProject(IProject curProject) {
try {
@@ -84,27 +75,30 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
}
@Override
- protected void setUp() throws Exception {
- super.setUp();
+ public void setUp() {
+ // Don't run super class setUp
+ }
+
+ @BeforeEach
+ public void setUpLocal() throws Exception {
allToolChains = ManagedBuildManager.getRealToolChains();
IWorkspaceDescription wsDescription = ResourcesPlugin.getWorkspace().getDescription();
wsDescription.setAutoBuilding(false);
ResourcesPlugin.getWorkspace().setDescription(wsDescription);
- assertNotNull("Cannot create tapp project", fTapp = ManagedBuildTestHelper.loadProject("tapp", PROJ_PATH));
- assertNotNull("Cannot create tlib project", fTlib = ManagedBuildTestHelper.loadProject("tlib", PROJ_PATH));
- assertNotNull("Cannot create tobjs project", fTobjs = ManagedBuildTestHelper.loadProject("tobjs", PROJ_PATH));
+ assertNotNull(fTapp = ManagedBuildTestHelper.loadProject("tapp", PROJ_PATH), "Cannot create tapp project");
+ assertNotNull(fTlib = ManagedBuildTestHelper.loadProject("tlib", PROJ_PATH), "Cannot create tlib project");
+ assertNotNull(fTobjs = ManagedBuildTestHelper.loadProject("tobjs", PROJ_PATH), "Cannot create tobjs project");
IProjectDescription projDescription = fTapp.getDescription();
projDescription.setReferencedProjects(new IProject[] { fTlib, fTobjs });
fTapp.setDescription(projDescription, new NullProgressMonitor());
IToolChain toolChain = setToolChain(fTapp, null);
- assertNotNull("No compatible tool chain.", toolChain);
+ assertNotNull(toolChain, "No compatible tool chain.");
setToolChain(fTlib, toolChain);
setToolChain(fTobjs, toolChain);
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @AfterEach
+ public void tearDownLocal() throws Exception {
ManagedBuildTestHelper.removeProject(fTapp.getName());
ManagedBuildTestHelper.removeProject(fTlib.getName());
ManagedBuildTestHelper.removeProject(fTobjs.getName());
@@ -215,6 +209,7 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
return name;
}
+ @Test
public void testDepLibs() {
buildProject(fTapp);
long timeStamp = getArtifactTimeStamp(fTapp);
@@ -238,6 +233,7 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
}
}
+ @Test
public void testDepUObjs() {
buildProject(fTapp);
long timeStamp = getArtifactTimeStamp(fTapp);
@@ -264,6 +260,7 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
// Tests that the URI used to get the time stamp of the artifact is escaped correctly
// See AdditionalInput.getArtifactTimeStamp(IToolChain toolChain)
+ @Test
public void testGetArtifactTimeStampEscapeURI_bug377295() throws CoreException {
setWorkspace("regressions");
final IProject project = loadProject("helloworldC");
diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/cdescriptor/tests/CDescriptorTests.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/cdescriptor/tests/CDescriptorTests.java
index 8c8b42f6f05..472d3650315 100644
--- a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/cdescriptor/tests/CDescriptorTests.java
+++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/cdescriptor/tests/CDescriptorTests.java
@@ -16,6 +16,12 @@
***********************************************************************/
package org.eclipse.cdt.core.cdescriptor.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+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.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -32,7 +38,7 @@ import org.eclipse.cdt.core.ICOwnerInfo;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
-import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.internal.core.pdom.PDOMManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -42,33 +48,20 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.junit.Assert;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-public class CDescriptorTests extends BaseTestCase {
+@Tag(BaseTestCase5.FLAKY_TEST_TAG)
+public class CDescriptorTests extends BaseTestCase5 {
static String projectId = CTestPlugin.PLUGIN_ID + ".TestProject";
static IProject fProject;
static CDescriptorListener listener = new CDescriptorListener();
static volatile CDescriptorEvent fLastEvent;
- /**
- * Constructor for CDescriptorTest.
- *
- * @param name
- */
- public CDescriptorTests(String name) {
- super(name);
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(CDescriptorTests.class);
- return suite;
- }
-
- @Override
- protected void setUp() throws Exception {
+ @BeforeEach
+ protected void setUpLocal() throws Exception {
CTestPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
@@ -97,8 +90,8 @@ public class CDescriptorTests extends BaseTestCase {
}, null);
}
- @Override
- protected void tearDown() throws Exception {
+ @AfterEach
+ protected void tearDownLocal() throws Exception {
fProject.delete(true, true, null);
}
@@ -120,29 +113,32 @@ public class CDescriptorTests extends BaseTestCase {
}
}
+ @Test
public void testDescriptorCreation() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
- Assert.assertNotNull(fLastEvent);
- Assert.assertEquals(fLastEvent.getDescriptor(), desc);
- Assert.assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_ADDED);
- Assert.assertEquals(fLastEvent.getFlags(), 0);
+ assertNotNull(fLastEvent);
+ assertEquals(fLastEvent.getDescriptor(), desc);
+ assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_ADDED);
+ assertEquals(fLastEvent.getFlags(), 0);
fLastEvent = null;
- Assert.assertEquals(fProject, desc.getProject());
- Assert.assertEquals("*", desc.getPlatform());
+ assertEquals(fProject, desc.getProject());
+ assertEquals("*", desc.getPlatform());
}
+ @Test
public void testDescriptorOwner() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
ICOwnerInfo owner = desc.getProjectOwner();
- Assert.assertEquals(projectId, owner.getID());
- Assert.assertEquals("*", owner.getPlatform());
- Assert.assertEquals("C/C++ Test Project", owner.getName());
+ assertEquals(projectId, owner.getID());
+ assertEquals("*", owner.getPlatform());
+ assertEquals("C/C++ Test Project", owner.getName());
}
// Disabled this test because it fails every now and then and it tests deprecated API
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340123
+ // @Test
public void _testConcurrentDescriptorCreation() throws Exception {
for (int i = 0; i < 100; i++) {
fProject.close(null);
@@ -179,6 +175,7 @@ public class CDescriptorTests extends BaseTestCase {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185930
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193503
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=196118
+ @Test
public void testConcurrentDescriptorModification() throws Exception {
int lastLength = 0;
for (int i = 0; i < 100; ++i) {
@@ -230,12 +227,12 @@ public class CDescriptorTests extends BaseTestCase {
} catch (InterruptedException e) {
}
}
- assertNull("Exception occurred: " + exception[j], exception[j]);
+ assertNull(exception[j], "Exception occurred: " + exception[j]);
}
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
int lengthAfter = desc.getProjectStorageElement("testElement").getChildren().length;
lastLength += threads.length; // Update last lengths to what we expect
- assertEquals("Iteration count: " + i, lastLength, lengthAfter);
+ assertEquals(lastLength, lengthAfter, "Iteration count: " + i);
fLastEvent = null;
}
@@ -245,6 +242,7 @@ public class CDescriptorTests extends BaseTestCase {
* This test should pass as two threads, operating on the different storage elements
* (outside of an operation) should be safe.
*/
+ @Test
public void testConcurrentDifferentStorageElementModification() throws Exception {
for (int i = 0; i < 100; ++i) {
Thread t = new Thread() {
@@ -273,15 +271,16 @@ public class CDescriptorTests extends BaseTestCase {
fLastEvent = null;
}
- Assert.assertEquals(100, CCorePlugin.getDefault().getCProjectDescription(fProject, false)
+ assertEquals(100, CCorePlugin.getDefault().getCProjectDescription(fProject, false)
.getProjectStorageElement("testElement4").getChildren().length);
- Assert.assertEquals(100, CCorePlugin.getDefault().getCProjectDescription(fProject, false)
+ assertEquals(100, CCorePlugin.getDefault().getCProjectDescription(fProject, false)
.getProjectStorageElement("testElement5").getChildren().length);
}
/*
* Tests that (non-structural) changes to the storage element tree work as expected.
*/
+ @Test
public void testConcurrentSameStorageElementModification() throws Exception {
for (int i = 0; i < 100; ++i) {
Thread t = new Thread() {
@@ -310,17 +309,18 @@ public class CDescriptorTests extends BaseTestCase {
fLastEvent = null;
}
- Assert.assertEquals(200, CCorePlugin.getDefault().getCProjectDescription(fProject, false)
+ assertEquals(200, CCorePlugin.getDefault().getCProjectDescription(fProject, false)
.getProjectStorageElement("testElement6").getChildren().length);
}
/*
* Tests deadlock when accessing c project description concurrently from two threads
*/
+ @Test
public void testDeadlockDuringProjectCreation() throws Exception {
for (int i = 0; i < 10; ++i) {
- tearDown();
- setUp();
+ tearDownLocal();
+ setUpLocal();
Thread t = new Thread() {
@Override
public void run() {
@@ -348,33 +348,37 @@ public class CDescriptorTests extends BaseTestCase {
}
}
+ @Test
public void testDescriptorConversion() {
}
+ @Test
public void testExtensionCreation() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
ICExtensionReference extRef = desc.create("org.eclipse.cdt.testextension", "org.eclipse.cdt.testextensionID");
- Assert.assertNotNull(fLastEvent);
- Assert.assertEquals(fLastEvent.getDescriptor(), desc);
- Assert.assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
- Assert.assertEquals(fLastEvent.getFlags(), CDescriptorEvent.EXTENSION_CHANGED);
+ assertNotNull(fLastEvent);
+ assertEquals(fLastEvent.getDescriptor(), desc);
+ assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
+ assertEquals(fLastEvent.getFlags(), CDescriptorEvent.EXTENSION_CHANGED);
fLastEvent = null;
- Assert.assertEquals("org.eclipse.cdt.testextension", extRef.getExtension());
- Assert.assertEquals("org.eclipse.cdt.testextensionID", extRef.getID());
+ assertEquals("org.eclipse.cdt.testextension", extRef.getExtension());
+ assertEquals("org.eclipse.cdt.testextensionID", extRef.getID());
}
+ @Test
public void testExtensionGet() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
desc.create("org.eclipse.cdt.testextension", "org.eclipse.cdt.testextensionID");
ICExtensionReference extRef[] = desc.get("org.eclipse.cdt.testextension");
- Assert.assertEquals("org.eclipse.cdt.testextension", extRef[0].getExtension());
- Assert.assertEquals("org.eclipse.cdt.testextensionID", extRef[0].getID());
+ assertEquals("org.eclipse.cdt.testextension", extRef[0].getExtension());
+ assertEquals("org.eclipse.cdt.testextensionID", extRef[0].getID());
}
+ @Test
public void testExtensionData() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
desc.create("org.eclipse.cdt.testextension", "org.eclipse.cdt.testextensionID");
@@ -382,17 +386,18 @@ public class CDescriptorTests extends BaseTestCase {
ICExtensionReference extRef[] = desc.get("org.eclipse.cdt.testextension");
extRef[0].setExtensionData("testKey", "testValue");
- Assert.assertNotNull(fLastEvent);
- Assert.assertEquals(fLastEvent.getDescriptor(), desc);
- Assert.assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
- Assert.assertEquals(fLastEvent.getFlags(), 0);
+ assertNotNull(fLastEvent);
+ assertEquals(fLastEvent.getDescriptor(), desc);
+ assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
+ assertEquals(fLastEvent.getFlags(), 0);
fLastEvent = null;
- Assert.assertEquals("testValue", extRef[0].getExtensionData("testKey"));
+ assertEquals("testValue", extRef[0].getExtensionData("testKey"));
extRef[0].setExtensionData("testKey", null);
- Assert.assertEquals(null, extRef[0].getExtensionData("testKey"));
+ assertEquals(null, extRef[0].getExtensionData("testKey"));
}
+ @Test
public void testExtensionRemove() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
desc.create("org.eclipse.cdt.testextension", "org.eclipse.cdt.testextensionID");
@@ -400,43 +405,46 @@ public class CDescriptorTests extends BaseTestCase {
ICExtensionReference extRef[] = desc.get("org.eclipse.cdt.testextension");
desc.remove(extRef[0]);
- Assert.assertNotNull(fLastEvent);
- Assert.assertEquals(fLastEvent.getDescriptor(), desc);
- Assert.assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
- Assert.assertEquals(fLastEvent.getFlags(), CDescriptorEvent.EXTENSION_CHANGED);
+ assertNotNull(fLastEvent);
+ assertEquals(fLastEvent.getDescriptor(), desc);
+ assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
+ assertEquals(fLastEvent.getFlags(), CDescriptorEvent.EXTENSION_CHANGED);
fLastEvent = null;
}
+ @Test
public void testProjectDataCreate() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
ICStorageElement data = desc.getProjectStorageElement("testElement");
data.createChild("test");
desc.saveProjectData();
- Assert.assertNotNull(fLastEvent);
- Assert.assertEquals(fLastEvent.getDescriptor(), desc);
- Assert.assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
- Assert.assertEquals(fLastEvent.getFlags(), 0);
+ assertNotNull(fLastEvent);
+ assertEquals(fLastEvent.getDescriptor(), desc);
+ assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
+ assertEquals(fLastEvent.getFlags(), 0);
fLastEvent = null;
}
+ @Test
public void testProjectDataDelete() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
ICStorageElement data = desc.getProjectStorageElement("testElement");
data.createChild("test");
ICStorageElement[] list = data.getChildrenByName("test");
- Assert.assertEquals(1, list.length);
+ assertEquals(1, list.length);
data.removeChild(list[0]);
desc.saveProjectData();
- Assert.assertNotNull(fLastEvent);
- Assert.assertEquals(fLastEvent.getDescriptor(), desc);
- Assert.assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
- Assert.assertEquals(fLastEvent.getFlags(), 0);
+ assertNotNull(fLastEvent);
+ assertEquals(fLastEvent.getDescriptor(), desc);
+ assertEquals(fLastEvent.getType(), CDescriptorEvent.CDTPROJECT_CHANGED);
+ assertEquals(fLastEvent.getFlags(), 0);
fLastEvent = null;
}
+ @Test
public void testCProjectDescriptionDescriptorInteraction() throws Exception {
for (int i = 1; i < 100; i++) {
// Create a descriptor with some test data
@@ -469,6 +477,7 @@ public class CDescriptorTests extends BaseTestCase {
}
}
+ @Test
public void testAccumulatingBlankLinesInProjectData() throws Exception {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(fProject, true);
ICStorageElement data = desc.getProjectStorageElement("testElement");
@@ -491,8 +500,8 @@ public class CDescriptorTests extends BaseTestCase {
String dotCProject2 = readDotCProjectFile(fProject);
long mtime2 = fProject.getFile(".cproject").getLocalTimeStamp();
- assertEquals("Difference in .cproject file", dotCProject1, dotCProject2);
- assertTrue(".cproject file has been written", mtime1 == mtime2);
+ assertEquals(dotCProject1, dotCProject2, "Difference in .cproject file");
+ assertTrue(mtime1 == mtime2, ".cproject file has been written");
// do it a second time - just to be sure
fProject.close(null);
@@ -508,8 +517,8 @@ public class CDescriptorTests extends BaseTestCase {
String dotCProject3 = readDotCProjectFile(fProject);
long mtime3 = fProject.getFile(".cproject").getLocalTimeStamp();
- assertEquals("Difference in .cproject file", dotCProject2, dotCProject3);
- assertTrue(".cproject file has been written", mtime2 == mtime3);
+ assertEquals(dotCProject2, dotCProject3, "Difference in .cproject file");
+ assertTrue(mtime2 == mtime3, ".cproject file has been written");
}
/**
diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTestSuite.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTestSuite.java
index 412b11440c2..e8c6498023e 100644
--- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/AllLanguageSettingsProvidersCoreTestSuite.java
@@ -32,7 +32,7 @@ public class AllLanguageSettingsProvidersCoreTestSuite {
suite.addTest(LanguageSettingsExtensionsTests.suite());
suite.addTest(LanguageSettingsManagerTests.suite());
suite.addTest(LanguageSettingsSerializableProviderTests.suite());
- suite.addTest(LanguageSettingsPersistenceProjectTests.suite());
+ // Test converted to JUnit5: suite.addTest(LanguageSettingsPersistenceProjectTests.suite());
suite.addTest(LanguageSettingsListenersTests.suite());
suite.addTest(LanguageSettingsScannerInfoProviderTests.suite());
suite.addTest(LanguageSettingsProviderReferencedProjectsTests.suite());
diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java
index 9ff5fd507b6..c2825c761d9 100644
--- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java
+++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/language/settings/providers/LanguageSettingsPersistenceProjectTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Andrew Gvozdev and others.
+ * Copyright (c) 2009, 2020 Andrew Gvozdev and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,13 @@
package org.eclipse.cdt.core.language.settings.providers;
+import static org.junit.Assert.assertNull;
+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.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -26,7 +33,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.WriteAccessException;
import org.eclipse.cdt.core.testplugin.CModelMock;
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.XmlUtil;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
@@ -34,15 +41,16 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import junit.framework.TestSuite;
-
/**
* Test cases testing LanguageSettingsProvider functionality related to persistence.
*/
-public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
+public class LanguageSettingsPersistenceProjectTests extends BaseTestCase5 {
// These should match extension points defined in plugin.xml
private static final String EXTENSION_BASE_PROVIDER_ID = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_ID;
private static final String EXTENSION_BASE_PROVIDER_NAME = LanguageSettingsExtensionsTests.EXTENSION_BASE_PROVIDER_NAME;
@@ -130,39 +138,9 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
}
}
- /**
- * Constructor.
- * @param name - name of the test.
- */
- public LanguageSettingsPersistenceProjectTests(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
+ @AfterEach
+ protected void tearDownLocal() throws Exception {
LanguageSettingsManager.setWorkspaceProviders(null);
- super.tearDown(); // includes ResourceHelper cleanup
- }
-
- /**
- * @return - new TestSuite.
- */
- public static TestSuite suite() {
- return new TestSuite(LanguageSettingsPersistenceProjectTests.class);
- }
-
- /**
- * main function of the class.
- *
- * @param args - arguments
- */
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
}
/**
@@ -195,6 +173,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Persist and reload when no customized providers are defined in the workspace.
*/
+ @Test
public void testWorkspacePersistence_NoProviders() throws Exception {
// serialize language settings of user defined providers (on workspace level)
LanguageSettingsProvidersSerializer.serializeLanguageSettingsWorkspace();
@@ -206,6 +185,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Make sure providers in configuration cannot be modified accidentally outside of API.
*/
+ @Test
public void testProjectDescription_PreventBackDoorAccess() throws Exception {
// create a project
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
@@ -239,6 +219,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test assigning providers to read-only vs. writable configuration descriptions.
*/
+ @Test
public void testProjectDescription_ReadWriteDescription() throws Exception {
// create a project
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
@@ -367,6 +348,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Persist and reload a customized provider defined in the workspace.
*/
+ @Test
public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception {
List<ICLanguageSettingEntry> entries = new ArrayList<>();
entries.add(new CIncludePathEntry("path0", 0));
@@ -416,6 +398,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Check persistence of unmodified extension provider in the workspace.
*/
+ @Test
public void testWorkspacePersistence_UnmodifiedExtensionProvider() throws Exception {
List<ICLanguageSettingEntry> extensionEntries = new ArrayList<>();
extensionEntries.add(EXTENSION_SERIALIZABLE_PROVIDER_ENTRY);
@@ -463,6 +446,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test persistence of global providers in the workspace.
*/
+ @Test
public void testWorkspacePersistence_GlobalProvider() throws Exception {
{
// get the raw extension provider
@@ -498,6 +482,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test persistence of global providers with ID matching an extension provider in the workspace.
*/
+ @Test
public void testWorkspacePersistence_ShadowedExtensionProvider() throws Exception {
{
// get the raw extension provider
@@ -569,6 +554,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization of providers to project storage.
*/
+ @Test
public void testProjectPersistence_SerializableProviderDOM() throws Exception {
Element rootElement = null;
@@ -631,6 +617,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test User language settings provider defined as extension in cdt.ui.
*/
+ @Test
public void testProjectPersistence_UserProviderDOM() throws Exception {
Element rootElement = null;
@@ -695,6 +682,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization of providers to project storage where the project has multiple configurations.
*/
+ @Test
public void testProjectPersistence_TwoConfigurationsDOM() throws Exception {
Element rootElement = null;
@@ -837,6 +825,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization of providers subclassing {@link LanguageSettingsSerializableProvider}.
*/
+ @Test
public void testProjectPersistence_SubclassedSerializableProviderDOM() throws Exception {
Element rootElement = null;
@@ -898,6 +887,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Serialization of providers exactly equal extension providers.
*/
+ @Test
public void testProjectPersistence_ReferenceExtensionProviderDOM() throws Exception {
Element rootElement = null;
@@ -953,6 +943,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization of providers overriding/shadowing extension providers.
*/
+ @Test
public void testProjectPersistence_OverrideExtensionProviderDOM() throws Exception {
Element rootElement = null;
@@ -1013,6 +1004,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization flavors in one storage.
*/
+ @Test
public void testProjectPersistence_MixedProvidersDOM() throws Exception {
Element rootElement = null;
@@ -1107,6 +1099,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization of real project.
*/
+ @Test
public void testProjectPersistence_RealProject() throws Exception {
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
IFile xmlStorageFilePrj = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML);
@@ -1224,17 +1217,17 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
String xmlStorageFileLocation = xmlStorageFilePrj.getLocation().toOSString();
java.io.File xmlFile = new java.io.File(xmlStorageFileLocation);
xmlFile.delete();
- assertFalse("File " + xmlFile + " still exist", xmlFile.exists());
+ assertNotExists(xmlFile);
java.io.File xmlFileOut = new java.io.File(xmlPrjOutOfTheWay);
xmlFileOut.renameTo(xmlFile);
- assertTrue("File " + xmlFile + " does not exist", xmlFile.exists());
- assertFalse("File " + xmlFileOut + " still exist", xmlFileOut.exists());
+ assertExists(xmlFile);
+ assertNotExists(xmlFileOut);
// Wait out in case indexer thread hijacks refreshLocal(), see bug 415970
waitForIndexer(CCorePlugin.getDefault().getCoreModel().create(project));
// Refresh storage in workspace
xmlStorageFilePrj.refreshLocal(IResource.DEPTH_ZERO, null);
- assertTrue("File " + xmlStorageFilePrj + " does not exist", xmlStorageFilePrj.exists());
+ assertExists(xmlStorageFilePrj);
// and close
project.close(null);
@@ -1266,6 +1259,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test case when the storage is split between project and workspace area.
*/
+ @Test
public void testProjectPersistence_SplitStorageDOM() throws Exception {
Element prjStorageElement = null;
Element wspStorageElement = null;
@@ -1343,6 +1337,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test split storage in a real project.
*/
+ @Test
public void testProjectPersistence_RealProjectSplitStorage() throws Exception {
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
IFile xmlStorageFilePrj;
@@ -1472,17 +1467,17 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
String xmlStorageFilePrjLocation = xmlStorageFilePrj.getLocation().toOSString();
java.io.File xmlFile = new java.io.File(xmlStorageFilePrjLocation);
xmlFile.delete();
- assertFalse("File " + xmlFile + " still exist", xmlFile.exists());
+ assertNotExists(xmlFile);
java.io.File xmlFileOut = new java.io.File(xmlPrjOutOfTheWay);
xmlFileOut.renameTo(xmlFile);
- assertTrue("File " + xmlFile + " does not exist", xmlFile.exists());
- assertFalse("File " + xmlFileOut + " still exist", xmlFileOut.exists());
+ assertExists(xmlFile);
+ assertNotExists(xmlFileOut);
// Wait out in case indexer thread hijacks refreshLocal(), see bug 415970
waitForIndexer(CCorePlugin.getDefault().getCoreModel().create(project));
// Refresh storage in workspace
xmlStorageFilePrj.refreshLocal(IResource.DEPTH_ZERO, null);
- assertTrue("File " + xmlStorageFilePrj + " does not exist", xmlStorageFilePrj.exists());
+ assertExists(xmlStorageFilePrj);
// and close
project.close(null);
@@ -1492,11 +1487,11 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
// Move workspace storage back
java.io.File xmlWspFile = new java.io.File(xmlStorageFileWspLocation);
xmlWspFile.delete();
- assertFalse("File " + xmlWspFile + " still exist", xmlWspFile.exists());
+ assertNotExists(xmlWspFile);
java.io.File xmlWspFileOut = new java.io.File(xmlWspOutOfTheWay);
xmlWspFileOut.renameTo(xmlWspFile);
- assertTrue("File " + xmlWspFile + " does not exist", xmlWspFile.exists());
- assertFalse("File " + xmlWspFileOut + " still exist", xmlWspFileOut.exists());
+ assertExists(xmlWspFile);
+ assertNotExists(xmlWspFileOut);
}
{
@@ -1525,6 +1520,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization of providers referring to global shared instance.
*/
+ @Test
public void testProjectPersistence_ProviderExtensionReferenceDOM() throws Exception {
Document doc = XmlUtil.newDocument();
Element storageElement = XmlUtil.appendElement(doc, ELEM_TEST);
@@ -1582,6 +1578,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Walk the scenario when a provider is cloned to a configuration from extension.
*/
+ @Test
public void testProjectPersistence_ProviderExtensionCopyDOM() throws Exception {
Document doc = XmlUtil.newDocument();
Element storageElement = XmlUtil.appendElement(doc, ELEM_TEST);
@@ -1639,6 +1636,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test that default settings do not cause the files to appear in the project or file-system.
*/
+ @Test
public void testProjectPersistence_Defaults() throws Exception {
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
IFile xmlStorageFilePrj = project.getFile(LANGUAGE_SETTINGS_PROJECT_XML);
@@ -1653,6 +1651,8 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test serialization of global providers exactly equal extension in workspace area.
*/
+ @Test
+ @Tag(FLAKY_TEST_TAG)
public void testWorkspacePersistence_ProviderExtensionCopy() throws Exception {
List<ICLanguageSettingEntry> entries = new ArrayList<>();
List<ILanguageSettingsProvider> providers = new ArrayList<>();
@@ -1698,6 +1698,7 @@ public class LanguageSettingsPersistenceProjectTests extends BaseTestCase {
/**
* Test that default settings do not cause the file to appear on the file-system.
*/
+ @Test
public void testWorkspacePersistence_Defaults() throws Exception {
// reset and serialize workspace providers
LanguageSettingsManager.setWorkspaceProviders(null);
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeExpensiveTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeExpensiveTests.java
index 6243210c693..cc937ccaa4d 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeExpensiveTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeExpensiveTests.java
@@ -13,7 +13,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
-import junit.framework.Test;
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Tests which are too expensive to run as part of normal testing, but
@@ -23,36 +25,31 @@ import junit.framework.Test;
* invariants after each B-tree operation, and so are especially
* expensive and cpu hungry.
*/
+@Tag(BaseTestCase5.SLOW_TEST_TAG)
public class BTreeExpensiveTests extends BTreeTests {
- public static Test suite() {
- return suite(BTreeExpensiveTests.class);
- }
-
+ @Test
public void testBySortedSetMirror() throws Exception {
sortedMirrorTest(100);
}
- // @Override
- @Override
- public void testInsertion() throws Exception {
- super.testInsertion();
- }
-
/*
* N.B. Each of the following tests are quite expensive (i.e. > 10mins each on a 2Ghz machine)
*/
+ @Test
public void testBySortedSetMirror1682762087() throws Exception {
System.out.println("1682762087 Full Checking");
trial(1682762087, true); // exposed bugs in 2a,b
}
+ @Test
public void testBySortedSetMirror322922974() throws Exception {
System.out.println("322922974 Full Checking");
trial(322922974, true); // exposed bugs in 3b(ii)
}
+ @Test
public void testBySortedSetMirror_588448152() throws Exception {
System.out.println("-588448152 Full Checking");
trial(-588448152, true); // exposed root-delete-on-merge problems
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java
index 85ccc104029..cdf508afccc 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/BTreeTests.java
@@ -14,6 +14,9 @@
*******************************************************************************/
package org.eclipse.cdt.internal.pdom.tests;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
@@ -22,22 +25,21 @@ import java.util.Random;
import java.util.SortedSet;
import java.util.TreeSet;
-import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
+import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.core.runtime.CoreException;
-
-import junit.framework.Test;
+import org.junit.jupiter.api.Test;
/**
* Test insertion/deletion of records of a mock record type in a B-tree.
*
* @author aferguso
*/
-public class BTreeTests extends BaseTestCase {
+public class BTreeTests extends BaseTestCase5 {
private static int DEBUG = 0;
protected File dbFile;
protected Database db;
@@ -45,10 +47,6 @@ public class BTreeTests extends BaseTestCase {
protected int rootRecord;
protected IBTreeComparator comparator;
- public static Test suite() {
- return suite(BTreeTests.class);
- }
-
// setUp is not used since we need to parameterize this method,
// and invoke it multiple times per Junit test
protected void init(int degree) throws Exception {
@@ -66,6 +64,7 @@ public class BTreeTests extends BaseTestCase {
dbFile.deleteOnExit();
}
+ @Test
public void testBySortedSetMirrorLite() throws Exception {
sortedMirrorTest(8);
}
@@ -91,6 +90,7 @@ public class BTreeTests extends BaseTestCase {
* and use TreeSet as a reference implementation to check behaviour against.
* @throws Exception
*/
+ @Test
public void testInsertion() throws Exception {
Random seeder = new Random();
@@ -105,6 +105,7 @@ public class BTreeTests extends BaseTestCase {
/**
* Bug 402177: BTree.insert should return the matching record if the new record was not inserted.
*/
+ @Test
public void testEquivalentRecordInsert_Bug402177() throws Exception {
init(8);
try {
@@ -208,7 +209,7 @@ public class BTreeTests extends BaseTestCase {
BTMockRecord btValue = new BTMockRecord(record, db);
if (i.hasNext()) {
Integer exp = ((Integer) i.next());
- assertEquals(msg + " Differ at index: " + k, btValue.intValue(), exp.intValue());
+ assertEquals(btValue.intValue(), exp.intValue(), msg + " Differ at index: " + k);
k++;
} else {
fail("Sizes different");
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestSuite.java
index c3f70a8a69f..a751b64317f 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestSuite.java
@@ -43,7 +43,7 @@ public class PDOMTestSuite extends TestSuite {
suite.addTest(IncludesTests.suite());
suite.addTest(OverloadsWithinSingleTUTests.suite());
suite.addTest(OverloadsWithinCommonHeaderTests.suite());
- suite.addTest(BTreeTests.suite());
+ // Test converted to JUnit5: suite.addTest(BTreeTests.suite());
suite.addTest(PDOMStringSetTests.suite());
suite.addTest(PDOMTagIndexTests.suite());
suite.addTest(FilesOnReindexTests.suite());
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
index df36f5a693e..c6e0b263bb1 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
@@ -17,7 +17,6 @@
package org.eclipse.cdt.core.suite;
import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorOldTests;
-import org.eclipse.cdt.core.cdescriptor.tests.CDescriptorTests;
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManagerTests;
import org.eclipse.cdt.core.internal.efsextension.tests.EFSExtensionTests;
import org.eclipse.cdt.core.internal.errorparsers.tests.ErrorParserTestSuite;
@@ -77,7 +76,7 @@ public class AutomatedIntegrationSuite extends TestSuite {
// Has intermittent failures
if (System.getProperty("cdt.skip.known.test.failures") == null) {
- suite.addTest(CDescriptorTests.suite());
+ // Test converted to JUnit5: suite.addTest(CDescriptorTests.suite());
}
suite.addTest(AllConstexprEvalTestSuite.suite());
suite.addTest(ParserTestSuite.suite());
diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java
index 8f9c529924f..d486ac35829 100644
--- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java
+++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/BaseTestCase5.java
@@ -43,14 +43,30 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestInfo;
+import junit.framework.Test;
import junit.framework.TestResult;
/**
* BaseTestCase for JUnit5.
*/
public abstract class BaseTestCase5 {
+ /**
+ * Bug 499777: Numerous tests are flaky and of little value on gerrit verification builds. This
+ * tag can be applied to JUnit5 tests with the {@link Tag} annotation to skip flaky tests in
+ * such circumstances.
+ */
+ public static final String FLAKY_TEST_TAG = "flakyTest";
+
+ /**
+ * Bug 499777: Numerous tests are very slow and of little value on gerrit verification builds. This
+ * tag can be applied to JUnit5 tests with the {@link Tag} annotation to skip slow tests in
+ * such circumstances.
+ */
+ public static final String SLOW_TEST_TAG = "slowTest";
+
protected static final String DEFAULT_INDEXER_TIMEOUT_SEC = "10";
protected static final String INDEXER_TIMEOUT_PROPERTY = "indexer.timeout";
/**
@@ -245,6 +261,15 @@ public abstract class BaseTestCase5 {
* This method is declared as final to help transition to JUnit5 to ensure that
* accidental override of the method is not left in subclasses when migrating.
*/
+ final protected static Test suite() {
+ fail("Test not migrated properly to JUnit5 yet.");
+ return null; // unreachable
+ }
+
+ /**
+ * This method is declared as final to help transition to JUnit5 to ensure that
+ * accidental override of the method is not left in subclasses when migrating.
+ */
final protected void tearDown() {
fail("Test not migrated properly to JUnit5 yet.");
}

Back to the top