diff options
author | Marco Stornelli | 2019-03-30 08:59:12 +0000 |
---|---|---|
committer | Marco Stornelli | 2019-05-08 04:50:59 +0000 |
commit | 838a12d8f4cca53657cb3e62fe2dfff2e4d50c6c (patch) | |
tree | f927a2f56c62341c48cf51e9b4ceacc1cfe4a297 /codan/org.eclipse.cdt.codan.core.tests | |
parent | 8b88c9bffea13b448e5149e4edb52245fcc916d6 (diff) | |
download | org.eclipse.cdt-838a12d8f4cca53657cb3e62fe2dfff2e4d50c6c.tar.gz org.eclipse.cdt-838a12d8f4cca53657cb3e62fe2dfff2e4d50c6c.tar.xz org.eclipse.cdt-838a12d8f4cca53657cb3e62fe2dfff2e4d50c6c.zip |
Bug 545952 - Added checker to check for goto usage
Change-Id: I5f7f157c5c208e686627bb90b001879953d83e70
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core.tests')
2 files changed, 56 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/GotoStatementCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/GotoStatementCheckerTest.java new file mode 100644 index 00000000000..3ab408939c6 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/GotoStatementCheckerTest.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2019 Marco Stornelli + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.codan.core.internal.checkers; + +import org.eclipse.cdt.codan.core.tests.CheckerTestCase; +import org.eclipse.cdt.codan.internal.checkers.GotoStatementChecker; + +/** + * Test for {@link GotoStatementChecker} class + */ +public class GotoStatementCheckerTest extends CheckerTestCase { + + public static final String ERR_ID = GotoStatementChecker.ERR_ID; + + @Override + public void setUp() throws Exception { + super.setUp(); + enableProblems(ERR_ID); + } + + @Override + public boolean isCpp() { + return true; + } + + //void foo() { + //while(1) { + // goto label; + //} + //label: + //return 1; + //} + public void testWithGoto() throws Exception { + loadCodeAndRun(getAboveComment()); + checkErrorLine(3, ERR_ID); + } + + //void foo() { + //while(1) { + // return 1; + //} + public void testWithoutGoto() throws Exception { + loadCodeAndRun(getAboveComment()); + checkNoErrorsOfKind(ERR_ID); + } +} diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java index 11258e2ef4d..2deb3a5030d 100644 --- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java +++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/tests/AutomatedIntegrationSuite.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.codan.core.internal.checkers.CommentCheckerLineTests; import org.eclipse.cdt.codan.core.internal.checkers.CommentCheckerNestedTests; import org.eclipse.cdt.codan.core.internal.checkers.DecltypeAutoCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.FormatStringCheckerTest; +import org.eclipse.cdt.codan.core.internal.checkers.GotoStatementCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.NonVirtualDestructorCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.ProblemBindingCheckerTest; import org.eclipse.cdt.codan.core.internal.checkers.ReturnCheckerTest; @@ -84,6 +85,7 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTestSuite(UnusedSymbolInFileScopeCheckerTest.class); suite.addTestSuite(CommentCheckerLineTests.class); suite.addTestSuite(CommentCheckerNestedTests.class); + suite.addTestSuite(GotoStatementCheckerTest.class); // framework suite.addTest(CodanFastTestSuite.suite()); // quick fixes |