|
From: David C. <dc...@us...> - 2005-11-12 19:16:03
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25435/src/org/rubypeople/rdt/internal/core/builder Modified Files: ShamSymbolIndex.java TC_MassIndexUpdater.java TS_InternalCoreBuilder.java ShamMarkerManager.java TC_IndexUpdater.java Added Files: TC_CleanRdtCompiler.java AbstractRdtTestCase.java TC_IncrementalRdtCompiler.java TC_RubyCodeAnalyzer.java ShamSingleCompiler.java Removed Files: TC_RdtCompiler.java Log Message: 1) refactored RubyBuilder again, this time with better unit tests. 2) refactored Location (and SymbolIndex) to be IFile based, rather than IPath based. 3) general improvement on maintainence of the SymbolIndex. Index: ShamMarkerManager.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/ShamMarkerManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ShamMarkerManager.java 1 Oct 2005 23:00:54 -0000 1.1 --- ShamMarkerManager.java 12 Nov 2005 19:15:53 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- package org.rubypeople.rdt.internal.core.builder; + import java.util.ArrayList; import java.util.List; *************** *** 13,16 **** --- 14,18 ---- import org.jruby.lexer.yacc.SyntaxException; import org.rubypeople.eclipse.shams.resources.ShamFile; + import org.rubypeople.rdt.internal.core.util.ListUtil; public class ShamMarkerManager implements IMarkerManager { *************** *** 23,30 **** --- 25,43 ---- private int endOffsetArg; private SyntaxException syntaxExceptionArg; + private List resourcesRemoved = new ArrayList(); public void removeProblemsAndTasksFor(IResource resource) { + resourcesRemoved.add(resource); + } + + public void assertMarkersRemovedFor(IResource expectedResource) { + assertMarkersRemovedFor(ListUtil.create(expectedResource)); } + + public void assertMarkersRemovedFor(List expectedFiles) { + Assert.assertEquals(expectedFiles, resourcesRemoved); + + } public void createSyntaxError(IFile file, SyntaxException syntaxException) { fileArg = file; *************** *** 73,75 **** --- 86,89 ---- } + } \ No newline at end of file --- TC_RdtCompiler.java DELETED --- --- NEW FILE: ShamSingleCompiler.java --- /** * */ package org.rubypeople.rdt.internal.core.builder; import java.util.HashSet; import java.util.Set; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; class ShamSingleCompiler implements SingleFileCompiler { private Set compiledFiles = new HashSet(); public void compileFile(IFile file) throws CoreException { compiledFiles.add(file); } public void assertCompiled(Set expectedFiles) { TC_CleanRdtCompiler.assertEquals(expectedFiles, compiledFiles); } } Index: TS_InternalCoreBuilder.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/TS_InternalCoreBuilder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TS_InternalCoreBuilder.java 16 Oct 2005 23:52:44 -0000 1.1 --- TS_InternalCoreBuilder.java 12 Nov 2005 19:15:53 -0000 1.2 *************** *** 20,26 **** suite.addTestSuite(TC_TaskCompiler.class); ! suite.addTestSuite(TC_RdtCompiler.class); suite.addTestSuite(TC_MassIndexUpdater.class); suite.addTestSuite(TC_IndexUpdater.class); return suite; --- 20,28 ---- suite.addTestSuite(TC_TaskCompiler.class); ! suite.addTestSuite(TC_RubyCodeAnalyzer.class); suite.addTestSuite(TC_MassIndexUpdater.class); suite.addTestSuite(TC_IndexUpdater.class); + suite.addTestSuite(TC_CleanRdtCompiler.class); + suite.addTestSuite(TC_IncrementalRdtCompiler.class); return suite; --- NEW FILE: TC_RubyCodeAnalyzer.java --- /* * Author: David Corbin * * Copyright (c) 2005 RubyPeople. * * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use * RDT except in compliance with the License. For further information see * org.rubypeople.rdt/rdt.license. */ package org.rubypeople.rdt.internal.core.builder; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.eclipse.core.resources.IFile; import org.jruby.ast.Node; import org.jruby.ast.visitor.NodeVisitor; import org.jruby.lexer.yacc.SyntaxException; import org.rubypeople.eclipse.shams.resources.ShamFile; public class TC_RubyCodeAnalyzer extends TestCase { private static final String FILE_CONTENTS = "file Contents"; private static final String FILENAME = "testFile.rb"; private ShamFile file; private ShamMarkerManager markerManager; private ShamRubyParser parser; private RubyCodeAnalyzer compiler; private MockIndexUpdater indexUpdater; private Node rootNode; public void setUp() { file = new ShamFile(FILENAME); file.setContents(FILE_CONTENTS); rootNode = new Node(null) { public void accept(NodeVisitor visitor) { } public List childNodes() { return new ArrayList(); } }; markerManager = new ShamMarkerManager(); parser = new ShamRubyParser(); parser.addParseResult(file, rootNode); indexUpdater = new MockIndexUpdater(); compiler = new RubyCodeAnalyzer(markerManager, parser, indexUpdater); } public void testParserInvocation() throws Exception { compiler.compileFile(file); parser.assertParsed(file, FILE_CONTENTS); file.assertContentStreamClosed(); indexUpdater.assertUpdated(file, rootNode); } public void testSyntaxException() throws Exception { SyntaxException syntaxException = new SyntaxException(null, ""); parser.setExceptionToThrow(syntaxException); compiler.compileFile(file); file.assertContentStreamClosed(); markerManager.assertErrorCreated(file, syntaxException); } private static final class MockIndexUpdater extends IndexUpdater { public MockIndexUpdater() { super(null); } private Node rootNodeArg; private IFile fileArg; public void update(IFile file, Node rootNode) { fileArg = file; rootNodeArg = rootNode; } public void assertUpdated(IFile expectedFile, Node expectedRootNode) { assertEquals("File", expectedFile, fileArg); assertEquals("Node", expectedRootNode, rootNodeArg); } } } Index: TC_MassIndexUpdater.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/TC_MassIndexUpdater.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TC_MassIndexUpdater.java 16 Oct 2005 23:52:44 -0000 1.2 --- TC_MassIndexUpdater.java 12 Nov 2005 19:15:53 -0000 1.3 *************** *** 23,27 **** import org.rubypeople.eclipse.shams.resources.ShamProject; import org.rubypeople.rdt.internal.core.parser.ShamNode; - import org.rubypeople.rdt.internal.core.util.ListUtil; public class TC_MassIndexUpdater extends TestCase { --- 23,26 ---- *************** *** 46,51 **** parser.addParseResult(file3, rootNode3); ! project1.setResourcesToVisit(ListUtil.create(file1, file2)); ! project2.setResourcesToVisit(ListUtil.create(file3)); List projects = new ArrayList(); --- 45,51 ---- parser.addParseResult(file3, rootNode3); ! project1.addResource(file1); ! project1.addResource(file2); ! project2.addResource(file3); List projects = new ArrayList(); *************** *** 56,61 **** RubySourceFileCollectingVisitor expectedVisitor = new RubySourceFileCollectingVisitor(new ArrayList()); - project1.assertAcceptCalled(expectedVisitor, 0); - project2.assertAcceptCalled(expectedVisitor, 0); parser.assertParsed(file1); --- 56,59 ---- --- NEW FILE: TC_IncrementalRdtCompiler.java --- package org.rubypeople.rdt.internal.core.builder; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; import org.rubypeople.rdt.internal.core.ShamResourceDelta; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; import org.rubypeople.rdt.internal.core.util.ListUtil; public class TC_IncrementalRdtCompiler extends AbstractRdtTestCase { private ShamResourceDelta delta = new ShamResourceDelta(); public void testDeletedResource() throws Exception { delta.addChildren(createDelta(t1, IResourceDelta.REMOVED)); compiler.compile(monitor); List expectedFiles = ListUtil.create(t1); monitor.assertTaskBegun("Building test...", 2); monitor.assertDone(2); List subTasks = ListUtil.create(EXPECTED_TASK_NAME); monitor.assertSubTasks(subTasks); assertMarkersRemoved(ListUtil.create(t1)); assertIndexFlushed(ListUtil.create(t1)); singleCompiler1.assertCompiled(new HashSet()); singleCompiler2.assertCompiled(new HashSet()); } protected void assertMarkersRemoved(List expectedFiles) { markerManager.assertMarkersRemovedFor(expectedFiles); } protected void assertIndexFlushed(List expectedFiles) { symbolIndex.assertFlushed(expectedFiles); } protected void setFiles(List filesForTest) throws Exception { setFiles(delta, filesForTest); } private void setFiles(ShamResourceDelta delta, List filesForTest) throws Exception { for (Iterator iter = filesForTest.iterator(); iter.hasNext();) { IResource resource = (IResource) iter.next(); if (resource instanceof IFolder) { IFolder container = (IFolder) resource; ShamResourceDelta folderDelta = createDelta(container, IResourceDelta.CHANGED); delta.addChildren(folderDelta); setFiles(delta, Arrays.asList(container.members())); return; } IFile file = (IFile) resource; ShamResourceDelta childDelta = createDelta(file, IResourceDelta.ADDED); delta.addChildren(childDelta); } } private ShamResourceDelta createDelta(IResource file, int kind) { ShamResourceDelta childDelta = new ShamResourceDelta(); childDelta.setResource(file); childDelta.setKind(kind); childDelta.setFlags(IResourceDelta.CONTENT); return childDelta; } AbstractRdtCompiler createCompiler(SymbolIndex shamSymbolIndex, IMarkerManager markerManager, List singleCompilers) { delta.setResource(project); return new IncrementalRdtCompiler(project, delta, symbolIndex, markerManager, singleCompilers); } } --- NEW FILE: TC_CleanRdtCompiler.java --- package org.rubypeople.rdt.internal.core.builder; import java.util.List; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; public class TC_CleanRdtCompiler extends AbstractRdtTestCase { AbstractRdtCompiler createCompiler(SymbolIndex symbolIndex, IMarkerManager markerManager, List singleCompilers) { return new CleanRdtCompiler(project, symbolIndex, markerManager, singleCompilers); } protected void assertIndexFlushed(List expectedFiles) { symbolIndex.assertFlushed(project); } protected void assertMarkersRemoved(List expectedFiles) { markerManager.assertMarkersRemovedFor(project); } } Index: ShamSymbolIndex.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/ShamSymbolIndex.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ShamSymbolIndex.java 23 Oct 2005 22:24:19 -0000 1.2 --- ShamSymbolIndex.java 12 Nov 2005 19:15:53 -0000 1.3 *************** *** 12,20 **** package org.rubypeople.rdt.internal.core.builder; import org.eclipse.core.resources.IFile; ! import org.eclipse.core.runtime.IPath; import org.jruby.lexer.yacc.ISourcePosition; import org.rubypeople.rdt.internal.core.symbols.Symbol; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; public class ShamSymbolIndex extends SymbolIndex { --- 12,27 ---- package org.rubypeople.rdt.internal.core.builder; + import java.util.ArrayList; + import java.util.List; + + import junit.framework.Assert; + import org.eclipse.core.resources.IFile; ! import org.eclipse.core.resources.IProject; import org.jruby.lexer.yacc.ISourcePosition; + import org.rubypeople.eclipse.shams.resources.ShamProject; import org.rubypeople.rdt.internal.core.symbols.Symbol; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; + import org.rubypeople.rdt.internal.core.util.ListUtil; public class ShamSymbolIndex extends SymbolIndex { *************** *** 23,43 **** private Symbol symbolArg; private ISourcePosition positionArg; ! private IPath flushedPathArg; ! public void flush(IPath path) { ! flushedPathArg = path; } ! public void assertFlushed(IPath expectedPath) { ! TC_IndexUpdater.assertEquals("Flushed path", expectedPath, flushedPathArg); } public void assertAddNotCalled() { ! TC_IndexUpdater.assertNull("Unexpected call to assertAddNotCalled()", fileArg); } public void assertAdded(Symbol expectedSymbol, IFile expectedFile, ISourcePosition expectedPosition) { ! TC_IndexUpdater.assertEquals("Symbol", expectedSymbol, symbolArg); ! TC_IndexUpdater.assertEquals("File", expectedFile, fileArg); ! TC_IndexUpdater.assertEquals("Position", expectedPosition, positionArg); } --- 30,52 ---- private Symbol symbolArg; private ISourcePosition positionArg; ! private List flushedFiles = new ArrayList(); ! private IProject flushedProjectArg; ! public void flush(IFile file) { ! flushedFiles.add(file); } ! ! public void assertFlushed(IFile expectedFile) { ! Assert.assertEquals("Flushed file", ListUtil.create(expectedFile), flushedFiles); } public void assertAddNotCalled() { ! Assert.assertNull("Unexpected call to assertAddNotCalled()", fileArg); } public void assertAdded(Symbol expectedSymbol, IFile expectedFile, ISourcePosition expectedPosition) { ! Assert.assertEquals("Symbol", expectedSymbol, symbolArg); ! Assert.assertEquals("File", expectedFile, fileArg); ! Assert.assertEquals("Position", expectedPosition, positionArg); } *************** *** 47,50 **** --- 56,72 ---- positionArg = position; } + + public void assertFlushed(ShamProject expectedProject) { + Assert.assertEquals("Flushed project", flushedProjectArg, expectedProject); + + } + + public void flush(IProject project) { + flushedProjectArg = project; + } + + public void assertFlushed(List expectedFiles) { + Assert.assertEquals(expectedFiles, flushedFiles); + } } \ No newline at end of file --- NEW FILE: AbstractRdtTestCase.java --- package org.rubypeople.rdt.internal.core.builder; import java.util.HashSet; import java.util.Iterator; import java.util.List; import junit.framework.TestCase; import org.eclipse.core.resources.IFile; import org.rubypeople.eclipse.shams.resources.ShamFile; import org.rubypeople.eclipse.shams.resources.ShamFolder; import org.rubypeople.eclipse.shams.resources.ShamProject; import org.rubypeople.eclipse.shams.runtime.ShamMonitor; import org.rubypeople.rdt.internal.core.symbols.SymbolIndex; import org.rubypeople.rdt.internal.core.util.ListUtil; public abstract class AbstractRdtTestCase extends TestCase { static protected final String EXPECTED_TASK_NAME = "Removing Markers..."; protected abstract void assertMarkersRemoved(List expectedFiles); protected abstract void assertIndexFlushed(List expectedFiles); abstract AbstractRdtCompiler createCompiler(SymbolIndex index, IMarkerManager markerManager, List singleCompilers); protected ShamMonitor monitor; protected ShamFile t1; protected ShamFile t2; protected ShamFile t3; protected ShamFolder f1; protected ShamProject project; protected ShamMarkerManager markerManager; protected ShamSymbolIndex symbolIndex; protected ShamSingleCompiler singleCompiler1; protected ShamSingleCompiler singleCompiler2; protected AbstractRdtCompiler compiler; private ShamFile nonRubyFile; public void setUp() { t1 = new ShamFile("/test/T1.rb"); t2 = new ShamFile("/test/T2.rb"); t3 = new ShamFile("/test/F1/T3.rb"); nonRubyFile = new ShamFile("/test/T3.txt"); f1 = new ShamFolder("/test/F1"); project = new ShamProject("test"); markerManager = new ShamMarkerManager(); symbolIndex = new ShamSymbolIndex(); singleCompiler1 = new ShamSingleCompiler(); singleCompiler2 = new ShamSingleCompiler(); List singleCompilers = ListUtil.create(singleCompiler1, singleCompiler2); compiler = createCompiler(symbolIndex, markerManager, singleCompilers); monitor = new ShamMonitor(); } public void testBasicCompile() throws Exception { project.addResource(t1); setFiles(ListUtil.create(t1)); compiler.compile(monitor); assertCompliationFor(ListUtil.create(t1), 4); } public void testNotARubyFile() throws Exception { project.addResource(nonRubyFile); setFiles(ListUtil.create(nonRubyFile)); compiler.compile(monitor); assertCompliationFor(ListUtil.create(), 2); } public void testCompileIncludesFolders() throws Exception { project.addResource(f1); f1.addResource(t3); setFiles(ListUtil.create(f1)); compiler.compile(monitor); assertCompliationFor(ListUtil.create(t3), 4); } public void testCompileMultipleFiles() throws Exception { project.addResource(t1); project.addResource(t2); setFiles(ListUtil.create(t1, t2)); compiler.compile(monitor); assertCompliationFor(ListUtil.create(t1, t2), 6); } public void testCancellation() throws Exception { monitor.cancelAfter(4); project.addResource(t1); project.addResource(t2); setFiles(ListUtil.create(t1, t2)); compiler.compile(monitor); List expectedFiles = ListUtil.create(t1); monitor.assertTaskBegun("Building test...", 6); monitor.assertDone(4); List subTasks = ListUtil.create(EXPECTED_TASK_NAME, t1.getFullPath().toString()); monitor.assertSubTasks(subTasks); assertMarkersRemoved(ListUtil.create(t1,t2)); assertIndexFlushed(ListUtil.create(t1,t2)); singleCompiler1.assertCompiled(new HashSet(expectedFiles)); singleCompiler2.assertCompiled(new HashSet(expectedFiles)); } public void testCompileSkipsNonRubyFiles() throws Exception { ShamFile x1 = new ShamFile("/test/x1"); project.addResource(t1); project.addResource(x1); setFiles(ListUtil.create(t1)); compiler.compile(monitor); assertCompliationFor(ListUtil.create(t1), 4); } protected void setFiles(List filesForTest) throws Exception { } protected void assertCompliationFor(List expectedFiles, int totalWork) { monitor.assertTaskBegun("Building test...", totalWork); monitor.assertDone(totalWork); List subTasks = ListUtil.create(EXPECTED_TASK_NAME); for (Iterator iter = expectedFiles.iterator(); iter.hasNext();) { IFile file = (IFile) iter.next(); subTasks.add(file.getFullPath().toString()); } monitor.assertSubTasks(subTasks); assertMarkersRemoved(expectedFiles); assertIndexFlushed(expectedFiles); singleCompiler1.assertCompiled(new HashSet(expectedFiles)); singleCompiler2.assertCompiled(new HashSet(expectedFiles)); } } Index: TC_IndexUpdater.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/core/builder/TC_IndexUpdater.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TC_IndexUpdater.java 23 Oct 2005 22:24:19 -0000 1.5 --- TC_IndexUpdater.java 12 Nov 2005 19:15:53 -0000 1.6 *************** *** 45,49 **** updater.update(file, node); ! symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAddNotCalled(); } --- 45,49 ---- updater.update(file, node); ! symbolIndex.assertFlushed(file); symbolIndex.assertAddNotCalled(); } *************** *** 54,58 **** updater.update(file, node); ! symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAdded(new ClassSymbol(TEST_CLASS_NAME), file, POSITION_1); } --- 54,58 ---- updater.update(file, node); ! symbolIndex.assertFlushed(file); symbolIndex.assertAdded(new ClassSymbol(TEST_CLASS_NAME), file, POSITION_1); } *************** *** 63,67 **** updater.update(file,node); ! symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAdded(new ClassSymbol("Foo"), file, new RdtPosition(1, 2, 14, 15)); } --- 63,67 ---- updater.update(file,node); ! symbolIndex.assertFlushed(file); symbolIndex.assertAdded(new ClassSymbol("Foo"), file, new RdtPosition(1, 2, 14, 15)); } *************** *** 72,76 **** updater.update(file,node); ! symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAdded(new ClassSymbol("Foo::Bar"), file, new RdtPosition(1, 2, 16, 20)); } --- 72,76 ---- updater.update(file,node); ! symbolIndex.assertFlushed(file); symbolIndex.assertAdded(new ClassSymbol("Foo::Bar"), file, new RdtPosition(1, 2, 16, 20)); } *************** *** 81,85 **** updater.update(file,node); ! symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAdded(new ClassSymbol("X::Foo::Bar"), file, new RdtPosition(1, 2, 19, 23)); } --- 81,85 ---- updater.update(file,node); ! symbolIndex.assertFlushed(file); symbolIndex.assertAdded(new ClassSymbol("X::Foo::Bar"), file, new RdtPosition(1, 2, 19, 23)); } *************** *** 90,94 **** updater.update(file,node); ! symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAdded(new ClassSymbol("Foo::Bar"), file, new RdtPosition(2, 3, 25, 26)); } --- 90,94 ---- updater.update(file,node); ! symbolIndex.assertFlushed(file); symbolIndex.assertAdded(new ClassSymbol("Foo::Bar"), file, new RdtPosition(2, 3, 25, 26)); } *************** *** 99,103 **** updater.update(file,node); ! symbolIndex.assertFlushed(file.getFullPath()); symbolIndex.assertAdded(new ClassSymbol("Foo::Bar::InnerBar"), file, new RdtPosition(2, 3, 35, 36)); } --- 99,103 ---- updater.update(file,node); ! symbolIndex.assertFlushed(file); symbolIndex.assertAdded(new ClassSymbol("Foo::Bar::InnerBar"), file, new RdtPosition(2, 3, 35, 36)); } |