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

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;
		}
		@Override
		public int visit(IASTStatement stmt) {
			if(stmt instanceof IASTPreprocessorUndefStatement)
				reportProblem(ER_ID, stmt, stmt.getRawSignature());
			return PROCESS_CONTINUE;
		}
	});
	}
}

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() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(2);
	}

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
		//suite.addTestSuite(StatementHasNoEffectCheckerTest.class);
		//suite.addTestSuite(SuggestedParenthesisCheckerTest.class);
		//suite.addTestSuite(ReturnCheckerTest.class);
		//suite.addTestSuite(CatchByReferenceTest.class);
		//suite.addTestSuite(AssignmentInConditionCheckerTest.class);
		//suite.addTestSuite(AssignmentToItselfCheckerTest.class);
		//suite.addTestSuite(ReturnStyleCheckerTest.class);
		//suite.addTestSuite(SuspiciousSemicolonCheckerTest.class);
		//suite.addTestSuite(CaseBreakCheckerTest.class);
		//suite.addTestSuite(FormatStringCheckerTest.class);
		suite.addTestSuite(NoUndefCheckerTest.class);
		// framework
		//suite.addTest(CodanFastTestSuite.suite());
		// quick fixes
		//suite.addTestSuite(SuggestedParenthesisQuickFixTest.class);
		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
Maxime



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?





Back to the top