|
From: <mba...@us...> - 2006-12-30 09:43:00
|
Revision: 1745
http://svn.sourceforge.net/rubyeclipse/?rev=1745&view=rev
Author: mbarchfe
Date: 2006-12-30 01:42:59 -0800 (Sat, 30 Dec 2006)
Log Message:
-----------
next step for ruby debug integration
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_RubyDebugCommunicationTest.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/WasteReader.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 2006-12-30 09:42:35 UTC (rev 1744)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_AbstractDebuggerCommunicationTest.java 2006-12-30 09:42:59 UTC (rev 1745)
@@ -19,7 +19,9 @@
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.ErrorReader;
+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;
@@ -104,6 +106,10 @@
return new VariableReader(multiReaderStrategy);
}
+ protected EvalReader getEvalExceptionReader() throws Exception {
+ return new EvalReader(multiReaderStrategy);
+ }
+
protected FramesReader getFramesReader() throws Exception {
return new FramesReader(multiReaderStrategy);
}
@@ -115,6 +121,14 @@
protected LoadResultReader getLoadResultReader() throws Exception {
return new LoadResultReader(multiReaderStrategy);
}
+
+ protected EvalReader getEvalReader() throws Exception {
+ return new EvalReader(multiReaderStrategy);
+ }
+
+ protected BreakpointAddedReader getBreakpointAddedReader() throws Exception {
+ return new BreakpointAddedReader(multiReaderStrategy);
+ }
protected String getOSIndependent(String path) {
return path.replace('\\', '/');
@@ -211,7 +225,7 @@
System.out.println("..done");
}
- private void writeFile(String name, String[] content) throws Exception {
+ protected void writeFile(String name, String[] content) throws Exception {
PrintWriter writer = new PrintWriter(new FileOutputStream(getTmpDir()
+ name));
for (int i = 0; i < content.length; i++) {
@@ -220,10 +234,10 @@
writer.close();
}
- private void createSocket(String[] lines) throws Exception {
+ protected void createSocket(String[] lines) throws Exception {
writeFile("test.rb", lines);
startRubyProcess();
- Thread.sleep(500);
+ Thread.sleep(1000);
try {
socket = new Socket("localhost", 1098);
} catch (ConnectException cex) {
@@ -237,7 +251,7 @@
public void run() {
try {
while (true) {
- new ErrorReader(multiReaderStrategy).read();
+ new WasteReader(multiReaderStrategy).read();
}
} catch (Exception e) {
e.printStackTrace();
@@ -245,7 +259,7 @@
};
};
new Thread(runnable).start();
-
+ Thread.sleep(500);
out = new PrintWriter(socket.getOutputStream(), true);
readSuspensionInFirstLine() ;
}
@@ -255,7 +269,7 @@
}
- private void sendRuby(String debuggerCommand) {
+ protected void sendRuby(String debuggerCommand) {
try {
process.exitValue();
throw new RuntimeException(
@@ -293,7 +307,9 @@
// Breakpoint in line 1 does not work yet.
createSocket(new String[] { "puts 'a'", "puts 'a'", "puts 'a'" });
sendRuby("b test.rb:2");
+ assertEquals(1, getBreakpointAddedReader().readBreakpointNo()) ;
sendRuby("b test.rb:3");
+ assertEquals(2, getBreakpointAddedReader().readBreakpointNo()) ;
sendRuby("cont");
System.out.println("Waiting for breakpoint..");
SuspensionPoint hit = getSuspensionReader().readSuspension();
@@ -301,7 +317,10 @@
assertTrue(hit.isBreakpoint());
assertEquals(2, hit.getLine());
assertEquals("test.rb", hit.getFile());
- sendRuby("b remove test.rb:3");
+ sendRuby("delete -1");
+ sendRuby("delete 100");
+ sendRuby("delete 1");
+ sendRuby("delete 2");
sendRuby("cont");
hit = getSuspensionReader().readSuspension();
assertNull(hit);
@@ -369,6 +388,7 @@
public void testBreakpointNeverReached() throws Exception {
createSocket(new String[] { "puts 'a'", "puts 'b'", "puts 'c'" });
sendRuby("b test.rb:10");
+ getBreakpointAddedReader().readBreakpointNo();
sendRuby("cont");
System.out.println("Waiting for breakpoint..");
SuspensionPoint hit = getSuspensionReader().readSuspension();
@@ -378,6 +398,7 @@
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");
@@ -397,6 +418,7 @@
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");
@@ -457,6 +479,7 @@
writeFile("test2.rb", new String[] { "class Test2", "def print",
"puts 'XX'", "puts 'XX'", "end", "end" });
sendRuby("b test2.rb:4");
+ getBreakpointAddedReader().readBreakpointNo();
runTo("test.rb", 2);
sendRuby("next");
SuspensionPoint info = getSuspensionReader().readSuspension();
@@ -481,12 +504,13 @@
sendRuby("cont");
}
- private void runToLine(int lineNumber) throws Exception {
+ 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) {
@@ -713,7 +737,7 @@
writeFile("test2.rb", new String[] { "class Test2", "def initialize",
"@y=5", "end", "def to_s", "'test'", "end", "end" });
runTo("test2.rb", 6);
- sendRuby("v i 2 customObject");
+ sendRuby("frame 2 ; v i customObject");
RubyVariable[] variables = getVariableReader().readVariables(
createStackFrame());
assertEquals(1, variables.length);
@@ -778,7 +802,7 @@
assertEquals(1, variables.length);
assertEquals("hash", variables[0].getName());
assertTrue("hash has children", variables[0].getValue().hasVariables());
- sendRuby("v i 1 " + variables[0].getObjectId());
+ sendRuby("frame 1 ; v i " + variables[0].getObjectId());
RubyVariable[] elements = getVariableReader().readVariables(
variables[0]);
assertEquals(1, elements.length);
@@ -787,7 +811,7 @@
assertEquals("KeyAndValue", elements[0].getValue()
.getReferenceTypeName());
// get the value
- sendRuby("v i 1 " + elements[0].getObjectId());
+ sendRuby("frame 1 ; v i " + elements[0].getObjectId());
RubyVariable[] values = getVariableReader().readVariables(variables[0]);
assertEquals(1, values.length);
assertEquals("@a", values[0].getName());
@@ -866,6 +890,7 @@
assertEquals("There is one variable returned.", 1, variables.length);
assertEquals("Result is 10", "10", variables[0].getValue()
.getValueString());
+ sendRuby("cont");
}
public void testInspectTemporaryArray() throws Exception {
@@ -889,7 +914,7 @@
RubyVariable[] elements = getVariableReader().readVariables(
variables[0]);
assertEquals("The array contains 3 elements", 3, elements.length);
-
+ sendRuby("cont");
}
public void testInspectNil() throws Exception {
@@ -898,9 +923,9 @@
sendRuby("v inspect nil");
RubyVariable[] variables = getVariableReader().readVariables(
createStackFrame());
- assertEquals("There is one variable returned which contains the array.", 1, variables.length);
+ assertEquals("There is one variable returned which is nil.", 1, variables.length);
assertEquals("nil", variables[0].getValue().getValueString()) ;
-
+ sendRuby("cont");
}
public void testSendCommandWithSpecialCharacters() throws Exception {
@@ -910,22 +935,38 @@
RubyVariable[] variables = getVariableReader().readVariables(
createStackFrame());
assertEquals(1, variables.length) ;
+ sendRuby("cont");
// just do not fail
}
public void testInspectError() throws Exception {
- createSocket(new String[] { "puts 'test'" });
- runToLine(1);
+ createSocket(new String[] { "puts 'test'", "puts 'test'" });
+ runToLine(2);
sendRuby("v inspect a*2");
try {
getVariableReader().readVariables(createStackFrame());
} catch (RubyProcessingException e) {
assertNotNull(e.getMessage());
+ sendRuby("cont");
return;
}
fail("RubyProcessingException not thrown.");
}
-
+
+ public void testEvalError() throws Exception {
+ createSocket(new String[] { "puts 'test'", "puts 'test'" });
+ runToLine(2);
+ sendRuby("eval unknown_") ;
+ try {
+ getEvalReader().readEvalResult() ;
+ } catch (RubyProcessingException e) {
+ assertNotNull(e.getMessage());
+ sendRuby("cont");
+ return;
+ }
+ 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",
@@ -981,6 +1022,7 @@
"puts 'Test2.print'", "end", "end" });
runTo("test2.rb", 3);
sendRuby("b test.rb:4");
+ getBreakpointAddedReader().readBreakpointNo();
sendRuby("w");
RubyThread thread = new RubyThread(null, 0);
getFramesReader().readFrames(thread);
@@ -1014,62 +1056,13 @@
assertEquals(2, thread.getStackFramesSize());
}
- public void testThreads() throws Exception {
- createSocket(new String[] { "Thread.new {", "puts 'a'", "}",
- "Thread.pass", "puts 'b'" });
- sendRuby("b test.rb:2");
- sendRuby("b test.rb:5");
- sendRuby("cont");
- SuspensionPoint point1 = getSuspensionReader().readSuspension();
- sendRuby("th l");
- ThreadInfo[] threadInfos = getThreadInfoReader().readThreads();
- assertEquals(2, threadInfos.length);
- sendRuby("cont");
- SuspensionPoint point2 = getSuspensionReader().readSuspension();
- sendRuby("th l");
- threadInfos = getThreadInfoReader().readThreads();
- assertEquals(1, threadInfos.length);
- assertNotSame(point1.getThreadId(), point2.getThreadId());
- }
-
- public void testThreadIdsAndResume() throws Exception {
- createSocket(new String[] { "threads=[]", "threads << Thread.new {",
- "puts 'a'", "}", "threads << Thread.new{", "puts 'b'", "}",
- "puts 'c'", "threads.each{|t| t.join()}" });
- sendRuby("b test.rb:3");
- sendRuby("b test.rb:6");
- sendRuby("b test.rb:8");
- sendRuby("cont");
- getSuspensionReader().readSuspension();
- getSuspensionReader().readSuspension();
- getSuspensionReader().readSuspension();
-
- sendRuby("th l");
- ThreadInfo[] threads = getThreadInfoReader().readThreads();
- assertEquals(3, threads.length);
- int threadId1 = threads[0].getId();
- int threadId2 = threads[1].getId();
- int threadId3 = threads[2].getId();
- sendRuby("th " + threadId2 + " ; cont");
-
- sendRuby("th l");
- threads = getThreadInfoReader().readThreads();
- assertEquals(2, threads.length);
- assertEquals(threadId1, threads[0].getId());
- assertEquals(threadId3, threads[1].getId());
- sendRuby("th " + threadId3 + " ; cont");
-
- sendRuby("th l");
- threads = getThreadInfoReader().readThreads();
- assertEquals(1, threads.length);
- assertEquals(threadId1, threads[0].getId());
- }
-
public void testThreadFramesAndVariables() throws Exception {
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");
+ getBreakpointAddedReader().readBreakpointNo();
sendRuby("th resume 1");
getSuspensionReader().readSuspension();
getSuspensionReader().readSuspension();
@@ -1109,103 +1102,4 @@
}
- public void testReloadAndInspect() throws Exception {
- String[] lines = new String[] { "class Test", "def calc(a)", "a = a*2",
- "return a", "end", "end", "test=Test.new()" };
- createSocket(lines);
- runToLine(7);
- // test variable value in stack 1 (top stack frame)
- lines[2] = "a=a*4";
- writeFile("test.rb", lines);
- sendRuby("load " + getTmpDir() + "test.rb");
- LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
- .readLoadResult();
- assertTrue("No Exception from load", loadResult.isOk());
- sendRuby("v inspect Test.new.calc(2)");
- RubyVariable[] variables = getVariableReader().readVariables(
- createStackFrame());
- assertEquals("There is one variable returned.", 1, variables.length);
- assertEquals("Result is 8", "8", variables[0].getValue()
- .getValueString());
- }
-
- public void testReloadAndStep() throws Exception {
- String[] lines = new String[] { "puts 'a'", "puts 'b'", "puts 'c'" };
- createSocket(lines);
- runToLine(2);
- lines = new String[] { "puts 'd'", "puts 'e'", "puts 'f'" };
- writeFile("test.rb", lines);
- sendRuby("load " + getTmpDir() + "test.rb");
- this.getLoadResultReader().readLoadResult();
- sendRuby("next");
- SuspensionPoint info = getSuspensionReader().readSuspension();
- assertEquals(3, info.getLine());
- }
-
- public void testReloadWithException() throws Exception {
- createSocket(new String[] { "puts 'a'" });
- runToLine(1);
- // test variable value in stack 1 (top stack frame)
- String[] lines = new String[] { "classs A;end" };
- writeFile("test.rb", lines);
-
- sendRuby("load " + getTmpDir() + "test.rb");
- LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
- .readLoadResult();
- assertFalse("Exception from load", loadResult.isOk());
- assertEquals(loadResult.getExceptionType(), "SyntaxError");
- }
-
- public void testReloadInRequire() throws Exception {
- // Deadlock
- String[] lines = new String[] { "def endless", "sleep 0.1", "end" };
- writeFile("content file.rb", lines);
- createSocket(new String[] { "require 'content file'", "while true",
- "endless()", "end" });
- sendRuby("cont");
- // test variable value in stack 1 (top stack frame)
- lines[1] = "exit 0";
- writeFile("content file.rb", lines);
- sendRuby("load " + getTmpDir() + "content file.rb");
- LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
- .readLoadResult();
- assertTrue("No Exception from load", loadResult.isOk());
- }
-
- public void testReloadInStackFrame() throws Exception {
- String[] lines = new String[] { "class Test", "def calc(a)", "a = a*2",
- "return a", "end", "end", "result = Test.new.calc(2)",
- "result = Test.new.calc(2)", "puts result" };
- createSocket(lines);
- runToLine(3);
- // a has not yet been calculated ...
- sendRuby("v local");
- RubyVariable[] localVariables = getVariableReader().readVariables(
- createStackFrame());
- assertEquals("2", localVariables[0].getValue().getValueString());
- // now change the code ...
- lines[2] = "a=a*4";
- writeFile("test.rb", lines);
- sendRuby("load " + getTmpDir() + "test.rb");
- LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
- .readLoadResult();
- assertTrue("No Exception from load", loadResult.isOk());
- runToLine(4);
- // now a is calculated and the result is 4. That means that ruby does
- // not change the code which
- // currently being executed in a stack frame, Java would have reset the
- // instruction pointer and the
- // result would be 8
- sendRuby("v local");
- localVariables = getVariableReader().readVariables(createStackFrame());
- assertEquals("4", localVariables[0].getValue().getValueString());
-
- // Now check that the new code is executed with the next call to calc
- runToLine(3);
- runToLine(4);
- sendRuby("v local");
- localVariables = getVariableReader().readVariables(createStackFrame());
- assertEquals("8", localVariables[0].getValue().getValueString());
- }
-
}
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 2006-12-30 09:42:35 UTC (rev 1744)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_ClassicDebuggerCommunicationTest.java 2006-12-30 09:42:59 UTC (rev 1745)
@@ -3,6 +3,10 @@
import java.io.File;
import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.debug.core.SuspensionPoint;
+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;
import org.rubypeople.rdt.internal.launching.RdtLaunchingPlugin;
public class FTC_ClassicDebuggerCommunicationTest extends
@@ -11,7 +15,7 @@
junit.framework.TestSuite suite = new junit.framework.TestSuite();
//suite.addTest(new FTC_DebuggerCommunicationTest("testBreakpointOnFirstLine"));
- //suite.addTest(new FTC_DebuggerCommunicationTest("testBreakpointAddAndRemove"));
+ suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testBreakpointAddAndRemove"));
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testVariableLocal"));
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testVariableArray"));
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testVariableArrayEmpty"));
@@ -25,7 +29,7 @@
// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testThreads"));
- suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testVariablesInFrames"));
+// suite.addTest(new FTC_ClassicDebuggerCommunicationTest("testVariablesInFrames"));
//suite.addTest(new TC_DebuggerCommunicationTest("testConstants"));
@@ -99,4 +103,154 @@
}
}
+ public void testThreads() throws Exception {
+ createSocket(new String[] { "Thread.new {", "puts 'a'", "}",
+ "Thread.pass", "puts 'b'" });
+ sendRuby("b test.rb:2");
+ sendRuby("b test.rb:5");
+ sendRuby("cont");
+ SuspensionPoint point1 = getSuspensionReader().readSuspension();
+ sendRuby("th l");
+ ThreadInfo[] threadInfos = getThreadInfoReader().readThreads();
+ assertEquals(2, threadInfos.length);
+ sendRuby("cont");
+ SuspensionPoint point2 = getSuspensionReader().readSuspension();
+ sendRuby("th l");
+ threadInfos = getThreadInfoReader().readThreads();
+ assertEquals(1, threadInfos.length);
+ assertNotSame(point1.getThreadId(), point2.getThreadId());
+ }
+
+ public void testThreadIdsAndResume() throws Exception {
+ createSocket(new String[] { "threads=[]", "threads << Thread.new {",
+ "puts 'a'", "}", "threads << Thread.new{", "puts 'b'", "}",
+ "puts 'c'", "threads.each{|t| t.join()}" });
+ sendRuby("b test.rb:3");
+ sendRuby("b test.rb:6");
+ sendRuby("b test.rb:8");
+ sendRuby("cont");
+ getSuspensionReader().readSuspension();
+ getSuspensionReader().readSuspension();
+ getSuspensionReader().readSuspension();
+
+ sendRuby("th l");
+ ThreadInfo[] threads = getThreadInfoReader().readThreads();
+ assertEquals(3, threads.length);
+ int threadId1 = threads[0].getId();
+ int threadId2 = threads[1].getId();
+ int threadId3 = threads[2].getId();
+ sendRuby("th " + threadId2 + " ; cont");
+
+ sendRuby("th l");
+ threads = getThreadInfoReader().readThreads();
+ assertEquals(2, threads.length);
+ assertEquals(threadId1, threads[0].getId());
+ assertEquals(threadId3, threads[1].getId());
+ sendRuby("th " + threadId3 + " ; cont");
+
+ sendRuby("th l");
+ threads = getThreadInfoReader().readThreads();
+ assertEquals(1, threads.length);
+ assertEquals(threadId1, threads[0].getId());
+ }
+
+ public void testReloadAndInspect() throws Exception {
+ String[] lines = new String[] { "class Test", "def calc(a)", "a = a*2",
+ "return a", "end", "end", "test=Test.new()" };
+ createSocket(lines);
+ runToLine(7);
+ // test variable value in stack 1 (top stack frame)
+ lines[2] = "a=a*4";
+ writeFile("test.rb", lines);
+ sendRuby("load " + getTmpDir() + "test.rb");
+ LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
+ .readLoadResult();
+ assertTrue("No Exception from load", loadResult.isOk());
+ sendRuby("v inspect Test.new.calc(2)");
+ RubyVariable[] variables = getVariableReader().readVariables(
+ createStackFrame());
+ assertEquals("There is one variable returned.", 1, variables.length);
+ assertEquals("Result is 8", "8", variables[0].getValue()
+ .getValueString());
+ }
+
+ public void testReloadAndStep() throws Exception {
+ String[] lines = new String[] { "puts 'a'", "puts 'b'", "puts 'c'" };
+ createSocket(lines);
+ runToLine(2);
+ lines = new String[] { "puts 'd'", "puts 'e'", "puts 'f'" };
+ writeFile("test.rb", lines);
+ sendRuby("load " + getTmpDir() + "test.rb");
+ this.getLoadResultReader().readLoadResult();
+ sendRuby("next");
+ SuspensionPoint info = getSuspensionReader().readSuspension();
+ assertEquals(3, info.getLine());
+ }
+
+ public void testReloadWithException() throws Exception {
+ createSocket(new String[] { "puts 'a'" });
+ runToLine(1);
+ // test variable value in stack 1 (top stack frame)
+ String[] lines = new String[] { "classs A;end" };
+ writeFile("test.rb", lines);
+
+ sendRuby("load " + getTmpDir() + "test.rb");
+ LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
+ .readLoadResult();
+ assertFalse("Exception from load", loadResult.isOk());
+ assertEquals(loadResult.getExceptionType(), "SyntaxError");
+ }
+
+ public void testReloadInRequire() throws Exception {
+ // Deadlock
+ String[] lines = new String[] { "def endless", "sleep 0.1", "end" };
+ writeFile("content file.rb", lines);
+ createSocket(new String[] { "require 'content file'", "while true",
+ "endless()", "end" });
+ sendRuby("cont");
+ // test variable value in stack 1 (top stack frame)
+ lines[1] = "exit 0";
+ writeFile("content file.rb", lines);
+ sendRuby("load " + getTmpDir() + "content file.rb");
+ LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
+ .readLoadResult();
+ assertTrue("No Exception from load", loadResult.isOk());
+ }
+
+ public void testReloadInStackFrame() throws Exception {
+ String[] lines = new String[] { "class Test", "def calc(a)", "a = a*2",
+ "return a", "end", "end", "result = Test.new.calc(2)",
+ "result = Test.new.calc(2)", "puts result" };
+ createSocket(lines);
+ runToLine(3);
+ // a has not yet been calculated ...
+ sendRuby("v local");
+ RubyVariable[] localVariables = getVariableReader().readVariables(
+ createStackFrame());
+ assertEquals("2", localVariables[0].getValue().getValueString());
+ // now change the code ...
+ lines[2] = "a=a*4";
+ writeFile("test.rb", lines);
+ sendRuby("load " + getTmpDir() + "test.rb");
+ LoadResultReader.LoadResult loadResult = this.getLoadResultReader()
+ .readLoadResult();
+ assertTrue("No Exception from load", loadResult.isOk());
+ runToLine(4);
+ // now a is calculated and the result is 4. That means that ruby does
+ // not change the code which
+ // currently being executed in a stack frame, Java would have reset the
+ // instruction pointer and the
+ // result would be 8
+ sendRuby("v local");
+ localVariables = getVariableReader().readVariables(createStackFrame());
+ assertEquals("4", localVariables[0].getValue().getValueString());
+
+ // Now check that the new code is executed with the next call to calc
+ runToLine(3);
+ runToLine(4);
+ sendRuby("v local");
+ localVariables = getVariableReader().readVariables(createStackFrame());
+ assertEquals("8", localVariables[0].getValue().getValueString());
+ }
+
}
Modified: trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_RubyDebugCommunicationTest.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_RubyDebugCommunicationTest.java 2006-12-30 09:42:35 UTC (rev 1744)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_RubyDebugCommunicationTest.java 2006-12-30 09:42:59 UTC (rev 1745)
@@ -1,22 +1,38 @@
package org.rubypeople.rdt.debug.core.tests;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.internal.debug.core.SuspensionPoint;
+import org.rubypeople.rdt.internal.debug.core.parsing.EvalReader;
+import org.rubypeople.rdt.internal.launching.DebuggerRunner;
+import org.rubypeople.rdt.internal.launching.RdtLaunchingPlugin;
-public class FTC_RubyDebugCommunicationTest extends
- FTC_ClassicDebuggerCommunicationTest {
-
+public class FTC_RubyDebugCommunicationTest extends FTC_ClassicDebuggerCommunicationTest {
+
public static junit.framework.TestSuite suite() {
junit.framework.TestSuite suite = new junit.framework.TestSuite();
+
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testCommandList"));
+
+ // breakpoint on first line is not yet implemented for ruby-debug
+ //suite.addTest(new FTC_RubyDebugCommunicationTest("testBreakpointOnFirstLine"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testBreakpointAddAndRemove"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testBreakpointNeverReached"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testException"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testIgnoreException"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testExceptionsIgnoredByDefault"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testExceptionHierarchy"));
- suite.addTest(new FTC_RubyDebugCommunicationTest("testCommandList"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testInspect"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testInspectTemporaryArray"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testInspectNil"));
-
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testInspectError"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testEvalError"));
+
suite.addTest(new FTC_RubyDebugCommunicationTest("testFrames"));
-
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testFramesWhenThreadSpawned"));
+
suite.addTest(new FTC_RubyDebugCommunicationTest("testStepOver"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testStepOverFrames"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testStepOverFramesValue2"));
@@ -24,33 +40,39 @@
suite.addTest(new FTC_RubyDebugCommunicationTest("testStepReturn"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testHitBreakpointWhileSteppingOver"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testStepInto"));
-
+
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableString"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableLocal"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableInstance"));
- //suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableInstanceNested"));
-
+ // is instance nested still needed?
+ // suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableInstanceNested"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableNil"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableWithXmlContent"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableInObject"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableArray"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableArrayEmpty"));
-
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableHashWithStringKeys"));
suite.addTest(new FTC_RubyDebugCommunicationTest("testVariableHashWithObjectKeys"));
-
+
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testStaticVariables"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testSingletonStaticVariables"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testConstants"));
+ suite.addTest(new FTC_RubyDebugCommunicationTest("testConstantDefinedInBothClassAndSuperclass"));
+
return suite;
}
-
+
public FTC_RubyDebugCommunicationTest(String arg0) {
super(arg0);
}
-
+
@Override
public void startRubyProcess() throws Exception {
// TODO Auto-generated method stub
- String cmd = "rdebug -s -p 1098 --cport 1099 -d -w -f xml -I " + getTmpDir().replace('\\', '/') + " " + getRubyTestFilename() ;
- //"FTC_DebuggerCommunicationTest.RUBY_INTERPRETER + " -I" + createIncludeDir() + " -I" + getTmpDir().replace('\\', '/') + " -reclipseDebugVerbose.rb " + ;
+ String cmd = "rdebug -s -p 1098 --cport 1099 -d -w -f xml -I " + getTmpDir().replace('\\', '/') + " " + getRubyTestFilename();
+ // "FTC_DebuggerCommunicationTest.RUBY_INTERPRETER + " -I" +
+ // createIncludeDir() + " -I" + getTmpDir().replace('\\', '/') + "
+ // -reclipseDebugVerbose.rb " + ;
System.out.println("Starting: " + cmd);
process = Runtime.getRuntime().exec(cmd);
rubyStderrRedirectorThread = new OutputRedirectorThread(process.getErrorStream());
@@ -60,11 +82,27 @@
}
+ protected String getDirectoryOfRubyDebuggerFile() {
+ String result = null;
+ if (RubyCore.getPlugin() != null) {
+ result = DebuggerRunner.getDirectoryOfRubyDebuggerFile();
+ } else {
+ result = RdtLaunchingPlugin.class.getResource(".").getPath() + "/../../../../../../ruby";
+ }
+ return result;
+ }
+
@Override
protected void readSuspensionInFirstLine() throws Exception {
- System.out.println("Waiting for suspension in first line") ;
+
+ System.out.println("Waiting for suspension in first line");
SuspensionPoint hit = getSuspensionReader().readSuspension();
- assertEquals(1, hit.getLine()) ;
+ assertEquals(1, hit.getLine());
+
+ String expression = "eval require '" + getDirectoryOfRubyDebuggerFile() + "/rdebugExtension.rb'";
+ sendRuby(expression);
+ String evalResult = getEvalReader().readEvalResult();
+ assertEquals("true", evalResult);
}
-
+
}
Added: trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/WasteReader.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/WasteReader.java (rev 0)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/WasteReader.java 2006-12-30 09:42:59 UTC (rev 1745)
@@ -0,0 +1,53 @@
+package org.rubypeople.rdt.debug.core.tests;
+
+import junit.framework.Assert;
+
+import org.rubypeople.rdt.internal.debug.core.RdtDebugCorePlugin;
+import org.rubypeople.rdt.internal.debug.core.parsing.AbstractReadStrategy;
+import org.rubypeople.rdt.internal.debug.core.parsing.XmlStreamReader;
+import org.rubypeople.rdt.internal.debug.core.parsing.XmlStreamReaderException;
+import org.xmlpull.v1.XmlPullParser;
+
+public class WasteReader extends XmlStreamReader {
+
+ private String name;
+ public WasteReader(XmlPullParser xpp) {
+ super(xpp);
+ }
+
+ public WasteReader(AbstractReadStrategy readStrategy) {
+ super(readStrategy);
+ }
+
+ @Override
+ protected boolean processStartElement(XmlPullParser xpp)
+ throws XmlStreamReaderException {
+ name = xpp.getName() ;
+ if (name.equals("exception") ) {
+ String exceptionType = xpp.getAttributeValue("", "type") ;
+ String exceptionMessage = xpp.getAttributeValue("", "message") ;
+ // Unfortunately JUnit does not stop the test because this assertion is thrown in another thread
+ Assert.fail("Exception " + exceptionType + " occurred: " + exceptionMessage) ;
+ }
+ return checkNAme();
+ }
+
+ private boolean checkNAme() {
+ return name.equals("error") || name.equals("message") || name.equals("frame") ;
+ }
+
+ @Override
+ public void processContent(String text) {
+ if (name.equals("error")) {
+ throw new RuntimeException("Error in test: " + text) ;
+ }
+ }
+ @Override
+ protected boolean processEndElement(XmlPullParser xpp) {
+ name = xpp.getName() ;
+ return checkNAme();
+ }
+
+
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|