Skip to content

Commit

Permalink
Make tests inherit from BaseTestCase or BaseTestCase5
Browse files Browse the repository at this point in the history
This provides the shared pre/post condition assertions to
help make sure tests are running in a clean environment.

If I had time I would convert all the tests to BaseTestCase5
which is JUnit5, but I only did the tests that had something
wrong with them.

Part of #117
  • Loading branch information
jonahgraham committed Oct 28, 2022
1 parent 151e4e1 commit 053681d
Show file tree
Hide file tree
Showing 25 changed files with 135 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
Expand Down Expand Up @@ -59,21 +60,23 @@
* <li>Cleaning up the workspace at the end</li>
* </ul>
*/
public abstract class AbstractBuilderTest {
public abstract class AbstractBuilderTest extends BaseTestCase5 {
private static final boolean WINDOWS = java.io.File.separatorChar == '\\';

static final String PATH = "builderTests";

private String workspace;
private List<IProject> projects;

private boolean autoBuildingRestoreValue;

@BeforeEach
public void setUp() throws Exception {
setAutoBuilding(false);
public void setUpBaseLocal() throws Exception {
autoBuildingRestoreValue = setAutoBuilding(false);
}

@AfterEach
public void tearDown(TestInfo testInfo) throws Exception {
public void tearDownBaseLocal(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());
Expand All @@ -86,6 +89,8 @@ public void tearDown(TestInfo testInfo) throws Exception {
}
projects.clear();
}

setAutoBuilding(autoBuildingRestoreValue);
}

/**
Expand Down Expand Up @@ -308,13 +313,17 @@ protected void printAllMarkers() throws CoreException {
}
}

protected void setAutoBuilding(boolean value) throws CoreException {
/**
* Return previous value
*/
protected boolean setAutoBuilding(boolean value) throws CoreException {
IWorkspace workspace = getWorkspace();
if (workspace.isAutoBuilding() == value)
return;
return value;
IWorkspaceDescription desc = workspace.getDescription();
desc.setAutoBuilding(value);
workspace.setDescription(desc);
return !value;
}

protected IWorkspace getWorkspace() throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@
import java.util.TreeSet;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;

import junit.framework.TestCase;

/**
* Check that preconditions for running managed builder tests are in place,
* see individual tests in this class for details.
*/
public class ManagedBuilderPreconditionsTests extends TestCase {
@Override
protected void setUp() throws Exception {
}

public class ManagedBuilderPreconditionsTests extends BaseTestCase {
/**
* Many MBS tests run make and gcc and will inspect resulting artifacts of the build.
* Make sure GNU tool-chain is available for the tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
import java.util.List;
import java.util.Map;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCSpecsConsoleParser;

import junit.framework.TestCase;

public class GCCSpecsConsoleParserTest extends TestCase {
public class GCCSpecsConsoleParserTest extends BaseTestCase {
GCCSpecsConsoleParser parser;
private IScannerInfoCollector collector;
List<String> includes;
List<String> symbols;

@Override
protected void setUp() throws Exception {
super.setUp();
collector = new IScannerInfoCollector() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildIOType;
Expand Down Expand Up @@ -70,10 +71,9 @@
import org.eclipse.ui.dialogs.IOverwriteQuery;

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

public class BuildDescriptionModelTests extends TestCase {
public class BuildDescriptionModelTests extends BaseTestCase {
private static final String PREFIX = "BuildDescription_";
private static final String PROJ_PATH = "testBuildDescriptionProjects";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
Expand All @@ -48,10 +49,9 @@
import org.eclipse.core.runtime.Platform;

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

public class BuildSystem40Tests extends TestCase {
public class BuildSystem40Tests extends BaseTestCase {
private IPath resourcesLocation = new Path(
CTestPlugin.getFileInPlugin(new Path("resources/test40Projects/")).getAbsolutePath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.List;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
Expand All @@ -34,10 +35,9 @@
import org.junit.Assert;

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

public class ManagedBuildCoreTests extends TestCase {
public class ManagedBuildCoreTests extends BaseTestCase {
private static IProjectType exeType;
private static IProjectType libType;
private static IProjectType dllType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
Expand Down Expand Up @@ -46,7 +47,6 @@
import org.eclipse.core.runtime.Platform;

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

// TODO LK - write test for resource configurations + IOptionCategory.getOptions(config)
Expand All @@ -56,7 +56,7 @@
/*
* These tests exercise CDT 3.0 shared tool options extensions
*/
public class ManagedBuildCore_SharedToolOptionsTests extends TestCase {
public class ManagedBuildCore_SharedToolOptionsTests extends BaseTestCase {

class IconComparator {
static final int None = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.FileFilter;
import java.util.ArrayList;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
Expand All @@ -36,10 +37,9 @@
import org.eclipse.ui.dialogs.IOverwriteQuery;

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

public class ManagedBuildDependencyCalculatorTests extends TestCase {
public class ManagedBuildDependencyCalculatorTests extends BaseTestCase {
private IPath resourcesLocation = new Path(
CTestPlugin.getFileInPlugin(new Path("resources/depCalcProjects/")).getAbsolutePath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
private IProject fTapp, fTlib, fTobjs;

private IToolChain[] allToolChains;
private boolean autoBuildingRestoreValue;

private void buildProject(IProject curProject) {

Expand All @@ -74,13 +75,10 @@ private void buildProject(IProject curProject) {

}

@Override
public void setUp() {
// Don't run super class setUp
}

@BeforeEach
public void setUpLocal() throws Exception {
autoBuildingRestoreValue = setAutoBuilding(true);

allToolChains = ManagedBuildManager.getRealToolChains();
IWorkspaceDescription wsDescription = ResourcesPlugin.getWorkspace().getDescription();
wsDescription.setAutoBuilding(false);
Expand All @@ -102,6 +100,8 @@ public void tearDownLocal() throws Exception {
ManagedBuildTestHelper.removeProject(fTapp.getName());
ManagedBuildTestHelper.removeProject(fTlib.getName());
ManagedBuildTestHelper.removeProject(fTobjs.getName());

setAutoBuilding(autoBuildingRestoreValue);
}

private void findFiles(IResource dir, String pattern, List<IFile> files) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
Expand All @@ -25,13 +26,12 @@
import org.eclipse.core.resources.IWorkspace;

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

/**
*
* */
public class ManagedBuildEnvironmentTests extends TestCase {
public class ManagedBuildEnvironmentTests extends BaseTestCase {
// test variable names
final private String NAME_CWD = "CWD"; //$NON-NLS-1$
final private String NAME_PWD = "PWD"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
Expand All @@ -47,10 +48,9 @@
import org.eclipse.core.runtime.NullProgressMonitor;

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

public class ManagedBuildMacrosTests extends TestCase {
public class ManagedBuildMacrosTests extends BaseTestCase {
static IProject proj = null;
static IManagedProject mproj = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
package org.eclipse.cdt.managedbuilder.core.tests;

import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain;

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

/**
*
* */
public class ManagedBuildTCSupportedTest extends TestCase {
public class ManagedBuildTCSupportedTest extends BaseTestCase {

public ManagedBuildTCSupportedTest() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Arrays;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
Expand All @@ -33,10 +34,9 @@
import org.eclipse.core.runtime.IPath;

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

public class ManagedCommandLineGeneratorTest extends TestCase {
public class ManagedCommandLineGeneratorTest extends BaseTestCase {

private static String[] testCommandLinePatterns = { null, "${COMMAND}", "${COMMAND} ${FLAGS}",
"${COMMAND} ${FLAGS} ${OUTPUT_FLAG}", "${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.file.Files;
import java.util.ArrayList;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
Expand All @@ -45,10 +46,9 @@
import org.eclipse.ui.dialogs.IOverwriteQuery;

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

public class ManagedProject21MakefileTests extends TestCase {
public class ManagedProject21MakefileTests extends BaseTestCase {
private IPath resourcesLocation = new Path(
CTestPlugin.getFileInPlugin(new Path("resources/test21Projects/")).getAbsolutePath());
public static final String MBS_TEMP_DIR = "MBSTemp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.file.Files;
import java.util.ArrayList;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IAdditionalInput;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IInputType;
Expand Down Expand Up @@ -54,10 +55,9 @@
import org.eclipse.ui.dialogs.IOverwriteQuery;

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

public class ManagedProject30MakefileTests extends TestCase {
public class ManagedProject30MakefileTests extends BaseTestCase {
public static final String MBS_TEMP_DIR = "MBSTemp";

boolean pathVariableCreated = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;

import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
Expand All @@ -31,10 +32,9 @@
import org.eclipse.core.resources.IProject;

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

public class OptionCategoryEnablementTests extends TestCase {
public class OptionCategoryEnablementTests extends BaseTestCase {

private static final String testName = "optcaten"; //$NON-NLS-1$
private static boolean fHandleValueCalled;
Expand Down
Loading

0 comments on commit 053681d

Please sign in to comment.