|
From: <mba...@us...> - 2007-01-31 22:31:16
|
Revision: 1903
http://svn.sourceforge.net/rubyeclipse/?rev=1903&view=rev
Author: mbarchfe
Date: 2007-01-31 14:31:15 -0800 (Wed, 31 Jan 2007)
Log Message:
-----------
Added better abstraction for debugger access since we need two socket connections for rubydebug
Modified Paths:
--------------
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_AbstractDebuggerCommunicationTest.java
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_ClassicDebuggerCommunicationTest.java
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerProxyTest.java
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_RubyDebugCommunicationTest.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RDebugVMDebugger.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMDebugger.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_Single.java
Modified: trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_AbstractDebuggerCommunicationTest.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_AbstractDebuggerCommunicationTest.java 2007-01-31 22:28:56 UTC (rev 1902)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_AbstractDebuggerCommunicationTest.java 2007-01-31 22:31:15 UTC (rev 1903)
@@ -1,34 +1,33 @@
package org.rubypeople.rdt.debug.core.tests;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.PrintWriter;
-import java.net.ConnectException;
-import java.net.Socket;
import junit.framework.TestCase;
import org.rubypeople.rdt.internal.debug.core.ExceptionSuspensionPoint;
import org.rubypeople.rdt.internal.debug.core.StepSuspensionPoint;
import org.rubypeople.rdt.internal.debug.core.SuspensionPoint;
+import org.rubypeople.rdt.internal.debug.core.commands.AbstractCommand;
+import org.rubypeople.rdt.internal.debug.core.commands.AbstractDebuggerConnection;
+import org.rubypeople.rdt.internal.debug.core.commands.BreakpointCommand;
+import org.rubypeople.rdt.internal.debug.core.commands.GenericCommand;
+import org.rubypeople.rdt.internal.debug.core.commands.StepCommand;
import org.rubypeople.rdt.internal.debug.core.model.RubyProcessingException;
import org.rubypeople.rdt.internal.debug.core.model.RubyStackFrame;
import org.rubypeople.rdt.internal.debug.core.model.RubyThread;
import org.rubypeople.rdt.internal.debug.core.model.RubyVariable;
import org.rubypeople.rdt.internal.debug.core.model.ThreadInfo;
-import org.rubypeople.rdt.internal.debug.core.parsing.BreakpointAddedReader;
+import org.rubypeople.rdt.internal.debug.core.parsing.AbstractReadStrategy;
+import org.rubypeople.rdt.internal.debug.core.parsing.BreakpointModificationReader;
import org.rubypeople.rdt.internal.debug.core.parsing.EvalReader;
import org.rubypeople.rdt.internal.debug.core.parsing.FramesReader;
import org.rubypeople.rdt.internal.debug.core.parsing.LoadResultReader;
-import org.rubypeople.rdt.internal.debug.core.parsing.MultiReaderStrategy;
import org.rubypeople.rdt.internal.debug.core.parsing.SuspensionReader;
import org.rubypeople.rdt.internal.debug.core.parsing.ThreadInfoReader;
import org.rubypeople.rdt.internal.debug.core.parsing.VariableReader;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserFactory;
public abstract class FTC_AbstractDebuggerCommunicationTest extends TestCase {
@@ -61,16 +60,13 @@
protected OutputRedirectorThread rubyStderrRedirectorThread;
- private Socket socket;
+ private AbstractDebuggerConnection debuggerConnection;
- private PrintWriter out;
-
- private MultiReaderStrategy multiReaderStrategy;
-
// for timeout handling
private Thread mainThread;
private Thread timeoutThread;
+ private AbstractReadStrategy readStrategy;
public FTC_AbstractDebuggerCommunicationTest(String arg0) {
super(arg0);
@@ -88,57 +84,45 @@
return getTestFilename().replace('\\', '/');
}
- protected XmlPullParser getXpp(Socket socket) throws Exception {
-
- XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
- "org.kxml2.io.KXmlParser,org.kxml2.io.KXmlSerializer", null);
- XmlPullParser xpp = factory.newPullParser();
- xpp.setInput(new BufferedReader(new InputStreamReader(socket
- .getInputStream())));
- return xpp;
- }
-
protected SuspensionReader getSuspensionReader() throws Exception {
- return new SuspensionReader(multiReaderStrategy);
+ return new SuspensionReader(readStrategy);
}
protected VariableReader getVariableReader() throws Exception {
- return new VariableReader(multiReaderStrategy);
+ return new VariableReader(readStrategy);
}
protected EvalReader getEvalExceptionReader() throws Exception {
- return new EvalReader(multiReaderStrategy);
+ return new EvalReader(readStrategy);
}
protected FramesReader getFramesReader() throws Exception {
- return new FramesReader(multiReaderStrategy);
+ return new FramesReader(readStrategy);
}
protected ThreadInfoReader getThreadInfoReader() throws Exception {
- return new ThreadInfoReader(multiReaderStrategy);
+ return new ThreadInfoReader(readStrategy);
}
protected LoadResultReader getLoadResultReader() throws Exception {
- return new LoadResultReader(multiReaderStrategy);
+ return new LoadResultReader(readStrategy);
}
-
+
protected EvalReader getEvalReader() throws Exception {
- return new EvalReader(multiReaderStrategy);
+ return new EvalReader(readStrategy);
}
-
- protected BreakpointAddedReader getBreakpointAddedReader() throws Exception {
- return new BreakpointAddedReader(multiReaderStrategy);
- }
+ protected BreakpointModificationReader getBreakpointAddedReader() throws Exception {
+ return new BreakpointModificationReader(readStrategy);
+ }
+
protected String getOSIndependent(String path) {
return path.replace('\\', '/');
}
public void setUp() throws Exception {
- if (!new File(getTmpDir()).exists()
- || !new File(getTmpDir()).isDirectory()) {
- throw new RuntimeException("Temp directory does not exist: "
- + getTmpDir());
+ if (!new File(getTmpDir()).exists() || !new File(getTmpDir()).isDirectory()) {
+ throw new RuntimeException("Temp directory does not exist: " + getTmpDir());
}
// if a reader hangs, because the expected data from the ruby process
// does not arrive, it gets interrupted from the timeout watchdog.
@@ -158,13 +142,13 @@
}
};
timeoutThread.start();
- log("Setup finished.") ;
+ log("Setup finished.");
}
public void tearDown() {
- log("TearDown") ;
+ log("TearDown");
timeoutThread.interrupt();
- if (process == null || socket == null) {
+ if (process == null) {
// here we go if there was an error in the creation of the process
// (process == null)
// or there was an error creating the socket, e.g. ruby process has
@@ -177,15 +161,14 @@
e.printStackTrace();
}
try {
- socket.close();
+ debuggerConnection.exit();
} catch (IOException e) {
- log("Exception while closing socket.") ;
+ log("Exception while closing socket.");
e.printStackTrace();
}
try {
if (process.exitValue() != 0) {
- log("Ruby finished with exit value: "
- + process.exitValue());
+ log("Ruby finished with exit value: " + process.exitValue());
}
} catch (IllegalThreadStateException ex) {
process.destroy();
@@ -197,12 +180,12 @@
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
- log("Exception while sleeping after destroying the ruby process") ;
+ log("Exception while sleeping after destroying the ruby process");
// TODO: find out what causes interruption!
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
- log("Exception again while sleeping after destroying the ruby process") ;
+ log("Exception again while sleeping after destroying the ruby process");
}
}
}
@@ -211,7 +194,7 @@
try {
rubyStdoutRedirectorThread.join();
} catch (InterruptedException e) {
- log("Exception while waiting for stdout redirector") ;
+ log("Exception while waiting for stdout redirector");
e.printStackTrace();
}
log("..done");
@@ -219,212 +202,218 @@
try {
rubyStderrRedirectorThread.join();
} catch (InterruptedException e) {
- log("Exception while waiting for stderr redirector") ;
+ log("Exception while waiting for stderr redirector");
e.printStackTrace();
}
log("..done");
}
protected void writeFile(String name, String[] content) throws Exception {
- PrintWriter writer = new PrintWriter(new FileOutputStream(getTmpDir()
- + name));
+ PrintWriter writer = new PrintWriter(new FileOutputStream(getTmpDir() + name));
for (int i = 0; i < content.length; i++) {
writer.println(content[i]);
}
writer.close();
}
+ protected abstract AbstractDebuggerConnection createDebuggerConnection();
+
+ protected abstract void startRubyProcess() throws Exception;
+
protected void createSocket(String[] lines) throws Exception {
writeFile("test.rb", lines);
startRubyProcess();
Thread.sleep(1000);
- try {
- socket = new Socket("localhost", 1098);
- } catch (ConnectException cex) {
- throw new RuntimeException(
- "Ruby process finished prematurely. Last line in stderr: "
- + rubyStderrRedirectorThread.getLastLine(), cex);
- }
- multiReaderStrategy = new MultiReaderStrategy(getXpp(socket));
+ debuggerConnection = createDebuggerConnection();
+ debuggerConnection.connect();
+ // new AbstractDebuggerConnection
+ // try {
+ // socket = new Socket("localhost", 1098);
+ // } catch (ConnectException cex) {
+ // throw new RuntimeException(
+ // "Ruby process finished prematurely. Last line in stderr: "
+ // + rubyStderrRedirectorThread.getLastLine(), cex);
+ // }
+ // multiReaderStrategy = new MultiReaderStrategy(getXpp(socket));
-// Runnable runnable = new Runnable() {
-// public void run() {
-// try {
-// while (true) {
-// new WasteReader(multiReaderStrategy).read();
-// }
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// };
-// };
-// new Thread(runnable).start();
- Thread.sleep(500);
- out = new PrintWriter(socket.getOutputStream(), true);
- readSuspensionInFirstLine() ;
+ // Runnable runnable = new Runnable() {
+ // public void run() {
+ // try {
+ // while (true) {
+ // new WasteReader(multiReaderStrategy).read();
+ // }
+ // } catch (Exception e) {
+ // e.printStackTrace();
+ // }
+ // };
+ // };
+ // new Thread(runnable).start();
+ // Thread.sleep(500);
+ // out = new PrintWriter(socket.getOutputStream(), true);
+ // createControlSocket() ;
}
- protected abstract void startRubyProcess() throws Exception;
- protected void readSuspensionInFirstLine() throws Exception {
-
+ protected SuspensionReader startDebugger() throws Exception {
+ return debuggerConnection.start();
}
-
- protected void sendRuby(String debuggerCommand) {
+
+ protected void sendCommand(AbstractCommand command) throws Exception {
+ command.execute(debuggerConnection);
+ }
+
+ /*
+ * @deprecated
+ */
+ protected void sendRuby(String debuggerCommand) throws Exception {
try {
process.exitValue();
- throw new RuntimeException(
- "Ruby debugger has finished prematurely.");
+ throw new RuntimeException("Ruby debugger has finished prematurely.");
} catch (IllegalThreadStateException ex) {
// not yet finished, normal behaviour
// why does process does not have a function like isRunning() ?
- log("Sending: " + debuggerCommand);
- out.println(debuggerCommand);
+ // TODO: remove generic command
+ GenericCommand command = new GenericCommand(debuggerCommand, false /* iscontrol */);
+ command.execute(debuggerConnection);
+ readStrategy = command.getReadStrategy();
}
}
- public void testNameError() throws Exception {
- createSocket(new String[] { "puts 'x'" });
- sendRuby("cont");
- SuspensionPoint hit = getSuspensionReader().readSuspension();
- // TODO: assertion is wrong, I want the debugger to suspend here
- // but there must be several catchpoints available
- assertNull(hit);
+ // public void testNameError() throws Exception {
+ // createSocket(new String[] { "puts 'x'" });
+ // sendRuby("cont");
+ // SuspensionPoint hit = getSuspensionReader().readSuspension();
+ // // TODO: assertion is wrong, I want the debugger to suspend here
+ // // but there must be several catchpoints available
+ // assertNull(hit);
+ // }
+
+ protected void runToLine(int lineNumber) throws Exception {
+ runTo("test.rb", lineNumber);
}
- public void testBreakpointOnFirstLine() throws Exception {
- // Breakpoint in line 1 does not work yet.
- createSocket(new String[] { "puts 'a'" });
- sendRuby("b test.rb:1");
- sendRuby("cont");
- log("Waiting for breakpoint..");
- SuspensionPoint hit = getSuspensionReader().readSuspension();
+ private void runTo(String filename, int lineNumber) throws Exception {
+ String command = "b " + filename + ":" + lineNumber;
+ new BreakpointCommand(command).executeWithResult(debuggerConnection);
+ SuspensionReader reader;
+ if (!debuggerConnection.isCommandPortConnected()) {
+ reader = debuggerConnection.start();
+ } else {
+ StepCommand stepCommand = new StepCommand("cont");
+ stepCommand.execute(debuggerConnection);
+ reader = stepCommand.getSuspensionReader();
+ }
+ SuspensionPoint hit = reader.readSuspension();
assertNotNull(hit);
assertTrue(hit.isBreakpoint());
- assertEquals(1, hit.getLine());
+ assertEquals(lineNumber, hit.getLine());
}
+ public void testBreakpointOnFirstLine() throws Exception {
+ createSocket(new String[] { "puts 'a'" });
+ runTo("test.rb", 1);
+ }
+
public void testBreakpointAddAndRemove() throws Exception {
createSocket(new String[] { "1.upto(3) {", "puts 'a'", "puts 'b'", "puts 'c'", "}" });
+ int breakpointId1 = new BreakpointCommand("b test.rb:2").executeWithResult(debuggerConnection);
+ assertEquals(1, breakpointId1);
+ int breakpointId2 = new BreakpointCommand("b test.rb:4").executeWithResult(debuggerConnection);
+ assertEquals(2, breakpointId2);
+
+ SuspensionPoint hit1 = startDebugger().readSuspension();
+ assertBreakpoint(hit1, "test.rb", 2);
+ SuspensionPoint hit2 = new StepCommand("cont").readSuspension(debuggerConnection);
+ assertBreakpoint(hit2, "test.rb", 4);
+ SuspensionPoint hit3 = new StepCommand("cont").readSuspension(debuggerConnection);
+ assertBreakpoint(hit3, "test.rb", 2);
+ int idDeleted = new BreakpointCommand("delete 100").executeWithResult(debuggerConnection);
+ assertEquals(-1, idDeleted);
+ idDeleted = new BreakpointCommand("delete 2").executeWithResult(debuggerConnection);
+ assertEquals(2, idDeleted);
+ SuspensionPoint hit4 = new StepCommand("cont").readSuspension(debuggerConnection);
+ assertBreakpoint(hit4, "test.rb", 2);
+ SuspensionPoint hit5 = new StepCommand("cont").readSuspension(debuggerConnection);
+ assertNull("null expected, but was: " + hit5, hit5);
+ }
+
+ public void testSimpleCycleSteppingWorks() throws Exception {
+ createSocket(new String[] { "1.upto(2) {", "puts 'a'", "}", "puts 'b'" });
+ int breakpointId1 = new BreakpointCommand("b test.rb:2").executeWithResult(debuggerConnection);
+ assertEquals(1, breakpointId1);
+ int breakpointId2 = new BreakpointCommand("b test.rb:4").executeWithResult(debuggerConnection);
+ assertEquals(2, breakpointId2);
+ SuspensionReader reader = startDebugger();
+ assertBreakpoint(reader.readSuspension(), "test.rb", 2);
+ sendRuby("cont"); // 2 -> 2
+ assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
+ sendRuby("cont"); // 2 -> 2
+ assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 4);
+ sendRuby("cont"); // 4 -> finish
+ SuspensionPoint hit = getSuspensionReader().readSuspension();
+ assertNull("null expected, but was: " + hit, hit);
+ }
+
+ public void testStoppingOnOneLineTwice() throws Exception {
+ createSocket(new String[] { "1.upto(2) {", "if true", "puts 'a'", "end", "}", "puts 'b'" });
sendRuby("b test.rb:2");
- assertEquals(1, getBreakpointAddedReader().readBreakpointNo()) ;
- sendRuby("b test.rb:4");
- assertEquals(2, getBreakpointAddedReader().readBreakpointNo()) ;
- sendRuby("cont"); // -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> 4
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 4);
- sendRuby("cont"); // 4 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("delete -1"); // should be ignored
- sendRuby("delete 100"); // should be ignored
- sendRuby("delete 2");
- sendRuby("cont"); // 2 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> finish
+ assertEquals(1, getBreakpointAddedReader().readBreakpointNo());
+ sendRuby("b test.rb:6");
+ assertEquals(2, getBreakpointAddedReader().readBreakpointNo());
+ sendRuby("cont"); // -> 2
+ assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
+ sendRuby("cont"); // 2 -> 2
+ assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
+ sendRuby("cont"); // 2 -> 2
+ assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
+ sendRuby("cont"); // 2 -> 2
+ assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
+ sendRuby("cont"); // 2 -> 2
+ assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 6);
+ sendRuby("cont"); // 6 -> finish
SuspensionPoint hit = getSuspensionReader().readSuspension();
- assertNull("null expected, but was: " + hit, hit);
- }
-
- public void testSimpleCycleSteppingWorks() throws Exception {
- createSocket(new String[] { "1.upto(2) {", "puts 'a'", "}", "puts 'b'" });
- sendRuby("b test.rb:2");
- assertEquals(1, getBreakpointAddedReader().readBreakpointNo());
- sendRuby("b test.rb:4");
- assertEquals(2, getBreakpointAddedReader().readBreakpointNo());
- sendRuby("cont"); // -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 4);
- sendRuby("cont"); // 4 -> finish
- SuspensionPoint hit = getSuspensionReader().readSuspension();
- assertNull("null expected, but was: " + hit, hit);
- }
-
- public void testStoppingOnOneLineTwice() throws Exception {
- createSocket(new String[] {
- "1.upto(2) {", "if true", "puts 'a'", "end", "}", "puts 'b'" });
- sendRuby("b test.rb:2");
- assertEquals(1, getBreakpointAddedReader().readBreakpointNo());
- sendRuby("b test.rb:6");
- assertEquals(2, getBreakpointAddedReader().readBreakpointNo());
- sendRuby("cont"); // -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 2);
- sendRuby("cont"); // 2 -> 2
- assertBreakpoint(getSuspensionReader().readSuspension(), "test.rb", 6);
- sendRuby("cont"); // 6 -> finish
- SuspensionPoint hit = getSuspensionReader().readSuspension();
- assertNull("null expected, but was: " + hit, hit);
- }
-
- public void assertBreakpoint(SuspensionPoint hit, String file, int line) {
- assertNotNull(hit);
+ assertNull("null expected, but was: " + hit, hit);
+ }
+
+ public void assertBreakpoint(SuspensionPoint hit, String file, int line) {
+ assertNotNull(hit);
assertTrue(hit.isBreakpoint());
- assertEquals(line, hit.getLine());
- assertEquals(file, hit.getFile());
+ assertEquals(line, hit.getLine());
+ assertEquals(file, hit.getFile());
}
-
+
public void testException() throws Exception {
// per default catch is set to StandardError, i.e. every raise of a
// subclass of StandardError
// will suspend
- createSocket(new String[] { "puts 'a'",
- "raise 'message \\dir\\file: <xml/>\n<8>'", "puts 'c'" });
- sendRuby("catch StandardError");
- sendRuby("cont");
- log("Waiting for exception");
- SuspensionPoint hit = getSuspensionReader().readSuspension();
+ createSocket(new String[] { "puts 'a'", "raise 'message \\dir\\file: <xml/>\n<8>'", "puts 'c'" });
+ GenericCommand catchCommand = new GenericCommand("catch StandardError", true /* iscontrol */);
+ catchCommand.execute(debuggerConnection);
+ SuspensionPoint hit = startDebugger().readSuspension();
assertNotNull(hit);
assertEquals(3, hit.getLine());
assertEquals(getOSIndependent(getTmpDir() + "test.rb"), hit.getFile());
assertTrue(hit.isException());
- assertEquals("message \\dir\\file: <xml/> <8>",
- ((ExceptionSuspensionPoint) hit).getExceptionMessage());
- assertEquals("RuntimeError", ((ExceptionSuspensionPoint) hit)
- .getExceptionType());
+ assertEquals("message \\dir\\file: <xml/> <8>", ((ExceptionSuspensionPoint) hit).getExceptionMessage());
+ assertEquals("RuntimeError", ((ExceptionSuspensionPoint) hit).getExceptionType());
+ // TODO: test catch off with a second exception
sendRuby("catch off");
sendRuby("cont");
}
- public void testIgnoreException() throws Exception {
- createSocket(new String[] { "puts 'a'", "raise 'dont stop'" });
- sendRuby("catch off");
- sendRuby("cont");
- System.out
- .println("Waiting for the program to finish without suspending at the raise command");
- SuspensionPoint hit = getSuspensionReader().readSuspension();
- assertNull(hit);
- }
-
public void testExceptionsIgnoredByDefault() throws Exception {
createSocket(new String[] { "puts 'a'", "raise 'dont stop'" });
- sendRuby("cont");
- System.out
- .println("Waiting for the program to finish without suspending at the raise command");
- SuspensionPoint hit = getSuspensionReader().readSuspension();
+ SuspensionPoint hit = startDebugger().readSuspension();
assertNull(hit);
}
public void testExceptionHierarchy() throws Exception {
- createSocket(new String[] { "class MyError < StandardError", "end",
- "begin", "raise StandardError.new", "rescue", "end",
- "raise MyError.new" });
- sendRuby("catch MyError");
- sendRuby("cont");
- System.out
- .println("Waiting for the program to finish without suspending at the raise command");
- SuspensionPoint hit = getSuspensionReader().readSuspension();
+ createSocket(new String[] { "class MyError < StandardError", "end", "begin", "raise StandardError.new", "rescue", "end", "raise MyError.new" });
+ GenericCommand catchCommand = new GenericCommand("catch StandardError", true /* iscontrol */);
+ catchCommand.execute(debuggerConnection);
+ SuspensionPoint hit = startDebugger().readSuspension();
assertNotNull(hit);
assertEquals(7, hit.getLine());
- assertEquals("MyError", ((ExceptionSuspensionPoint) hit)
- .getExceptionType());
+ assertEquals("MyError", ((ExceptionSuspensionPoint) hit).getExceptionType());
sendRuby("cont");
hit = getSuspensionReader().readSuspension();
assertNull(hit);
@@ -432,55 +421,38 @@
public void testBreakpointNeverReached() throws Exception {
createSocket(new String[] { "puts 'a'", "puts 'b'", "puts 'c'" });
- sendRuby("b test.rb:10");
- getBreakpointAddedReader().readBreakpointNo();
- sendRuby("cont");
+ new BreakpointCommand("b test.rb:10").executeWithResult(debuggerConnection);
log("Waiting for breakpoint..");
- SuspensionPoint hit = getSuspensionReader().readSuspension();
+ SuspensionPoint hit = startDebugger().readSuspension();
assertNull(hit);
}
private void log(String string) {
if (VERBOSE)
- System.out.println(string);
+ System.out.println(string);
}
public void testStepOver() throws Exception {
createSocket(new String[] { "puts 'a'", "puts 'b'", "puts 'c'" });
- sendRuby("b test.rb:2");
- getBreakpointAddedReader().readBreakpointNo();
- sendRuby("cont");
- getSuspensionReader().readSuspension();
- sendRuby("next");
- SuspensionPoint info = getSuspensionReader().readSuspension();
+ BreakpointCommand breakpointCommand = new BreakpointCommand("b test.rb:2");
+ sendCommand(breakpointCommand);
+ breakpointCommand.getBreakpointAddedReader().readBreakpointNo();
+
+ startDebugger().readSuspension();
+
+ SuspensionPoint info = new StepCommand("next").readSuspension(debuggerConnection);
assertEquals(3, info.getLine());
assertEquals(getOSIndependent(getTmpDir() + "test.rb"), info.getFile());
assertTrue(info.isStep());
assertEquals(1, ((StepSuspensionPoint) info).getFramesNumber());
- sendRuby("next");
- info = getSuspensionReader().readSuspension();
- assertNull(info);
- }
- public void testStepOverFrames() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "puts 'a'",
- "Test2.new.print()" });
- writeFile("test2.rb", new String[] { "class Test2", "def print",
- "puts 'XX'", "end", "end" });
- sendRuby("b test.rb:3");
- getBreakpointAddedReader().readBreakpointNo();
- sendRuby("cont");
- getSuspensionReader().readSuspension();
- sendRuby("next");
- SuspensionPoint info = getSuspensionReader().readSuspension();
+ info = new StepCommand("next").readSuspension(debuggerConnection);
assertNull(info);
}
- public void testStepOverFramesValue2() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "puts 'a'",
- "Test2.new.print()" });
- writeFile("test2.rb", new String[] { "class Test2", "def print",
- "puts 'XX'", "puts 'XX'", "end", "end" });
+ public void testStepOverFrames() throws Exception {
+ createSocket(new String[] { "require 'test2.rb'", "puts 'a'", "Test2.new.print()" });
+ writeFile("test2.rb", new String[] { "class Test2", "def print", "puts 'XX'", "puts 'XX'", "end", "end" });
runTo("test2.rb", 3);
sendRuby("next");
SuspensionPoint info = getSuspensionReader().readSuspension();
@@ -494,10 +466,8 @@
}
public void testStepOverInDifferentFrame() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "Test2.new.print()",
- "puts 'a'" });
- writeFile("test2.rb", new String[] { "class Test2", "def print",
- "puts 'XX'", "puts 'XX'", "end", "end" });
+ createSocket(new String[] { "require 'test2.rb'", "Test2.new.print()", "puts 'a'" });
+ writeFile("test2.rb", new String[] { "class Test2", "def print", "puts 'XX'", "puts 'XX'", "end", "end" });
runTo("test2.rb", 4);
sendRuby("next");
SuspensionPoint info = getSuspensionReader().readSuspension();
@@ -509,10 +479,8 @@
}
public void testStepReturn() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "Test2.new.print()",
- "puts 'a'" });
- writeFile("test2.rb", new String[] { "class Test2", "def print",
- "puts 'XX'", "puts 'XX'", "end", "end" });
+ createSocket(new String[] { "require 'test2.rb'", "Test2.new.print()", "puts 'a'" });
+ writeFile("test2.rb", new String[] { "class Test2", "def print", "puts 'XX'", "puts 'XX'", "end", "end" });
runTo("test2.rb", 4);
sendRuby("next");
SuspensionPoint info = getSuspensionReader().readSuspension();
@@ -524,12 +492,9 @@
}
public void testHitBreakpointWhileSteppingOver() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "Test2.new.print()",
- "puts 'a'" });
- writeFile("test2.rb", new String[] { "class Test2", "def print",
- "puts 'XX'", "puts 'XX'", "end", "end" });
- sendRuby("b test2.rb:4");
- getBreakpointAddedReader().readBreakpointNo();
+ createSocket(new String[] { "require 'test2.rb'", "Test2.new.print()", "puts 'a'" });
+ writeFile("test2.rb", new String[] { "class Test2", "def print", "puts 'XX'", "puts 'XX'", "end", "end" });
+ new BreakpointCommand("b test2.rb:4").executeWithResult(debuggerConnection);
runTo("test.rb", 2);
sendRuby("next");
SuspensionPoint info = getSuspensionReader().readSuspension();
@@ -540,10 +505,8 @@
}
public void testStepInto() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "puts 'a'",
- "Test2.new.print()" });
- writeFile("test2.rb", new String[] { "class Test2", "def print",
- "puts 'XX'", "puts 'XX'", "end", "end" });
+ createSocket(new String[] { "require 'test2.rb'", "puts 'a'", "Test2.new.print()" });
+ writeFile("test2.rb", new String[] { "class Test2", "def print", "puts 'XX'", "puts 'XX'", "end", "end" });
runTo("test.rb", 3);
sendRuby("step");
SuspensionPoint info = getSuspensionReader().readSuspension();
@@ -554,46 +517,28 @@
sendRuby("cont");
}
- protected void runToLine(int lineNumber) throws Exception {
- runTo("test.rb", lineNumber);
- }
-
- private void runTo(String filename, int lineNumber) throws Exception {
- sendRuby("b " + filename + ":" + lineNumber);
- getBreakpointAddedReader().readBreakpointNo() ;
- sendRuby("cont");
- SuspensionPoint suspension = getSuspensionReader().readSuspension();
- if (suspension == null) {
- throw new RuntimeException(
- "Expected suspension, but program exited.");
- }
- }
-
protected RubyStackFrame createStackFrame() throws Exception {
RubyStackFrame stackFrame = new RubyStackFrame(null, "", 5, 1); // RubyThread
- // thread
- // = new
- // RubyThread(null)
- // ;
+ // thread
+ // = new
+ // RubyThread(null)
+ // ;
// thread.addStackFrame(stackFrame) ;
return stackFrame;
}
-
+
public void testCommandList() throws Exception {
// test that commands separated by comma will be processed
createSocket(new String[] { "a=5", "puts a" });
runToLine(2);
sendRuby("v l ; v i a");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
- variables = getVariableReader().readVariables(
- createStackFrame());
+ variables = getVariableReader().readVariables(createStackFrame());
assertEquals(0, variables.length);
// escaped semicolon
sendRuby("v inspect a=1\\;a+1");
- variables = getVariableReader().readVariables(
- createStackFrame());
+ variables = getVariableReader().readVariables(createStackFrame());
assertEquals("Handled escaded semicolon", 1, variables.length);
assertEquals("2", variables[0].getValue().getValueString());
sendRuby("cont");
@@ -603,8 +548,7 @@
createSocket(new String[] { "puts 'a'", "puts 'b'", "stringA='XX'" });
runToLine(2);
sendRuby("v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("stringA", variables[0].getName());
assertEquals("nil", variables[0].getValue().getValueString());
@@ -614,16 +558,13 @@
}
public void testVariableWithXmlContent() throws Exception {
- createSocket(new String[] { "stringA='<start test=\"&\"/>'",
- "testHashValue=Hash[ '$&' => nil]", "puts 'b'" });
+ createSocket(new String[] { "stringA='<start test=\"&\"/>'", "testHashValue=Hash[ '$&' => nil]", "puts 'b'" });
runToLine(3);
sendRuby("v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(2, variables.length);
assertEquals("stringA", variables[0].getName());
- assertEquals("<start test=\"&\"/>", variables[0].getValue()
- .getValueString());
+ assertEquals("<start test=\"&\"/>", variables[0].getValue().getValueString());
assertTrue(variables[0].isLocal());
// the testHashValue contains an example, where the name consists of
// special characters
@@ -635,14 +576,11 @@
}
public void testVariableInObject() throws Exception {
- createSocket(new String[] { "class Test", "def initialize", "@y=5",
- "puts @y", "end", "def to_s", "'test'", "end", "end",
- "Test.new()" });
+ createSocket(new String[] { "class Test", "def initialize", "@y=5", "puts @y", "end", "def to_s", "'test'", "end", "end", "Test.new()" });
runTo("test.rb", 4);
// Read numerical variable
sendRuby("v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("self", variables[0].getName());
assertEquals("test", variables[0].getValue().getValueString());
@@ -662,13 +600,10 @@
}
public void testStaticVariables() throws Exception {
- createSocket(new String[] { "class Test", "@@staticVar=55",
- "def method", "puts 'a'", "end", "end", "test=Test.new()",
- "test.method()" });
+ createSocket(new String[] { "class Test", "@@staticVar=55", "def method", "puts 'a'", "end", "end", "test=Test.new()", "test.method()" });
runTo("test.rb", 4);
sendRuby("v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("self", variables[0].getName());
assertTrue(variables[0].getValue().hasVariables());
@@ -686,13 +621,10 @@
}
public void testSingletonStaticVariables() throws Exception {
- createSocket(new String[] { "class Test", "def method", "puts 'a'",
- "end", "class << Test", "@@staticVar=55", "end", "end",
- "Test.new().method()" });
+ createSocket(new String[] { "class Test", "def method", "puts 'a'", "end", "class << Test", "@@staticVar=55", "end", "end", "Test.new().method()" });
runTo("test.rb", 3);
sendRuby("v i self");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("@@staticVar", variables[0].getName());
assertEquals("55", variables[0].getValue().getValueString());
@@ -705,12 +637,10 @@
}
public void testConstants() throws Exception {
- createSocket(new String[] { "class Test", "TestConstant=5", "end",
- "test=Test.new()", "puts 'a'" });
+ createSocket(new String[] { "class Test", "TestConstant=5", "end", "test=Test.new()", "puts 'a'" });
runTo("test.rb", 5);
sendRuby("v i test");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("TestConstant", variables[0].getName());
assertEquals("5", variables[0].getValue().getValueString());
@@ -724,13 +654,10 @@
}
public void testConstantDefinedInBothClassAndSuperclass() throws Exception {
- createSocket(new String[] { "class A", "TestConstant=5",
- "TestConstant2=2", "end", "class B < A", "TestConstant=6",
- "end", "b=B.new()", "puts 'a'" });
+ createSocket(new String[] { "class A", "TestConstant=5", "TestConstant2=2", "end", "class B < A", "TestConstant=6", "end", "b=B.new()", "puts 'a'" });
runTo("test.rb", 9);
sendRuby("v i b");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("TestConstant", variables[0].getName());
assertEquals("6", variables[0].getValue().getValueString());
@@ -748,8 +675,7 @@
runToLine(2);
// Read numerical variable
sendRuby("v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("stringA", variables[0].getName());
assertEquals("XX", variables[0].getValue().getValueString());
@@ -759,37 +685,29 @@
}
public void testVariableLocal() throws Exception {
- createSocket(new String[] { "class User", "def initialize(id)",
- "@id=id", "end", "end", "class CallClass", "def method(user)",
- "puts user", "end", "end", "CallClass.new.method(User.new(22))" });
+ createSocket(new String[] { "class User", "def initialize(id)", "@id=id", "end", "end", "class CallClass", "def method(user)", "puts user", "end", "end", "CallClass.new.method(User.new(22))" });
runTo("test.rb", 8);
sendRuby("v local");
- RubyVariable[] localVariables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] localVariables = getVariableReader().readVariables(createStackFrame());
assertEquals(2, localVariables.length);
RubyVariable userVariable = localVariables[1];
// sendRuby("v i 1 " + userVariable.getObjectId());
sendRuby("v i " + userVariable.getObjectId());
- RubyVariable[] userVariables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] userVariables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, userVariables.length);
assertEquals("@id", userVariables[0].getName());
assertEquals("22", userVariables[0].getValue().getValueString());
- assertEquals("Fixnum", userVariables[0].getValue()
- .getReferenceTypeName());
+ assertEquals("Fixnum", userVariables[0].getValue().getReferenceTypeName());
assertTrue(!userVariables[0].getValue().hasVariables());
sendRuby("cont");
}
public void testVariableInstance() throws Exception {
- createSocket(new String[] { "require 'test2.rb'",
- "customObject=Test2.new", "puts customObject" });
- writeFile("test2.rb", new String[] { "class Test2", "def initialize",
- "@y=5", "end", "def to_s", "'test'", "end", "end" });
+ createSocket(new String[] { "require 'test2.rb'", "customObject=Test2.new", "puts customObject" });
+ writeFile("test2.rb", new String[] { "class Test2", "def initialize", "@y=5", "end", "def to_s", "'test'", "end", "end" });
runTo("test2.rb", 6);
sendRuby("frame 2 ; v i customObject");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("@y", variables[0].getName());
assertEquals("5", variables[0].getValue().getValueString());
@@ -799,18 +717,15 @@
}
public void testVariableArray() throws Exception {
- createSocket(new String[] { "array = []", "array << 1", "array << 2",
- "puts 'a'" });
+ createSocket(new String[] { "array = []", "array << 1", "array << 2", "puts 'a'" });
runTo("test.rb", 4);
sendRuby("v local");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("array", variables[0].getName());
assertTrue("array has children", variables[0].getValue().hasVariables());
sendRuby("v i array");
- RubyVariable[] elements = getVariableReader().readVariables(
- variables[0]);
+ RubyVariable[] elements = getVariableReader().readVariables(variables[0]);
assertEquals(2, elements.length);
assertEquals("[0]", elements[0].getName());
assertEquals("1", elements[0].getValue().getValueString());
@@ -820,18 +735,15 @@
}
public void testVariableHashWithStringKeys() throws Exception {
- createSocket(new String[] { "hash = Hash['a' => 'z', 'b' => 'y']",
- "puts 'a'" });
+ createSocket(new String[] { "hash = Hash['a' => 'z', 'b' => 'y']", "puts 'a'" });
runTo("test.rb", 2);
sendRuby("v local");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("hash", variables[0].getName());
assertTrue("hash has children", variables[0].getValue().hasVariables());
sendRuby("v i hash");
- RubyVariable[] elements = getVariableReader().readVariables(
- variables[0]);
+ RubyVariable[] elements = getVariableReader().readVariables(variables[0]);
assertEquals(2, elements.length);
assertEquals("'a'", elements[0].getName());
assertEquals("z", elements[0].getValue().getValueString());
@@ -841,25 +753,19 @@
}
public void testVariableHashWithObjectKeys() throws Exception {
- createSocket(new String[] { "class KeyAndValue", "def initialize(v)",
- "@a=v", "end", "def to_s", "return @a.to_s", "end", "end",
- "hash = Hash[KeyAndValue.new(55) => KeyAndValue.new(66)]",
- "puts 'a'" });
+ createSocket(new String[] { "class KeyAndValue", "def initialize(v)", "@a=v", "end", "def to_s", "return @a.to_s", "end", "end", "hash = Hash[KeyAndValue.new(55) => KeyAndValue.new(66)]", "puts 'a'" });
runTo("test.rb", 10);
sendRuby("v local");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("hash", variables[0].getName());
assertTrue("hash has children", variables[0].getValue().hasVariables());
sendRuby("frame 1 ; v i " + variables[0].getObjectId());
- RubyVariable[] elements = getVariableReader().readVariables(
- variables[0]);
+ RubyVariable[] elements = getVariableReader().readVariables(variables[0]);
assertEquals(1, elements.length);
assertEquals("55", elements[0].getName());
// assertEquals("z", elements[0].getValue().getValueString());
- assertEquals("KeyAndValue", elements[0].getValue()
- .getReferenceTypeName());
+ assertEquals("KeyAndValue", elements[0].getValue().getReferenceTypeName());
// get the value
sendRuby("frame 1 ; v i " + elements[0].getObjectId());
RubyVariable[] values = getVariableReader().readVariables(variables[0]);
@@ -874,23 +780,18 @@
createSocket(new String[] { "emptyArray = []", "puts 'a'" });
runTo("test.rb", 2);
sendRuby("v local");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
assertEquals("emptyArray", variables[0].getName());
- assertTrue("array does not have children", !variables[0].getValue()
- .hasVariables());
+ assertTrue("array does not have children", !variables[0].getValue().hasVariables());
sendRuby("cont");
}
public void testVariableInstanceNested() throws Exception {
- createSocket(new String[] { "class Test", "def initialize(test)",
- "@privateTest = test", "end", "end",
- "test2 = Test.new(Test.new(nil))", "puts test2" });
+ createSocket(new String[] { "class Test", "def initialize(test)", "@privateTest = test", "end", "end", "test2 = Test.new(Test.new(nil))", "puts test2" });
runToLine(7);
sendRuby("v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(1, variables.length);
RubyVariable test2Variable = variables[0];
assertEquals("test2", test2Variable.getName());
@@ -900,91 +801,81 @@
assertEquals(1, variables.length);
RubyVariable privateTestVariable = variables[0];
assertEquals("@privateTest", privateTestVariable.getName());
- assertEquals("test2.@privateTest", privateTestVariable
- .getQualifiedName());
+ assertEquals("test2.@privateTest", privateTestVariable.getQualifiedName());
assertTrue(privateTestVariable.getValue().hasVariables());
sendRuby("v i " + privateTestVariable.getQualifiedName());
variables = getVariableReader().readVariables(privateTestVariable);
assertEquals(1, variables.length);
RubyVariable privateTestprivateTestVariable = variables[0];
assertEquals("@privateTest", privateTestprivateTestVariable.getName());
- assertEquals("test2.@privateTest.@privateTest",
- privateTestprivateTestVariable.getQualifiedName());
- assertEquals("nil", privateTestprivateTestVariable.getValue()
- .getValueString());
+ assertEquals("test2.@privateTest.@privateTest", privateTestprivateTestVariable.getQualifiedName());
+ assertEquals("nil", privateTestprivateTestVariable.getValue().getValueString());
assertTrue(!privateTestprivateTestVariable.getValue().hasVariables());
sendRuby("cont");
}
public void testInspect() throws Exception {
- createSocket(new String[] { "class Test", "def calc(a)", "a = a*2",
- "return a", "end", "end", "test=Test.new()", "a=3",
- "test.calc(a)" });
+ createSocket(new String[] { "class Test", "def calc(a)", "a = a*2", "return a", "end", "end", "test=Test.new()", "a=3", "test.calc(a)" });
runToLine(4);
// test variable value in stack 1 (top stack frame)
sendRuby("frame 1 ; v inspect a*2");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals("There is one variable returned.", 1, variables.length);
- assertEquals("Result in frame 1 is 12", "12", variables[0].getValue()
- .getValueString());
+ assertEquals("Result in frame 1 is 12", "12", variables[0].getValue().getValueString());
// test variable value in stack 2 (caller stack)
sendRuby("frame 2 ; v inspect a*2");
variables = getVariableReader().readVariables(createStackFrame());
assertEquals("There is one variable returned.", 1, variables.length);
- assertEquals("Result in frame 2 is 6", "6", variables[0].getValue()
- .getValueString());
+ assertEquals("Result in frame 2 is 6", "6", variables[0].getValue().getValueString());
// test more complex expression
sendRuby("frame 1 ; v inspect Test.new().calc(5)");
variables = getVariableReader().readVariables(createStackFrame());
assertEquals("There is one variable returned.", 1, variables.length);
- assertEquals("Result is 10", "10", variables[0].getValue()
- .getValueString());
+ assertEquals("Result is 10", "10", variables[0].getValue().getValueString());
sendRuby("cont");
}
-
+
public void testInspectTemporaryArray() throws Exception {
createSocket(new String[] { "a=0", "puts a=2" });
runToLine(2);
sendRuby("v inspect %w[a b c]");
// this inspection will create a new temporary arrray object
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals("There is one variable returned which contains the array.", 1, variables.length);
// the following two commands starts the garbage collector. This test
- // is somehow implementation aware. It makes sure that the objects which are
- // created as a result of an expression are referenced so that they will not be
+ // is somehow implementation aware. It makes sure that the objects which
+ // are
+ // created as a result of an expression are referenced so that they will
+ // not be
// swept away from the GC
- // TODO: actually garbage_collect does nothing, also the GC can not be enabled with GC.enable()
+ // TODO: actually garbage_collect does nothing, also the GC can not be
+ // enabled with GC.enable()
sendRuby("v inspect ObjectSpace.garbage_collect\\;sleep(2)");
- RubyVariable[] gcResult = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] gcResult = getVariableReader().readVariables(createStackFrame());
assertEquals("There is one variable returned as result of running the GC", 1, gcResult.length);
sendRuby("v i " + variables[0].getObjectId());
- RubyVariable[] elements = getVariableReader().readVariables(
- variables[0]);
+ RubyVariable[] elements = getVariableReader().readVariables(variables[0]);
assertEquals("The array contains 3 elements", 3, elements.length);
sendRuby("cont");
}
-
+
public void testInspectNil() throws Exception {
createSocket(new String[] { "puts 'dummy'", "puts 'dummy'" });
runToLine(2);
sendRuby("v inspect nil");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals("There is one variable returned which is nil.", 1, variables.length);
- assertEquals("nil", variables[0].getValue().getValueString()) ;
+ assertEquals("nil", variables[0].getValue().getValueString());
sendRuby("cont");
- }
-
+ }
+
public void testSendCommandWithSpecialCharacters() throws Exception {
- // the inspect command can contain arbitrary characters
- // a %w for example can raise an error when it is directly given to printf
+ // the inspect command can contain arbitrary characters
+ // a %w for example can raise an error when it is directly given to
+ // printf
sendRuby("v inspect %w[a b]");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
- assertEquals(1, variables.length) ;
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
+ assertEquals(1, variables.length);
sendRuby("cont");
// just do not fail
}
@@ -1002,13 +893,13 @@
}
fail("RubyProcessingException not thrown.");
}
-
+
public void testEvalError() throws Exception {
createSocket(new String[] { "puts 'test'", "puts 'test'" });
- runToLine(2);
- sendRuby("eval unknown_") ;
+ runToLine(2);
+ sendRuby("eval unknown_");
try {
- getEvalReader().readEvalResult() ;
+ getEvalReader().readEvalResult();
} catch (RubyProcessingException e) {
assertNotNull(e.getMessage());
sendRuby("cont");
@@ -1016,15 +907,12 @@
}
fail("RubyProcessingException not thrown.");
}
-
+
public void testStaticVariableInstanceNested() throws Exception {
- createSocket(new String[] { "class TestStatic", "def initialize(no)",
- "@no = no", "end", "@@staticVar=TestStatic.new(2)", "end",
- "test = TestStatic.new(1)", "puts test" });
+ createSocket(new String[] { "class TestStatic", "def initialize(no)", "@no = no", "end", "@@staticVar=TestStatic.new(2)", "end", "test = TestStatic.new(1)", "puts test" });
runToLine(8);
sendRuby("v i test.@@staticVar");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
assertEquals(2, variables.length);
assertEquals("@no", variables[0].getName());
assertEquals("2", variables[0].getValue().getValueString());
@@ -1033,14 +921,11 @@
}
public void testVariablesInFrames() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "y=5",
- "Test2.new().test()" });
- writeFile("test2.rb", new String[] { "class Test2", "def test", "y=6",
- "puts y", "end", "end" });
+ createSocket(new String[] { "require 'test2.rb'", "y=5", "Test2.new().test()" });
+ writeFile("test2.rb", new String[] { "class Test2", "def test", "y=6", "puts y", "end", "end" });
runTo("test2.rb", 4);
sendRuby("v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
+ RubyVariable[] variables = getVariableReader().readVariables(createStackFrame());
// there are 2 variables self and y
assertEquals(2, variables.length);
// the variables are sorted: self = variables[0], y = variables[1]
@@ -1056,7 +941,8 @@
assertEquals(1, variables.length);
assertEquals("y", variables[0].getName());
assertEquals("5", variables[0].getValue().getValueString());
- // 20 is out of range, then the top level (the one with the highest number)
+ // 20 is out of range, then the top level (the one with the highest
+ // number)
// will be used, in this case 2
sendRuby("frame 20 ; v l");
variables = getVariableReader().readVariables(createStackFrame());
@@ -1066,10 +952,8 @@
}
public void testFrames() throws Exception {
- createSocket(new String[] { "require 'test2.rb'", "test = Test2.new()",
- "test.print()", "test.print()" });
- writeFile("test2.rb", new String[] { "class Test2", "def print",
- "puts 'Test2.print'", "end", "end" });
+ createSocket(new String[] { "require 'test2.rb'", "test = Test2.new()", "test.print()", "test.print()" });
+ writeFile("test2.rb", new String[] { "class Test2", "def print", "puts 'Test2.print'", "end", "end" });
runTo("test2.rb", 3);
sendRuby("b test.rb:4");
getBreakpointAddedReader().readBreakpointNo();
@@ -1078,13 +962,11 @@
getFramesReader().readFrames(thread);
assertEquals(2, thread.getStackFrames().length);
RubyStackFrame frame1 = (RubyStackFrame) thread.getStackFrames()[0];
- assertEquals(getOSIndependent(getTmpDir() + "test2.rb"), frame1
- .getFileName());
+ assertEquals(getOSIndependent(getTmpDir() + "test2.rb"), frame1.getFileName());
assertEquals(1, frame1.getIndex());
assertEquals(3, frame1.getLineNumber());
RubyStackFrame frame2 = (RubyStackFrame) thread.getStackFrames()[1];
- assertEquals(getOSIndependent(getTmpDir() + "test.rb"), frame2
- .getFileName());
+ assertEquals(getOSIndependent(getTmpDir() + "test.rb"), frame2.getFileName());
assertEquals(2, frame2.getIndex());
assertEquals(3, frame2.getLineNumber());
sendRuby("cont");
@@ -1096,9 +978,7 @@
}
public void testFramesWhenThreadSpawned() throws Exception {
- createSocket(new String[] { "def startThread",
- "Thread.new() { a = 5 }", "end", "def calc", "5 + 5", "end",
- "startThread()", "calc()" });
+ createSocket(new String[] { "def startThread", "Thread.new() { a = 5 }", "end", "def calc", "5 + 5", "end", "startThread()", "calc()" });
runTo("test.rb", 5);
RubyThread thread = new RubyThread(null, 0);
sendRuby("w");
@@ -1107,8 +987,7 @@
}
public void testThreadFramesAndVariables() throws Exception {
- createSocket(new String[] { "Thread.new {", "a=5", "x=6", "puts 'x'",
- "}", "b=10", "b=11" });
+ createSocket(new String[] { "Thread.new {", "a=5", "x=6", "puts 'x'", "}", "b=10", "b=11" });
sendRuby("b test.rb:3");
getBreakpointAddedReader().readBreakpointNo();
sendRuby("b test.rb:7");
@@ -1120,16 +999,13 @@
sendRuby("th l");
ThreadInfo[] threads = getThreadInfoReader().readThreads();
assertEquals(2, threads.length);
-
-
- sendRuby("th "+threads[0].getId()+" ; w ");
- RubyStackFrame[] stackFrames = getFramesReader().readFrames(
- new RubyThread(null, 1));
+
+ sendRuby("th " + threads[0].getId() + " ; w ");
+ RubyStackFrame[] stackFrames = getFramesReader().readFrames(new RubyThread(null, 1));
assertEquals(1, stackFrames.length);
assertEquals(7, stackFrames[0].getLineNumber());
- sendRuby("th "+threads[0].getId()+" ; v l");
- RubyVariable[] variables = getVariableReader().readVariables(
- stackFrames[0]);
+ sendRuby("th " + threads[0].getId() + " ; v l");
+ RubyVariable[] variables = getVariableReader().readVariables(stackFrames[0]);
assertEquals(1, variables.length);
assertEquals("b", variables[0].getName());
sendRuby("th " + threads[1].getId() + " ; w");
Modified: trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_ClassicDebuggerCommunicationTest.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_ClassicDebuggerCommunicationTest.java 2007-01-31 22:28:56 UTC (rev 1902)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_ClassicDebuggerCommunicationTest.java 2007-01-31 22:31:15 UTC (rev 1903)
@@ -4,6 +4,8 @@
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.internal.debug.core.SuspensionPoint;
+import org.rubypeople.rdt.internal.debug.core.commands.AbstractDebuggerConnection;
+import org.rubypeople.rdt.internal.debug.core.commands.ClassicDebuggerConnection;
import org.rubypeople.rdt.internal.debug.core.model.RubyVariable;
import org.rubypeople.rdt.internal.debug.core.model.ThreadInfo;
import org.rubypeople.rdt.internal.debug.core.parsing.LoadResultReader;
@@ -28,7 +30,7 @@
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testThreadIdsAndResume"));
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testThreadFramesAndVariables"));
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testFrames"));
-// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testThreads"));
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testThreads"));
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testVariablesInFrames"));
@@ -39,7 +41,7 @@
//suite.addTest(new TC_DebuggerCommunicationTest("testVariablesInFrames"));
//suite.addTest(new TC_DebuggerCommunicationTest("testFramesWhenThreadSpawned"));
- //suite.addTest(new TC_DebuggerCommunicationTest("testThreadIdsAndResume"));
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testThreadIdsAndResume"));
//suite.addTest(new TC_DebuggerCommunicationTest("testThreadsAndFrames"));
//suite.addTest(new TC_DebuggerCommunicationTest("testStepOver"));
//suite.addTest(new TC_DebuggerCommunicationTest("testVariableNil"));
@@ -53,11 +55,11 @@
//suite.addTest(new TC_DebuggerCommunicationTest("testVariableString"));
// suite.addTest(new TC_DebuggerCommunicationTest("testInspect"));
//suite.addTest(new TC_DebuggerCommunicationTest("testInspectError"));
- //suite.addTest(new TC_DebuggerCommunicationTest("testReloadAndInspect")) ;
- //suite.addTest(new TC_DebuggerCommunicationTest("testReloadWithException")) ;
- //suite.addTest(new TC_DebuggerCommunicationTest("testReloadAndStep")) ;
- //suite.addTest(new TC_DebuggerCommunicationTest("testReloadInRequire")) ;
- //suite.addTest(new TC_DebuggerCommunicationTest("testReloadInStackFrame")) ;
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testReloadAndInspect")) ;
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testReloadWithException")) ;
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testReloadAndStep")) ;
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testReloadInRequire")) ;
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testReloadInStackFrame")) ;
// suite.addTest(new TC_DebuggerCommunicationTest("testIgnoreException"));
// suite.addTest(new TC_DebuggerCommunicationTest("testExceptionHierarchy"));
// suite.addTest(new TC_DebuggerCommunicationTest("testException"));
@@ -255,4 +257,9 @@
assertEquals("8", localVariables[0].getValue().getValueString());
}
+ @Override
+ protected AbstractDebuggerConnection createDebuggerConnection() {
+ return new ClassicDebuggerConnection(1098) ;
+ }
+
}
Modified: trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerProxyTest.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerProxyTest.java 2007-01-31 22:28:56 UTC (rev 1902)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerProxyTest.java 2007-01-31 22:31:15 UTC (rev 1903)
@@ -51,17 +51,18 @@
public void setUp() throws Exception {
target = new TestRubyDebugTarget() ;
- proxy = new RubyDebuggerProxy(target, false /*useRubyDebug*/) ;
+ //TODO: get proper directory
+ String rubyFileDirectory ="launching/ruby " ;
+ proxy = new RubyDebuggerProxy(target, rubyFileDirectory, false /*useRubyDebug*/) ;
PipedInputStream pipedInputStream = new PipedInputStream() ;
PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream) ;
- proxy.setWriter(new PrintWriter(pipedOutputStream)) ;
XmlPullParserFactory factory = XmlPullParserFactory.newInst...
[truncated message content] |