Skip to content
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

Interpreter=busted fails to debug busted script #552

Closed
ildar opened this issue Nov 10, 2015 · 8 comments
Closed

Interpreter=busted fails to debug busted script #552

ildar opened this issue Nov 10, 2015 · 8 comments
Assignees

Comments

@ildar
Copy link

ildar commented Nov 10, 2015

Simple
https://github.com/Olivine-Labs/busted/blob/master/spec/test_runner/interface_spec.lua
in ZBS:

Program starting as '"/usr/bin/busted" --output=TAP "/tmp/.private/ildar/.yG6Pnt"'.
Program 'busted' started in '/tmp/busted-2.0.rc11-0/spec/test_runner' (pid: 7855).
1..0
Program completed in 0.55 seconds (pid: 7855).

I don't understand this output.
But running in the console shows correctly:

$ busted --output=TAP interface_spec.lua
ok 1 - does a describe does 1000 its
ok 2 - does a describe does 1000 its
...
ok 1000 - does a describe does 1000 its
1..1000

@pkulchenko
Copy link
Owner

@ildar, does this only happen when you are debugging the script? When you are using Run, it should show the actual file name instead of using a temporary file and I'd be interested to see if that works.

@pkulchenko pkulchenko self-assigned this Nov 10, 2015
@ildar
Copy link
Author

ildar commented Nov 10, 2015 via email

@pkulchenko
Copy link
Owner

I think this is caused by one level of indirection that the IDE needs to setup for debugging to work, but this fails because describe is not defined in the global namespace.

Basically, create dofile_spec.lua in the same folder as interface_spec.lua and add dofile [[.\interface_spec.lua]] to it. I'm getting Failure message: .\interface_spec.lua:1: attempt to call global 'describe' (a nil value) when trying to run busted on it. This is the same error you'd get from the "original" script, but it's not see as it's "printed" and is "eaten" by busted.

One workaround is to use Run if you don't need to debug and add require('mobdebug').start() manually to your script if you need debugging. I guess something has changed in the environment handling inside busted as this used to be working. I don't have a better solution yet.

@pkulchenko
Copy link
Owner

@ildar, what Lua version are you using to run busted?

@ildar
Copy link
Author

ildar commented Nov 10, 2015 via email

@pkulchenko
Copy link
Owner

@ildar, can you try the following diff:

diff --git a/interpreters/busted.lua b/interpreters/busted.lua
index 0fb271e..45f1213 100644
--- a/interpreters/busted.lua
+++ b/interpreters/busted.lua
@@ -29,35 +29,28 @@ return {
       end
     end

-    local file
+    local file = wfilename:GetFullPath()
+    local helper
     if rundebug then
       -- start running the application right away
-      DebuggerAttachDefault({runstart = ide.config.debugger.runonstart == true})
-      local code = (
-[=[xpcall(function() io.stdout:setvbuf('no')
-    require('mobdebug').start(); dofile [[%s]]
-  end, function(err) print(debug.traceback(err)) end)]=])
-        :format(wfilename:GetFullPath())
+      DebuggerAttachDefault({runstart = ide.config.debugger.runonstart ~= false})
       local tmpfile = wx.wxFileName()
       tmpfile:AssignTempFileName(".")
-      file = tmpfile:GetFullPath()
-      local f = io.open(file, "w")
+      helper = tmpfile:GetFullPath()..".lua" -- busted likes .lua files more than .tmp files
+      local f = io.open(helper, "w")
       if not f then
-        DisplayOutputLn("Can't open temporary file '"..file.."' for writing.")
+        DisplayOutputLn("Can't open temporary file '"..helper.."' for writing.")
         return 
       end
-      f:write(code)
+      f:write("require('mobdebug').start()")
       f:close()
     end

-    file = file or wfilename:GetFullPath()
-
-    local options = ide.config.busted and ide.config.busted.options
-      or "--output=TAP"
-    local cmd = ('"%s" %s "%s"'):format(busted, options, file)
-    -- CommandLineRun(cmd,wdir,tooutput,nohide,stringcallback,uid,endcallback)
+    local options = ide.config.busted and ide.config.busted.options or "--output=TAP"
+    local cmd = ('"%s" %s %s "%s"'):format(busted, options, helper and "--helper="..helper or "", file)
+     -- CommandLineRun(cmd,wdir,tooutput,nohide,stringcallback,uid,endcallback)
     return CommandLineRun(cmd,self:fworkdir(wfilename),true,false,nil,nil,
-      function() if rundebug then wx.wxRemoveFile(file) end end)
+      function() if helper then wx.wxRemoveFile(helper) end end)
   end,
   hasdebugger = true,
   fattachdebug = function(self) DebuggerAttachDefault() end,

It should fix debugging for the scripts (but you need to set a breakpoint if you want to stop in the script or use Break).

@ildar
Copy link
Author

ildar commented Nov 10, 2015 via email

@pkulchenko
Copy link
Owner

@ildar, pushed the changes; thanks for the report!

@pkulchenko pkulchenko changed the title Interpreter=busted misbehaves Interpreter=busted fails to debug busted script Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants