1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 18:25:40 +02:00

fail tests which log non-OK status objects in CCorePlugin

This commit is contained in:
Andrew Ferguson 2007-03-21 14:46:23 +00:00
parent 2dfdde8c56
commit eeb3c25c4a
2 changed files with 64 additions and 8 deletions

View file

@ -90,13 +90,15 @@ public class TeamSharedIndexTest extends IndexTestBase {
private ICProject recreateProject(final String prjName) throws Exception {
final boolean[] changed= {false};
CoreModel.getDefault().addElementChangedListener(new IElementChangedListener() {
IElementChangedListener waitListener= new IElementChangedListener() {
public void elementChanged(ElementChangedEvent event) {
synchronized (changed) {
changed[0]= true;
changed.notifyAll();
}
changed.notifyAll();
}});
}
};
CoreModel.getDefault().addElementChangedListener(waitListener);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject prjHandle= workspace.getRoot().getProject(prjName);
workspace.run(new IWorkspaceRunnable() {
@ -112,6 +114,7 @@ public class TeamSharedIndexTest extends IndexTestBase {
assertTrue(changed[0]);
}
}
CoreModel.getDefault().removeElementChangedListener(waitListener);
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
return CoreModel.getDefault().create(workspace.getRoot().getProject(prjName));
}

View file

@ -7,17 +7,19 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.core.testplugin.util;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
@ -25,11 +27,18 @@ import junit.framework.TestFailure;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
public class BaseTestCase extends TestCase {
protected static final IProgressMonitor NPM= new NullProgressMonitor();
private boolean fExpectFailure= false;
private int fBugnumber= 0;
private boolean allowsCoreLogErrors= false;
public BaseTestCase() {
super();
@ -74,7 +83,7 @@ public class BaseTestCase extends TestCase {
if (name.startsWith("test") || (prefix != null && !name.startsWith(prefix))) {
return;
}
if (name.equals("tearDown") || name.equals("setUp")) {
if (name.equals("tearDown") || name.equals("setUp") || name.equals("runBare")) {
return;
}
if (Modifier.isPublic(m.getModifiers())) {
@ -88,6 +97,40 @@ public class BaseTestCase extends TestCase {
}
}
public void runBare() throws Throwable {
final List statusLog= Collections.synchronizedList(new ArrayList());
ILogListener logListener= new ILogListener() {
public void logging(IStatus status, String plugin) {
if(!status.isOK()) {
statusLog.add(status);
}
}
};
CCorePlugin.getDefault().getLog().addLogListener(logListener);
try {
super.runBare();
if(!allowsCoreLogErrors && !statusLog.isEmpty()) {
StringBuffer msg= new StringBuffer("Non-OK Status was logged to CCorePlugin: \n");
Throwable cause= null;
for(Iterator i= statusLog.iterator(); i.hasNext(); ) {
IStatus status= (IStatus) i.next();
if(cause==null) {
cause= status.getException();
}
Throwable t= status.getException();
msg.append("\t"+status.getMessage()+" "+(t!=null?t.getMessage():"")+"\n");
}
AssertionFailedError afe= new AssertionFailedError(msg.toString());
afe.initCause(cause);
throw afe;
}
} finally {
CCorePlugin.getDefault().getLog().removeLogListener(logListener);
}
}
public void run( TestResult result ) {
if (!fExpectFailure) {
super.run(result);
@ -121,4 +164,14 @@ public class BaseTestCase extends TestCase {
fExpectFailure= true;
fBugnumber= bugnumber;
}
/**
* The last value passed to this method in the body of a testXXX method
* will be used to determine whether or not the presence of non-OK status objects
* in the log should fail the test.
* @param value
*/
public void setAllowCCorePluginLogErrors(boolean value) {
allowsCoreLogErrors= value;
}
}