mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 313622 Tests for "Make checking for !a && b optional and off by default"
This commit is contained in:
parent
dab37d2d92
commit
fc70a0f70d
2 changed files with 44 additions and 31 deletions
|
@ -10,41 +10,42 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.codan.core.internal.checkers;
|
||||
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
|
||||
import org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisChecker;
|
||||
|
||||
/**
|
||||
* Test for {@see SuggestedParenthesisChecker} class
|
||||
*
|
||||
*/
|
||||
public class SuggestedParenthesisCheckerTest extends CheckerTestCase {
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if (!a<10) b=4; // error here on line 3
|
||||
// }
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if (!a<10) b=4; // error here on line 3
|
||||
// }
|
||||
public void test1() {
|
||||
IProblemPreference macro = getPreference(
|
||||
SuggestedParenthesisChecker.ER_ID,
|
||||
SuggestedParenthesisChecker.PARAM_NOT);
|
||||
macro.setValue(Boolean.TRUE);
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkErrorLine(3);
|
||||
}
|
||||
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
//
|
||||
// if (b+a && a>b || b-a) b--; // error here on line 4
|
||||
// }
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
//
|
||||
// if (b+a && a>b || b-a) b--; // error here on line 4
|
||||
// }
|
||||
public void test2() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkErrorLine(4);
|
||||
}
|
||||
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if (!(a<10)) b=4; // no error here on line 3
|
||||
// }
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if (!(a<10)) b=4; // no error here on line 3
|
||||
// }
|
||||
public void test3() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkNoErrors();
|
||||
|
@ -54,29 +55,24 @@ public class SuggestedParenthesisCheckerTest extends CheckerTestCase {
|
|||
// int a=1,b=3;
|
||||
// if (a && !b) b=4; // no error here on line 3
|
||||
// }
|
||||
|
||||
public void test_lastnot() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkNoErrors();
|
||||
}
|
||||
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if ((!a) && 10) b=4; // no error here on line 3
|
||||
// }
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if ((!a) && 10) b=4; // no error here on line 3
|
||||
// }
|
||||
public void test_fixed() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkNoErrors();
|
||||
}
|
||||
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if (a && b & a) b=4; // error here on line 3
|
||||
// }
|
||||
|
||||
// main() {
|
||||
// int a=1,b=3;
|
||||
// if (a && b & a) b=4; // error here on line 3
|
||||
// }
|
||||
public void test_mixedbin() {
|
||||
loadCodeAndRun(getAboveComment());
|
||||
checkErrorLine(3);
|
||||
|
|
|
@ -14,7 +14,10 @@ import java.io.File;
|
|||
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.IProblemReporter;
|
||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||
import org.eclipse.cdt.codan.core.param.MapProblemPreference;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
@ -114,4 +117,18 @@ public class CheckerTestCase extends CodanTestCase {
|
|||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param problemId
|
||||
* @param paramId
|
||||
* @return
|
||||
*/
|
||||
protected IProblemPreference getPreference(String problemId,
|
||||
String paramId) {
|
||||
IProblem problem = CodanRuntime.getInstance().getChechersRegistry()
|
||||
.getWorkspaceProfile().findProblem(problemId);
|
||||
IProblemPreference pref = ((MapProblemPreference) problem
|
||||
.getPreference()).getChildDescriptor(paramId);
|
||||
return pref;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue