mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
fixed tests - only tested problems should be turned on
This commit is contained in:
parent
3c182b8cf9
commit
df967e4408
4 changed files with 47 additions and 1 deletions
|
@ -19,6 +19,17 @@ import org.eclipse.core.resources.IMarker;
|
|||
*
|
||||
*/
|
||||
public class AssignmentInConditionCheckerTest extends CheckerTestCase {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.codan.core.test.CodanTestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableProblems("org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem");
|
||||
}
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if (a=b) b=4; // error here on line 3
|
||||
|
|
|
@ -23,6 +23,12 @@ public class CatchByReferenceTest extends CheckerTestCase {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableProblems(CatchByReference.ER_ID);
|
||||
}
|
||||
|
||||
// void main() {
|
||||
// try {
|
||||
// foo();
|
||||
|
|
|
@ -23,6 +23,12 @@ import org.eclipse.core.resources.IMarker;
|
|||
*
|
||||
*/
|
||||
public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableProblems(StatementHasNoEffectChecker.ER_ID);
|
||||
}
|
||||
|
||||
// main() {
|
||||
// int a;
|
||||
// +a; // error here on line 3
|
||||
|
|
|
@ -15,9 +15,11 @@ import java.io.IOException;
|
|||
|
||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||
import org.eclipse.cdt.codan.core.model.IProblemReporter;
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
||||
import org.eclipse.cdt.codan.internal.core.model.CodanProblem;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
@ -129,7 +131,8 @@ public class CheckerTestCase extends CodanTestCase {
|
|||
*/
|
||||
protected IProblemPreference getPreference(String problemId, String paramId) {
|
||||
IProblem problem = CodanRuntime.getInstance().getCheckersRegistry()
|
||||
.getWorkspaceProfile().findProblem(problemId);
|
||||
.getResourceProfile(cproject.getResource())
|
||||
.findProblem(problemId);
|
||||
IProblemPreference pref = ((MapProblemPreference) problem
|
||||
.getPreference()).getChildDescriptor(paramId);
|
||||
return pref;
|
||||
|
@ -157,4 +160,24 @@ public class CheckerTestCase extends CodanTestCase {
|
|||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void enableProblems(String... ids) {
|
||||
IProblemProfile profile = CodanRuntime.getInstance()
|
||||
.getCheckersRegistry().getWorkspaceProfile();
|
||||
IProblem[] problems = profile.getProblems();
|
||||
for (int i = 0; i < problems.length; i++) {
|
||||
IProblem p = problems[i];
|
||||
for (int j = 0; j < ids.length; j++) {
|
||||
String pid = ids[j];
|
||||
if (p.getId().equals(pid)) {
|
||||
((CodanProblem) p).setEnabled(true);
|
||||
} else {
|
||||
((CodanProblem) p).setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
CodanRuntime.getInstance().getCheckersRegistry()
|
||||
.updateProfile(cproject.getProject(), profile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue