Closed ariya closed 12 years ago
@ariya I can't seem to reproduce your issue:
Octavian:~/work/node-cover ineeman$ cat foo.js var a = 2; Octavian:~/work/node-cover ineeman$ bin/cover run foo.js Octavian:~/work/node-cover ineeman$ bin/cover report ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┓ ┃ Filename ┃ % Covered┃ Missed Lines ┃ # Lines ┃ % Blocks ┃ Missed Blocks┃ # Blocks ┃ ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━╋━━━━━━━━━━┫ ┃ foo.js ┃ 100% ┃ 0 ┃ 2 ┃ 100% ┃ 0 ┃ 0 ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━┛
Note that in this case foo.js
is actually a two-line file, as I have an empty newline at the end. However, same result if I don't have it, or if I have multiple trailing new lines.
I'm sure I have a bug somewhere, but I can't seem to make it happen :)
cat test.js x = 42; if (false) x = -1; wc -l test.js 3 test.js cover report ┃ Filename ┃ % Covered┃ Missed Lines ┃ # Lines ┃ % Blocks ┃ Missed Blocks┃ # Blocks ┃ ┃ test.js ┃ 75% ┃ 1 ┃ 4 ┃ 0% ┃ 1 ┃ 1 ┃
As you can see, 'wc' reports 3 lines. 1 line is not covered (x = -1) and the % covered should be 67% instead.
@ariya which version of Node/cover are you using? I'm getting 3 lines with the above test, but I'm starting to think there is some odd version thing here. I've tried both 0.6.11 and 0.6.5, no problems.
node 0.6.12 and cover 0.2.1.
OK, it happens on Linux, but not OS X. Will debug now.
OK, so it seems like Linux appends an empty line to the end of the file when I read it from the filesystem. I'll make sure to call a trim and then we shouldn't have this problem anymore. Sorry for the trouble!
Should be fixed in 0.2.2
Just try it on a one-line JS program. cover reports # Lines as '2'.
This also means that '% Covered' is falsified.