Skip to content

Commit e0c16a3

Browse files
committed
add coverage handler spec
1 parent 619db4b commit e0c16a3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

spec/coverage_output_handler.moon

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
load_line_table = (chunk_name) ->
3+
import to_lua from require "moonscript.base"
4+
5+
return unless chunk_name\match "^@"
6+
fname = chunk_name\sub 2
7+
8+
file = assert io.open fname
9+
code = file\read "*a"
10+
file\close!
11+
12+
c, ltable = to_lua code
13+
14+
return nil, ltable unless c
15+
16+
line_tables = require "moonscript.line_tables"
17+
line_tables[chunk_name] = ltable
18+
true
19+
20+
(options) ->
21+
busted = require "busted"
22+
handler = require("busted.outputHandlers.utfTerminal") options
23+
24+
local spec_name
25+
26+
coverage = require "moonscript.cmd.coverage"
27+
cov = coverage.CodeCoverage!
28+
29+
busted.subscribe { "test", "start" }, (context) ->
30+
cov\start!
31+
32+
busted.subscribe { "test", "end" }, ->
33+
cov\stop!
34+
35+
busted.subscribe { "suite", "end" }, (context) ->
36+
line_counts = {}
37+
38+
for chunk_name, counts in pairs cov.line_counts
39+
continue unless chunk_name\match("^@$./") or chunk_name\match "@[^/]"
40+
continue if chunk_name\match "^@spec/"
41+
42+
if chunk_name\match "%.lua$"
43+
chunk_name = chunk_name\gsub "lua$", "moon"
44+
continue unless load_line_table chunk_name
45+
46+
line_counts[chunk_name] = counts
47+
48+
cov.line_counts = line_counts
49+
cov\format_results!
50+
51+
handler

0 commit comments

Comments
 (0)