mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +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 {
|
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() {
|
// main() {
|
||||||
// int a=1,b=3;
|
// int a=1,b=3;
|
||||||
// if (a=b) b=4; // error here on line 3
|
// if (a=b) b=4; // error here on line 3
|
||||||
|
|
|
@ -23,6 +23,12 @@ public class CatchByReferenceTest extends CheckerTestCase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
enableProblems(CatchByReference.ER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
// void main() {
|
// void main() {
|
||||||
// try {
|
// try {
|
||||||
// foo();
|
// foo();
|
||||||
|
|
|
@ -23,6 +23,12 @@ import org.eclipse.core.resources.IMarker;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
|
public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
enableProblems(StatementHasNoEffectChecker.ER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
// main() {
|
// main() {
|
||||||
// int a;
|
// int a;
|
||||||
// +a; // error here on line 3
|
// +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.CodanRuntime;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
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.model.IProblemReporter;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
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.resources.IMarker;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
@ -129,7 +131,8 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
*/
|
*/
|
||||||
protected IProblemPreference getPreference(String problemId, String paramId) {
|
protected IProblemPreference getPreference(String problemId, String paramId) {
|
||||||
IProblem problem = CodanRuntime.getInstance().getCheckersRegistry()
|
IProblem problem = CodanRuntime.getInstance().getCheckersRegistry()
|
||||||
.getWorkspaceProfile().findProblem(problemId);
|
.getResourceProfile(cproject.getResource())
|
||||||
|
.findProblem(problemId);
|
||||||
IProblemPreference pref = ((MapProblemPreference) problem
|
IProblemPreference pref = ((MapProblemPreference) problem
|
||||||
.getPreference()).getChildDescriptor(paramId);
|
.getPreference()).getChildDescriptor(paramId);
|
||||||
return pref;
|
return pref;
|
||||||
|
@ -157,4 +160,24 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
fail(e.getMessage());
|
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