diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java index acd394207e4..6cada9317bc 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteBaseTest.java @@ -14,19 +14,18 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.BufferedReader; import java.io.InputStreamReader; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; import org.eclipse.cdt.core.tests.BaseTestFramework; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.ILogListener; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; import org.eclipse.jface.text.TextSelection; +import org.junit.jupiter.api.AfterEach; /** * @author Guido Zgraggen IFS @@ -34,48 +33,9 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogListener { protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); - protected TreeMap fileMap = new TreeMap<>(); protected String fileWithSelection; protected TextSelection selection; - protected RewriteBaseTest(String name) { - super(name); - } - - public RewriteBaseTest(String name, List files) { - super(name); - for (TestSourceFile file : files) { - fileMap.put(file.getName(), file); - } - } - - @Override - protected abstract void runTest() throws Throwable; - - @Override - protected void setUp() throws Exception { - super.setUp(); - for (TestSourceFile testFile : fileMap.values()) { - if (testFile.getSource().length() > 0) { - importFile(testFile.getName(), testFile.getSource()); - } - } - } - - protected void assertEquals(TestSourceFile file, IFile file2) throws Exception { - StringBuilder code = getCodeFromFile(file2); - assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString())); - } - - protected void compareFiles(Map testResourceFiles) throws Exception { - for (String fileName : testResourceFiles.keySet()) { - TestSourceFile file = testResourceFiles.get(fileName); - IFile iFile = project.getFile(new Path(fileName)); - StringBuilder code = getCodeFromFile(iFile); - assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString())); - } - } - protected StringBuilder getCodeFromFile(IFile file) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents())); StringBuilder code = new StringBuilder(); @@ -88,11 +48,10 @@ protected StringBuilder getCodeFromFile(IFile file) throws Exception { return code; } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void closeAllFiles() throws Exception { System.gc(); fileManager.closeAllFiles(); - super.tearDown(); } @Override diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java index 1d4bbdeaba7..02d69f4c700 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/RewriteTester.java @@ -14,30 +14,32 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.cdt.core.parser.tests.rewrite.comenthandler.CommentHandlingTest; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.TextSelection; +import org.junit.jupiter.params.provider.Arguments; import org.osgi.framework.Bundle; -import junit.framework.Test; -import junit.framework.TestSuite; - /** + * This is not actually a test, but a test provider. See loadTests and its uses + * + * The possibly unusual structure here is a result of migrating this JUnit 3 test + * suite creator to JUnit 5 + * * @author Emanuel Graf */ -public class RewriteTester extends TestSuite { +public class RewriteTester { enum MatcherState { skip, inTest, inSource, inExpectedResult } @@ -47,12 +49,12 @@ enum MatcherState { private static final String fileRegexp = "//@(.*)\\s*(\\w*)*$"; //$NON-NLS-1$ private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$ - public static Test suite(String name, String file) throws Exception { + public static List loadTests(Class clazz, String file) throws Exception { BufferedReader in = createReader(file); - ArrayList testCases = createTests(in); + List testCases = createTests(clazz, in); in.close(); - return createSuite(testCases, name); + return testCases; } protected static BufferedReader createReader(String file) throws IOException { @@ -62,12 +64,13 @@ protected static BufferedReader createReader(String file) throws IOException { return new BufferedReader(new FileReader(file2)); } - private static ArrayList createTests(BufferedReader inputReader) throws Exception { + private static List createTests(Class clazz, BufferedReader inputReader) + throws Exception { String line; List files = new ArrayList<>(); TestSourceFile actFile = null; MatcherState matcherState = MatcherState.skip; - ArrayList testCases = new ArrayList<>(); + List testCases = new ArrayList<>(); String testName = null; String className = null; boolean bevorFirstTest = true; @@ -75,7 +78,7 @@ private static ArrayList createTests(BufferedReader inputReader while ((line = inputReader.readLine()) != null) { if (lineMatchesBeginOfTest(line)) { if (!bevorFirstTest) { - RewriteBaseTest test = createTestClass(className, testName, files); + Arguments test = createTestClass(clazz, className, testName, files); testCases.add(test); files = new ArrayList<>(); className = null; @@ -113,42 +116,17 @@ private static ArrayList createTests(BufferedReader inputReader break; } } - RewriteBaseTest test = createTestClass(className, testName, files); + Arguments test = createTestClass(clazz, className, testName, files); testCases.add(test); return testCases; } - private static RewriteBaseTest createTestClass(String className, String testName, List files) - throws Exception { - try { - Class refClass = Class.forName(className); - Constructor ct = refClass.getConstructor(new Class[] { String.class, List.class }); - RewriteBaseTest test = (RewriteBaseTest) ct.newInstance(new Object[] { testName, files }); - for (TestSourceFile file : files) { - TextSelection sel = file.getSelection(); - if (sel != null) { - test.setFileWithSelection(file.getName()); - test.setSelection(sel); - break; - } - } - return test; - } catch (ClassNotFoundException e) { - throw new Exception("Unknown TestClass: " + e.getMessage() - + ". Make sure the test's sourcefile specifies a valid test class."); - } catch (SecurityException e) { - throw new Exception("Security Exception during Test creation", e); - } catch (NoSuchMethodException e) { - throw new Exception("Test class does not provied required constructor."); - } catch (IllegalArgumentException e) { - throw new Exception("IllegalArgumentException during Test creation", e); - } catch (InstantiationException e) { - throw new Exception("InstantiationException during Test creation", e); - } catch (IllegalAccessException e) { - throw new Exception("IllegalAccessException during Test creation", e); - } catch (InvocationTargetException e) { - throw new Exception("InvocationTargetException during Test creation", e); - } + private static Arguments createTestClass(Class clazz, String className, + String testName, List files) throws Exception { + // For historical reasons, the Java classname of the test exists in the rts files. + // This is a check that the rts file matches the test currently being loaded. + assertEquals(clazz.getName(), className); + return Arguments.argumentSet(testName, files); } private static String getFileName(String line) { @@ -191,14 +169,4 @@ private static String getNameOfTest(String line) { private static boolean lineMatchesBeginOfResult(String line) { return createMatcherFromString(resultRegexp, line).find(); } - - private static TestSuite createSuite(ArrayList testCases, String name) { - TestSuite suite = new TestSuite(name); - Iterator it = testCases.iterator(); - while (it.hasNext()) { - RewriteBaseTest subject = it.next(); - suite.addTest(subject); - } - return suite; - } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTester.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTester.java index c7cd80c8c4b..3e1308d9a04 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTester.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/ASTWriterTester.java @@ -14,7 +14,9 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.astwriter; -import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.parser.ISourceCodeParser; @@ -43,47 +45,47 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.core.resources.IFile; +import org.eclipse.jface.text.TextSelection; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * @author Guido Zgraggen */ -public abstract class ASTWriterTester extends RewriteBaseTest { +public class ASTWriterTester extends RewriteBaseTest { + private static final IParserLogService NULL_LOG = new NullLogService(); private IFile file; - public ASTWriterTester(String name, ASTWriterTestSourceFile file) { - super(name); - fileMap.put(file.getName(), file); + public static List loadTests() throws Exception { + return SourceRewriteTest.loadTests(); } - @Override - protected void setUp() throws Exception { - super.setUp(); - for (TestSourceFile testFile : fileMap.values()) { - if (testFile.getSource().length() > 0) { - file = importFile(testFile.getName(), testFile.getSource()); - } + @ParameterizedTest + @MethodSource("loadTests") + protected void test(ASTWriterTestSourceFile testFile) throws Throwable { + if (testFile.getSource().length() > 0) { + importFile(testFile.getName(), testFile.getSource()); + } + TextSelection sel = testFile.getSelection(); + if (sel != null) { + setFileWithSelection(testFile.getName()); + setSelection(sel); } - } - @Override - protected void runTest() throws Throwable { file = project.getFile("ASTWritterTest.h"); //$NON-NLS-1$ - compareFiles(fileMap); + compareFiles(testFile); } - @Override - protected void compareFiles(Map testResourceFiles) throws Exception { - for (String fileName : testResourceFiles.keySet()) { - TestSourceFile testFile = testResourceFiles.get(fileName); - String code = generateSource(testFile); - assertEquals(TestHelper.unifyNewLines(testFile.getExpectedSource()), - TestHelper.unifyNewLines(code + System.getProperty("line.separator"))); //$NON-NLS-1$ - } + private void compareFiles(ASTWriterTestSourceFile testFile) throws Exception { + String code = generateSource(testFile); + assertEquals(TestHelper.unifyNewLines(testFile.getExpectedSource()), + TestHelper.unifyNewLines(code + System.getProperty("line.separator"))); //$NON-NLS-1$ } - public String generateSource(TestSourceFile testFile) throws Exception { + private String generateSource(TestSourceFile testFile) throws Exception { IASTTranslationUnit unit = getParser(testFile).parse(); NodeCommentMap commentMap = ASTCommenter.getCommentedNodeMap(unit); ASTModificationMap map = new ASTModificationMap(); @@ -92,7 +94,7 @@ public String generateSource(TestSourceFile testFile) throws Exception { return writer.write(unit, commentMap); } - protected ISourceCodeParser getParser(TestSourceFile testFile) throws Exception { + private ISourceCodeParser getParser(TestSourceFile testFile) throws Exception { FileContent codeReader = FileContent.create(file); ParserLanguage language = getLanguage(testFile); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTest.java index 4709a38eea3..12547afc437 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/astwriter/SourceRewriteTest.java @@ -18,22 +18,25 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.tests.ast2.AST2TestBase.ScannerKind; -import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest; import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.TextSelection; +import org.junit.jupiter.params.provider.Arguments; import org.osgi.framework.Bundle; -import junit.framework.Test; -import junit.framework.TestSuite; - -public class SourceRewriteTest extends TestSuite { +/** + * This is not actually a test, but a test provider. See loadTests and its uses + * + * The possibly unusual structure here is a result of migrating this JUnit 3 test + * suite creator to JUnit 5 + */ +public class SourceRewriteTest { private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$ private static final String codeTypeRegexp = "//%(C|CPP|CPP20)( GNU)?$"; //$NON-NLS-1$ private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$ @@ -42,83 +45,73 @@ enum MatcherState { skip, inTest, inSource, inExpectedResult } - protected static BufferedReader createReader(String file) throws IOException { + private static BufferedReader createReader(String file) throws IOException { Bundle bundle = CTestPlugin.getDefault().getBundle(); Path path = new Path(file); file = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile(); return new BufferedReader(new FileReader(file)); } - public static Test suite() throws Exception { - TestSuite suite = new TestSuite("AstWriterTests"); - suite.addTest( + public static List loadTests() throws Exception { + List suite = new ArrayList<>(); + suite.addAll( SourceRewriteTest.suite("ExpressionTests", "resources/rewrite/ASTWriterExpressionTestSource.awts")); - suite.addTest( + suite.addAll( SourceRewriteTest.suite("DelcSpecifierTests", "resources/rewrite/ASTWriterDeclSpecTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("Commented DelcSpecifierTests", + suite.addAll(SourceRewriteTest.suite("Commented DelcSpecifierTests", "resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts")); - suite.addTest( + suite.addAll( SourceRewriteTest.suite("DeclaratorTests", "resources/rewrite/ASTWriterDeclaratorTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("Commented DeclaratorTests", + suite.addAll(SourceRewriteTest.suite("Commented DeclaratorTests", "resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts")); - suite.addTest( - SourceRewriteTest.suite("StatementsTests", "resources/rewrite/ASTWriterStatementTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("Commented StatementsTests", + suite.addAll(SourceRewriteTest.suite("StatementsTests", "resources/rewrite/ASTWriterStatementTestSource.awts")); + suite.addAll(SourceRewriteTest.suite("Commented StatementsTests", "resources/rewrite/ASTWriterCommentedStatementTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("NameTests", "resources/rewrite/ASTWriterNameTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("Commented NameTests", + suite.addAll(SourceRewriteTest.suite("NameTests", "resources/rewrite/ASTWriterNameTestSource.awts")); + suite.addAll(SourceRewriteTest.suite("Commented NameTests", "resources/rewrite/ASTWriterCommentedNameTestSource.awts")); - suite.addTest( + suite.addAll( SourceRewriteTest.suite("InitializerTests", "resources/rewrite/ASTWriterInitializerTestSource.awts")); - suite.addTest( + suite.addAll( SourceRewriteTest.suite("DeclarationTests", "resources/rewrite/ASTWriterDeclarationTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("Commented DeclarationTests", + suite.addAll(SourceRewriteTest.suite("Commented DeclarationTests", "resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("TemplatesTests", "resources/rewrite/ASTWriterTemplateTestSource.awts")); + suite.addAll(SourceRewriteTest.suite("TemplatesTests", "resources/rewrite/ASTWriterTemplateTestSource.awts")); - suite.addTest(SourceRewriteTest.suite("CommentTests", "resources/rewrite/ASTWriterCommentedTestSource.awts")); - suite.addTest( + suite.addAll(SourceRewriteTest.suite("CommentTests", "resources/rewrite/ASTWriterCommentedTestSource.awts")); + suite.addAll( SourceRewriteTest.suite("NewCommentTests", "resources/rewrite/ASTWriterCommentedTestSource2.awts")); - suite.addTest(SourceRewriteTest.suite("AttributeTests", "resources/rewrite/ASTWriterAttributeTestSource.awts")); - suite.addTestSuite(ExpressionWriterTest.class); + suite.addAll(SourceRewriteTest.suite("AttributeTests", "resources/rewrite/ASTWriterAttributeTestSource.awts")); return suite; } - public static Test suite(String name, String file) throws Exception { + private static List suite(String name, String file) throws Exception { BufferedReader in = createReader(file); - ArrayList testCases = createTests(in); + List testCases = createTests(name, in); in.close(); - return createSuite(testCases, name); - } - - private static TestSuite createSuite(ArrayList testCases, String name) { - TestSuite suite = new TestSuite(name); - for (RewriteBaseTest subject : testCases) { - suite.addTest(subject); - } - return suite; + return testCases; } - protected static boolean lineMatchesBeginOfTest(String line) { + private static boolean lineMatchesBeginOfTest(String line) { return createMatcherFromString(testRegexp, line).find(); } - protected static boolean lineMatchesCodeType(String line) { + private static boolean lineMatchesCodeType(String line) { return createMatcherFromString(codeTypeRegexp, line).find(); } - protected static Matcher createMatcherFromString(String pattern, String line) { + private static Matcher createMatcherFromString(String pattern, String line) { return Pattern.compile(pattern).matcher(line); } - protected static String getNameOfTest(String line) { + private static String getNameOfTest(String line) { Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line); if (matcherBeginOfTest.find()) { return matcherBeginOfTest.group(1); @@ -127,21 +120,21 @@ protected static String getNameOfTest(String line) { } } - protected static boolean lineMatchesBeginOfResult(String line) { + private static boolean lineMatchesBeginOfResult(String line) { return createMatcherFromString(resultRegexp, line).find(); } - private static ArrayList createTests(BufferedReader inputReader) throws Exception { + private static List createTests(String name, BufferedReader inputReader) throws Exception { ASTWriterTestSourceFile file = null; MatcherState matcherState = MatcherState.skip; - ArrayList testCases = new ArrayList<>(); + ArrayList testCases = new ArrayList<>(); String line; while ((line = inputReader.readLine()) != null) { if (lineMatchesBeginOfTest(line)) { matcherState = MatcherState.inTest; file = new ASTWriterTestSourceFile("ASTWritterTest.h"); //$NON-NLS-1$ - testCases.add(createTestClass(getNameOfTest(line), file)); + testCases.add(Arguments.argumentSet(name + "." + getNameOfTest(line), file)); continue; } else if (lineMatchesBeginOfResult(line)) { matcherState = MatcherState.inExpectedResult; @@ -173,7 +166,7 @@ private static ArrayList createTests(BufferedReader inputReader return testCases; } - protected static ScannerKind getScannerKind(String line) { + private static ScannerKind getScannerKind(String line) { Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line); if (matcherBeginOfTest.find()) { String codeType = matcherBeginOfTest.group(1); @@ -189,7 +182,7 @@ protected static ScannerKind getScannerKind(String line) { return ScannerKind.STD; } - protected static ParserLanguage getParserLanguage(String line) { + private static ParserLanguage getParserLanguage(String line) { Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line); if (matcherBeginOfTest.find()) { String codeType = matcherBeginOfTest.group(1); @@ -203,17 +196,4 @@ protected static ParserLanguage getParserLanguage(String line) { } return ParserLanguage.C; } - - private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file) throws Exception { - ASTWriterTester test = new ASTWriterTester(testName, file) { - // ASTWriterTester is an abstract class so it doesn't - // look like a test, make it a concrete class here - }; - TextSelection sel = file.getSelection(); - if (sel != null) { - test.setFileWithSelection(file.getName()); - test.setSelection(sel); - } - return test; - } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/AppendTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/AppendTests.java index 302de275be7..a43e35d0800 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/AppendTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/AppendTests.java @@ -53,18 +53,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore; - -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; public class AppendTests extends ChangeGeneratorTest { - public static TestSuite suite() { - return new TestSuite(AppendTests.class); - } - //int *pi[5]; //int *pi[5][3]; + @Test public void testArrayModifier() throws Exception { compareResult(new ASTVisitor() { { @@ -87,6 +83,7 @@ public int visit(IASTDeclarator declarator) { //int *values = new int[6]; //int *values = new int[6][5]; + @Test public void testArraySizeExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -119,6 +116,7 @@ public int visit(IASTExpression expression) { // beta(b), alpha(a) { //} // + @Test public void testCtorChainInitializer() throws Exception { compareResult(new ASTVisitor() { { @@ -147,6 +145,7 @@ public int visit(IASTDeclaration decl) { //void foo(int parameter) throw (int) { //} + @Test public void testException() throws Exception { compareResult(new ASTVisitor() { { @@ -177,6 +176,7 @@ public int visit(IASTDeclarator declarator) { // int s = 0, c = 0, h = 0; // s = 3, h = 5, c = 9; //} + @Test public void testExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -207,6 +207,7 @@ public int visit(IASTExpression expression) { // } else if (cond2) { // } //} + @Test public void testNestedElseifStatement() throws Exception { compareResult(new ASTVisitor() { { @@ -237,6 +238,7 @@ public int visit(IASTStatement statement) { //void foo(int existing, int newParameter) { //} + @Test public void testParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -266,6 +268,7 @@ public int visit(IASTDeclarator declarator) { //void foo(int newParameter) { //} + @Test public void testParameterToList() throws Exception { compareResult(new ASTVisitor() { { @@ -294,6 +297,7 @@ public int visit(IASTDeclarator declarator) { //void foo(int *parameter) { //} + @Test public void testPointerToParamter() throws Exception { compareResult(new ASTVisitor() { { @@ -325,6 +329,7 @@ public int visit(IASTDeclarator declarator) { //void foo(int **parameter) { //} + @Test public void testPointerToPointerParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -373,6 +378,7 @@ public int visit(IASTDeclarator declarator) { // int help(); // int exp(int i); //}; + @Test public void testAddDeclarationBugTest() throws Exception { compareResult(new ASTVisitor() { { @@ -417,6 +423,7 @@ public int visit(IASTDeclSpecifier declSpec) { // int j; // } //} + @Test public void testMultilineWhitespaceHandling() throws Exception { compareResult(new ASTVisitor() { { @@ -459,6 +466,7 @@ private void addIntDeclaration(final ASTModificationStore modStore, IASTStatemen // for (int i = 0; i < 10; i++) { // } //} + @Test public void testAppendNull() throws Exception { compareResult(new ASTVisitor() { { @@ -491,6 +499,7 @@ public int visit(IASTStatement statement) { // } //} // + @Test public void testSelfInsertion() throws Exception { compareResult(new ASTVisitor() { { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java index e8e5dc7089a..60ad08d8e33 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java @@ -17,6 +17,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; @@ -45,31 +47,23 @@ import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.CompositeChange; import org.eclipse.ltk.core.refactoring.TextFileChange; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; public abstract class ChangeGeneratorTest extends BaseTestFramework { protected ASTModificationStore modStore; protected final ICPPNodeFactory factory = CPPNodeFactory.getDefault(); - public ChangeGeneratorTest() { - super(); - } - - public ChangeGeneratorTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { + @BeforeEach + protected void setUpModStore() throws Exception { modStore = new ASTModificationStore(); CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor()); - super.setUp(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void tearDownLocal() throws Exception { System.gc(); fileManager.closeAllFiles(); - super.tearDown(); } protected StringBuilder[] getTestSource(int sections) throws IOException { @@ -110,7 +104,7 @@ private void compareResult(ASTVisitor visitor, String source, String expected, b if (shouldValidateAST) { ProblemNodeChecker validator = new ProblemNodeChecker(); unit.accept(validator); - assertFalse("Problem nodes found, AST is invalid.", validator.problemsFound()); + assertFalse(validator.problemsFound(), "Problem nodes found, AST is invalid."); } final ChangeGenerator changeGenerator = new ChangeGenerator(modStore, ASTCommenter.getCommentedNodeMap(unit)); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/InsertBeforeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/InsertBeforeTests.java index 64b5f9d887d..4ae1b1aa8e8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/InsertBeforeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/InsertBeforeTests.java @@ -50,18 +50,14 @@ import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ContainerNode; - -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; public class InsertBeforeTests extends ChangeGeneratorTest { - public static TestSuite suite() { - return new TestSuite(InsertBeforeTests.class); - } - //int *pi[3]; //int *pi[5][3]; + @Test public void testArrayModifier() throws Exception { compareResult(new ASTVisitor() { { @@ -87,6 +83,7 @@ public int visit(IASTDeclarator declarator) { //int *values = new int[5]; //int *values = new int[6][5]; + @Test public void testArraySizeExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -116,6 +113,7 @@ public int visit(IASTExpression expression) { //TestClass::TestClass(int a, int b) : // alpha(a), beta(b) { //} + @Test public void testCtorChainInitializer() throws Exception { compareResult(new ASTVisitor() { { @@ -147,6 +145,7 @@ public int visit(IASTDeclaration declaration) { //void foo(int parameter) throw (int, /*Test*/float) /*Test2*/{ //} + @Test public void testException() throws Exception { compareResult(new ASTVisitor() { { @@ -180,6 +179,7 @@ public int visit(IASTDeclarator declarator) { // int s = 0, c = 0, h = 0; // s = 3, c = 9, h = 5; //} + @Test public void testExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -209,6 +209,7 @@ public int visit(IASTExpression expression) { //void foo(int newParameter, int a) { //} + @Test public void testFirstParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -250,6 +251,7 @@ public int visit(IASTDeclarator declarator) { // s2; // int j; //} + @Test public void testInsertMultipleStatements() throws Exception { compareResult(new ASTVisitor() { { @@ -289,6 +291,7 @@ private IASTNode createStatement(String name) { // int j; // int j; //} + @Test public void testInsertStatement() throws Exception { compareResult(new ASTVisitor() { { @@ -314,6 +317,7 @@ public int visit(IASTStatement statement) { //void foo(int **parameter) { //} + @Test public void testPointerParameter() throws Exception { compareResult(new ASTVisitor() { { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/RemoveTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/RemoveTests.java index 0d638ca2531..02ba7ce79b0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/RemoveTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/RemoveTests.java @@ -38,18 +38,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression; - -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; public class RemoveTests extends ChangeGeneratorTest { - public static TestSuite suite() { - return new TestSuite(RemoveTests.class); - } - //int *pi[3]; //int *pi; + @Test public void testArrayModifier() throws Exception { compareResult(new ASTVisitor() { { @@ -72,6 +68,7 @@ public int visit(IASTDeclarator declarator) { //int *values = new int[5][6]; //int *values = new int[5]; + @Test public void testArraySizeExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -98,6 +95,7 @@ public int visit(IASTExpression expression) { //TestClass::TestClass(int a) { //} + @Test public void testCtorChainInitializer() throws Exception { compareResult(new ASTVisitor() { { @@ -142,6 +140,7 @@ public int visit(IASTDeclaration declaration) { //}; // //#endif /*A_H_*/ + @Test public void testDeclaration() throws Exception { compareResult(new ASTVisitor() { { @@ -170,6 +169,7 @@ public int visit(IASTDeclaration declaration) { //void foo(int parameter) throw () { //} + @Test public void testException() throws Exception { compareResult(new ASTVisitor() { { @@ -200,6 +200,7 @@ public int visit(IASTDeclarator declarator) { // int s = 0, c = 0, h = 0; // s = 3, h = 5; //} + @Test public void testExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -224,6 +225,7 @@ public int visit(IASTExpression expression) { //void foo(int b, int c) { //} + @Test public void testFirstParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -253,6 +255,7 @@ public int visit(IASTDeclarator declarator) { //void foo(int a, int b) { //} + @Test public void testLastParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -282,6 +285,7 @@ public int visit(IASTDeclarator declarator) { //void foo(int a, int c) { //} + @Test public void testMiddleParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -309,6 +313,7 @@ public int visit(IASTDeclarator declarator) { //int *value = new int(5); //int *value = new int(); + @Test public void testNewInitializerExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -334,6 +339,7 @@ public int visit(IASTExpression expression) { //void foo(int parameter) { //} + @Test public void testPointerInParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -364,6 +370,7 @@ public int visit(IASTDeclarator declarator) { //void foo() { //} + @Test public void testSingleParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -400,6 +407,7 @@ public int visit(IASTDeclarator declarator) { //{ // int i = 0; //} + @Test public void testStatement() throws Exception { compareResult(new ASTVisitor() { { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ReplaceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ReplaceTests.java index 2cb6deaaf6c..672fabf8d25 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ReplaceTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ReplaceTests.java @@ -74,15 +74,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind; - -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; public class ReplaceTests extends ChangeGeneratorTest { - public static TestSuite suite() { - return new TestSuite(ReplaceTests.class); - } - private IASTAttribute createAttribute(String name) { return factory.newAttribute(name.toCharArray(), null); } @@ -122,6 +117,7 @@ private void addAttributeListModification(IASTAttributeOwner owner, String attri //int *pi[3]; //int *pi[15]; + @Test public void testArrayModifier() throws Exception { compareResult(new ASTVisitor() { { @@ -146,6 +142,7 @@ public int visit(IASTDeclarator declarator) { //int *values = new int[5][6]; //int *values = new int[5][7]; + @Test public void testArraySizeExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -175,6 +172,7 @@ public int visit(IASTExpression expression) { //TestClass::TestClass(int a) : // alpha(a) { //} + @Test public void testCtorChainInitializer() throws Exception { compareResult(new ASTVisitor() { { @@ -209,6 +207,7 @@ public int visit(IASTDeclaration declaration) { //void foo(int parameter) throw (int) { //} + @Test public void testExceptionTest() throws Exception { compareResult(new ASTVisitor() { { @@ -243,6 +242,7 @@ public int visit(IASTDeclarator declarator) { // int s = 0, c = 0, h = 0; // s = 3, c = 9, h = 5; //} + @Test public void testExpressionTest() throws Exception { compareResult(new ASTVisitor() { { @@ -292,6 +292,7 @@ public int visit(IASTExpression expression) { //#endif /*A_H_*/ // // + @Test public void testIdentical() throws Exception { compareResult(new ASTVisitor() { { @@ -310,6 +311,7 @@ public int visit(IASTDeclarator declarator) { //int hs = 5; //int hs = 999; + @Test public void testInitializer() throws Exception { compareResult(new ASTVisitor() { { @@ -352,6 +354,7 @@ public int visit(IASTDeclarator declarator) { //}; // //#endif /*A_H_*/ + @Test public void testMoveRename() throws Exception { compareResult(new ASTVisitor() { { @@ -400,6 +403,7 @@ public int visit(IASTDeclSpecifier declSpec) { //#endif /*A_H_*/ // // + @Test public void testMove() throws Exception { compareResult(new ASTVisitor() { { @@ -444,6 +448,7 @@ public int visit(IASTDeclSpecifier declSpec) { //#endif /*A_H_*/ // // + @Test public void testName() throws Exception { compareResult(new ASTVisitor() { { @@ -467,6 +472,7 @@ public int visit(IASTDeclarator declarator) { //void foo(int x) { // x++; //} + @Test public void testNestedReplace() throws Exception { compareResult(new ASTVisitor() { { @@ -506,6 +512,7 @@ public int visit(IASTStatement statement) { //int *value = new int(5); //int *value = new int(6); + @Test public void testNewInitializerExpression() throws Exception { compareResult(new ASTVisitor() { { @@ -531,6 +538,7 @@ public int visit(IASTExpression expression) { //void foo(int *parameter) { //} + @Test public void testPointerInParameter() throws Exception { compareResult(new ASTVisitor() { { @@ -580,6 +588,7 @@ public int visit(IASTDeclarator declarator) { // } // //} + @Test public void testReplaceForLoopBody() throws Exception { compareResult(new ASTVisitor() { { @@ -610,6 +619,7 @@ public int visit(IASTStatement statement) { // i = 42; // i++; //} + @Test public void testReplaceInsertStatement() throws Exception { compareResult(new ASTVisitor() { { @@ -647,6 +657,7 @@ public int visit(IASTStatement statement) { //void bar() { //} + @Test public void testReplaceReplacedNode() throws Exception { compareResult(new ASTVisitor() { { @@ -691,6 +702,7 @@ public int visit(IASTName name) { //#endif /*A_H_*/ // // + @Test public void testSameName() throws Exception { compareResult(new ASTVisitor() { { @@ -721,6 +733,7 @@ public int visit(IASTDeclarator declarator) { // i++; // } //} + @Test public void testStatement() throws Exception { compareResult(new ASTVisitor() { { @@ -770,6 +783,7 @@ public int visit(IASTStatement statement) { // } // //} + @Test public void testWhitespaceHandling() throws Exception { compareResult(new ASTVisitor() { { @@ -811,6 +825,7 @@ public int visit(IASTStatement statement) { // int two = 2; // } //} + @Test public void testNestedReplacementInIfStatementWithMacroInSibling_474020() throws Exception { compareResult(new ASTVisitor() { private ASTModification parentModification; @@ -861,6 +876,7 @@ public int visit(IASTName name) { // int two = 2; // } //} + @Test public void testNestedReplacementInIfStatementWithMacroInCondition_474020() throws Exception { compareResult(new ASTVisitor() { private ASTModification parentModification; @@ -911,6 +927,7 @@ public int visit(IASTName name) { // int two = 2; // } //} + @Test public void testNestedReplacementInIfStatementWithMacroAsFirstPartOfCondition_474020() throws Exception { compareResult(new ASTVisitor() { private ASTModification parentModification; @@ -961,6 +978,7 @@ public int visit(IASTName name) { // int two = 2; // } //} + @Test public void testNestedReplacementInIfStatementWithMacroAsInnerPartOfCondition_474020() throws Exception { compareResult(new ASTVisitor() { private ASTModification parentModification; @@ -1011,6 +1029,7 @@ public int visit(IASTName name) { // int two = 2; // } //} + @Test public void testNestedReplacementInIfStatementWithMacroAsLastPartOfCondition_474020() throws Exception { compareResult(new ASTVisitor() { private ASTModification parentModification; @@ -1067,6 +1086,7 @@ public int visit(IASTName name) { // void func3() override final; // void func4() final override; //}; + @Test public void testReplaceFunctionDeclaratorWithVirtualSpecifier_Bug518628() throws Exception { compareResult(new ASTVisitor() { { @@ -1090,6 +1110,7 @@ public int visit(IASTDeclarator declarator) { //{ // virtual void foo() throw (int) = 0; //}; + @Test public void testPureVirtualFunction() throws Exception { compareResult(new ASTVisitor() { { @@ -1110,26 +1131,31 @@ public int visit(IASTDeclarator declarator) { } //[[foo]] int hs = 5; + @Test public void testCopyReplaceAttribute_Bug533552_1a() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, IASTDeclaration.class::isInstance)); } //[[foo, bar]][[foobar]] int hs = 5; + @Test public void testCopyReplaceAttribute_Bug533552_1b() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, IASTDeclaration.class::isInstance)); } //[[foo, bar]][[foobar]] int [[asdf]] hs = 5; + @Test public void testCopyReplaceAttribute_Bug533552_1c() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, IASTDeclaration.class::isInstance)); } //using I [[attribute]] = int; + @Test public void testCopyReplaceAliasDeclarationWithAttributes_Bug533552_1d() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, ICPPASTAliasDeclaration.class::isInstance)); } //int i [[attribute]]; + @Test public void testCopyReplaceDeclaratorWithAttributes_Bug533552_1e() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, IASTDeclarator.class::isInstance)); } @@ -1137,6 +1163,7 @@ public void testCopyReplaceDeclaratorWithAttributes_Bug533552_1e() throws Except //[[foo]] int hs = 5; //[[foo, bar]] int hs = 5; + @Test public void testAddAttribute_Bug533552_2a() throws Exception { compareResult(new ASTVisitor() { { @@ -1157,6 +1184,7 @@ public int visit(IASTDeclaration declaration) { //[[foo]] int hs = 5; //[[foo]][[bar]] int hs = 5; + @Test public void testAddAttribute_Bug533552_2b() throws Exception { compareResult(new ASTVisitor() { { @@ -1182,6 +1210,7 @@ public int visit(IASTDeclaration declaration) { // break; // } //} + @Test public void testCopyReplaceAttribute_Bug535265_1() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, IASTSwitchStatement.class::isInstance)); } @@ -1195,6 +1224,7 @@ public void testCopyReplaceAttribute_Bug535265_1() throws Exception { // [[foo]][[bar]] switch (true) { // } //} + @Test public void testCopyReplaceAttributeOnSwitchStatement_Bug535263_1() throws Exception { compareResult(new ASTVisitor() { { @@ -1221,6 +1251,7 @@ public int visit(IASTStatement statement) { // [[foo]] switch (true) [[bar]][[foobar]] { // } //} + @Test public void testCopyReplaceAttributeOnSwitchCompoundStatement_Bug535263_2() throws Exception { compareResult(new ASTVisitor() { { @@ -1241,12 +1272,14 @@ public int visit(IASTStatement statement) { //void f([[attr1]] int p1, int [[attr2]] p2, [[attr3]] int p3) { //} + @Test public void testCopyReplaceAttribute_Bug535275() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, ICPPASTFunctionDeclarator.class::isInstance)); } //enum [[foo]] X : int [[bar]] { //}; + @Test public void testEnumReplacementRetainsAttributes_Bug535256_1() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, ICPPASTEnumerationSpecifier.class::isInstance)); } @@ -1255,6 +1288,7 @@ public void testEnumReplacementRetainsAttributes_Bug535256_1() throws Exception //}; //enum struct ES { //}; + @Test public void testScopedEnumReplacementRetains_Bug535256_2() throws Exception { compareCopyResult(new CopyReplaceVisitor(this, ICPPASTEnumerationSpecifier.class::isInstance)); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java index 183b40c156e..5ff5a871116 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingTest.java @@ -14,6 +14,9 @@ ******************************************************************************/ package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.Comparator; import java.util.List; import java.util.Map; @@ -30,14 +33,17 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.tests.rewrite.RewriteBaseTest; import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTester; +import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper; import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.ASTCommenter; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.eclipse.jface.text.TextSelection; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * This test tests the behavior of the class ASTCommenter. It checks if the ASTCommenter assigns @@ -81,6 +87,7 @@ * @author Guido Zgraggen IFS, Lukas Felber IFS */ public class CommentHandlingTest extends RewriteBaseTest { + private static final String ANY_CHAR_REGEXP = "(.*)"; //$NON-NLS-1$ private static final String SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$ @@ -92,26 +99,44 @@ public class CommentHandlingTest extends RewriteBaseTest { private static final String TRAILING_COMMENT_TITLE = "<<<=== Trailing Comment Test Section ===>>>"; //$NON-NLS-1$ private static final String FREESTANDING_COMMENT_TITLE = "<<<=== Freestanding Comment Test Section ===>>>"; //$NON-NLS-1$ - public CommentHandlingTest(String name, List files) { - super(name, files); + public static List loadTests() throws Exception { + return RewriteTester.loadTests(CommentHandlingTest.class, "resources/rewrite/CommentHandlingTestSource.rts"); } - public static Test suite() throws Exception { - TestSuite suite = new TestSuite(CommentHandlingTest.class.getName()); - suite.addTest(RewriteTester.suite("CommentTests", "resources/rewrite/CommentHandlingTestSource.rts")); //$NON-NLS-1$ - return suite; + @ParameterizedTest + @MethodSource("loadTests") + protected void test(List testFiles) throws Throwable { + loadFiles(testFiles); + runTest(testFiles); } - @Override - protected void runTest() throws Throwable { - if (fileMap.isEmpty()) { - fail("No file for testing"); //$NON-NLS-1$ + protected void loadFiles(List testFiles) throws Exception { + for (TestSourceFile testFile : testFiles) { + if (testFile.getSource().length() > 0) { + importFile(testFile.getName(), testFile.getSource()); + } + TextSelection sel = testFile.getSelection(); + if (sel != null) { + setFileWithSelection(testFile.getName()); + setSelection(sel); + break; + } } + } + + protected void runTest(List testFiles) throws Exception { + for (TestSourceFile testFile : testFiles) { + NodeCommentMap nodeMap = getNodeMapForFile(testFile.getName()); + assertEquals(buildExpectedResult(testFile).toString(), buildActualResult(nodeMap).toString()); + } + } - for (String fileName : fileMap.keySet()) { - TestSourceFile file = fileMap.get(fileName); - NodeCommentMap nodeMap = getNodeMapForFile(fileName); - assertEquals(buildExpectedResult(file).toString(), buildActualResult(nodeMap).toString()); + private void compareFiles(Map testResourceFiles) throws Exception { + for (String fileName : testResourceFiles.keySet()) { + TestSourceFile file = testResourceFiles.get(fileName); + IFile iFile = project.getFile(new Path(fileName)); + StringBuilder code = getCodeFromFile(iFile); + assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString())); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingWithRewriteTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingWithRewriteTest.java index 9d008a452fe..eac5406b6e8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingWithRewriteTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/comenthandler/CommentHandlingWithRewriteTest.java @@ -24,26 +24,23 @@ import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.text.edits.TextEditGroup; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; public class CommentHandlingWithRewriteTest extends CommentHandlingTest { private ASTRewrite newRewrite; - public CommentHandlingWithRewriteTest(String name, List files) { - super(name, files); - } - - public static Test suite() throws Exception { - TestSuite suite = new TestSuite(CommentHandlingWithRewriteTest.class.getName()); - suite.addTest( - RewriteTester.suite("CommentMultiFileTests", "resources/rewrite/CommentHandlingWithRewriteTest.rts")); //$NON-NLS-1$ - return suite; + public static List loadTestsWithRewrite() throws Exception { + return RewriteTester.loadTests(CommentHandlingWithRewriteTest.class, + "resources/rewrite/CommentHandlingWithRewriteTest.rts"); } @Override - protected void runTest() throws Throwable { + @ParameterizedTest + @MethodSource("loadTestsWithRewrite") + protected void test(List testFiles) throws Throwable { + loadFiles(testFiles); IASTTranslationUnit tu = getUnit("main.cpp"); IASTTranslationUnit otherTu = getUnit("other.cpp"); @@ -53,7 +50,7 @@ protected void runTest() throws Throwable { ASTRewrite rewrite = ASTRewrite.create(tu); newRewrite = rewrite.insertBefore(fooBody, iNode, jNode, new TextEditGroup("test group")); - super.runTest(); + runTest(testFiles); } @Override diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java index e452b161def..fa6c200698e 100644 --- a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java +++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java @@ -18,6 +18,8 @@ */ package org.eclipse.cdt.core.tests; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -25,7 +27,6 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -34,11 +35,13 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; /** * @author aniefer */ -abstract public class BaseTestFramework extends BaseTestCase { +abstract public class BaseTestFramework extends BaseTestCase5 { protected NullProgressMonitor monitor; protected IWorkspace workspace; protected IProject project; @@ -46,20 +49,8 @@ abstract public class BaseTestFramework extends BaseTestCase { protected FileManager fileManager; protected boolean indexDisabled = false; - public BaseTestFramework() { - super(); - } - - /** - * @param name - */ - public BaseTestFramework(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void createProjectBefore() throws Exception { monitor = new NullProgressMonitor(); workspace = ResourcesPlugin.getWorkspace(); cproject = CProjectHelper.createCCProject("RegressionTestProject", "bin", IPDOMManager.ID_NO_INDEXER); //$NON-NLS-1$ //$NON-NLS-2$ @@ -70,14 +61,13 @@ protected void setUp() throws Exception { fileManager = new FileManager(); } - @Override - protected void tearDown() throws Exception { + @AfterEach + protected void cleanUpProjectAfter() throws Exception { if (project == null || !project.exists()) return; project.delete(true, true, monitor); BaseTestCase5.assertWorkspaceIsEmpty(); - super.tearDown(); } protected IFile importFile(String fileName, String contents) throws Exception { diff --git a/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF index 66a39ede36c..a16b410f322 100644 --- a/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF @@ -44,4 +44,5 @@ Bundle-ActivationPolicy: lazy Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.cdt.ui.tests -Import-Package: org.junit.jupiter.api;version="5.9.0" +Import-Package: org.junit.jupiter.api;version="5.9.0", + org.opentest4j;version="[1.3.0,2.0.0)" diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java index f6d51d3d3ab..4528952d18b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java @@ -13,6 +13,12 @@ ******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.rename; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.StringWriter; import org.eclipse.cdt.core.CCorePlugin; @@ -31,6 +37,8 @@ import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.TextEdit; import org.eclipse.text.edits.TextEditGroup; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; /** * @author markus.schorn@windriver.com @@ -38,24 +46,15 @@ public abstract class RefactoringTests extends BaseTestFramework { private int fBufferSize; - public RefactoringTests() { - } - - public RefactoringTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @BeforeEach + protected void setUpProject() throws Exception { CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); fBufferSize = FileCharSequenceProvider.BUFFER_SIZE; FileCharSequenceProvider.BUFFER_SIZE = 1024 * 4; } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + protected void tearDownFlush() throws Exception { SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush(); FileCharSequenceProvider.BUFFER_SIZE = fBufferSize; } @@ -70,8 +69,8 @@ protected void assertTotalChanges(int numChanges, int potChanges, int commentCh, countChanges(changes, count); } assertEquals(numChanges, count[0]); - assertEquals("potential changes: ", potChanges, count[1]); - assertEquals("comment changes: ", commentCh, count[2]); + assertEquals((long) potChanges, (long) count[1], "potential changes: "); + assertEquals((long) commentCh, (long) count[2], "comment changes: "); } private void countChanges(Change change, int[] count) { @@ -156,7 +155,7 @@ private boolean checkTranslationUnitChange(TextFileChange change, int startOffse private boolean checkTextEdit(TextEdit edit, int startOffset, int numChars, String newText) { if (edit instanceof MultiTextEdit) { - if (checkTextEdits(((MultiTextEdit) edit).getChildren(), startOffset, numChars, newText)) { + if (checkTextEdits(edit.getChildren(), startOffset, numChars, newText)) { return true; } } else if (edit instanceof ReplaceEdit) { @@ -255,18 +254,18 @@ protected IFile createCDefs(String fileName) throws Exception { protected void assertRefactoringError(RefactoringStatus status, String msg) { RefactoringStatusEntry e = status.getEntryMatchingSeverity(RefactoringStatus.ERROR); - assertNotNull("Expected refactoring error!", e); + assertNotNull(e, "Expected refactoring error!"); assertEquals(msg, e.getMessage()); } protected void assertRefactoringWarning(RefactoringStatus status, String msg) { RefactoringStatusEntry e = status.getEntryMatchingSeverity(RefactoringStatus.WARNING); - assertNotNull("Expected refactoring warning!", e); + assertNotNull(e, "Expected refactoring warning!"); assertEquals(msg, e.getMessage()); } protected void assertRefactoringOk(RefactoringStatus status) { - assertTrue("Expected refactoring status ok: " + status.getMessageMatchingSeverity(status.getSeverity()), - status.getSeverity() == RefactoringStatus.OK); + assertTrue(status.getSeverity() == RefactoringStatus.OK, + "Expected refactoring status ok: " + status.getMessageMatchingSeverity(status.getSeverity())); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java index 702387fedf8..8142b8c49d0 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java @@ -18,20 +18,11 @@ import org.eclipse.core.resources.IFile; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; public class RenameFunctionTests extends RenameTestBase { - public RenameFunctionTests(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(RenameFunctionTests.class); - } - + @Test public void testFunctionNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -309,6 +300,7 @@ public void testFunctionNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testFunctionsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -333,6 +325,7 @@ public void testFunctionsPlainC() throws Exception { assertTotalChanges(2, change); } + @Test public void testFunctionNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -417,6 +410,7 @@ public void testFunctionNameConflictsPlainC() throws Exception { assertRefactoringOk(status); } + @Test public void testMethodNameConflicts1() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -514,6 +508,7 @@ public void testMethodNameConflicts1() throws Exception { + "New element: static_method \n" + "Conflicting element type: Method"); } + @Test public void testMethodNameConflicts2() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -696,6 +691,7 @@ public void testMethodNameConflicts2() throws Exception { assertRefactoringOk(status); } + @Test public void testBug72605() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo { \n"); @@ -713,6 +709,7 @@ public void testBug72605() throws Exception { assertTotalChanges(2, changes); } + @Test public void testBug72732() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo { \n"); @@ -729,6 +726,7 @@ public void testBug72732() throws Exception { assertTotalChanges(2, changes); } + @Test public void testBug330123() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java index 2b7a5a79b2d..88a72c1d6c0 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java @@ -17,20 +17,11 @@ import org.eclipse.core.resources.IFile; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; public class RenameMacroTests extends RenameTestBase { - public RenameMacroTests(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(RenameMacroTests.class); - } - + @Test public void testMacroRename() throws Exception { StringBuilder buf = new StringBuilder(); buf.append("#define HALLO x \n"); @@ -91,6 +82,7 @@ public void testMacroRename() throws Exception { off = contents.indexOf("HALLO", off + 1); } + @Test public void testMacroNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -142,6 +134,7 @@ public void testMacroNameConflicts() throws Exception { + "New element: enum_item \n" + "Conflicting element type: Enumerator"); } + @Test public void testClassMacroClash() throws Exception { StringBuilder buf = new StringBuilder(); buf.append("class CC {int a;}; \n"); @@ -163,6 +156,7 @@ public void testClassMacroClash() throws Exception { assertTotalChanges(2, ch); } + @Test public void testMacroRename_434917() throws Exception { StringBuilder buf = new StringBuilder(); buf.append("#define CC mm\n"); @@ -180,6 +174,7 @@ public void testMacroRename_434917() throws Exception { assertTotalChanges(2, ch); } + @Test public void testIncludeGuard() throws Exception { StringBuilder buf = new StringBuilder(); buf.append("#ifndef _guard \n"); @@ -199,6 +194,7 @@ public void testIncludeGuard() throws Exception { assertChange(ch, cpp, off, 6, "WELT"); } + @Test public void testMacroParameters() throws Exception { StringBuilder buf = new StringBuilder(); buf.append("int var; \n"); @@ -213,6 +209,7 @@ public void testMacroParameters() throws Exception { assertTotalChanges(1, 1, 0, ch); } + @Test public void testRenameMacroAsMacroArgument() throws Exception { StringBuilder buf = new StringBuilder(); buf.append("#define M1(var) var \n"); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java index 21af7f5d33d..66663f8e84e 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java @@ -14,6 +14,11 @@ *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.rename; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.StringWriter; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -21,23 +26,12 @@ import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.participants.RenameArguments; - -import junit.framework.AssertionFailedError; -import junit.framework.Test; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; public class RenameRegressionTests extends RenameTestBase { - public RenameRegressionTests() { - super(); - } - - public RenameRegressionTests(String name) { - super(name); - } - - public static Test suite() { - return suite(RenameRegressionTests.class, "_"); - } + @Test public void testSimpleRename() throws Exception { StringWriter writer = new StringWriter(); writer.write("int boo; // boo \n"); @@ -57,6 +51,7 @@ public void testSimpleRename() throws Exception { assertChange(changes, file, contents.indexOf("boo++"), 3, "ooga"); } + @Test public void testLocalVar() throws Exception { StringWriter writer = new StringWriter(); writer.write("void f() { \n"); @@ -82,6 +77,7 @@ public void testLocalVar() throws Exception { assertChange(changes, file, offset, 3, "ooga"); } + @Test public void testParameter() throws Exception { StringWriter writer = new StringWriter(); writer.write("void f(int boo) { \n"); @@ -106,6 +102,7 @@ public void testParameter() throws Exception { assertChange(changes, file, offset, 3, "ooga"); } + @Test public void testFileStaticVar() throws Exception { StringWriter writer = new StringWriter(); writer.write("static int boo; \n"); @@ -129,6 +126,7 @@ public void testFileStaticVar() throws Exception { assertChange(changes, file, offset, 3, "ooga"); } + @Test public void testClass_1() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo/*vp1*/{}; \n"); @@ -146,6 +144,7 @@ public void testClass_1() throws Exception { assertChange(changes, file, contents.indexOf("Boo a"), 3, "Ooga"); } + @Test public void testAttribute_2() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo{ \n"); @@ -166,6 +165,7 @@ public void testAttribute_2() throws Exception { assertChange(changes, file, contents.indexOf("att1;//res2"), 4, "ooga"); } + @Test public void testMethod_1() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -190,6 +190,7 @@ public void testMethod_1() throws Exception { assertChange(changes, cpp, source.indexOf("method1(\"hello"), 7, "m1"); } + @Test public void testMethod_3() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo{ \n"); @@ -215,6 +216,7 @@ public void testMethod_3() throws Exception { // However, the UI does display the error in the preview panel. Defect 78769 states // the error should be shown on the first page. The parser passes, but the UI could be // better. + @Test public void testConstructor_27() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo{ \n"); @@ -238,6 +240,7 @@ public void testConstructor_27() throws Exception { fail("An error should have occurred in the input check."); } + @Test public void testDestructor_29_72612() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo{ \n"); @@ -261,6 +264,7 @@ public void testDestructor_29_72612() throws Exception { fail("An error should have occurred in the input check."); } + @Test public void testFunction_31() throws Exception { StringWriter writer = new StringWriter(); writer.write("void foo(){} \n"); @@ -281,6 +285,7 @@ public void testFunction_31() throws Exception { assertChange(changes, file, contents.indexOf("foo(3)"), 3, "ooga"); } + @Test public void testMethod_32_72717() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Base { \n"); @@ -303,6 +308,7 @@ public void testMethod_32_72717() throws Exception { + "Type of problem: Overloading \n" + "New element: foo \n" + "Conflicting element type: Method"); } + @Test public void testMethod_33_72605() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo { \n"); @@ -318,6 +324,7 @@ public void testMethod_33_72605() throws Exception { assertChange(changes, file, contents.indexOf("aMethod(int x)"), 7, "ooga"); } + @Test public void testMethod_33b_72605() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo { \n"); @@ -346,6 +353,7 @@ public void testMethod_33b_72605() throws Exception { assertChange(changes, cppfile, cppoffset, 7, "ooga"); } + @Test public void testMethod_34() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Base{ \n"); @@ -393,6 +401,7 @@ public void _testMethod_35_72726() throws Exception { } + @Test public void testMethod_39() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -431,6 +440,7 @@ public void testMethod_39() throws Exception { assertChange(changes, cpp, source.indexOf("method2(3"), 7, "m2"); } + @Test public void testMethod_40() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -468,6 +478,7 @@ public void testMethod_40() throws Exception { assertChange(changes, cpp, source.indexOf("method2(3"), 7, "m2"); } + @Test public void testMethod_41() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -499,6 +510,7 @@ public void testMethod_41() throws Exception { assertChange(changes, cpp, source.indexOf("method1(1"), 7, "m1"); } + @Test public void testMethod_43() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -528,6 +540,7 @@ public void testMethod_43() throws Exception { assertChange(changes, cpp, source.indexOf("method1(1"), 7, "m1"); } + @Test public void testMethod_44() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Base{ \n"); @@ -553,6 +566,7 @@ public void testMethod_44() throws Exception { assertChange(changes, file, contents.indexOf("v(){i++;}"), 1, "v1"); } + @Test public void testMethod_45() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Base{ \n"); @@ -579,6 +593,7 @@ public void testMethod_45() throws Exception { assertChange(changes, file, contents.indexOf("v(){i"), 1, "v1"); } + @Test public void testStruct_46() throws Exception { StringWriter writer = new StringWriter(); writer.write("struct st1/*vp1*/{}; \n"); @@ -618,6 +633,7 @@ public void testStruct_46() throws Exception { assertChange(changes, file, contents.indexOf("st3 ss"), 3, "Ooga3"); } + @Test public void testUnion_47() throws Exception { StringWriter writer = new StringWriter(); writer.write("union st1/*vp1*/{}; \n"); @@ -657,6 +673,7 @@ public void testUnion_47() throws Exception { assertChange(changes, file, contents.indexOf("st3 ss"), 3, "Ooga3"); } + @Test public void testEnumeration_48() throws Exception { StringWriter writer = new StringWriter(); writer.write("enum e1/*vp1*/{E0}; \n"); @@ -696,6 +713,7 @@ public void testEnumeration_48() throws Exception { assertChange(changes, file, contents.indexOf("e3 ss"), 2, "Ooga3"); } + @Test public void testTemplate_49_72626() throws Exception { StringWriter writer = new StringWriter(); writer.write("template \n"); @@ -720,6 +738,7 @@ public void testTemplate_49_72626() throws Exception { assertChange(changes, file, offset = contents.indexOf("Array", offset + 1), 5, "Arr2"); } + @Test public void testClass_52() throws Exception { StringWriter writer = new StringWriter(); writer.write("namespace N1 { \n"); @@ -743,6 +762,7 @@ public void testClass_52() throws Exception { assertChange(changes, file, contents.indexOf("Boo c2"), 3, "Ooga"); } + @Test public void testClass_53() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo/*vp1*/ {//ren1 \n"); @@ -774,6 +794,7 @@ public void testClass_53() throws Exception { assertChange(changes, file, contents.indexOf("Foo();//ren10"), 3, "Ooga"); } + @Test public void testAttribute_54() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo{ \n"); @@ -796,6 +817,7 @@ public void testAttribute_54() throws Exception { assertChange(changes, file, contents.indexOf("att;//rn3"), 3, "ooga"); } + @Test public void testClass_55() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -821,6 +843,7 @@ public void testClass_55() throws Exception { assertChange(changes, file, contents.indexOf("Hoo(){}"), 3, "ooga"); } + @Test public void testClass_55_79231() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo{};//vp1 \n"); @@ -842,6 +865,7 @@ public void testClass_55_79231() throws Exception { assertChange(changes, file, contents.indexOf("Boo{};//vp1"), 3, "Ooga"); } + @Test public void testClass_55_72748() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{};//vp1 \n"); @@ -862,6 +886,7 @@ public void testClass_55_72748() throws Exception { assertChange(changes, file, contents.indexOf("Foo*>(0)"), 3, "Ooga"); } + @Test public void testClass_56() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{};//vp1,rn1 \n"); @@ -882,6 +907,7 @@ public void testClass_56() throws Exception { assertChange(changes, file, contents.indexOf("Foo(){}//rn3"), 3, "Ooga"); } + @Test public void testAttribute_61() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -903,6 +929,7 @@ public void testAttribute_61() throws Exception { assertChange(changes, cpp, source.indexOf("count"), 5, "ooga"); } + @Test public void testEnumerator_62() throws Exception { StringWriter writer = new StringWriter(); writer.write("enum Foo{E0, E1};//vp1 \n"); @@ -927,6 +954,7 @@ public void testEnumerator_62() throws Exception { assertChange(changes, cpp, source.indexOf("E1"), 2, "ooga"); } + @Test public void testAttribute_63() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -951,6 +979,7 @@ public void testAttribute_63() throws Exception { assertChange(changes, cpp, source.indexOf("att"), 3, "ooga"); } + @Test public void testAttribute_64() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Foo{ \n"); @@ -977,6 +1006,7 @@ public void testAttribute_64() throws Exception { assertChange(changes, h, header.indexOf("b;//rn2"), 1, "ooga"); } + @Test public void testAttribute_65() throws Exception { StringWriter writer = new StringWriter(); writer.write("class A{ \n"); @@ -1005,6 +1035,7 @@ public void testAttribute_65() throws Exception { assertChange(changes, cpp, source.indexOf("att;"), 3, "ooga"); } + @Test public void testNamespace_66() throws Exception { StringWriter writer = new StringWriter(); writer.write("namespace Foo/*vp1*/{ \n"); @@ -1033,6 +1064,7 @@ public void testNamespace_66() throws Exception { assertChange(changes, file, contents.indexOf("Baz;"), 3, "Wooga"); } + @Test public void testNamespace_66_79281() throws Exception { StringWriter writer = new StringWriter(); writer.write("namespace Foo{ \n"); @@ -1052,6 +1084,7 @@ public void testNamespace_66_79281() throws Exception { assertChange(changes, file, contents.indexOf("Bar::"), 3, "Ooga"); } + @Test public void testNamespace_66_79282() throws Exception { StringWriter writer = new StringWriter(); writer.write("namespace Foo/*vp1*/{} \n"); @@ -1067,6 +1100,7 @@ public void testNamespace_66_79282() throws Exception { assertChange(changes, file, contents.indexOf("Foo;"), 3, "Ooga"); } + @Test public void testFunction_67() throws Exception { StringWriter writer = new StringWriter(); writer.write("void foo/*vp1*/(){}//rn1 \n"); @@ -1089,6 +1123,7 @@ public void testFunction_67() throws Exception { assertChange(changes, file, contents.indexOf("foo();}//rn3"), 3, "ooga"); } + @Test public void testVariable_68() throws Exception { StringWriter writer = new StringWriter(); writer.write("class A{ \n"); @@ -1114,6 +1149,7 @@ public void testVariable_68() throws Exception { assertChange(changes, file, contents.indexOf("var.i=3;//rn3"), 3, "ooga"); } + @Test public void testVariable_68_79295() throws Exception { StringWriter writer = new StringWriter(); writer.write("int var;//vp1 \n"); @@ -1132,6 +1168,7 @@ public void testVariable_68_79295() throws Exception { // similar to test 92, except this one will continue with warning, or error status // while case in 92 must stop refactor with fatal status + @Test public void testClass_81_72620() throws Exception { StringWriter writer = new StringWriter(); writer.write("union u_haul{}; \n"); @@ -1148,6 +1185,7 @@ public void testClass_81_72620() throws Exception { fail("An error should have occurred in the input check."); } + @Test public void testVariable_88_72617() throws Exception { StringWriter writer = new StringWriter(); writer.write("class A{}; \n"); @@ -1172,6 +1210,7 @@ public void testVariable_88_72617() throws Exception { // if you don't know the error message, catch on getRefactorChanges // or if you want to verify a message or severity, use getRefactorMessages // and getRefactorSeverity + @Test public void testClass_92A() throws Exception { StringWriter writer = new StringWriter(); writer.write("class Boo{}; \n"); @@ -1191,6 +1230,7 @@ public void testClass_92A() throws Exception { fail("An error or warning should have occurred in the input check."); } + @Test public void testClass_92B() throws Exception { StringWriter writer = new StringWriter(); writer.write("class A{}; \n"); @@ -1209,6 +1249,7 @@ public void testClass_92B() throws Exception { assertEquals(RefactoringStatus.ERROR, s); } + @Test public void testRenameParticipant() throws Exception { TestRenameParticipant.reset(); StringWriter writer = new StringWriter(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java index 3ee13988bf0..8c33fd59120 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java @@ -18,23 +18,14 @@ import org.eclipse.core.resources.IFile; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; /** * @author markus.schorn@windriver.com */ public class RenameTemplatesTests extends RenameTestBase { - public RenameTemplatesTests(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(RenameTemplatesTests.class); - } - + @Test public void testClassTemplate() throws Exception { StringWriter writer = new StringWriter(); writer.write("template \n"); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTestBase.java index 2854f98b3b8..dd3b2e3fe14 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTestBase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTestBase.java @@ -14,6 +14,8 @@ ******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.rename; +import static org.junit.jupiter.api.Assertions.fail; + import org.eclipse.cdt.internal.ui.refactoring.rename.CRefactoringArgument; import org.eclipse.cdt.internal.ui.refactoring.rename.CRefactory; import org.eclipse.cdt.internal.ui.refactoring.rename.CRenameProcessor; @@ -33,13 +35,6 @@ public abstract class RenameTestBase extends RefactoringTests { private static final IProgressMonitor NPM = new NullProgressMonitor(); - protected RenameTestBase(String name) { - super(name); - } - - protected RenameTestBase() { - } - /** * @param element the CElement to rename * @param newName the new name for the element diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java index 8ddc9dca43f..8be91a4b271 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java @@ -19,23 +19,14 @@ import org.eclipse.core.resources.IFile; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; /** * @author markus.schorn@windriver.com */ public class RenameTypeTests extends RenameTestBase { - public RenameTypeTests(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(RenameTypeTests.class); - } - + @Test public void testClassNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -340,6 +331,7 @@ public void testClassNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testNamespaceNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -642,6 +634,7 @@ public void testNamespaceNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testStructNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -944,6 +937,7 @@ public void testStructNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testStructNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -1021,6 +1015,7 @@ public void testStructNameConflictsPlainC() throws Exception { } + @Test public void testUnionNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -1323,6 +1318,7 @@ public void testUnionNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testUnionNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -1393,6 +1389,7 @@ public void testUnionNameConflictsPlainC() throws Exception { } + @Test public void testEnumNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -1629,6 +1626,7 @@ public void testEnumNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testEnumNameConflictsPlainC() throws Exception { createCppFwdDecls("c_fwd.h"); createCppDefs("c_def.h"); @@ -1707,6 +1705,7 @@ public void testEnumNameConflictsPlainC() throws Exception { assertRefactoringOk(status); } + @Test public void testTypedefNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -1941,6 +1940,7 @@ public void testTypedefNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testTypedefNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -2021,6 +2021,7 @@ public void testTypedefNameConflictsPlainC() throws Exception { assertRefactoringOk(status); } + @Test public void testRenameClass() throws Exception { StringWriter writer = new StringWriter(); writer.write("class String \n"); @@ -2048,6 +2049,7 @@ public void testRenameClass() throws Exception { assertTotalChanges(countOccurrences(contents, "String"), ch); } + @Test public void testRenameClassFromCtor() throws Exception { StringWriter writer = new StringWriter(); writer.write("class String \n"); //$NON-NLS-1$ @@ -2074,6 +2076,7 @@ public void testRenameClassFromCtor() throws Exception { assertTotalChanges(countOccurrences(contents, "String"), ch); //$NON-NLS-1$ } + @Test public void testRenameClassFromDtor() throws Exception { StringWriter writer = new StringWriter(); writer.write("class String \n"); //$NON-NLS-1$ @@ -2100,6 +2103,7 @@ public void testRenameClassFromDtor() throws Exception { assertTotalChanges(countOccurrences(contents, "String"), ch); //$NON-NLS-1$ } + @Test public void testUsingDeclaration_332895() throws Exception { StringWriter writer = new StringWriter(); writer.write("namespace ns { \n"); @@ -2119,6 +2123,7 @@ public void testUsingDeclaration_332895() throws Exception { assertTotalChanges(countOccurrences(contents, "MyType"), ch); } + @Test public void testBug72888() throws Exception { StringWriter writer = new StringWriter(); writer.write("class MyEx {}; \n"); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java index fffc9b59b23..814bc20ffc7 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java @@ -18,23 +18,14 @@ import org.eclipse.core.resources.IFile; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; /** * @author markus.schorn@windriver.com */ public class RenameVariableTests extends RenameTestBase { - public RenameVariableTests(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(RenameVariableTests.class); - } - + @Test public void testLocalNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -277,6 +268,7 @@ public void testLocalNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testLocalNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -345,6 +337,7 @@ public void testLocalNameConflictsPlainC() throws Exception { } + @Test public void testParameterNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -585,6 +578,7 @@ public void testParameterNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testParameterNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -656,6 +650,7 @@ public void testParameterNameConflictsPlainC() throws Exception { assertRefactoringOk(status); } + @Test public void testVaribleNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -937,6 +932,7 @@ public void testVaribleNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testVaribleNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -1025,6 +1021,7 @@ public void testVaribleNameConflictsPlainC() throws Exception { assertRefactoringOk(status); } + @Test public void testEnumeratorNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -1297,6 +1294,7 @@ public void testEnumeratorNameConflicts() throws Exception { assertRefactoringOk(status); } + @Test public void testEnumeratorNameConflictsPlainC() throws Exception { createCFwdDecls("c_fwd.h"); createCDefs("c_def.h"); @@ -1373,6 +1371,7 @@ public void testEnumeratorNameConflictsPlainC() throws Exception { assertRefactoringOk(status); } + @Test public void testMemberNameConflicts1() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -1475,6 +1474,7 @@ public void testMemberNameConflicts1() throws Exception { + "New element: static_method \n" + "Conflicting element type: Method"); } + @Test public void testMemberNameConflicts2() throws Exception { createCppFwdDecls("cpp_fwd.hh"); createCppDefs("cpp_def.hh"); @@ -1657,6 +1657,7 @@ public void testMemberNameConflicts2() throws Exception { assertRefactoringOk(status); } + @Test public void testReferenceViaMacro() throws Exception { StringWriter writer = new StringWriter(); writer.write("#define PASSON(x) (x) \n"); @@ -1676,6 +1677,7 @@ public void testReferenceViaMacro() throws Exception { assertChange(changes, cpp, offset2, 2, "z"); } + @Test public void testReferenceViaMacro2() throws Exception { StringWriter writer = new StringWriter(); writer.write("#define INC(x,y) x+=y \n"); @@ -1694,6 +1696,7 @@ public void testReferenceViaMacro2() throws Exception { assertChange(changes, cpp, offset2, 2, "z"); } + @Test public void testReferenceViaMacro3() throws Exception { StringWriter writer = new StringWriter(); writer.write("#define INC(x,y) x+=y \n"); @@ -1714,6 +1717,7 @@ public void testReferenceViaMacro3() throws Exception { assertChange(changes, cpp, offset, 2, "z"); } + @Test public void testReferenceViaMacro4() throws Exception { StringWriter writer = new StringWriter(); writer.write("#define INC(x) v2++ \n"); @@ -1730,6 +1734,7 @@ public void testReferenceViaMacro4() throws Exception { assertChange(changes, cpp, offset, 2, "z"); } + @Test public void testReferenceViaMacro5() throws Exception { StringWriter writer = new StringWriter(); writer.write("#define INC(x) v1++ \n"); @@ -1752,6 +1757,7 @@ public void testReferenceViaMacro5() throws Exception { assertChange(changes, cpp, offset2, 2, "z"); } + @Test public void testBug72646() throws Exception { StringWriter writer = new StringWriter(); writer.write("class C2: public C1 { \n");