Open snowyu opened 9 years ago
I think I know what's going on here. As a workaround, if you change:
content = readFile(file).caught(->)
to
content = readFile(file).caught(-> undefined)
I bet it will work. I suspect what's going on here is we're instrumenting the empty function, adding a lineCount++
at the start, which means instead of returning undefined, it ends up returning the count.
why should inject the code to empty function and return a value?
Yeah, it's a bug for sure. The way coffee-coverage works is to instrument the original coffee-script before compilation, so we change:
->
to something like:
__coverageVar['filename.coffee].s[0]++
->
__coverageVar['filename.coffee].f[0]++
__coverageVar['filename.coffee].s[1]++
At the end of the test, we know how many times the 0th function and 1st statement were run. But, of course, this is wrong; it should be generating:
__coverageVar['filename.coffee].s[0]++
->
__coverageVar['filename.coffee].f[0]++
__coverageVar['filename.coffee].s[1]++
return undefined
It will solve the first problem in above list if so. But It still make the checker(isEmptyFunction) error.
The test whether empty function(second problem in the list) is important for my case too, My createObject function in the inherits-ex depends on it. this make it easier to write a class.
inherits = require 'inherits-ex'
createObject = require 'inherits-ex/lib/createObject'
class A
constructor: ->console.log 'A'
class B
inherits B, A
b = new B # the original way
b = createObject B # the constructor of A will be executed because the B's constructor is empty.
I have to work around the coverage's bug in my isEmptyFunction function temporarily.
Hmm, interesting corner case. You can make a truly empty function with something like:
### !pragma no-coverage-next ###
x = ->
(We could add a ### !pragma no-coverage-block ###
too, which would be a bit finer-grained.) But I'm not sure this is really going to help your use case. We could not instrument empty functions, but then you wouldn't know if your empty function was being called or not.
class B
inherits B, A
The empty constructor is generated by coffee-script compiler. So unless modify the compiler...
maybe add a switcher to enable the measuring the calls of empty function.
reproduce:
the result should be:
But after injected: