@@ -2,24 +2,31 @@ using JuliaInterpreter, Test
2
2
using JuliaInterpreter: enter_call, enter_call_expr, get_return, @lookup
3
3
using Base. Meta: isexpr
4
4
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" )
11
6
12
- function step_through_function (f, args... )
13
- frame = JuliaInterpreter. enter_call (f, args... )
7
+ function step_through_command (fr:: Frame , cmd:: String )
14
8
while true
15
- ret = JuliaInterpreter. debug_command (JuliaInterpreter. finish_and_return!, frame, " s " )
9
+ ret = JuliaInterpreter. debug_command (JuliaInterpreter. finish_and_return!, fr, cmd )
16
10
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)
18
24
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 ]
22
27
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))
23
30
24
31
@generated function generatedfoo (T)
25
32
:(return $ T)
@@ -64,21 +71,18 @@ struct B{T} end
64
71
end
65
72
66
73
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"
69
75
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"
72
77
73
78
frame = enter_call (trivial, 2 )
74
79
@test debug_command (frame, " s" ) === nothing
75
80
@test get_return (frame) == 2
76
81
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 )
82
86
end
83
87
84
88
@testset " generated" begin
@@ -236,8 +240,7 @@ struct B{T} end
236
240
return x + y
237
241
end
238
242
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 )
241
244
end
242
245
243
246
@testset " Exceptions" begin
0 commit comments