1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

moved standard make test into it own plugin

This commit is contained in:
David Inglis 2006-02-25 04:29:00 +00:00
parent 06a50c17f7
commit a622b064ff
11 changed files with 291 additions and 73 deletions

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.standardbuilder.core.tests;
package org.eclipse.cdt.make.builder.tests;
import java.util.ArrayList;
import java.util.List;

View file

@ -8,7 +8,7 @@
* Contributors:
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.standardbuilder.core.tests;
package org.eclipse.cdt.make.builder.tests;
import java.io.ByteArrayInputStream;
import java.util.Map;
@ -21,8 +21,8 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.MakeProjectNature;
import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature;
import org.eclipse.cdt.make.core.tests.StandardBuildTestHelper;
import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
@ -50,7 +50,7 @@ public class ScannerConfigDiscoveryTests extends TestCase {
protected void setUp() throws Exception {
fMonitor = new NullProgressMonitor();
fCProject = ManagedBuildTestHelper.createProject("SCD", (IPath)null, MakeCorePlugin.MAKE_PROJECT_ID, null);
fCProject = StandardBuildTestHelper.createProject("SCD", (IPath)null, MakeCorePlugin.MAKE_PROJECT_ID);
fCFile = fCProject.getProject().getFile("main.c");
if (!fCFile.exists()) {
fCFile.create(new ByteArrayInputStream(" \n".getBytes()), false, fMonitor);
@ -58,7 +58,7 @@ public class ScannerConfigDiscoveryTests extends TestCase {
}
protected void tearDown() throws Exception {
ManagedBuildTestHelper.removeProject("SCDC");
StandardBuildTestHelper.removeProject("SCDC");
}
public void testGetCCompilerBuiltins() throws CoreException {

View file

@ -54,6 +54,10 @@ public class StandardBuildTests extends TestCase {
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;
}

View file

@ -0,0 +1,269 @@
package org.eclipse.cdt.make.core.tests;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import junit.framework.Assert;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
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.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
public class StandardBuildTestHelper {
/* (non-Javadoc)
* Create a new project named <code>name</code> or return the project in
* the workspace of the same name if it exists.
*
* @param name The name of the project to create or retrieve.
* @return
* @throws CoreException
*/
static public IProject createProject(
final String name,
final IPath location,
final String projectId)
throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IProject newProjectHandle = root.getProject(name);
IProject project = null;
if (!newProjectHandle.exists()) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceDescription workspaceDesc = workspace.getDescription();
workspaceDesc.setAutoBuilding(false);
workspace.setDescription(workspaceDesc);
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
//description.setLocation(root.getLocation());
project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), projectId);
} else {
project = newProjectHandle;
}
// Open the project if we have to
if (!project.isOpen()) {
project.open(new NullProgressMonitor());
}
return project;
}
/**
* Remove the <code>IProject</code> with the name specified in the argument from the
* receiver's workspace.
*
* @param name
*/
static public void removeProject(String name) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IProject project = root.getProject(name);
if (project.exists()) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
System.gc();
System.runFinalization();
project.delete(true, true, null);
}
};
NullProgressMonitor monitor = new NullProgressMonitor();
try {
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e2) {
Assert.assertTrue(false);
}
}
}
static public boolean compareBenchmarks(final IProject project, IPath testDir, IPath[] files) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
};
try {
NullProgressMonitor monitor = new NullProgressMonitor();
workspace.run(runnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
} catch (Exception e) {
Assert.fail("File " + files[0].lastSegment() + " - project refresh failed.");
}
for (int i=0; i<files.length; i++) {
IPath testFile = testDir.append(files[i]);
IPath benchmarkFile = Path.fromOSString("Benchmarks/" + files[i]);
StringBuffer testBuffer = readContentsStripLineEnds(project, testFile);
StringBuffer benchmarkBuffer = readContentsStripLineEnds(project, benchmarkFile);
if (!testBuffer.toString().equals(benchmarkBuffer.toString())) {
Assert.fail("File " + testFile.lastSegment() + " does not match its benchmark.");
}
}
return true;
}
static public boolean verifyFilesDoNotExist(final IProject project, IPath testDir, IPath[] files) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
};
try {
NullProgressMonitor monitor = new NullProgressMonitor();
workspace.run(runnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
} catch (Exception e) {
Assert.fail("File " + files[0].lastSegment() + " - project refresh failed.");
}
for (int i=0; i<files.length; i++) {
IPath testFile = testDir.append(files[i]);
IPath fullPath = project.getLocation().append(testFile);
try {
if (fullPath.toFile().exists()) {
Assert.fail("File " + testFile.lastSegment() + " unexpectedly found.");
return false;
}
} catch (Exception e) {
Assert.fail("File " + fullPath.toString() + " could not be referenced.");
}
}
return true;
}
static public StringBuffer readContentsStripLineEnds(IProject project, IPath path) {
StringBuffer buff = new StringBuffer();
IPath fullPath = project.getLocation().append(path);
try {
FileReader input = null;
try {
input = new FileReader(fullPath.toFile());
} catch (Exception e) {
Assert.fail("File " + fullPath.toString() + " could not be read.");
}
//InputStream input = file.getContents(true); // A different way to read the file...
int c;
do {
c = input.read();
if (c == -1) break;
if (c != '\r' && c != '\n') {
buff.append((char)c);
}
} while (c != -1);
input.close();
} catch (Exception e) {
Assert.fail("File " + fullPath.toString() + " could not be read.");
}
return buff;
}
static public IPath copyFilesToTempDir(IPath srcDir, IPath tmpSubDir, IPath[] files) {
IPath tmpSrcDir = null;
String userDirStr = System.getProperty("user.home");
if (userDirStr != null) {
IPath userDir = Path.fromOSString(userDirStr);
tmpSrcDir = userDir.append(tmpSubDir);
if (userDir.toString().equalsIgnoreCase(tmpSrcDir.toString())) {
Assert.fail("Temporary sub-directory cannot be the empty string.");
} else {
File tmpSrcDirFile = tmpSrcDir.toFile();
if (tmpSrcDirFile.exists()) {
// Make sure that this is the expected directory before we delete it...
if (tmpSrcDir.lastSegment().equals(tmpSubDir.lastSegment())) {
deleteDirectory(tmpSrcDirFile);
} else {
Assert.fail("Temporary directory " + tmpSrcDirFile.toString() + " already exists.");
}
}
boolean succeed = tmpSrcDirFile.mkdir();
if (succeed) {
for (int i=0; i<files.length; i++) {
IPath file = files[i];
IPath srcFile = srcDir.append(file);
FileReader srcReader = null;
try {
srcReader = new FileReader(srcFile.toFile());
} catch (Exception e) {
Assert.fail("File " + file.toString() + " could not be read.");
}
if (file.segmentCount() > 1) {
IPath newDir = tmpSrcDir;
do {
IPath dir = file.uptoSegment(1);
newDir = newDir.append(dir);
file = file.removeFirstSegments(1);
succeed = newDir.toFile().mkdir();
} while (file.segmentCount() > 1);
}
IPath destFile = tmpSrcDir.append(files[i]);
FileWriter writer = null;
try {
writer = new FileWriter(destFile.toFile());
} catch (Exception e) {
Assert.fail("File " + files[i].toString() + " could not be written.");
}
try {
int c;
do {
c = srcReader.read();
if (c == -1) break;
writer.write(c);
} while (c != -1);
srcReader.close();
writer.close();
} catch (Exception e) {
Assert.fail("File " + file.toString() + " could not be copied.");
}
}
}
}
}
return tmpSrcDir;
}
static public void deleteTempDir(IPath tmpSubDir, IPath[] files) {
IPath tmpSrcDir = null;
String userDirStr = System.getProperty("user.home");
if (userDirStr != null) {
IPath userDir = Path.fromOSString(userDirStr);
tmpSrcDir = userDir.append(tmpSubDir);
if (userDir.toString().equalsIgnoreCase(tmpSrcDir.toString())) {
Assert.fail("Temporary sub-directory cannot be the empty string.");
} else {
File tmpSrcDirFile = tmpSrcDir.toFile();
if (!tmpSrcDirFile.exists()) {
Assert.fail("Temporary directory " + tmpSrcDirFile.toString() + " does not exist.");
} else {
for (int i=0; i<files.length; i++) {
// Delete the file
IPath thisFile = tmpSrcDir.append(files[i]);
thisFile.toFile().delete();
}
// Delete the dir
tmpSrcDirFile.delete();
}
}
}
}
static private void deleteDirectory(File dir) {
File[] toDelete = dir.listFiles();
for (int i=0; i<toDelete.length; i++) {
File fileToDelete = toDelete[i];
if (fileToDelete.isDirectory()) {
deleteDirectory(fileToDelete);
}
fileToDelete.delete();
}
dir.delete();
}
}

View file

@ -9,8 +9,7 @@ Bundle-Vendor: Eclipse.org
Bundle-Localization: plugin
Export-Package: org.eclipse.cdt.managedbuilder.core.tests,
org.eclipse.cdt.managedbuilder.testplugin,
org.eclipse.cdt.managedbuilder.tests.suite,
org.eclipse.cdt.standardbuilder.core.tests
org.eclipse.cdt.managedbuilder.tests.suite
Require-Bundle: org.eclipse.core.runtime,
org.junit,
org.eclipse.cdt.managedbuilder.core,

View file

@ -48,8 +48,6 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
//import org.eclipse.compare.structuremergeviewer.Differencer;
//import org.eclipse.compare.ResourceNode;;
public class ManagedBuildTestHelper {

View file

@ -1,42 +0,0 @@
/*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.standardbuilder.core.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Invokes all standard builder tests
*
* @author vhirsl
*/
public class AllStandardBuildTests extends TestSuite {
/**
* @param string
*/
public AllStandardBuildTests(String title) {
super(title);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(AllStandardBuildTests.suite());
}
public static Test suite() {
TestSuite suite = new AllStandardBuildTests("Test for org.eclipse.cdt.standardbuild.core.tests");
//$JUnit-BEGIN$
suite.addTestSuite(ScannerConfigConsoleParserTests.class);
suite.addTestSuite(ScannerConfigDiscoveryTests.class);
//$JUnit-END$
return suite;
}
}

View file

@ -17,10 +17,6 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
@ -29,9 +25,12 @@ import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.cdt.managedbuilder.core.ManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
@ -217,7 +216,7 @@ public class ManagedBuildCoreTests_SharedToolOptions extends TestCase {
workspace.setDescription(workspaceDesc);
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
//description.setLocation(root.getLocation());
project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), MakeCorePlugin.MAKE_PROJECT_ID);
project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
} else {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

View file

@ -20,7 +20,6 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -31,6 +30,7 @@ import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider;
@ -732,7 +732,7 @@ public class ManagedBuildMacrosTests extends TestCase {
try {
workspace.setDescription(workspaceDesc);
proj = CCorePlugin.getDefault().createCProject(workspace.newProjectDescription(proj.getName()),
proj, new NullProgressMonitor(), MakeCorePlugin.MAKE_PROJECT_ID);
proj, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
// add ManagedBuildNature
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(proj);

View file

@ -13,11 +13,9 @@ package org.eclipse.cdt.managedbuilder.core.tests;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
@ -28,7 +26,6 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -38,24 +35,20 @@ import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.dialogs.IOverwriteQuery;
@ -326,7 +319,7 @@ public class MultiVersionSupportTests extends TestCase {
try {
workspace.setDescription(workspaceDesc);
proj = CCorePlugin.getDefault().createCProject(workspace.newProjectDescription(proj.getName()),
proj, new NullProgressMonitor(), MakeCorePlugin.MAKE_PROJECT_ID);
proj, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
// add ManagedBuildNature
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(proj);

View file

@ -11,14 +11,12 @@
package org.eclipse.cdt.managedbuilder.core.tests;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -29,6 +27,7 @@ import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.cdt.managedbuilder.internal.core.Tool;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
@ -46,7 +45,6 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
public class ResourceBuildCoreTests extends TestCase {
@ -585,7 +583,7 @@ public class ResourceBuildCoreTests extends TestCase {
workspace.setDescription(workspaceDesc);
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
//description.setLocation(root.getLocation());
project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), MakeCorePlugin.MAKE_PROJECT_ID);
project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
} else {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {