1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 13:55:39 +02:00

Bug 539307 - Set correct project nature in Codan tests to fix wrong content type

When the lsp4e-cpp plugin is present, two content types are associated with
.cpp extension. The lsp4e-cpp one is chosen because it happens to be first.
Normally, the CDT C++ content type gets its priority boosted when the C++
project nature is present. Some Codan tests run on .cpp files but without
the C++ project nature so the files are of wrong content type and the tests
fail. Once the nature is fixed, some tests were failing because they should
run on C files but loadCode was not loading them as C++ files because of the
project nature.

Change-Id: I61b77d409e81c3cf78e60adf0c77a9bf976ac9d5
Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
Marc-Andre Laperle 2018-09-27 23:50:18 -04:00 committed by Nathan Ridge
parent 956ce6b2dc
commit 467aab5559
9 changed files with 72 additions and 22 deletions

View file

@ -29,6 +29,11 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
setLast(true);
}
@Override
public boolean isCpp() {
return true;
}
// void foo(void) {
// int a;
// switch (a) {
@ -256,7 +261,7 @@ public class CaseBreakCheckerTest extends CheckerTestCase {
// case 1:
// b = 2;
// /* no break */
// bye();
// foo();
// }
// }
public void testLastCaseBadCommentNotLast() throws Exception {

View file

@ -26,12 +26,17 @@ public class CommentCheckerLineTests extends CheckerTestCase {
enableProblems(CommentChecker.COMMENT_NO_LINE);
}
@Override
public boolean isCpp() {
return true;
}
// void foo() {
// return; // error
// }
@Test
public void testLineComment() throws Exception {
checkSampleAbove();
checkSampleAboveC();
}
// void foo() {
@ -39,7 +44,7 @@ public class CommentCheckerLineTests extends CheckerTestCase {
// }
@Test
public void testNoLineComment() throws Exception {
checkSampleAbove();
checkSampleAboveC();
}
// char * foo() {
@ -47,7 +52,7 @@ public class CommentCheckerLineTests extends CheckerTestCase {
// }
@Test
public void testNoLineCommentInString() throws Exception {
checkSampleAbove();
checkSampleAboveC();
}
// void foo() {
@ -61,7 +66,7 @@ public class CommentCheckerLineTests extends CheckerTestCase {
// #define AAA // error even in prepro
@Test
public void testLineCommentInPrepro() throws Exception {
checkSampleAbove();
checkSampleAboveC();
}
// @file:test.h

View file

@ -26,7 +26,12 @@ public class ReturnCheckerTest extends CheckerTestCase {
enableProblems(ReturnChecker.RET_NORET_ID,ReturnChecker.RET_ERR_VALUE_ID,ReturnChecker.RET_NO_VALUE_ID);
}
// dummy() {
@Override
public boolean isCpp() {
return true;
}
// void dummy() {
// return; // no error here on line 2
// }
public void testDummyFunction() throws Exception {

View file

@ -27,7 +27,12 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
enableProblems(StatementHasNoEffectChecker.ER_ID);
}
// main() {
@Override
public boolean isCpp() {
return true;
}
// int main() {
// int a;
// +a; // error here on line 3
// }
@ -35,7 +40,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
// main() {
// int main() {
// int a,b;
//
// b+a; // error here on line 4
@ -44,7 +49,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
// main() {
// int main() {
// int a,b;
//
// a=b+a; // no error here
@ -53,7 +58,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
// main() {
// int main() {
// int a,b;
//
// (a=b); // no errors here
@ -71,7 +76,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
// main() {
// int main() {
// int a;
// a; // error here on line 3
// }
@ -79,7 +84,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
// main() {
// int main() {
// int a=({foo();a;}); // no error here on line 2
// char *p=({char s[]="Some string";&s[0];}); // no error here on line 3
// }
@ -87,19 +92,19 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
// main() {
// int main() {
// int z=({int a=0; +a; a;}) // error here on line 2
// }
public void testGNUExpressionCompoundStmtInside() throws Exception {
checkSampleAbove();
}
// main() {
// int main() {
// int a;
// +a; // error here on line 3
// }
// foo() {
// void foo() {
// int a;
//
// +a; // error here on line 4
@ -114,7 +119,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkErrorLine(f2, 4);
}
// main() {
// int main() {
// for (a=b;a;a=a->next);
// }
public void testForTestExpression() throws Exception {
@ -131,7 +136,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAboveCpp();
}
// main() {
// int main() {
// A a,b;
//
// b+=a; // no error here on line 4
@ -141,7 +146,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
}
//#define FUNC(a) a
// main() {
// int main() {
// int a;
// FUNC(a); // error by default
// }
@ -152,7 +157,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
}
//#define FUNC(a) a
// main() {
// int main() {
// int x;
// FUNC(x); // error
// }
@ -163,7 +168,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
}
//#define FUNC(a) a
// main() {
// int main() {
// int a;
// FUNC(a); // no error if macro exp turned off
// }
@ -173,7 +178,7 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase {
checkSampleAbove();
}
// main() {
// int main() {
// int a;
// +a; // error here on line 3
// }

View file

@ -27,6 +27,11 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
UnusedSymbolInFileScopeChecker.ER_UNUSED_STATIC_FUNCTION_ID);
}
@Override
public boolean isCpp() {
return true;
}
////////////////////////////////////////////////////////////////////////////
// extern function declarations
////////////////////////////////////////////////////////////////////////////
@ -314,7 +319,7 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
// static void f4() __attribute__((unused)) {}
// static void __attribute__((unused)) f5();
public void testAttributeUnused() throws Exception {
loadCodeAndRun(getAboveComment());
loadCodeAndRunC(getAboveComment());
checkNoErrors();
loadCodeAndRunCpp(getAboveComment());

View file

@ -159,6 +159,11 @@ public class CheckerTestCase extends CodanTestCase {
runCodan();
}
public void loadCodeAndRunC(String code) throws CoreException {
loadcode(code, false);
runCodan();
}
public void loadCodeAndRunCpp(String code) throws CoreException {
loadcode(code, true);
runCodan();
@ -254,6 +259,11 @@ public class CheckerTestCase extends CodanTestCase {
checkErrorComments();
}
protected void checkSampleAboveC() throws CoreException {
loadCodeAndRunC(getAboveComment());
checkErrorComments();
}
protected void checkSampleAboveCpp() throws CoreException {
loadCodeAndRunCpp(getAboveComment());
checkErrorComments();

View file

@ -17,6 +17,11 @@ public class CaseBreakQuickFixCommentTest extends QuickFixTestCase {
return new CaseBreakQuickFixComment();
}
@Override
public boolean isCpp() {
return true;
}
//void hello() {}
//void func() {
// int a;

View file

@ -28,6 +28,11 @@ public class CaseBreakQuickFixFallthroughAttributeTest extends QuickFixTestCase
super.tearDown();
}
@Override
public boolean isCpp() {
return true;
}
@Override
protected AbstractCodanCMarkerResolution createQuickFix() {
return new CaseBreakQuickFixFallthroughAttribute();

View file

@ -23,6 +23,11 @@ public class QuickFixSuppressProblemTest extends QuickFixTestCase {
return new QuickFixSuppressProblem();
}
@Override
public boolean isCpp() {
return true;
}
//struct s {};
//void func() {
// try {