erikedin / Behavior.jl

Tool for Behavior Driven Development in Julia
Other
25 stars 3 forks source link

Enable debugging into steps #116

Open amanica opened 2 weeks ago

amanica commented 2 weeks ago

hi, I'm trying out Behaviour and am really liking it so far. The only thing that I found so far that will prevent me from using it more widely is that I can't seem to get debugging working into step files in vscode - my breakpoints in steps just get ignored.

I started investigating. I saw some people had issues with anonymous do functions, but I tried a normal anonymous do function and it is working fine for me - I could get my breakpoints hitting. I did try to see if I can figure out to make a @given where I rather pass in a function as variable, but I could not figure that out.

I know from past experience that things like eval() can cause debugging to not work, so I looked at the code and could only find one eval. I was able to remove it as below, but it did not solve my problem yet.

+++ b/src/stepdefinitions.jl
@@ -222,7 +222,8 @@ julia> converttypes(:Int, "123")
 """
 function converttypes(typesymbol::Symbol, value) :: Any
-    t = eval(typesymbol)
+    #t = eval(typesymbol)
+    t =getfield(Main, typesymbol)

I'm not sure if the issue is with this package or with vs-code, but I figured I can log it here then others having the same problem may also find this..

thanks

erikedin commented 2 weeks ago

Hi! Thanks for trying Behavior. As you can maybe tell, I haven't worked actively on it for a while, but I'm trying to get back into it.

I haven't used VS Code debugging myself, so I'll have to look into it. My initial thought is that the issue is probably maybe here: https://github.com/erikedin/Behavior.jl/blob/6b81c39aab19e960c51639f25960de76066a057b/src/executor.jl#L112 This is the line of code that actually calls the given/when/then functions defines in your step files. The Base.invokelatest thing was something I only barely understood at the time of writing, and even less now years later, but it was necessary for Julia to see those functions as defined. I'll try to reproduce your issue with break points first, then I'll see if I can figure out how to work around it or fix it.

erikedin commented 2 weeks ago

I did manage to reproduce your issue. I can set breakpoints in the Behavior code, but breakpoints in the step files are not found. I have seen hints that the issue is in fact Base.invokelatest, but I'm still not sure. My best guess right now is that this is a limitation that is hard to overcome. I found similar issues people had with breakpoints in @testset tests, like here: https://discourse.julialang.org/t/why-is-test-so-meta-programming-heavy/94619

I'll keep this issue open, and keep looking into it.