Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Adding a checker to codan

Great solution, problem solved.
I did'nt know that that I could use directly the ASTTranslation to get results.


Lukas Felber <lfelber@xxxxxx> a écrit :

Well I think I can help you with that.
The ASTVisitor does not visit the TranslationUnit's preprocessor
statements. so what you have to do is something like.

for(IASTPreprocessorStatement stmt : ast.getAllPreprocessorStatements) {
  if(stmt instanceof ...)

True is that if you run your test in debug mode as "junit plugin test"
and place a breakpoint in process ast, you should be able to figure out
yourself that these nodes are not visited.


On Wed, 2011-03-09 at 16:27 +0100, maximed@xxxxxxxxxxxxxxxxxxx wrote:
Tests are better now that my version of Eclipse is better too. I can
now run my project as a "JUnit Plug-in Test", and I have to admit that
it works better =).

So now I can figure out my coding problems, a my worst is: event a
simple checker doesn't act like I thought. Indeed, I worked on
something easier: if there's a #undef statement in a file, this file
is not valid. So my Checker is like this:

public class NoUndefChecker extends AbstractIndexAstChecker {
	public static final String ER_ID =
"org.eclipse.cdt.codan.internal.checkers.UndefProblem"; //$NON-NLS-1$

	public void processAst(IASTTranslationUnit ast) {
		ast.accept(new ASTVisitor(){
			shouldVisitStatements = true;
		public int visit(IASTStatement stmt) {
			if(stmt instanceof IASTPreprocessorUndefStatement)
				reportProblem(ER_ID, stmt, stmt.getRawSignature());

And I got got a test case like this:

         // #define BOB 128
	// #undef BOB
	// void main() {
	// 		int i=0;
	//		if(0)
	//			i=2;
	//		else i=3;
	//		return 0;
	//	}
	public void test_undef() {

When I run my JUnit suite, this case gives me this result:
junit.framework.AssertionFailedError: No problems found but should

So I deduced that my checker was not really working... Can you help me
on this?

PS: even with commenting all this:
public static Test suite() {
		final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite();
		// checkers
		// framework
		// quick fixes
		return suite;

I got 154 tests running... Any idea of what to do to test only my
checkers? (I totally trust your work =) )

Best regards

Alena Laskavaia <elaskavaia.cdt@xxxxxxxxx> a écrit :

> You are doing something wrong - some of your plugins are not resolved
> and codan is not loaded. You can check error
> messages of what is not loaded and why. Are you debugging an "Eclipse
> Application" with all plugins enabled?

cdt-dev mailing list

cdt-dev mailing list

Back to the top