Skip to content

more thorough testing of commands #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions test/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@ using JuliaInterpreter, Test
using JuliaInterpreter: enter_call, enter_call_expr, get_return, @lookup
using Base.Meta: isexpr

function step_through(frame)
r = root(frame)
@test debug_command(JuliaInterpreter.finish_and_return!, frame, "c") === nothing
@test r.callee === nothing
return get_return(r)
end
const ALL_COMMANDS = ("n", "s", "c", "finish", "nc", "se", "si")

function step_through_function(f, args...)
frame = JuliaInterpreter.enter_call(f, args...)
function step_through_command(fr::Frame, cmd::String)
while true
ret = JuliaInterpreter.debug_command(JuliaInterpreter.finish_and_return!, frame, "s")
ret = JuliaInterpreter.debug_command(JuliaInterpreter.finish_and_return!, fr, cmd)
ret == nothing && break
frame, pc = ret
fr, pc = ret
end
@test fr.callee === nothing
@test fr.caller === nothing
return get_return(fr)
end

function step_through_frame(frame_creator)
rets = []
for cmd in ALL_COMMANDS
frame = frame_creator()
ret = step_through_command(frame, cmd)
push!(rets, ret)
end
@test frame.callee === nothing
@test frame.caller === nothing
return JuliaInterpreter.get_return(frame)
@test all(ret -> ret == rets[1], rets)
return rets[1]
end
step_through(f, args...; kwargs...) = step_through_frame(() -> enter_call(f, args...; kwargs...))
step_through(expr::Expr) = step_through_frame(() -> enter_call_expr(expr))

@generated function generatedfoo(T)
:(return $T)
Expand Down Expand Up @@ -60,21 +67,18 @@ struct B{T} end
end

f22() = string(:(a+b))
@test step_through(enter_call(f22)) == "a + b"
@test step_through_function(f22) == "a + b"
@test step_through(f22) == "a + b"
f22() = string(QuoteNode(:a))
@test step_through(enter_call(f22)) == ":a"
@test step_through_function(f22) == ":a"
@test step_through(f22) == ":a"

frame = enter_call(trivial, 2)
@test debug_command(frame, "s") === nothing
@test get_return(frame) == 2

@test step_through(enter_call(trivial, 2)) == 2
@test step_through_function(trivial, 2) == 2
@test step_through(enter_call_expr(:($(+)(1,2.5)))) == 3.5
@test step_through(enter_call_expr(:($(sin)(1)))) == sin(1)
@test step_through(enter_call_expr(:($(gcd)(10,20)))) == gcd(10, 20)
@test step_through(trivial, 2) == 2
@test step_through(:($(+)(1,2.5))) == 3.5
@test step_through(:($(sin)(1))) == sin(1)
@test step_through(:($(gcd)(10,20))) == gcd(10, 20)
end

@testset "generated" begin
Expand Down Expand Up @@ -221,8 +225,7 @@ struct B{T} end
return x + y
end
B_inst = B{Int}()
step_through(JuliaInterpreter.enter_call(B_inst, 10)) == B_inst(10)
step_through_function(B_inst, 10) == B_inst(10)
step_through(B_inst, 10) == B_inst(10)
end

@testset "Exceptions" begin
Expand Down