mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 07:25:23 +02:00
codan tests - make use of comment tags in tests
Change-Id: I822ea36bfa49164b43954ae80bc9fd223ae8d0f6
This commit is contained in:
parent
f680519739
commit
2fca26b8e5
3 changed files with 68 additions and 89 deletions
|
@ -27,22 +27,21 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
enableProblems(ReturnChecker.RET_NORET_ID,ReturnChecker.RET_ERR_VALUE_ID,ReturnChecker.RET_NO_VALUE_ID);
|
enableProblems(ReturnChecker.RET_NORET_ID,ReturnChecker.RET_ERR_VALUE_ID,ReturnChecker.RET_NO_VALUE_ID);
|
||||||
}
|
}
|
||||||
// dummy() {
|
// dummy() {
|
||||||
// return; // error here on line 2
|
// return; // no error here on line 2
|
||||||
// }
|
// }
|
||||||
public void testDummyFunction() {
|
public void testDummyFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors(); // because return type if not defined, usually people don't care
|
// because return type if not defined, usually people don't care
|
||||||
}
|
}
|
||||||
|
|
||||||
// void void_function(void) {
|
// void void_function(void) {
|
||||||
// return; // no error here
|
// return; // no error here
|
||||||
// }
|
// }
|
||||||
public void testVoidFunction() {
|
public void testVoidFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int integer_return_function(void) {
|
// int integer_return_function(void) { // error
|
||||||
// if (global) {
|
// if (global) {
|
||||||
// if (global == 100) {
|
// if (global == 100) {
|
||||||
// return; // error here on line 4
|
// return; // error here on line 4
|
||||||
|
@ -50,8 +49,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
public void testBasicTypeFunction() {
|
public void testBasicTypeFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -63,8 +61,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return; // error here on line 6
|
// return; // error here on line 6
|
||||||
// }
|
// }
|
||||||
public void testUserDefinedFunction() {
|
public void testUserDefinedFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef unsigned int uint8_t;
|
// typedef unsigned int uint8_t;
|
||||||
|
@ -73,10 +70,10 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return; // error here on line 4
|
// return; // error here on line 4
|
||||||
// }
|
// }
|
||||||
public void testTypedefReturnFunction() {
|
public void testTypedefReturnFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// typedef unsigned int uint8_t;
|
// typedef unsigned int uint8_t;
|
||||||
//
|
//
|
||||||
// uint8_t (*return_fp_no_typedef(void))(void)
|
// uint8_t (*return_fp_no_typedef(void))(void)
|
||||||
|
@ -84,8 +81,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return; // error here on line 5
|
// return; // error here on line 5
|
||||||
// }
|
// }
|
||||||
public void testFunctionPointerReturnFunction() {
|
public void testFunctionPointerReturnFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void test() {
|
// void test() {
|
||||||
|
@ -97,21 +93,19 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
public void testInnerFunction_Bug315525() {
|
public void testInnerFunction_Bug315525() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void test() {
|
// void test() {
|
||||||
// class A {
|
// class A {
|
||||||
// public:
|
// public:
|
||||||
// int m() {
|
// int m() {
|
||||||
// return; // should be an error here
|
// return; // error here
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
public void testInnerFunction_Bug316154() {
|
public void testInnerFunction_Bug316154() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// class c {
|
// class c {
|
||||||
|
@ -149,8 +143,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// [](int r){return r;}(5);
|
// [](int r){return r;}(5);
|
||||||
// }
|
// }
|
||||||
public void testLambda_Bug332285() {
|
public void testLambda_Bug332285() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
// void f()
|
// void f()
|
||||||
// {
|
// {
|
||||||
|
@ -158,37 +151,33 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// ;
|
// ;
|
||||||
// }
|
// }
|
||||||
public void testLambda2_Bug332285() {
|
public void testLambda2_Bug332285() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void g()
|
// void g()
|
||||||
// {
|
// {
|
||||||
// int r;
|
// int r;
|
||||||
// ({return r;});
|
// ({return r;}); // error
|
||||||
// }
|
// }
|
||||||
public void testGccExtensions() {
|
public void testGccExtensions() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto f() -> void
|
// auto f() -> void
|
||||||
// {
|
// {
|
||||||
// }
|
// }
|
||||||
public void testVoidLateSpecifiedReturnType_Bug337677() {
|
public void testVoidLateSpecifiedReturnType_Bug337677() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto f() -> void*
|
// auto f() -> void* // error
|
||||||
// {
|
// {
|
||||||
// }
|
// }
|
||||||
public void testVoidPointerLateSpecifiedReturnType_Bug337677() {
|
public void testVoidPointerLateSpecifiedReturnType_Bug337677() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int f()
|
// int f() // error
|
||||||
// {
|
// {
|
||||||
// if (g())
|
// if (g())
|
||||||
// h();
|
// h();
|
||||||
|
@ -196,11 +185,10 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
public void testBranches_Bug342906() {
|
public void testBranches_Bug342906() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int f()
|
// int f() // error
|
||||||
// {
|
// {
|
||||||
// switch (g()) {
|
// switch (g()) {
|
||||||
// case 1: h(); break;
|
// case 1: h(); break;
|
||||||
|
@ -208,8 +196,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
public void testSwitch() {
|
public void testSwitch() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//int bar(int foo)
|
//int bar(int foo)
|
||||||
|
@ -220,8 +207,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return 0;
|
// return 0;
|
||||||
//}
|
//}
|
||||||
public void testBranches_Bug343767() {
|
public void testBranches_Bug343767() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//int bar(int foo)
|
//int bar(int foo)
|
||||||
|
@ -233,19 +219,18 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// foo++;
|
// foo++;
|
||||||
//}
|
//}
|
||||||
public void testBranchesDeadCode_Bug343767() {
|
public void testBranchesDeadCode_Bug343767() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int f()
|
// int f() // error
|
||||||
// {
|
// {
|
||||||
// switch (g()) {
|
// switch (g()) {
|
||||||
// case 1: return 1;
|
// case 1: return 1;
|
||||||
// case 2: return 0;
|
// case 2: return 0;
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
public void testBranchesSwitch_Bug343767a() {
|
public void testBranchesSwitch_Bug343767a() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
// int f()
|
// int f()
|
||||||
// {
|
// {
|
||||||
|
@ -253,10 +238,10 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// case 1: return 1;
|
// case 1: return 1;
|
||||||
// case 2: return 0;
|
// case 2: return 0;
|
||||||
// default: return -1;
|
// default: return -1;
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
public void testBranchesSwitch_Bug343767b() {
|
public void testBranchesSwitch_Bug343767b() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
//int bar(int foo)
|
//int bar(int foo)
|
||||||
//{
|
//{
|
||||||
|
@ -267,18 +252,16 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// else return 1;
|
// else return 1;
|
||||||
//}
|
//}
|
||||||
public void testBranches2_Bug343767() {
|
public void testBranches2_Bug343767() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
//int bar(int foo)
|
//int bar(int foo) // error
|
||||||
//{
|
//{
|
||||||
// while(foo) {
|
// while(foo) {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
public void testWhile() {
|
public void testWhile() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int f345687() {
|
// int f345687() {
|
||||||
|
@ -287,8 +270,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
public void testNextedBlock_Bug345687() {
|
public void testNextedBlock_Bug345687() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int
|
// int
|
||||||
|
@ -301,8 +283,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return (a);
|
// return (a);
|
||||||
// }
|
// }
|
||||||
public void testGoto_Bug346559() {
|
public void testGoto_Bug346559() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int main()
|
// int main()
|
||||||
|
@ -311,8 +292,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// // no error since return value in main is optional
|
// // no error since return value in main is optional
|
||||||
// }
|
// }
|
||||||
public void testMainFunction() {
|
public void testMainFunction() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #include <vector>
|
// #include <vector>
|
||||||
|
@ -320,8 +300,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return {1,2,3};
|
// return {1,2,3};
|
||||||
// }
|
// }
|
||||||
public void testReturnInitializerList() {
|
public void testReturnInitializerList() {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,8 +311,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public void testNoReturn() {
|
public void testNoReturn() {
|
||||||
loadCodeAndRun(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int try1() {
|
// int try1() {
|
||||||
|
@ -345,30 +323,27 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
public void testTryBlock1() throws Exception {
|
public void testTryBlock1() throws Exception {
|
||||||
// bug 348387
|
// bug 348387
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int try2() {
|
// int try2() { // error
|
||||||
// try {
|
// try {
|
||||||
// return 5;
|
// return 5;
|
||||||
// } catch (int) {
|
// } catch (int) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
public void testTryBlock2() throws Exception {
|
public void testTryBlock2() throws Exception {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int try3() {
|
// int try3() { // error
|
||||||
// try {
|
// try {
|
||||||
// } catch (int a) {
|
// } catch (int a) {
|
||||||
// return 5;
|
// return 5;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
public void testTryBlock3() throws Exception {
|
public void testTryBlock3() throws Exception {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int retindead() {
|
// int retindead() {
|
||||||
|
@ -377,8 +352,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
public void testRetInDeadCode1() throws Exception {
|
public void testRetInDeadCode1() throws Exception {
|
||||||
// bug 348386
|
// bug 348386
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int retindead() {
|
// int retindead() {
|
||||||
|
@ -387,8 +361,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
public void testRetInDeadCodeThrow() throws Exception {
|
public void testRetInDeadCodeThrow() throws Exception {
|
||||||
// bug 356908
|
// bug 356908
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bool func( int i )
|
// bool func( int i )
|
||||||
|
@ -404,8 +377,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
public void testRetInDeadCodeCase() throws Exception {
|
public void testRetInDeadCodeCase() throws Exception {
|
||||||
// Bug 350168
|
// Bug 350168
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int test1() {
|
// int test1() {
|
||||||
|
@ -415,8 +387,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
public void testNoRetInfinitLoop() throws Exception {
|
public void testNoRetInfinitLoop() throws Exception {
|
||||||
// Bug 394521
|
// Bug 394521
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int test1_f() // WARNING HERE: "No return, in function returning non-void"
|
// int test1_f() // WARNING HERE: "No return, in function returning non-void"
|
||||||
|
@ -427,29 +398,27 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
public void testNoRetInfinitLoop2() throws Exception {
|
public void testNoRetInfinitLoop2() throws Exception {
|
||||||
// Bug 394521
|
// Bug 394521
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkNoErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int foo() {
|
// int foo() { // error
|
||||||
// int waldo = waldo();
|
// int waldo = waldo();
|
||||||
// if (waldo);
|
// if (waldo);
|
||||||
// }
|
// }
|
||||||
public void testSelfReferencingVariable_452325() throws Exception {
|
public void testSelfReferencingVariable_452325() throws Exception {
|
||||||
// Just check that codan runs without any exceptions being thrown.
|
// Just check that codan runs without any exceptions being thrown.
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// int foo(int x) { // no warning
|
// int foo(int x) { // error
|
||||||
// switch (x) {
|
// switch (x) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
public void testEmptySwitch_455828() throws Exception {
|
public void testEmptySwitch_455828() throws Exception {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAbove();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// int foo(int x) {
|
// int foo(int x) { // error
|
||||||
// switch (x) {
|
// switch (x) {
|
||||||
// case 0:
|
// case 0:
|
||||||
// return 42;;
|
// return 42;;
|
||||||
|
@ -457,7 +426,6 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
public void testDoubleSemicolonInSwitchCase_455828() throws Exception {
|
public void testDoubleSemicolonInSwitchCase_455828() throws Exception {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
checkSampleAboveCpp();
|
||||||
checkErrorLine(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,4 +244,14 @@ public class CheckerTestCase extends CodanTestCase {
|
||||||
}
|
}
|
||||||
CodanRuntime.getInstance().getCheckersRegistry().updateProfile(cproject.getProject(), profile);
|
CodanRuntime.getInstance().getCheckersRegistry().updateProfile(cproject.getProject(), profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void checkSampleAbove() {
|
||||||
|
loadCodeAndRun(getAboveComment());
|
||||||
|
checkErrorComments();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkSampleAboveCpp() {
|
||||||
|
loadCodeAndRunCpp(getAboveComment());
|
||||||
|
checkErrorComments();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
|
@ -245,12 +246,12 @@ public class CodanTestCase extends BaseTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Pattern COMMENT_TAG_PATTERN = Pattern.compile("//\\s*(err|ERR|ERROR|error)\\b");
|
||||||
private void loadErrorComments(String trim) {
|
private void loadErrorComments(String trim) {
|
||||||
String[] lines = trim.split("\n");
|
String[] lines = trim.split("\n");
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
String string = lines[i];
|
String string = lines[i];
|
||||||
if (string.matches(".*//\\s*err\\s*")) {
|
if (COMMENT_TAG_PATTERN.matcher(string).find()) {
|
||||||
|
|
||||||
errLines.add(i+1);
|
errLines.add(i+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue