Bug? Loader applied to wrong language
HiPhish opened this issue · 0 comments
If I have tests written in multiple languages, such as Moonscript and Lua, the getTrace
of one loader might get applied to a test of another language. I am able to reproduce the issue with two test files.
Steps to reproduce
Let's take the following tests as example:
-- test/arithmetic_spec.moon
it "Adds two numbers", ->
assert.are.equal 5, 2 + 3
-- test/derp_spec.lua
it('Does something', function()
assert.is_true(true)
assert.is_true(false)
end)
-- .busted
return {
_all = {
ROOT = {'test'},
},
}
I now run busted in the root directory of the project.
busted
1 success / 1 failure / 0 errors / 0 pending : 0.18589 seconds
Failure → test/derp_spec.lua @ 1
Does something
test/derp_spec.lua:3: Expected objects to be the same.
Passed in:
(boolean) false
Expected:
(boolean) true
Everything looks good, right? Let's hack a little log into busted/modules/files/moonscript.lua
.
local getTrace = function(filename, info)
print(filename, info.source) -- Added
local index = info.traceback:find('\n%s*%[C]')
-- ...
end
The printed output is
test/arithmetic_spec.moon @/home/hiphish/Developer/busted/luarocks/lib/luarocks/rocks-5.3/busted/scm-1/bin/busted
test/arithmetic_spec.moon @test/derp_spec.lua
Note the second line. The file name passed to getTrace
is that of the Moonscript test file, but the info
object actually belongs to the Lua file.
Expected behaviour
Please correct me if I'm wrong, but shouldn't the getTrace
from the Moonscript loader only apply to Moonscript tests? In the case of Moonscript it does not seem to corrupt the Lua result, but it could mess up results in other loaders. I first noticed this weird behaviour when I was trying to write a Fennel loader and the Lua test results were getting messed up.
Other notes
- I was able to track down the problem to the function
busted.context.parent
. For some reason it returns the Moonscript (or Fennel) test as the parent of the Lua test. - The file names seem to matter, or at least their alphabetical ordering does