Skip to content

Commit

Permalink
[Truffle] Proper fix for RubyDebugTest.
Browse files Browse the repository at this point in the history
* Don't hide hard-coded lines in the code.
  • Loading branch information
eregon committed Nov 30, 2016
1 parent 3204907 commit 420a12a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
18 changes: 10 additions & 8 deletions truffle/src/test/java/org/jruby/truffle/tck/RubyDebugTest.java
Expand Up @@ -39,6 +39,8 @@

public class RubyDebugTest {

private static final int BREAKPOINT_LINE = 13;

private Debugger debugger;
private DebuggerSession debuggerSession;
private final LinkedList<Runnable> run = new LinkedList<>();
Expand Down Expand Up @@ -90,7 +92,7 @@ public void testBreakpoint() throws Throwable {
run.addLast(() -> {
assertNull(suspendedEvent);
assertNotNull(debuggerSession);
Breakpoint breakpoint = Breakpoint.newBuilder(factorial).lineIs(3).build();
Breakpoint breakpoint = Breakpoint.newBuilder(factorial).lineIs(BREAKPOINT_LINE).build();
debuggerSession.install(breakpoint);
});

Expand All @@ -100,7 +102,7 @@ public void testBreakpoint() throws Throwable {

assertExecutedOK("Algorithm loaded");

assertLocation(3, "1",
assertLocation(13, "1",
"n", "1",
"nMinusOne", "nil",
"nMOFact", "nil",
Expand All @@ -127,32 +129,32 @@ public void stepInStepOver() throws Throwable {
debuggerSession.suspendNextExecution();
});

assertLocation(13, "res = fac(2)", "res", "nil");
assertLocation(23, "res = fac(2)", "res", "nil");
stepInto(1);
assertLocation(2, "if n <= 1",
assertLocation(12, "if n <= 1",
"n", "2",
"nMinusOne", "nil",
"nMOFact", "nil",
"res", "nil");
stepOver(1);
assertLocation(5, "nMinusOne = n - 1",
assertLocation(15, "nMinusOne = n - 1",
"n", "2",
"nMinusOne", "nil",
"nMOFact", "nil",
"res", "nil");
stepOver(1);
assertLocation(6, "nMOFact = fac(nMinusOne)",
assertLocation(16, "nMOFact = fac(nMinusOne)",
"n", "2",
"nMinusOne", "1",
"nMOFact", "nil",
"res", "nil");
stepOver(1);
assertLocation(7, "res = n * nMOFact",
assertLocation(17, "res = n * nMOFact",
"n", "2", "nMinusOne", "1",
"nMOFact", "1",
"res", "nil");
stepOut();
assertLocation(13, "res = fac(2)" + System.lineSeparator()
assertLocation(23, "res = fac(2)" + System.lineSeparator()
+ " puts res" + System.lineSeparator() // wrong!?
+ " res", // wrong!?
"res", "2");
Expand Down
12 changes: 10 additions & 2 deletions truffle/src/test/ruby/factorial.rb
@@ -1,3 +1,13 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# Beware, RubyDebutTest use hard-coded line numbers from this file!

def fac(n)
if n <= 1
1
Expand All @@ -15,5 +25,3 @@ def main
res
end
Truffle::Interop.export_method(:main)

# Don't add a licence header to this file - we use the line offets!

0 comments on commit 420a12a

Please sign in to comment.