diff options
author | Sergey Prigogin | 2012-01-04 00:14:11 +0000 |
---|---|---|
committer | Sergey Prigogin | 2012-01-04 00:15:22 +0000 |
commit | 2737d2c708e30b8b983411062a3c8ec13632ec2a (patch) | |
tree | 68d544b300b3d2a662dd130563253b8579f66f8c /core/org.eclipse.cdt.core.tests | |
parent | c42f98e33308f2881e9291f5ef9b8c42e41ac30d (diff) | |
download | org.eclipse.cdt-2737d2c708e30b8b983411062a3c8ec13632ec2a.tar.gz org.eclipse.cdt-2737d2c708e30b8b983411062a3c8ec13632ec2a.tar.xz org.eclipse.cdt-2737d2c708e30b8b983411062a3c8ec13632ec2a.zip |
Fixed reporting of "Test data not found" errors.
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
3 files changed, 75 insertions, 65 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 5e0d7a9d55a..bae3b12d150 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -120,12 +120,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { len= section.length()+len; } IASTName name= findName(section, len); - assertNotNull("name not found for \""+section+"\"", name); + assertNotNull("Name not found for \"" + section + "\"", name); assertEquals(section.substring(0, len), name.getRawSignature()); IBinding binding = name.resolveBinding(); - assertNotNull("No binding for "+name.getRawSignature(), binding); - assertFalse("Binding is a ProblemBinding for name "+name.getRawSignature(), IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); + assertNotNull("No binding for " + name.getRawSignature(), binding); + assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); assertInstance(binding, clazz, cs); return clazz.cast(binding); } @@ -135,15 +135,15 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { */ protected <T extends IBinding> T getBindingFromASTName(String section, int len) { if (len <= 0) - len+= section.length(); + len += section.length(); IASTName name= findName(section, len); - assertNotNull("name not found for \""+section+"\"", name); + assertNotNull("Name not found for \"" + section + "\"", name); assertEquals(section.substring(0, len), name.getRawSignature()); IBinding binding = name.resolveBinding(); - assertNotNull("No binding for "+name.getRawSignature(), binding); - assertFalse("Binding is a ProblemBinding for name "+name.getRawSignature(), IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); + assertNotNull("No binding for " + name.getRawSignature(), binding); + assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); return (T) binding; } @@ -155,12 +155,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { */ protected IBinding getProblemFromASTName(String section, int len) { IASTName name= findName(section, len); - assertNotNull("name not found for \""+section+"\"", name); + assertNotNull("Name not found for \"" + section + "\"", name); assertEquals(section.substring(0, len), name.getRawSignature()); IBinding binding = name.resolveBinding(); - assertNotNull("No binding for "+name.getRawSignature(), binding); - assertTrue("Binding is not a ProblemBinding for name "+name.getRawSignature(), IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); + assertNotNull("No binding for " + name.getRawSignature(), binding); + assertTrue("Binding is not a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass())); return name.resolveBinding(); } @@ -200,10 +200,10 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { } protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) { - assertNotNull("Expected "+clazz.getName()+" but got null", o); - assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o)); + assertNotNull("Expected " + clazz.getName() + " but got null", o); + assertTrue("Expected " + clazz.getName() + " but got " + o.getClass().getName(), clazz.isInstance(o)); for (Class c : cs) { - assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), c.isInstance(o)); + assertTrue("Expected " + clazz.getName() + " but got " + o.getClass().getName(), c.isInstance(o)); } return clazz.cast(o); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugsSingleProjectFirstAST.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugsSingleProjectFirstAST.java index 1cd104e79be..b537ab53a38 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugsSingleProjectFirstAST.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugsSingleProjectFirstAST.java @@ -16,8 +16,11 @@ public class IndexCPPBindingResolutionBugsSingleProjectFirstAST extends IndexCPP public IndexCPPBindingResolutionBugsSingleProjectFirstAST() { setStrategy(new SinglePDOMTestFirstASTStrategy(true)); } - public static TestSuite suite() {return suite(IndexCPPBindingResolutionBugsSingleProjectFirstAST.class);} - // invalid tests for this strategy, they assume that the second file is already indexed. + public static TestSuite suite() { + return suite(IndexCPPBindingResolutionBugsSingleProjectFirstAST.class); + } + + // Invalid tests for this strategy, they assume that the second file is already indexed. @Override public void testBug208558() {} @Override public void testBug176708_CCE() {} @Override public void testIsSameAnonymousType_Bug193962() {} diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java index e6a90d99bf7..e4bffbbbc57 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/util/TestSourceReader.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; import junit.framework.Assert; -import junit.framework.TestCase; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ILinkage; @@ -54,10 +53,10 @@ import org.osgi.framework.Bundle; * Utilities for reading test source code from plug-in .java sources */ public class TestSourceReader { - /** * Returns an array of StringBuilder objects for each comment section found preceding the named - * test in the source code. + * test in the source code. + * * @param bundle the bundle containing the source, if null can try to load using classpath * (source folder has to be in the classpath for this to work) * @param srcRoot the directory inside the bundle containing the packages @@ -71,54 +70,61 @@ public class TestSourceReader { */ public static StringBuilder[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz, final String testName, int sections) throws IOException { - String fqn = clazz.getName().replace('.', '/'); - fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$")); - String classFile = fqn + ".java"; - IPath filePath= new Path(srcRoot + '/' + classFile); - - InputStream in; - try { - if (bundle != null) { - in = FileLocator.openStream(bundle, filePath, false); - } else { - in = clazz.getResourceAsStream('/' + classFile); + while (true) { + String fqn = clazz.getName().replace('.', '/'); + fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$")); + String classFile = fqn + ".java"; + IPath filePath= new Path(srcRoot + '/' + classFile); + + InputStream in; + Class superclass = clazz.getSuperclass(); + try { + if (bundle != null) { + in = FileLocator.openStream(bundle, filePath, false); + } else { + in = clazz.getResourceAsStream('/' + classFile); + } + } catch (IOException e) { + if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { + throw e; + } + clazz = superclass; + continue; } - } catch (IOException e) { - if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) { - return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections); + + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + try { + List<StringBuilder> contents = new ArrayList<StringBuilder>(); + StringBuilder content = new StringBuilder(); + for (String line = br.readLine(); line != null; line = br.readLine()) { + line = line.replaceFirst("^\\s*", ""); // Replace leading whitespace, preserve trailing + if (line.startsWith("//")) { + content.append(line.substring(2) + "\n"); + } else { + if (content.length() > 0) { + contents.add(content); + if (sections > 0 && contents.size() == sections + 1) + contents.remove(0); + content = new StringBuilder(); + } + if (line.length() > 0 && !contents.isEmpty()) { + int idx= line.indexOf(testName); + if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) { + return contents.toArray(new StringBuilder[contents.size()]); + } + contents.clear(); + } + } + } + } finally { + br.close(); } - throw e; + + if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { + throw new IOException("Test data not found for " + clazz.getName() + "." + testName); + } + clazz = superclass; } - - BufferedReader br = new BufferedReader(new InputStreamReader(in)); - - List<StringBuilder> contents = new ArrayList<StringBuilder>(); - StringBuilder content = new StringBuilder(); - for (String line = br.readLine(); line != null; line = br.readLine()) { - line = line.replaceFirst("^\\s*", ""); // replace leading whitespace, preserve trailing - if (line.startsWith("//")) { - content.append(line.substring(2) + "\n"); - } else { - if (content.length() > 0) { - contents.add(content); - if (sections > 0 && contents.size() == sections + 1) - contents.remove(0); - content = new StringBuilder(); - } - if (line.length() > 0 && !contents.isEmpty()) { - int idx= line.indexOf(testName); - if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) { - return contents.toArray(new StringBuilder[contents.size()]); - } - contents.clear(); - } - } - } - - if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) { - return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections); - } - throw new IOException("Test data not found for " + clazz + " " + testName); } /** @@ -251,6 +257,7 @@ public class TestSourceReader { } result[0]= file; } + private void createFolders(IResource res) throws CoreException { IContainer container= res.getParent(); if (!container.exists() && container instanceof IFolder) { @@ -305,7 +312,7 @@ public class TestSourceReader { Thread.sleep(50); timeLeft= (int) (endTime - System.currentTimeMillis()); } - Assert.fail("Indexing " + file.getFullPath() + " did not complete in time!"); + Assert.fail("Indexing " + file.getFullPath() + " did not complete in " + maxmillis / 1000. + " sec"); } private static boolean areAllFilesNotOlderThan(IIndexFile[] files, long timestamp) throws CoreException { @@ -323,7 +330,7 @@ public class TestSourceReader { ITranslationUnit tu= (ITranslationUnit) elem; return tu.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS); } - Assert.fail("Could not create ast for " + file.getFullPath()); + Assert.fail("Could not create AST for " + file.getFullPath()); return null; } } |