Skip to content

Commit

Permalink
Solve the problem with "Step Over" in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skinny85 committed Jan 1, 2025
1 parent 67a0c1e commit e2a27e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ public final class BlockStmtNode extends SkippedStmtNode {
@Children
private final EasyScriptStmtNode[] stmts;

private final boolean programBlock;

@CompilationFinal(dimensions = 1)
private RefObject[] findLocalVarRefsCache;

public BlockStmtNode(List<EasyScriptStmtNode> stmts) {
this(stmts, false);
}

public BlockStmtNode(List<EasyScriptStmtNode> stmts, boolean programBlock) {
this.stmts = stmts.toArray(new EasyScriptStmtNode[]{});
this.programBlock = programBlock;
}

/**
Expand All @@ -55,7 +62,7 @@ public Object executeStatement(VirtualFrame frame) {
*/
@Override
public boolean hasTag(Class<? extends Tag> tag) {
return tag == StandardTags.RootTag.class;
return this.programBlock && tag == StandardTags.RootTag.class;
}

public RefObject[] getLocalVarRefs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private EasyScriptTruffleParser(Source source, ShapesAndPrototypes shapesAndProt
public ParsingResult parse() {
List<EasyScriptStmtNode> stmts = this.parseStmtsList(this.parser.start().stmt());
return new ParsingResult(
new BlockStmtNode(stmts),
new BlockStmtNode(stmts, true),
this.frameDescriptor.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ void step_over_global_var_decl_and_into_func_call() {
" return Math.abs(num);\n" +
" }",
List.of(Map.of("num", "2", "this", "undefined", "n1", "0", "n2", "1")));
// for some reason, step over doesn't work in tests,
// even though they work in the real debugger
event.prepareStepInto(1);
event.prepareStepOver(1);
});
this.debuggerTester.expectSuspended(event -> {
assertState(event, "fib", 4, SuspendAnchor.BEFORE, "let i = 1;",
Expand All @@ -115,8 +113,7 @@ void step_over_global_var_decl_and_into_func_call() {
List.of(
Map.of("num", "2", "this", "undefined", "n1", "0", "n2", "1"),
Map.of("i", "1")));
// same here, we need to "step into" instead of "step over"
event.prepareStepInto(1);
event.prepareStepOver(1);
});
this.debuggerTester.expectSuspended(event -> {
assertState(event, "fib", 6, SuspendAnchor.BEFORE, "const next = n1 + n2;",
Expand Down Expand Up @@ -150,10 +147,6 @@ void step_over_global_var_decl_and_into_func_call() {
Map.of("next", "1")));
event.prepareStepOver(1);
});
this.debuggerTester.expectSuspended(event -> {
assertState(event, ":program", 18, SuspendAnchor.AFTER, "fib2 = fib('unused2', 2, 'superfluous2');");
event.prepareStepOver(1);
});
this.debuggerTester.expectSuspended(event -> {
assertState(event, "fib", 11, SuspendAnchor.BEFORE, "return n2;",
List.of(
Expand Down

0 comments on commit e2a27e8

Please sign in to comment.