mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +02:00
update standard make tests
This commit is contained in:
parent
3949e8e7db
commit
9f68b6cf5e
2 changed files with 67 additions and 54 deletions
|
@ -10,18 +10,22 @@ import junit.framework.TestSuite;
|
||||||
import org.eclipse.cdt.core.CCProjectNature;
|
import org.eclipse.cdt.core.CCProjectNature;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.CProjectNature;
|
import org.eclipse.cdt.core.CProjectNature;
|
||||||
import org.eclipse.cdt.core.ICDescriptor;
|
|
||||||
import org.eclipse.cdt.core.build.standard.StandardBuildManager;
|
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
|
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||||
import org.eclipse.cdt.core.resources.IStandardBuildInfo;
|
import org.eclipse.cdt.make.core.IMakeBuilderInfo;
|
||||||
|
import org.eclipse.cdt.make.core.MakeBuilder;
|
||||||
|
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||||
|
import org.eclipse.cdt.make.core.MakeProjectNature;
|
||||||
|
import org.eclipse.cdt.make.core.MakeScannerInfo;
|
||||||
|
import org.eclipse.cdt.make.core.MakeScannerProvider;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||||
|
@ -35,12 +39,13 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
public class StandardBuildTests extends TestCase {
|
public class StandardBuildTests extends TestCase {
|
||||||
private static final String DEFAULT_MAKE_CMD = "make";
|
private static final String DEFAULT_BUILD_COMMAND = "make";
|
||||||
private static final String EMPTY_STRING = "";
|
private static final String EMPTY_STRING = "";
|
||||||
private static final boolean OFF = false;
|
private static final boolean OFF = false;
|
||||||
private static final boolean ON = true;
|
private static final boolean ON = true;
|
||||||
private static final String OVR_BUILD_ARGS = "all";
|
private static final String OVR_BUILD_ARGS = "-f";
|
||||||
private static final String OVR_BUILD_LOCATION = "/home/tester/bin/nmake";
|
private static final String OVR_BUILD_COMMAND = "/home/tester/bin/nmake";
|
||||||
|
private static final String OVR_BUILD_LOCATION = "src";
|
||||||
private static final String[] OVR_INC_PATHS = {"/test", "C:\\windows", "//dev/home/include"};
|
private static final String[] OVR_INC_PATHS = {"/test", "C:\\windows", "//dev/home/include"};
|
||||||
private static final String[] OVR_PREPROC_SYMS = {"_RELEASE", "NO ", " YES=1"};
|
private static final String[] OVR_PREPROC_SYMS = {"_RELEASE", "NO ", " YES=1"};
|
||||||
private static final String PROJECT_NAME = "StandardBuildTest";
|
private static final String PROJECT_NAME = "StandardBuildTest";
|
||||||
|
@ -48,7 +53,8 @@ public class StandardBuildTests extends TestCase {
|
||||||
private class ScannerListener implements IScannerInfoChangeListener {
|
private class ScannerListener implements IScannerInfoChangeListener {
|
||||||
private final String[] expectedPaths = {"/usr/include", "/home/tester/include", "/opt/gnome/include"};
|
private final String[] expectedPaths = {"/usr/include", "/home/tester/include", "/opt/gnome/include"};
|
||||||
private final String[] expectedSymbols = {"_DEBUG", "TRUE=1", "FALSE ", ""};
|
private final String[] expectedSymbols = {"_DEBUG", "TRUE=1", "FALSE ", ""};
|
||||||
|
private boolean bNotified = false;
|
||||||
|
|
||||||
public void changeNotification(IResource project, IScannerInfo info) {
|
public void changeNotification(IResource project, IScannerInfo info) {
|
||||||
// Are there any symbols
|
// Are there any symbols
|
||||||
Map definedSymbols = info.getDefinedSymbols();
|
Map definedSymbols = info.getDefinedSymbols();
|
||||||
|
@ -69,6 +75,7 @@ public class StandardBuildTests extends TestCase {
|
||||||
if (paths.length > 0) {
|
if (paths.length > 0) {
|
||||||
assertTrue(Arrays.equals(expectedPaths, paths));
|
assertTrue(Arrays.equals(expectedPaths, paths));
|
||||||
}
|
}
|
||||||
|
bNotified = true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
|
@ -77,6 +84,9 @@ public class StandardBuildTests extends TestCase {
|
||||||
return expectedPaths;
|
return expectedPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean triggedNotification() {
|
||||||
|
return bNotified;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -109,44 +119,50 @@ public class StandardBuildTests extends TestCase {
|
||||||
assertNotNull(project);
|
assertNotNull(project);
|
||||||
|
|
||||||
// There should not be any include path or defined symbols for the project
|
// There should not be any include path or defined symbols for the project
|
||||||
IStandardBuildInfo info = StandardBuildManager.getBuildInfo(project);
|
MakeScannerInfo scannerInfo = MakeScannerProvider.getDefault().getMakeScannerInfo(project, true);
|
||||||
assertNotNull(info);
|
assertNotNull(scannerInfo);
|
||||||
String[] includePaths = info.getIncludePaths();
|
String[] includePaths = scannerInfo.getIncludePaths();
|
||||||
assertNotNull(includePaths);
|
assertNotNull(includePaths);
|
||||||
assertEquals(0, includePaths.length);
|
assertEquals(0, includePaths.length);
|
||||||
String[] definedSymbols = info.getPreprocessorSymbols();
|
String[] definedSymbols = scannerInfo.getPreprocessorSymbols();
|
||||||
assertNotNull(definedSymbols);
|
assertNotNull(definedSymbols);
|
||||||
assertEquals(0, definedSymbols.length);
|
assertEquals(0, definedSymbols.length);
|
||||||
|
|
||||||
|
IMakeBuilderInfo builderInfo = MakeCorePlugin.createBuildInfo(project, MakeBuilder.BUILDER_ID);
|
||||||
// Check the rest of the project information
|
// Check the rest of the project information
|
||||||
assertEquals(ON, info.isDefaultBuildCmd());
|
assertEquals(ON, builderInfo.isDefaultBuildCmd());
|
||||||
assertEquals(OFF,info.isStopOnError());
|
assertEquals(OFF,builderInfo.isStopOnError());
|
||||||
assertEquals(DEFAULT_MAKE_CMD, info.getBuildLocation());
|
assertEquals(new Path(DEFAULT_BUILD_COMMAND), builderInfo.getBuildCommand());
|
||||||
assertEquals(EMPTY_STRING, info.getFullBuildArguments());
|
assertEquals(EMPTY_STRING, builderInfo.getBuildArguments());
|
||||||
assertEquals(EMPTY_STRING, info.getIncrementalBuildArguments());
|
assertEquals(false, builderInfo.isAutoBuildEnable());
|
||||||
|
assertEquals("all", builderInfo.getAutoBuildTarget());
|
||||||
|
assertEquals(true, builderInfo.isIncrementalBuildEnabled());
|
||||||
|
assertEquals("all", builderInfo.getIncrementalBuildTarget());
|
||||||
|
assertEquals(true, builderInfo.isFullBuildEnabled());
|
||||||
|
assertEquals("clean all", builderInfo.getFullBuildTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkOverriddenProjectSettings(IProject project) throws Exception {
|
private void checkOverriddenProjectSettings(IProject project) throws Exception {
|
||||||
assertNotNull(project);
|
assertNotNull(project);
|
||||||
|
|
||||||
// Check that the new stuff is there
|
MakeScannerInfo scannerInfo = MakeScannerProvider.getDefault().getMakeScannerInfo(project, true);
|
||||||
IStandardBuildInfo info = StandardBuildManager.getBuildInfo(project);
|
assertNotNull(scannerInfo);
|
||||||
assertNotNull(info);
|
String[] includePaths = scannerInfo.getIncludePaths();
|
||||||
String[] includePaths = info.getIncludePaths();
|
|
||||||
assertNotNull(includePaths);
|
assertNotNull(includePaths);
|
||||||
assertEquals(3, includePaths.length);
|
assertEquals(3, includePaths.length);
|
||||||
assertTrue(Arrays.equals(includePaths, OVR_INC_PATHS));
|
assertTrue(Arrays.equals(includePaths, OVR_INC_PATHS));
|
||||||
String[] definedSymbols = info.getPreprocessorSymbols();
|
String[] definedSymbols = scannerInfo.getPreprocessorSymbols();
|
||||||
assertNotNull(definedSymbols);
|
assertNotNull(definedSymbols);
|
||||||
assertEquals(3, definedSymbols.length);
|
assertEquals(3, definedSymbols.length);
|
||||||
assertTrue(Arrays.equals(definedSymbols, OVR_PREPROC_SYMS));
|
assertTrue(Arrays.equals(definedSymbols, OVR_PREPROC_SYMS));
|
||||||
|
|
||||||
// Check the rest of the project information
|
// Check the rest of the project information
|
||||||
assertEquals(OFF, info.isDefaultBuildCmd());
|
IMakeBuilderInfo builderInfo = MakeCorePlugin.createBuildInfo(project, MakeBuilder.BUILDER_ID);
|
||||||
assertEquals(ON, info.isStopOnError());
|
assertEquals(OFF, builderInfo.isDefaultBuildCmd());
|
||||||
assertEquals(OVR_BUILD_LOCATION, info.getBuildLocation());
|
assertEquals(ON, builderInfo.isStopOnError());
|
||||||
assertEquals(OVR_BUILD_ARGS, info.getFullBuildArguments());
|
assertEquals(new Path(OVR_BUILD_COMMAND), builderInfo.getBuildCommand());
|
||||||
assertEquals(EMPTY_STRING, info.getIncrementalBuildArguments());
|
assertEquals(OVR_BUILD_ARGS, builderInfo.getBuildArguments());
|
||||||
|
assertEquals(new Path(OVR_BUILD_LOCATION), builderInfo.getBuildLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,14 +234,12 @@ public class StandardBuildTests extends TestCase {
|
||||||
fail("StandardBuildTest testProjectConversion failed to convert project: " + e.getLocalizedMessage());
|
fail("StandardBuildTest testProjectConversion failed to convert project: " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save, Close, and Reopen the project
|
// Close, and Reopen the project
|
||||||
StandardBuildManager.saveBuildInfo(project);
|
|
||||||
try {
|
try {
|
||||||
project.close(new NullProgressMonitor());
|
project.close(new NullProgressMonitor());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
fail("StandardBuildTest testProjectConversion failed to close project " + e.getLocalizedMessage());
|
fail("StandardBuildTest testProjectConversion failed to close project " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
StandardBuildManager.removeBuildInfo(project);
|
|
||||||
try {
|
try {
|
||||||
project.open(new NullProgressMonitor());
|
project.open(new NullProgressMonitor());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -252,7 +266,8 @@ public class StandardBuildTests extends TestCase {
|
||||||
try {
|
try {
|
||||||
project = createProject(PROJECT_NAME);
|
project = createProject(PROJECT_NAME);
|
||||||
// Convert the new project to a standard make project
|
// Convert the new project to a standard make project
|
||||||
CCorePlugin.getDefault().convertProjectToCC(project, new NullProgressMonitor(), CCorePlugin.PLUGIN_ID + ".make");
|
CCorePlugin.getDefault().convertProjectToCC(project, new NullProgressMonitor(), MakeCorePlugin.getUniqueIdentifier() + ".make");
|
||||||
|
MakeProjectNature.addNature(project, null);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
fail("StandardBuildTest testProjectCreation failed creating project: " + e.getLocalizedMessage());
|
fail("StandardBuildTest testProjectCreation failed creating project: " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
@ -264,16 +279,12 @@ public class StandardBuildTests extends TestCase {
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
fail("StandardBuildTest testProjectCreation failed getting nature: " + e.getLocalizedMessage());
|
fail("StandardBuildTest testProjectCreation failed getting nature: " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
// Make sure it has a MakeNature
|
||||||
// Associate the project with the standard builder so the clients can get proper information
|
|
||||||
try {
|
try {
|
||||||
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project);
|
project.hasNature(MakeProjectNature.NATURE_ID);
|
||||||
desc.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID);
|
|
||||||
desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, StandardBuildManager.INTERFACE_IDENTITY);
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
fail("StandardBuildTest testProjectCreation failed setting the StandardBuildManager: " + e.getLocalizedMessage());
|
fail("StandardBuildTest testProjectCreation failed getting nature: " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the default settings
|
// Check the default settings
|
||||||
checkDefaultProjectSettings(project);
|
checkDefaultProjectSettings(project);
|
||||||
}
|
}
|
||||||
|
@ -289,24 +300,23 @@ public class StandardBuildTests extends TestCase {
|
||||||
assertNotNull(project);
|
assertNotNull(project);
|
||||||
|
|
||||||
// Change the settings
|
// Change the settings
|
||||||
StandardBuildManager.setIncludePaths(project, OVR_INC_PATHS);
|
MakeScannerInfo scannerInfo = MakeScannerProvider.getDefault().getMakeScannerInfo(project, false);
|
||||||
StandardBuildManager.setPreprocessorSymbols(project, OVR_PREPROC_SYMS);
|
scannerInfo.setIncludePaths(OVR_INC_PATHS);
|
||||||
|
scannerInfo.setPreprocessorSymbols(OVR_PREPROC_SYMS);
|
||||||
|
scannerInfo.update();
|
||||||
|
|
||||||
// Use the build info for the rest of the settings
|
// Use the build info for the rest of the settings
|
||||||
IStandardBuildInfo info = StandardBuildManager.getBuildInfo(project);
|
IMakeBuilderInfo builderInfo = MakeCorePlugin.createBuildInfo(project, MakeBuilder.BUILDER_ID);
|
||||||
info.setStopOnError(ON);
|
builderInfo.setStopOnError(ON);
|
||||||
info.setUseDefaultBuildCmd(OFF);
|
builderInfo.setUseDefaultBuildCmd(OFF);
|
||||||
info.setBuildLocation(OVR_BUILD_LOCATION);
|
builderInfo.setBuildCommand(new Path(OVR_BUILD_COMMAND));
|
||||||
info.setFullBuildArguments(OVR_BUILD_ARGS);
|
builderInfo.setBuildArguments(OVR_BUILD_ARGS);
|
||||||
|
builderInfo.setBuildLocation(new Path(OVR_BUILD_LOCATION));
|
||||||
// Save, Close, and Reopen the project
|
|
||||||
StandardBuildManager.saveBuildInfo(project);
|
|
||||||
try {
|
try {
|
||||||
project.close(new NullProgressMonitor());
|
project.close(new NullProgressMonitor());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
fail("StandardBuildTest testProjectSettings failed to close project " + e.getLocalizedMessage());
|
fail("StandardBuildTest testProjectSettings failed to close project " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
StandardBuildManager.removeBuildInfo(project);
|
|
||||||
try {
|
try {
|
||||||
project.open(new NullProgressMonitor());
|
project.open(new NullProgressMonitor());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -344,17 +354,19 @@ public class StandardBuildTests extends TestCase {
|
||||||
assertTrue(Arrays.equals(OVR_INC_PATHS, currentPaths));
|
assertTrue(Arrays.equals(OVR_INC_PATHS, currentPaths));
|
||||||
|
|
||||||
// Remove what's there
|
// Remove what's there
|
||||||
StandardBuildManager.setIncludePaths(project, new String[0]);
|
MakeScannerInfo info = MakeScannerProvider.getDefault().getMakeScannerInfo(project, false);
|
||||||
StandardBuildManager.setPreprocessorSymbols(project, new String[0]);
|
info.setIncludePaths(new String[0]);
|
||||||
|
info.setPreprocessorSymbols(new String[0]);
|
||||||
|
info.update();
|
||||||
// Subscribe
|
// Subscribe
|
||||||
ScannerListener listener = new ScannerListener();
|
ScannerListener listener = new ScannerListener();
|
||||||
provider.subscribe(project, listener);
|
provider.subscribe(project, listener);
|
||||||
|
|
||||||
// Change the settings
|
// Change the settings
|
||||||
StandardBuildManager.setIncludePaths(project, listener.getExpectedPaths());
|
info.setIncludePaths(listener.getExpectedPaths());
|
||||||
StandardBuildManager.setPreprocessorSymbols(project, listener.getExpectedSymbols());
|
info.setPreprocessorSymbols(listener.getExpectedSymbols());
|
||||||
|
info.update();
|
||||||
|
assertEquals(true, listener.triggedNotification());
|
||||||
// Unsubscribe
|
// Unsubscribe
|
||||||
provider.unsubscribe(project, listener);
|
provider.unsubscribe(project, listener);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
<import plugin="org.eclipse.ui"/>
|
<import plugin="org.eclipse.ui"/>
|
||||||
<import plugin="org.junit"/>
|
<import plugin="org.junit"/>
|
||||||
<import plugin="org.eclipse.cdt.managedbuilder.core"/>
|
<import plugin="org.eclipse.cdt.managedbuilder.core"/>
|
||||||
|
<import plugin="org.eclipse.cdt.make.core"/>
|
||||||
</requires>
|
</requires>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue