Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More test stability fixes #120

Merged
merged 32 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f707199
Typos and remove unused SuppressWarnings
jonahgraham Oct 26, 2022
1251f6b
Use correct version of GDB on Jenkins
jonahgraham Oct 26, 2022
41ab286
Convert pdom tests to JUnit5 format
jonahgraham Oct 26, 2022
6cfff65
Reduce API warning in test
jonahgraham Oct 26, 2022
f3d1267
Fail test if there are any files left over in the workspace directory
jonahgraham Oct 27, 2022
c9c9b17
Remove incorrect assumptions of lifecycle of test
jonahgraham Oct 27, 2022
6d1abe1
Convert test to JUnit5 and cleanup projects made during test
jonahgraham Oct 27, 2022
e04e023
Clean up projects created during test
jonahgraham Oct 27, 2022
aba8b23
Delete contents on disk when cleaning up after test
jonahgraham Oct 27, 2022
95524a0
Better test error messages when workspace is not empty after test
jonahgraham Oct 27, 2022
8879798
Remove test for code that is no longer supported
jonahgraham Oct 27, 2022
95b10be
Convert more of the tests to JUnit5
jonahgraham Oct 27, 2022
a28fbaf
Delete projects fully at the end of tests
jonahgraham Oct 27, 2022
8974260
Try to catch uncleaned up files earlier
jonahgraham Oct 27, 2022
3b93d3f
Delete test that was never run
jonahgraham Oct 27, 2022
c8a6953
Make ASTWriterTester abstract so it doesn't look like a test
jonahgraham Oct 27, 2022
72c55b9
There is a new way to mark tests as failing
jonahgraham Oct 27, 2022
695a63b
Add JUnit5 dependencies
jonahgraham Oct 28, 2022
ad2177a
Pass exceptions up the stack
jonahgraham Oct 28, 2022
5b21f4f
Add missing abstract keyword to abstract tests
jonahgraham Oct 28, 2022
658ac45
Clean up created projects in tearDown
jonahgraham Oct 28, 2022
d5dbb36
Create temporary files with ResourceHelper so they get cleanedup
jonahgraham Oct 28, 2022
a6ba37d
Delete settings.xml file at end of test
jonahgraham Oct 28, 2022
2fcbee3
Convert to JUnit5 and cleanup resources
jonahgraham Oct 28, 2022
5d8de2c
Convert test to JUnit5
jonahgraham Oct 28, 2022
71a2fa1
Make sure test does not leave projects around
jonahgraham Oct 28, 2022
6518d81
Cosmetic changes to unit test
jonahgraham Oct 28, 2022
9bf8421
Delete test for CDT 2.x functionality
jonahgraham Oct 28, 2022
9c6bc92
Make tests inherit from BaseTestCase or BaseTestCase5
jonahgraham Oct 28, 2022
e4b8ae5
Place each test run in its own project
jonahgraham Oct 29, 2022
059e16d
Wait until all threads are stopped before continuing test
jonahgraham Nov 5, 2022
3e63144
Include the full stack trace in exception message
jonahgraham Nov 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pipeline {
-Dindexer.timeout=300 \
-P production \
-P build-standalone-debugger-rcp \
-Ddsf.gdb.tests.gdbPath=/shared/common/gdb/gdb-all/bin \
-Dcdt.tests.dsf.gdb.versions=gdb.10,gdbserver.10 \
-Dmaven.repo.local=/home/jenkins/.m2/repository \
--settings /home/jenkins/.m2/settings.xml \
"
Expand Down
3 changes: 2 additions & 1 deletion build/org.eclipse.cdt.make.core.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: org.eclipse.core.filesystem
Import-Package: org.eclipse.core.filesystem,
org.junit.jupiter.api;version="5.9.0"
Automatic-Module-Name: org.eclipse.cdt.make.core.tests
Bundle-Localization: plugin
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
Expand All @@ -28,11 +30,10 @@
import org.eclipse.core.runtime.NullProgressMonitor;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

@SuppressWarnings("nls")
public class CDataProviderTests extends TestCase {
public class CDataProviderTests extends BaseTestCase {
/**
* @param name
*/
Expand All @@ -41,18 +42,14 @@ public CDataProviderTests(String name) {
}

public static Test suite() {
TestSuite suite = new TestSuite(CDataProviderTests.class);

// // Add the relevant tests to the suite
// suite.addTest(new StandardBuildTests("testProjectCreation"));
// suite.addTest(new StandardBuildTests("testProjectSettings"));
// suite.addTest(new StandardBuildTests("testProjectConversion"));
// suite.addTest(new StandardBuildTests("testProjectCleanup"));
//
// suite.addTestSuite(ScannerConfigConsoleParserTests.class);
// suite.addTestSuite(ScannerConfigDiscoveryTests.class);

return suite;
return new TestSuite(CDataProviderTests.class);
}

@Override
protected void tearDown() throws Exception {
BaseTestCase5.removeLeftOverProjects();

super.tearDown();
}

public void testCData() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,59 @@
*******************************************************************************/
package org.eclipse.cdt.make.builder.tests;

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 java.io.IOException;

import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.make.core.IMakeBuilderInfo;
import org.eclipse.cdt.make.core.IMakeCommonBuildInfo;
import org.eclipse.cdt.make.core.MakeBuilder;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.MakeProjectNature;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

@SuppressWarnings("nls")
public class StandardBuildTests extends TestCase {
public class StandardBuildTests extends BaseTestCase5 {
private static final boolean OFF = false;
private static final boolean ON = true;
private static final String OVR_BUILD_ARGS = "-f";
private static final String OVR_BUILD_COMMAND = "/home/tester/bin/nmake";
private static final String OVR_BUILD_LOCATION = "src";
private static final String PROJECT_NAME = "StandardBuildTest";
private IProject project;

/**
* @param name
*/
public StandardBuildTests(String name) {
super(name);
@BeforeEach
public void projectCreation() throws Exception {
project = createProject(PROJECT_NAME);
// Convert the new project to a standard make project
MakeProjectNature.addNature(project, null);
}

public static Test suite() {
TestSuite suite = new TestSuite(StandardBuildTests.class.getName());

// Add the relevant tests to the suite
suite.addTest(new StandardBuildTests("testProjectCreation"));
suite.addTest(new StandardBuildTests("testProjectSettings"));
suite.addTest(new StandardBuildTests("testProjectConversion"));
suite.addTest(new StandardBuildTests("testProjectCleanup"));
@AfterEach
public void projectCleanup() throws CoreException, IOException {
project.delete(true, true, null);
}

return suite;
@Test
public void test() throws Exception {
doProjectSettings();
doProjectConversion();
}

private void checkDefaultProjectSettings(IProject project) throws Exception {
Expand Down Expand Up @@ -120,11 +122,8 @@ private IProject createProject(final String name) throws CoreException {
public void run(IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(name);
if (!project.exists()) {
project.create(null);
} else {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
assertFalse(project.exists());
project.create(null);

if (!project.isOpen()) {
project.open(null);
Expand All @@ -137,114 +136,36 @@ public void run(IProgressMonitor monitor) throws CoreException {
return (IProject) result[0];
}

/**
* Remove the <code>IProject</code> with the name specified in the argument from the
* receiver's workspace.
*
* @param name
*/
private void removeProject(String name) throws CoreException, IOException {
ResourceHelper.cleanUp(getName());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(name);
if (project.exists()) {
try {
project.delete(true, false, null);
} catch (CoreException e) {
assertTrue(false);
}
}
}

/**
* Remove all the project information associated with the project used during test.
*/
public void testProjectCleanup() throws CoreException, IOException {
removeProject(PROJECT_NAME);
}

public void testProjectConversion() throws Exception {
// Open the project
IProject project = null;
try {
project = createProject(PROJECT_NAME);
} catch (CoreException e) {
fail("StandardBuildTest testProjectConversion failed opening project: " + e.getLocalizedMessage());
}
assertNotNull(project);

public void doProjectConversion() throws Exception {
// Check the settings (they should be the override values)
checkOverriddenProjectSettings(project);

// Now convert the project
try {
CCorePlugin.getDefault().convertProjectFromCtoCC(project, new NullProgressMonitor());
} catch (CoreException e) {
fail("StandardBuildTest testProjectConversion failed to convert project: " + e.getLocalizedMessage());
}
CCorePlugin.getDefault().convertProjectFromCtoCC(project, new NullProgressMonitor());

// Close, and Reopen the project
try {
project.close(new NullProgressMonitor());
} catch (CoreException e) {
fail("StandardBuildTest testProjectConversion failed to close project " + e.getLocalizedMessage());
}
try {
project.open(new NullProgressMonitor());
} catch (CoreException e) {
fail("StandardBuildTest testProjectConversion failed to open project " + e.getLocalizedMessage());
}
project.close(new NullProgressMonitor());
project.open(new NullProgressMonitor());

// Make sure it has a CCNature
try {
project.hasNature(CCProjectNature.CC_NATURE_ID);
} catch (CoreException e) {
fail("StandardBuildTest testProjectConversion failed getting nature: " + e.getLocalizedMessage());
}
assertTrue(project.hasNature(CCProjectNature.CC_NATURE_ID));

// Nothing should have changed in the settings
checkOverriddenProjectSettings(project);
}

/**
*
*/
public void testProjectCreation() throws Exception {
// Create a new project
IProject project = null;
try {
project = createProject(PROJECT_NAME);
// Convert the new project to a standard make project
MakeProjectNature.addNature(project, null);
} catch (CoreException e) {
fail("StandardBuildTest testProjectCreation failed creating project: " + e.getLocalizedMessage());
}
assertNotNull(project);

private void doCheckInitialSettings() throws CoreException, Exception {
// Make sure it has a CNature
try {
project.hasNature(CProjectNature.C_NATURE_ID);
} catch (CoreException e) {
fail("StandardBuildTest testProjectCreation failed getting nature: " + e.getLocalizedMessage());
}
assertTrue(project.hasNature(CProjectNature.C_NATURE_ID));

// Make sure it has a MakeNature
try {
project.hasNature(MakeProjectNature.NATURE_ID);
} catch (CoreException e) {
fail("StandardBuildTest testProjectCreation failed getting nature: " + e.getLocalizedMessage());
}
assertTrue(project.hasNature(MakeProjectNature.NATURE_ID));

// Check the default settings
checkDefaultProjectSettings(project);
}

public void testProjectSettings() throws Exception {
// Get the project
IProject project = null;
try {
project = createProject(PROJECT_NAME);
} catch (CoreException e) {
fail("StandardBuildTest testProjectSettings failed opening project: " + e.getLocalizedMessage());
}
public void doProjectSettings() throws Exception {
assertNotNull(project);

// Use the build info for the rest of the settings
Expand All @@ -254,16 +175,9 @@ public void testProjectSettings() throws Exception {
builderInfo.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, OVR_BUILD_COMMAND);
builderInfo.setBuildAttribute(IMakeCommonBuildInfo.BUILD_ARGUMENTS, OVR_BUILD_ARGS);
builderInfo.setBuildAttribute(IMakeCommonBuildInfo.BUILD_LOCATION, OVR_BUILD_LOCATION);
try {
project.close(new NullProgressMonitor());
} catch (CoreException e) {
fail("StandardBuildTest testProjectSettings failed to close project " + e.getLocalizedMessage());
}
try {
project.open(new NullProgressMonitor());
} catch (CoreException e) {
fail("StandardBuildTest testProjectSettings failed to open project " + e.getLocalizedMessage());
}

project.close(new NullProgressMonitor());
project.open(new NullProgressMonitor());

// Retest
checkOverriddenProjectSettings(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ protected void setUp() throws Exception {

@Override
protected void tearDown() throws Exception {
super.tearDown();
if (fOutputParser != null) {
fOutputParser.shutdown();
}
ResourceHelper.cleanUp(getName());
if (fCProject != null) {
CProjectHelper.delete(fCProject);
}
super.tearDown();
}

public void testParsingIfStatement_bug197930() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ protected void setUp() throws Exception {

@Override
protected void tearDown() throws Exception {
super.tearDown();
fOutputParser.shutdown();
super.tearDown();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
package org.eclipse.cdt.make.scannerdiscovery;

import java.io.ByteArrayInputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.parser.IScannerInfo;
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.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.MakeProjectNature;
import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature;
Expand Down Expand Up @@ -53,9 +56,11 @@ public ScannerConfigDiscoveryTests(String name) {

@Override
protected void setUp() throws Exception {
super.setUp();
fMonitor = new NullProgressMonitor();

fCProject = StandardBuildTestHelper.createProject("SCD", (IPath) null, MakeCorePlugin.MAKE_PROJECT_ID);
fCProject = StandardBuildTestHelper.createProject("SCD" + getName(), (IPath) null,
MakeCorePlugin.MAKE_PROJECT_ID);
fCFile = fCProject.getProject().getFile("main.c");
if (!fCFile.exists()) {
fCFile.create(new ByteArrayInputStream(" \n".getBytes()), false, fMonitor);
Expand All @@ -65,7 +70,8 @@ protected void setUp() throws Exception {
@Override
protected void tearDown() throws Exception {
ResourceHelper.cleanUp(getName());
StandardBuildTestHelper.removeProject("SCDC");
fCProject.getProject().delete(true, true, null);
super.tearDown();
}

public void testGetCCompilerBuiltins() throws CoreException {
Expand All @@ -76,9 +82,9 @@ public void testGetCCompilerBuiltins() throws CoreException {
IScannerInfo scInfo = CCorePlugin.getDefault().getScannerInfoProvider(fCProject).getScannerInformation(fCFile);
assertNotNull(scInfo);
String[] includes = scInfo.getIncludePaths();
assertTrue(includes.length == 0);
assertEquals(List.of(), Arrays.asList(includes));
Map<String, String> symbols = scInfo.getDefinedSymbols();
assertTrue(symbols.isEmpty());
assertEquals(Map.of(), symbols);
}

public void testGetCCCompilerBuiltins() throws CoreException {
Expand All @@ -90,9 +96,9 @@ public void testGetCCCompilerBuiltins() throws CoreException {
IScannerInfo scInfo = CCorePlugin.getDefault().getScannerInfoProvider(fCProject).getScannerInformation(fCFile);
assertNotNull(scInfo);
String[] includes = scInfo.getIncludePaths();
assertTrue(includes.length == 0);
assertEquals(List.of(), Arrays.asList(includes));
Map<String, String> symbols = scInfo.getDefinedSymbols();
assertTrue(symbols.isEmpty());
assertEquals(Map.of(), symbols);
}

}
Loading