mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Automated creation of failing tests
This commit is contained in:
parent
72d7147e77
commit
04f43e66f3
6 changed files with 117 additions and 77 deletions
|
@ -16,11 +16,16 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Vector;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestFailure;
|
||||
import junit.framework.TestResult;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -53,6 +58,50 @@ public class BaseTestCase extends TestCase {
|
|||
super(name);
|
||||
}
|
||||
|
||||
protected static TestSuite suite(Class clazz) {
|
||||
return suite(clazz, null);
|
||||
}
|
||||
|
||||
protected static TestSuite suite(Class clazz, String failingTestPrefix) {
|
||||
TestSuite suite= new TestSuite(clazz);
|
||||
Test failing= getFailingTests(clazz, failingTestPrefix);
|
||||
if (failing != null) {
|
||||
suite.addTest(failing);
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static Test getFailingTests(Class clazz, String prefix) {
|
||||
TestSuite suite= new TestSuite("Failing Tests");
|
||||
Vector names= new Vector();
|
||||
if (Test.class.isAssignableFrom(clazz)) {
|
||||
Method[] methods= clazz.getDeclaredMethods();
|
||||
for (int i= 0; i < methods.length; i++) {
|
||||
addFailingMethod(suite, methods[i], clazz, prefix);
|
||||
}
|
||||
}
|
||||
if (suite.countTestCases() == 0) {
|
||||
return null;
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static void addFailingMethod(TestSuite suite, Method m, Class clazz, String prefix) {
|
||||
String name= m.getName();
|
||||
if (name.startsWith("test") || (prefix != null && !name.startsWith(prefix))) {
|
||||
return;
|
||||
}
|
||||
if (Modifier.isPublic(m.getModifiers())) {
|
||||
Class[] parameters= m.getParameterTypes();
|
||||
Class returnType= m.getReturnType();
|
||||
if (parameters.length == 0 && returnType.equals(Void.TYPE)) {
|
||||
Test test= TestSuite.createTest(clazz, name);
|
||||
((BaseTestCase) test).setExpectFailure(0);
|
||||
suite.addTest(test);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run( TestResult result ) {
|
||||
if (!fExpectFailure) {
|
||||
super.run(result);
|
||||
|
@ -72,9 +121,10 @@ public class BaseTestCase extends TestCase {
|
|||
}
|
||||
else if( r.errorCount() == 0 && r.failureCount() == 0 )
|
||||
{
|
||||
String err = "Unexpected success"; //$NON-NLS-1$
|
||||
if( fBugnumber != -1 )
|
||||
err += ", bug #" + fBugnumber; //$NON-NLS-1$
|
||||
String err = "Unexpected success of " + getName();
|
||||
if( fBugnumber > 0 ) {
|
||||
err += ", bug #" + fBugnumber;
|
||||
}
|
||||
result.addFailure( this, new AssertionFailedError( err ) );
|
||||
}
|
||||
|
||||
|
@ -200,5 +250,4 @@ public class BaseTestCase extends TestCase {
|
|||
} while (System.currentTimeMillis() < endTime);
|
||||
throw new Exception("Indexer did not complete in time!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.ui.tests.callhierarchy;
|
|||
import java.io.IOException;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
|
@ -23,8 +22,6 @@ import org.eclipse.ui.PartInitException;
|
|||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.BaseTestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
|
||||
|
||||
|
@ -35,27 +32,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite= new TestSuite("BasicCallHierarchyTest");
|
||||
suite.addTestSuite(BasicCallHierarchyTest.class);
|
||||
suite.addTest(getFailingTests());
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static Test getFailingTests() {
|
||||
TestSuite suite= new TestSuite("Failing Tests");
|
||||
suite.addTest(getFailingTest("_testAnonymousEnumeratorC", 156671));
|
||||
suite.addTest(getFailingTest("_testAnonymousEnumeratorCpp", 156671));
|
||||
suite.addTest(getFailingTest("_testAnonymousStructMembersC", 156671));
|
||||
suite.addTest(getFailingTest("_testAnonymousStructMembersCpp", 156671));
|
||||
suite.addTest(getFailingTest("_testAnonymousUnionMembersC", 156671));
|
||||
suite.addTest(getFailingTest("_testAnonymousUnionMembersCpp", 156671));
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static Test getFailingTest(String name, int bugzilla) {
|
||||
BaseTestCase failingTest= new BasicCallHierarchyTest(name);
|
||||
failingTest.setExpectFailure(bugzilla);
|
||||
return failingTest;
|
||||
return suite(BasicCallHierarchyTest.class);
|
||||
}
|
||||
|
||||
public void testFunctionsC() throws Exception {
|
||||
|
@ -159,11 +136,11 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
doTestEnumerator("enumerator.cpp", "testEnumerator");
|
||||
}
|
||||
|
||||
public void _testAnonymousEnumeratorC() throws Exception {
|
||||
public void _testAnonymousEnumeratorC_156671() throws Exception {
|
||||
doTestEnumerator("enumerator.c", "testAnonymousEnumerator");
|
||||
}
|
||||
|
||||
public void _testAnonymousEnumeratorCpp() throws Exception {
|
||||
public void _testAnonymousEnumeratorCpp_156671() throws Exception {
|
||||
doTestEnumerator("enumerator.cpp", "testAnonymousEnumerator");
|
||||
}
|
||||
|
||||
|
@ -293,11 +270,11 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
checkTreeNode(tree, 0, 0, "main()");
|
||||
}
|
||||
|
||||
public void _testAnonymousStructMembersC() throws Exception {
|
||||
public void _testAnonymousStructMembersC_156671() throws Exception {
|
||||
doTestAnonymousStructMembers("anon_struct_member.c");
|
||||
}
|
||||
|
||||
public void _testAnonymousStructMembersCpp() throws Exception {
|
||||
public void _testAnonymousStructMembersCpp_156671() throws Exception {
|
||||
doTestAnonymousStructMembers("anon_struct_member.cpp");
|
||||
}
|
||||
|
||||
|
@ -425,11 +402,11 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
checkTreeNode(tree, 0, 0, "main()");
|
||||
}
|
||||
|
||||
public void _testAnonymousUnionMembersC() throws Exception {
|
||||
public void _testAnonymousUnionMembersC_156671() throws Exception {
|
||||
doTestAnonymousUnionMembers("anon_union_member.c");
|
||||
}
|
||||
|
||||
public void _testAnonymousUnionMembersCpp() throws Exception {
|
||||
public void _testAnonymousUnionMembersCpp_156671() throws Exception {
|
||||
doTestAnonymousUnionMembers("anon_union_member.cpp");
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
package org.eclipse.cdt.ui.tests.callhierarchy;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
|
@ -20,8 +19,6 @@ import org.eclipse.ui.IWorkbenchPage;
|
|||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.BaseTestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
|
||||
|
||||
|
@ -34,24 +31,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite= new TestSuite("BasicCppCallHierarchyTest");
|
||||
suite.addTestSuite(BasicCppCallHierarchyTest.class);
|
||||
suite.addTest(getFailingTests());
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static Test getFailingTests() {
|
||||
TestSuite suite= new TestSuite("Failing Tests");
|
||||
suite.addTest(getFailingTest("_testAutomaticConstructor", 156668));
|
||||
suite.addTest(getFailingTest("_testDestructor", 156669));
|
||||
suite.addTest(getFailingTest("_testNamespacePart2", 156519));
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static Test getFailingTest(String name, int bugzilla) {
|
||||
BaseTestCase failingTest= new BasicCppCallHierarchyTest(name);
|
||||
failingTest.setExpectFailure(bugzilla);
|
||||
return failingTest;
|
||||
return suite(BasicCppCallHierarchyTest.class);
|
||||
}
|
||||
|
||||
// {testMethods}
|
||||
|
@ -322,7 +302,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
// void automatic() {
|
||||
// MyClass m;
|
||||
// }
|
||||
public void _testAutomaticConstructor() throws Exception {
|
||||
public void _testAutomaticConstructor_156668() throws Exception {
|
||||
String content = readTaggedComment("testAutomaticConstructor");
|
||||
IFile file= createFile(getProject(), "testConstructor.cpp", content);
|
||||
waitForIndexer(fPdom, file, MAX_TIME_INDEXER);
|
||||
|
@ -366,7 +346,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
checkTreeNode(tree, 0, 0, "heap()");
|
||||
}
|
||||
|
||||
public void _testDestructor() throws Exception {
|
||||
public void _testDestructor_156669() throws Exception {
|
||||
String content = readTaggedComment("testConstructor");
|
||||
IFile file= createFile(getProject(), "testConstructor.cpp", content);
|
||||
waitForIndexer(fPdom, file, MAX_TIME_INDEXER);
|
||||
|
@ -460,7 +440,7 @@ public class BasicCppCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
checkTreeNode(tree, 0, 2, "ns::func()");
|
||||
}
|
||||
|
||||
public void _testNamespacePart2() throws Exception {
|
||||
public void _testNamespacePart2_156519() throws Exception {
|
||||
String content = readTaggedComment("testNamespace");
|
||||
IFile file= createFile(getProject(), "testNamespace.cpp", content);
|
||||
waitForIndexer(fPdom, file, MAX_TIME_INDEXER);
|
||||
|
|
|
@ -23,5 +23,6 @@ public class CallHierarchyTestSuite extends TestSuite {
|
|||
super("Tests in package org.eclipse.cdt.ui.tests.callhierarchy");
|
||||
addTest(BasicCallHierarchyTest.suite());
|
||||
addTest(BasicCppCallHierarchyTest.suite());
|
||||
addTest(InitializersInCallHierarchyTest.suite());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.callhierarchy;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
|
||||
public class InitializersInCallHierarchyTest extends CallHierarchyBaseTest {
|
||||
|
||||
public InitializersInCallHierarchyTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return suite(InitializersInCallHierarchyTest.class);
|
||||
}
|
||||
|
||||
// {intvar}
|
||||
// enum Enum{a= 12};
|
||||
// int b= a;
|
||||
public void testCIntVarInitializer() throws Exception {
|
||||
String content = readTaggedComment("intvar");
|
||||
IFile file= createFile(getProject(), "intvar.c", content);
|
||||
waitForIndexer(fPdom, file, 1000);
|
||||
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||
CEditor editor= (CEditor) IDE.openEditor(page, file);
|
||||
|
||||
editor.selectAndReveal(content.indexOf("a"), 5);
|
||||
openCallHierarchy(editor);
|
||||
Tree tree = getCHTree(page);
|
||||
checkTreeNode(tree, 0, "a");
|
||||
checkTreeNode(tree, 0, 0, "{init b}()");
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@
|
|||
package org.eclipse.cdt.ui.tests.text.selection;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -40,22 +39,7 @@ public class ResolveBindingTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite= new TestSuite("ResolveBindingTests");
|
||||
suite.addTestSuite(ResolveBindingTests.class);
|
||||
suite.addTest(getFailingTests());
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static Test getFailingTests() {
|
||||
TestSuite suite= new TestSuite("Failing Tests");
|
||||
suite.addTest(getFailingTest("_testNamespaceVarBinding2", 156519));
|
||||
return suite;
|
||||
}
|
||||
|
||||
private static Test getFailingTest(String name, int bug) {
|
||||
BaseTestCase failingTest= new ResolveBindingTests(name);
|
||||
failingTest.setExpectFailure(bug);
|
||||
return failingTest;
|
||||
return suite(ResolveBindingTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
|
@ -118,7 +102,7 @@ public class ResolveBindingTests extends BaseTestCase {
|
|||
checkBinding(name, IVariable.class);
|
||||
}
|
||||
|
||||
public void _testNamespaceVarBinding2() throws Exception {
|
||||
public void _testNamespaceVarBinding_156519() throws Exception {
|
||||
String content = readTaggedComment("namespace-var-test");
|
||||
IFile file= createFile(fCProject.getProject(), "nsvar.cpp", content);
|
||||
waitForIndexer(fPdom, file, 2000);
|
||||
|
@ -132,5 +116,4 @@ public class ResolveBindingTests extends BaseTestCase {
|
|||
name= getSelectedName(astTU, content.indexOf("var; // r2"), 3);
|
||||
checkBinding(name, IVariable.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue