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:
parent
2dfdde8c56
commit
eeb3c25c4a
2 changed files with 64 additions and 8 deletions
|
@ -90,13 +90,15 @@ public class TeamSharedIndexTest extends IndexTestBase {
|
||||||
|
|
||||||
private ICProject recreateProject(final String prjName) throws Exception {
|
private ICProject recreateProject(final String prjName) throws Exception {
|
||||||
final boolean[] changed= {false};
|
final boolean[] changed= {false};
|
||||||
CoreModel.getDefault().addElementChangedListener(new IElementChangedListener() {
|
IElementChangedListener waitListener= new IElementChangedListener() {
|
||||||
public void elementChanged(ElementChangedEvent event) {
|
public void elementChanged(ElementChangedEvent event) {
|
||||||
synchronized (changed) {
|
synchronized (changed) {
|
||||||
changed[0]= true;
|
changed[0]= true;
|
||||||
|
changed.notifyAll();
|
||||||
}
|
}
|
||||||
changed.notifyAll();
|
}
|
||||||
}});
|
};
|
||||||
|
CoreModel.getDefault().addElementChangedListener(waitListener);
|
||||||
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
final IProject prjHandle= workspace.getRoot().getProject(prjName);
|
final IProject prjHandle= workspace.getRoot().getProject(prjName);
|
||||||
workspace.run(new IWorkspaceRunnable() {
|
workspace.run(new IWorkspaceRunnable() {
|
||||||
|
@ -112,6 +114,7 @@ public class TeamSharedIndexTest extends IndexTestBase {
|
||||||
assertTrue(changed[0]);
|
assertTrue(changed[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CoreModel.getDefault().removeElementChangedListener(waitListener);
|
||||||
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
fPDOMManager.joinIndexer(INDEXER_WAIT_TIME, NPM);
|
||||||
return CoreModel.getDefault().create(workspace.getRoot().getProject(prjName));
|
return CoreModel.getDefault().create(workspace.getRoot().getProject(prjName));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,19 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Andrew Ferguson (Symbian)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.core.testplugin.util;
|
package org.eclipse.cdt.core.testplugin.util;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
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 java.util.Vector;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
@ -25,11 +27,18 @@ import junit.framework.TestFailure;
|
||||||
import junit.framework.TestResult;
|
import junit.framework.TestResult;
|
||||||
import junit.framework.TestSuite;
|
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 {
|
public class BaseTestCase extends TestCase {
|
||||||
protected static final IProgressMonitor NPM= new NullProgressMonitor();
|
protected static final IProgressMonitor NPM= new NullProgressMonitor();
|
||||||
|
|
||||||
private boolean fExpectFailure= false;
|
private boolean fExpectFailure= false;
|
||||||
private int fBugnumber= 0;
|
private int fBugnumber= 0;
|
||||||
|
private boolean allowsCoreLogErrors= false;
|
||||||
|
|
||||||
public BaseTestCase() {
|
public BaseTestCase() {
|
||||||
super();
|
super();
|
||||||
|
@ -74,7 +83,7 @@ public class BaseTestCase extends TestCase {
|
||||||
if (name.startsWith("test") || (prefix != null && !name.startsWith(prefix))) {
|
if (name.startsWith("test") || (prefix != null && !name.startsWith(prefix))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (name.equals("tearDown") || name.equals("setUp")) {
|
if (name.equals("tearDown") || name.equals("setUp") || name.equals("runBare")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Modifier.isPublic(m.getModifiers())) {
|
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 ) {
|
public void run( TestResult result ) {
|
||||||
if (!fExpectFailure) {
|
if (!fExpectFailure) {
|
||||||
super.run(result);
|
super.run(result);
|
||||||
|
@ -121,4 +164,14 @@ public class BaseTestCase extends TestCase {
|
||||||
fExpectFailure= true;
|
fExpectFailure= true;
|
||||||
fBugnumber= bugnumber;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue