Skip to content

Commit ad58eb9

Browse files
authored
more thorough testing of commands (#157)
* more thorough testing of commands
1 parent cb6ed25 commit ad58eb9

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

test/debug.jl

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@ using JuliaInterpreter, Test
22
using JuliaInterpreter: enter_call, enter_call_expr, get_return, @lookup
33
using Base.Meta: isexpr
44

5-
function step_through(frame)
6-
r = root(frame)
7-
@test debug_command(JuliaInterpreter.finish_and_return!, frame, "c") === nothing
8-
@test r.callee === nothing
9-
return get_return(r)
10-
end
5+
const ALL_COMMANDS = ("n", "s", "c", "finish", "nc", "se", "si")
116

12-
function step_through_function(f, args...)
13-
frame = JuliaInterpreter.enter_call(f, args...)
7+
function step_through_command(fr::Frame, cmd::String)
148
while true
15-
ret = JuliaInterpreter.debug_command(JuliaInterpreter.finish_and_return!, frame, "s")
9+
ret = JuliaInterpreter.debug_command(JuliaInterpreter.finish_and_return!, fr, cmd)
1610
ret == nothing && break
17-
frame, pc = ret
11+
fr, pc = ret
12+
end
13+
@test fr.callee === nothing
14+
@test fr.caller === nothing
15+
return get_return(fr)
16+
end
17+
18+
function step_through_frame(frame_creator)
19+
rets = []
20+
for cmd in ALL_COMMANDS
21+
frame = frame_creator()
22+
ret = step_through_command(frame, cmd)
23+
push!(rets, ret)
1824
end
19-
@test frame.callee === nothing
20-
@test frame.caller === nothing
21-
return JuliaInterpreter.get_return(frame)
25+
@test all(ret -> ret == rets[1], rets)
26+
return rets[1]
2227
end
28+
step_through(f, args...; kwargs...) = step_through_frame(() -> enter_call(f, args...; kwargs...))
29+
step_through(expr::Expr) = step_through_frame(() -> enter_call_expr(expr))
2330

2431
@generated function generatedfoo(T)
2532
:(return $T)
@@ -64,21 +71,18 @@ struct B{T} end
6471
end
6572

6673
f22() = string(:(a+b))
67-
@test step_through(enter_call(f22)) == "a + b"
68-
@test step_through_function(f22) == "a + b"
74+
@test step_through(f22) == "a + b"
6975
f22() = string(QuoteNode(:a))
70-
@test step_through(enter_call(f22)) == ":a"
71-
@test step_through_function(f22) == ":a"
76+
@test step_through(f22) == ":a"
7277

7378
frame = enter_call(trivial, 2)
7479
@test debug_command(frame, "s") === nothing
7580
@test get_return(frame) == 2
7681

77-
@test step_through(enter_call(trivial, 2)) == 2
78-
@test step_through_function(trivial, 2) == 2
79-
@test step_through(enter_call_expr(:($(+)(1,2.5)))) == 3.5
80-
@test step_through(enter_call_expr(:($(sin)(1)))) == sin(1)
81-
@test step_through(enter_call_expr(:($(gcd)(10,20)))) == gcd(10, 20)
82+
@test step_through(trivial, 2) == 2
83+
@test step_through(:($(+)(1,2.5))) == 3.5
84+
@test step_through(:($(sin)(1))) == sin(1)
85+
@test step_through(:($(gcd)(10,20))) == gcd(10, 20)
8286
end
8387

8488
@testset "generated" begin
@@ -236,8 +240,7 @@ struct B{T} end
236240
return x + y
237241
end
238242
B_inst = B{Int}()
239-
step_through(JuliaInterpreter.enter_call(B_inst, 10)) == B_inst(10)
240-
step_through_function(B_inst, 10) == B_inst(10)
243+
step_through(B_inst, 10) == B_inst(10)
241244
end
242245

243246
@testset "Exceptions" begin

0 commit comments

Comments
 (0)