From 8034e44101b1c565c8cfed01ee42d6bb75761013 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 10 Feb 2012 17:37:35 -0800 Subject: [PATCH] Fixed few failing Codan tests. --- .../checkers/StatementHasNoEffectCheckerTest.java | 11 +++++------ .../ui/quickfix/CatchByReferenceQuickFixTest.java | 6 +----- .../ui/quickfix/SuggestedParenthesisQuickFixTest.java | 9 ++++----- .../cdt/core/testplugin/util/TestSourceReader.java | 6 ++++-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java index 3848fedd717..53b7b037077 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/StatementHasNoEffectCheckerTest.java @@ -10,14 +10,14 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.internal.checkers; +import java.io.File; +import java.io.IOException; + import org.eclipse.cdt.codan.core.param.IProblemPreference; import org.eclipse.cdt.codan.core.test.CheckerTestCase; import org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectChecker; import org.eclipse.core.resources.IMarker; -import java.io.File; -import java.io.IOException; - /** * Test for {@see StatementHasNoEffectChecker} class * @@ -94,19 +94,18 @@ public class StatementHasNoEffectCheckerTest extends CheckerTestCase { checkNoErrors(); } - /* first file */ // main() { // int a; // +a; // error here on line 3 // } - /* second file */ + // foo() { // int a; // // +a; // error here on line 4 // } - /* this test is using two files */ public void test2FilesUnaryExpression() throws IOException { + /* This test is using two files */ CharSequence[] code = getContents(2); File f1 = loadcode(code[0].toString()); File f2 = loadcode(code[1].toString()); diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java index 3d28009ae56..f2770e6d93e 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFixTest.java @@ -16,8 +16,8 @@ import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; /** * @author Tomasz Wesolowski */ +@SuppressWarnings("restriction") public class CatchByReferenceQuickFixTest extends QuickFixTestCase { - @Override public void setUp() throws Exception { super.setUp(); @@ -41,7 +41,6 @@ public class CatchByReferenceQuickFixTest extends QuickFixTestCase { // } catch (C exception) { // } // } - @SuppressWarnings("restriction") public void testCatchByReference() throws Exception { setQuickFix(new CatchByReferenceQuickFix()); loadcode(getAboveComment()); @@ -56,7 +55,6 @@ public class CatchByReferenceQuickFixTest extends QuickFixTestCase { // } catch (C) { // } // } - @SuppressWarnings("restriction") public void testCatchByReferenceNoDeclName() throws Exception { setQuickFix(new CatchByReferenceQuickFix()); loadcode(getAboveComment()); @@ -71,7 +69,6 @@ public class CatchByReferenceQuickFixTest extends QuickFixTestCase { // } catch (C exception) { // } // } - @SuppressWarnings("restriction") public void testCatchByConstReference() throws Exception { setQuickFix(new CatchByConstReferenceQuickFix()); loadcode(getAboveComment()); @@ -86,7 +83,6 @@ public class CatchByReferenceQuickFixTest extends QuickFixTestCase { // } catch (C) { // } // } - @SuppressWarnings("restriction") public void testCatchByConstReferenceNoDeclName() throws Exception { setQuickFix(new CatchByConstReferenceQuickFix()); loadcode(getAboveComment()); diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java index 14195e97256..3213b763c50 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/SuggestedParenthesisQuickFixTest.java @@ -39,17 +39,16 @@ public class SuggestedParenthesisQuickFixTest extends QuickFixTestCase { // @file:header.h // int foo(); - /* ---- */ + // @file:main.c // #include "header.h" // main() { // foo(); // } - /* - * this test is using two files, there was not actually bugs here so - * quick fix is not called - */ public void test2FilesExample() throws Exception { + /* + * There are no problems in either of the two files, so quick fix is not called. + */ CharSequence[] code = getContents(2); File f1 = loadcode(code[0].toString()); File f2 = loadcode(code[1].toString()); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index c43165b2a58..b9767eed4f2 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -117,7 +117,7 @@ public class TestSourceReader { if (line.startsWith("//")) { content.append(line.substring(2) + "\n"); } else { - if (content.length() > 0) { + if (!line.startsWith("@") && content.length() > 0) { contents.add(content); if (sections > 0 && contents.size() == sections + 1) contents.remove(0); @@ -128,7 +128,9 @@ public class TestSourceReader { if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) { return contents.toArray(new StringBuilder[contents.size()]); } - contents.clear(); + if (!line.startsWith("@")) { + contents.clear(); + } } } }