Permalink
Browse files

Updated unit tests to succeed again. Added master test suite.

Updated EasyMock to give us the resetToDefault() function.
Made some changes to GhcCompiler for the benefit of the unit tests.
  • Loading branch information...
ttencate committed Jul 27, 2009
1 parent 1508a2f commit b0128ed5cc3e8a5a75a258ee25431192270133ac
Showing with 371 additions and 154 deletions.
  1. +0 −18 ...lipsefp.haskell.core.jparser.test/src/net/sf/eclipsefp/haskell/core/jparser/test/AllAllTests.java
  2. +3 −4 ...p.haskell.core.jparser.test/src/net/sf/eclipsefp/haskell/core/jparser/test/AllTests_PDESuite.java
  3. +3 −4 .../src/net/sf/eclipsefp/haskell/core/jparser/test/{AllAllTests_PDESuite.java → AllTests_Suite.java}
  4. +2 −3 ...core.jparser.test/src/net/sf/eclipsefp/haskell/core/jparser/test/{AllTests.java → MainTests.java}
  5. +17 −0 ....haskell.core.jparser.test/src/net/sf/eclipsefp/haskell/core/jparser/test/MainTests_PDESuite.java
  6. +25 −11 ...fp.haskell.core.test/src/net/sf/eclipsefp/haskell/core/halamo/WorkspaceChangeMonitor_PDETest.java
  7. +2 −2 net.sf.eclipsefp.haskell.core.test/src/net/sf/eclipsefp/haskell/core/test/TestCaseWithProject.java
  8. +43 −42 net.sf.eclipsefp.haskell.core.test/src/net/sf/eclipsefp/haskell/core/util/ProcessRunner_Test.java
  9. +10 −5 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/util/IProcessRunner.java
  10. +16 −22 net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/util/ProcessRunner.java
  11. +1 −1 ...st/INTERNAL/java/test/net/sf/eclipsefp/haskell/debug/ui/test/{internal → }/AllTests_PDESuite.java
  12. +1 −0 net.sf.eclipsefp.haskell.debug.ui.test/META-INF/MANIFEST.MF
  13. +1 −0 net.sf.eclipsefp.haskell.ghccompiler.test/META-INF/MANIFEST.MF
  14. +41 −7 ....ghccompiler.test/src/net/sf/eclipsefp/haskell/ghccompiler/test/core/GhcCompilerTest_PDETest.java
  15. +10 −6 net.sf.eclipsefp.haskell.ghccompiler/src/net/sf/eclipsefp/haskell/ghccompiler/core/GhcCompiler.java
  16. +7 −3 ...lipsefp.haskell.ghccompiler/src/net/sf/eclipsefp/haskell/ghccompiler/core/GhcOutputProcessor.java
  17. +15 −0 ...ipsefp.haskell.ghccompiler/src/net/sf/eclipsefp/haskell/ghccompiler/core/IGhcOutputProcessor.java
  18. +12 −0 net.sf.eclipsefp.haskell.scion.client/src/net/sf/eclipsefp/haskell/scion/types/Location.java
  19. +13 −0 net.sf.eclipsefp.haskell.scion.client/src/net/sf/eclipsefp/haskell/scion/types/Note.java
  20. +13 −0 net.sf.eclipsefp.haskell.test/.classpath
  21. +1 −0 net.sf.eclipsefp.haskell.test/.gitignore
  22. +28 −0 net.sf.eclipsefp.haskell.test/.project
  23. +8 −0 net.sf.eclipsefp.haskell.test/.settings/org.eclipse.jdt.core.prefs
  24. +14 −0 net.sf.eclipsefp.haskell.test/META-INF/MANIFEST.MF
  25. +4 −0 net.sf.eclipsefp.haskell.test/build.properties
  26. +19 −0 net.sf.eclipsefp.haskell.test/src/net/sf/eclipsefp/test/AllTests_PDESuite.java
  27. +17 −0 net.sf.eclipsefp.haskell.test/src/net/sf/eclipsefp/test/AllTests_Suite.java
  28. +26 −15 net.sf.eclipsefp.haskell.ui.test/.settings/org.eclipse.pde.prefs
  29. +19 −11 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/scion/ScionManager.java
  30. BIN org.easymock/lib/easymock.jar
@@ -1,18 +0,0 @@
-package net.sf.eclipsefp.haskell.core.jparser.test;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllAllTests {
-
- public static Test suite() {
- TestSuite suite = new TestSuite(
- "Test for net.sf.eclipsefp.haskell.core.jparser.test");
- //$JUnit-BEGIN$
- suite.addTest(net.sf.eclipsefp.haskell.core.jparser.test.AllTests.suite());
- suite.addTest(net.sf.eclipsefp.haskell.core.jparser.ast.test.AllTests.suite());
- //$JUnit-END$
- return suite;
- }
-
-}
@@ -6,11 +6,10 @@
public class AllTests_PDESuite {
public static Test suite() {
- TestSuite suite = new TestSuite(
- "Test for net.sf.eclipsefp.haskell.core.jparser.test");
+ TestSuite suite = new TestSuite();
//$JUnit-BEGIN$
- suite.addTestSuite(ParserPlugin_PDETest.class);
- suite.addTest(AllTests.suite());
+ suite.addTest(net.sf.eclipsefp.haskell.core.jparser.test.MainTests_PDESuite.suite());
+ suite.addTest(net.sf.eclipsefp.haskell.core.jparser.ast.test.AllTests.suite());
//$JUnit-END$
return suite;
}
@@ -3,13 +3,12 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-public class AllAllTests_PDESuite {
+public class AllTests_Suite {
public static Test suite() {
- TestSuite suite = new TestSuite(
- "JParser plugin full test suit");
+ TestSuite suite = new TestSuite();
//$JUnit-BEGIN$
- suite.addTest(net.sf.eclipsefp.haskell.core.jparser.test.AllTests_PDESuite.suite());
+ suite.addTest(net.sf.eclipsefp.haskell.core.jparser.test.MainTests.suite());
suite.addTest(net.sf.eclipsefp.haskell.core.jparser.ast.test.AllTests.suite());
//$JUnit-END$
return suite;
@@ -3,11 +3,10 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-public class AllTests {
+public class MainTests {
public static Test suite() {
- TestSuite suite = new TestSuite(
- "Test for net.sf.eclipsefp.haskell.core.jparser.test");
+ TestSuite suite = new TestSuite();
//$JUnit-BEGIN$
suite.addTestSuite(ParserIntegrationTest.class);
suite.addTestSuite(LexerTest.class);
@@ -0,0 +1,17 @@
+package net.sf.eclipsefp.haskell.core.jparser.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class MainTests_PDESuite {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ //$JUnit-BEGIN$
+ suite.addTestSuite(ParserPlugin_PDETest.class);
+ suite.addTest(MainTests.suite());
+ //$JUnit-END$
+ return suite;
+ }
+
+}
@@ -1,10 +1,12 @@
package net.sf.eclipsefp.haskell.core.halamo;
import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.checkOrder;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.resetToDefault;
import static org.easymock.EasyMock.verify;
import junit.framework.TestCase;
import net.sf.eclipsefp.haskell.core.internal.util.TestHaskellProject;
@@ -23,15 +25,15 @@
public void testCreatesChangeMonitorWhenProjectIsCreated()
throws CoreException
{
- expect(getFactory().createProjectChangeMonitor((IProject) anyObject())).
- andReturn(null).
- atLeastOnce();
- replay(getFactory());
+ IProjectChangeMonitorFactory factory = getFactory();
+ expect(factory.createProjectChangeMonitor((IProject) anyObject())).
+ andReturn( createMock(IResourceChangeListener.class) );
+ replay(factory);
- TestHaskellProject prj = new TestHaskellProject("testing-project");
+ TestHaskellProject prj = new TestHaskellProject("createsChangeMonitorProject");
prj.destroy();
- verify(getFactory());
+ verify(factory);
}
public void testDelegatesProjectEventsToCorrespondingMonitor() throws CoreException {
@@ -43,7 +45,7 @@ public void testDelegatesProjectEventsToCorrespondingMonitor() throws CoreExcept
andReturn(sndMonitor);
replay(getFactory());
- TestHaskellProject fstPrj = new TestHaskellProject("fisrt-project");
+ TestHaskellProject fstPrj = new TestHaskellProject("first-project");
TestHaskellProject sndPrj = new TestHaskellProject("second-project");
try {
@@ -64,8 +66,12 @@ public void testCreatesProjectMonitorsForLoadedWorkspace()
IProjectChangeMonitorFactory factory =
createMock(IProjectChangeMonitorFactory.class);
- expect(factory.createProjectChangeMonitor(prj.getPlatformProject())).
- andReturn(createNiceMock(IResourceChangeListener.class));
+ expect(factory.createProjectChangeMonitor(prj.getPlatformProject()))
+ .andReturn(createNiceMock(IResourceChangeListener.class));
+ expect(factory.createProjectChangeMonitor( (IProject ) anyObject() ))
+ .andReturn( createNiceMock(IResourceChangeListener.class) )
+ .atLeastOnce(); // projects might already exist in the workspace
+ checkOrder(factory, false);
replay(factory);
WorkspaceChangeMonitor mon = new WorkspaceChangeMonitor(factory);
@@ -84,9 +90,17 @@ private IWorkspace getWorkspace() {
private IProjectChangeMonitorFactory getFactory() {
if (fFactory == null) {
- fFactory = createNiceMock(IProjectChangeMonitorFactory.class);
- fMonitor = new WorkspaceChangeMonitor(getFactory());
+ // WorkspaceChangeMonitor.observeChangesOn() will cause some calls on IProjectChangeMonitorFactory
+ // and expects it to return non-null
+ fFactory = createMock(IProjectChangeMonitorFactory.class);
+ expect(fFactory.createProjectChangeMonitor( (IProject ) anyObject() ))
+ .andStubReturn( createNiceMock(IResourceChangeListener.class) );
+ replay(fFactory);
+
+ fMonitor = new WorkspaceChangeMonitor(fFactory);
fMonitor.observeChangesOn(getWorkspace());
+
+ resetToDefault(fFactory);
}
return fFactory;
}
@@ -29,7 +29,7 @@
public static void waitForAutoBuild() throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.build( IncrementalProjectBuilder.CLEAN_BUILD, null );
- System.out.print( " Waiting for autobuild to complete ..." ); //$NON-NLS-1$
+ // System.out.print( " Waiting for autobuild to complete ..." ); //$NON-NLS-1$
IJobManager jobMan = Job.getJobManager();
boolean retry = true;
while( retry ) {
@@ -42,7 +42,7 @@ public static void waitForAutoBuild() throws CoreException {
// ignore and retry
}
}
- System.out.print( " OK.\n" ); //$NON-NLS-1$
+ // System.out.print( " OK.\n" ); //$NON-NLS-1$
}
@@ -12,47 +12,48 @@
public class ProcessRunner_Test extends TestCase {
- public void testReturnsStandardOutput() throws IOException {
- final String expectedResult = "standard output contents";
- IProcessFactory factory = createProcessFactory(expectedResult, "");
-
- ProcessRunner runner = new ProcessRunner(factory);
- String actualResult = runner.executeBlocking(new File("unimportant"),
- new NullWriter(),
- "unimportant");
- assertEquals(expectedResult, actualResult);
- }
-
- public void testReturnsStandardError() throws IOException {
- final String expectedResult = "standard error stream contents\n";
- IProcessFactory factory = createProcessFactory("", expectedResult);
-
- ProcessRunner runner = new ProcessRunner(factory);
- String actualResult = runner.executeBlocking(new File("unimportant"),
- new NullWriter(),
- "unimportant");
- assertEquals(expectedResult, actualResult);
- }
-
- public void testMergesOutputStreams() throws IOException {
- final String expectedOut = "standard output stream contents\n";
- final String expectedErr = "standard error stream contents\n";
- IProcessFactory factory = createProcessFactory(expectedOut, expectedErr);
-
- ProcessRunner runner = new ProcessRunner(factory);
- final StringWriter out = new StringWriter();
- runner.executeBlocking(new File("unimportant"), out, "unimportant");
-
- assertTrue(out.toString().contains(expectedOut));
- assertTrue(out.toString().contains(expectedErr));
- }
-
- private IProcessFactory createProcessFactory(final String stdout, final String stderr) throws IOException {
- IProcessFactory factory = createMock(IProcessFactory.class);
- expect(factory.startProcess((File) anyObject(), (String[]) anyObject()))
- .andReturn(new StubProcess(stdout, stderr));
- replay(factory);
- return factory;
- }
+ public void testReturnsStandardOutput() throws IOException {
+ final String expectedResult = "standard output contents";
+ IProcessFactory factory = createProcessFactory( expectedResult, "" );
+
+ ProcessRunner runner = new ProcessRunner( factory );
+ StringWriter actualResult = new StringWriter();
+ runner.executeBlocking( new File( "unimportant" ),
+ actualResult, new NullWriter(), "unimportant" );
+ assertEquals( expectedResult, actualResult.toString() );
+ }
+
+ public void testReturnsStandardError() throws IOException {
+ final String expectedResult = "standard error stream contents\n";
+ IProcessFactory factory = createProcessFactory( "", expectedResult );
+
+ ProcessRunner runner = new ProcessRunner( factory );
+ StringWriter actualResult = new StringWriter();
+ runner.executeBlocking( new File( "unimportant" ),
+ new NullWriter(), actualResult, "unimportant" );
+ assertEquals( expectedResult, actualResult.toString() );
+ }
+
+ public void testMergesOutputStreams() throws IOException {
+ final String expectedOut = "standard output stream contents\n";
+ final String expectedErr = "standard error stream contents\n";
+ IProcessFactory factory = createProcessFactory( expectedOut, expectedErr );
+
+ ProcessRunner runner = new ProcessRunner( factory );
+ final StringWriter actualResult = new StringWriter();
+ runner.executeBlocking( new File( "unimportant" ), actualResult, actualResult, "unimportant" );
+
+ assertTrue( actualResult.toString().contains( expectedOut ) );
+ assertTrue( actualResult.toString().contains( expectedErr ) );
+ }
+
+ private IProcessFactory createProcessFactory( final String stdout,
+ final String stderr ) throws IOException {
+ IProcessFactory factory = createMock( IProcessFactory.class );
+ expect( factory.startProcess( ( File )anyObject(), ( String[] )anyObject() ) )
+ .andReturn( new StubProcess( stdout, stderr ) );
+ replay( factory );
+ return factory;
+ }
}
@@ -14,29 +14,34 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
+import net.sf.eclipsefp.haskell.core.compiler.NullWriter;
public interface IProcessRunner {
/**
* Runs the program, and returns when it completes.
*
* @param workingDir the working directory from which the program should be started
- * @param out the {@link Writer} to receive the process's merged stdout/stderr streams
+ * @param out the {@link Writer} to receive the process's stdout stream (may be equal to err, but not null)
+ * @param err the {@link Writer} to receive the process's stderr stream (may be equal to out, but not null)
* @param args the command line
*
- * @returns all output generated on the program's stdout/stderr streams
+ * @see {@link NullWriter}
*/
- String executeBlocking(File workingDir, Writer out, String... args);
+ void executeBlocking(File workingDir, Writer out, Writer err, String... args) throws IOException;
/**
* Runs the program and returns immediately.
*
* @param workingDir the working directory from which the program should be started
- * @param outs the {@link Writer}s to receive the process's merged stdout/stderr streams
+ * @param out the {@link Writer} to receive the process's stdout stream (may be equal to err, but not null)
+ * @param err the {@link Writer} to receive the process's stderr stream (may be equal to out, but not null)
* @param args the command line
*
* @return the running process
+ *
+ * @see {@link NullWriter}
*/
- Process executeNonblocking(File workingDir, Writer out, String... args) throws IOException;
+ Process executeNonblocking(File workingDir, Writer out, Writer err, String... args) throws IOException;
}
@@ -4,11 +4,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.io.StringWriter;
import java.io.Writer;
-import java.util.ArrayList;
-import java.util.List;
-import net.sf.eclipsefp.haskell.core.internal.util.MultiplexedWriter;
import net.sf.eclipsefp.haskell.core.internal.util.StreamRedirect;
public class ProcessRunner implements IProcessRunner {
@@ -23,34 +19,32 @@ public ProcessRunner( final IProcessFactory factory ) {
fProcessFactory = factory;
}
- public String executeBlocking( final File workingDir, final Writer out,
- final String ... args ) {
- List<Exception> excList = new ArrayList<Exception>();
- StringWriter returnedOut = new StringWriter();
- try {
- Writer outs = new MultiplexedWriter(returnedOut, out);
- Process proc = doExecute( workingDir, args );
- Thread outRedirect = redirect( new InputStreamReader(proc.getInputStream()), outs );
+ public void executeBlocking( final File workingDir, final Writer out,
+ final Writer err, final String ... args ) throws IOException {
+
+ Process proc = doExecute( workingDir, args );
+ Thread outRedirect = redirect( new InputStreamReader( proc.getInputStream() ), out );
+ Thread errRedirect = redirect( new InputStreamReader( proc.getErrorStream() ), err );
+
+ try {
proc.waitFor(); // wait for process to finish
outRedirect.join(); // wait until out stream content is redirected
- } catch( Exception e ) {
- excList.add( e );
- } finally {
- returnedOut.flush();
+ errRedirect.join(); // wait until err stream content is redirected
+ } catch (InterruptedException ex) {
+ // ignore
}
-
- return returnedOut.toString();
}
- public Process executeNonblocking( final File workingDir,
- final Writer out, final String... args ) throws IOException {
+ public Process executeNonblocking( final File workingDir, final Writer out,
+ final Writer err, final String ... args ) throws IOException {
Process proc = doExecute( workingDir, args );
- redirect( new InputStreamReader(proc.getInputStream()), out );
+ redirect( new InputStreamReader( proc.getInputStream() ), out );
+ redirect( new InputStreamReader( proc.getErrorStream() ), err );
return proc;
}
- private Process doExecute( final File workingDir, final String... args )
+ private Process doExecute( final File workingDir, final String ... args )
throws IOException {
Process proc = fProcessFactory.startProcess( workingDir, args );
return proc;
@@ -1,7 +1,7 @@
// Copyright (c) 2003-2008 by Leif Frenzel. All rights reserved.
// This code is made available under the terms of the Eclipse Public License,
// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
-package net.sf.eclipsefp.haskell.debug.ui.test.internal;
+package net.sf.eclipsefp.haskell.debug.ui.test;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -15,3 +15,4 @@ Require-Bundle: net.sf.eclipsefp.haskell.core,
org.junit
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: net.sf.eclipsefp.haskell.debug.ui.test
@@ -13,3 +13,4 @@ Require-Bundle: org.easymock;bundle-version="[2.2.0,3.0.0)",
net.sf.eclipsefp.haskell.core.test
Export-Package: net.sf.eclipsefp.haskell.ghccompiler.test
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: net.sf.eclipsefp.haskell.scion.types
Oops, something went wrong.

0 comments on commit b0128ed

Please sign in to comment.