forked from drone-plugins/drone-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_lcov.go
58 lines (49 loc) · 1.08 KB
/
cmd_lcov.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/drone-plugins/drone-coverage/coverage/lcov"
"github.com/mattn/go-zglob"
"github.com/urfave/cli"
"golang.org/x/tools/cover"
)
// LcovCmd is the exported command for converting LCOV files.
var LcovCmd = cli.Command{
Name: "lcov",
Usage: "parse lcov files",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
return parseLcov(c)
},
}
func parseLcov(c *cli.Context) error {
pattern := c.Args().First()
if pattern == "" {
pattern = "**/lcov.info"
}
matches, err := zglob.Glob(pattern)
if err != nil {
return err
}
parser := lcov.New()
var profiles []*cover.Profile
for _, match := range matches {
parsed, err := parser.ReadFile(match)
if err != nil {
return err
}
for _, p := range parsed {
profiles = addProfile(profiles, p)
}
}
// create the coverage payload that gets sent to the
// coverage reporting server.
report := profileToReport(profiles)
out, err := json.MarshalIndent(report, " ", " ")
if err != nil {
return err
}
fmt.Fprintf(os.Stdout, "%s", out)
return nil
}