mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +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;
|
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.core.test.CheckerTestCase;
|
||||||
|
import org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisChecker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@see SuggestedParenthesisChecker} class
|
* Test for {@see SuggestedParenthesisChecker} class
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SuggestedParenthesisCheckerTest extends CheckerTestCase {
|
public class SuggestedParenthesisCheckerTest extends CheckerTestCase {
|
||||||
|
|
||||||
// main() {
|
// main() {
|
||||||
// int a=1,b=3;
|
// int a=1,b=3;
|
||||||
// if (!a<10) b=4; // error here on line 3
|
// if (!a<10) b=4; // error here on line 3
|
||||||
// }
|
// }
|
||||||
public void test1() {
|
public void test1() {
|
||||||
|
IProblemPreference macro = getPreference(
|
||||||
|
SuggestedParenthesisChecker.ER_ID,
|
||||||
|
SuggestedParenthesisChecker.PARAM_NOT);
|
||||||
|
macro.setValue(Boolean.TRUE);
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(3);
|
checkErrorLine(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// main() {
|
// main() {
|
||||||
// int a=1,b=3;
|
// int a=1,b=3;
|
||||||
//
|
//
|
||||||
// if (b+a && a>b || b-a) b--; // error here on line 4
|
// if (b+a && a>b || b-a) b--; // error here on line 4
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void test2() {
|
public void test2() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(4);
|
checkErrorLine(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// main() {
|
// main() {
|
||||||
// int a=1,b=3;
|
// int a=1,b=3;
|
||||||
// if (!(a<10)) b=4; // no error here on line 3
|
// if (!(a<10)) b=4; // no error here on line 3
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void test3() {
|
public void test3() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
|
@ -54,29 +55,24 @@ public class SuggestedParenthesisCheckerTest extends CheckerTestCase {
|
||||||
// int a=1,b=3;
|
// int a=1,b=3;
|
||||||
// if (a && !b) b=4; // no error here on line 3
|
// if (a && !b) b=4; // no error here on line 3
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void test_lastnot() {
|
public void test_lastnot() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// main() {
|
// main() {
|
||||||
// int a=1,b=3;
|
// int a=1,b=3;
|
||||||
// if ((!a) && 10) b=4; // no error here on line 3
|
// if ((!a) && 10) b=4; // no error here on line 3
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void test_fixed() {
|
public void test_fixed() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// main() {
|
// main() {
|
||||||
// int a=1,b=3;
|
// int a=1,b=3;
|
||||||
// if (a && b & a) b=4; // error here on line 3
|
// if (a && b & a) b=4; // error here on line 3
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void test_mixedbin() {
|
public void test_mixedbin() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(3);
|
checkErrorLine(3);
|
||||||
|
|
|
@ -14,7 +14,10 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
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.IProblemReporter;
|
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.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;
|
||||||
|
@ -114,4 +117,18 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
fail(e.getMessage());
|
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