Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added reverse order flag #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cov/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (rp *reportPackage) percentageReached() float64 {
return rv
}

func buildReportPackage(pkg *gocov.Package) reportPackage {
func buildReportPackage(pkg *gocov.Package, lowCoverageOnTop bool) reportPackage {
rv := reportPackage{
pkg: pkg,
functions: make(reportFunctionList, len(pkg.Functions)),
Expand All @@ -143,12 +143,16 @@ func buildReportPackage(pkg *gocov.Package) reportPackage {
rv.totalStatements += len(fn.Statements)
rv.reachedStatements += reached
}
sort.Sort(reverse{rv.functions})
if lowCoverageOnTop {
sort.Sort(rv.functions)
} else {
sort.Sort(reverse{rv.functions})
}
return rv
}

// PrintReport prints a coverage report to the given writer.
func printReport(w io.Writer, r *report) {
func printReport(w io.Writer, lowCoverageOnTop bool, r *report) {
css := defaultCSS
if len(r.stylesheet) > 0 {
css = fmt.Sprintf("<link rel=\"stylesheet\" href=\"%s\" />", r.stylesheet)
Expand All @@ -157,7 +161,7 @@ func printReport(w io.Writer, r *report) {

reportPackages := make(reportPackageList, len(r.packages))
for i, pkg := range r.packages {
reportPackages[i] = buildReportPackage(pkg)
reportPackages[i] = buildReportPackage(pkg, lowCoverageOnTop)
}

if len(reportPackages) == 0 {
Expand Down Expand Up @@ -252,7 +256,7 @@ func exists(path string) (bool, error) {
// parsing JSON data generated by axw/gocov. The css parameter
// is an absolute path to a custom stylesheet. Use an empty
// string to use the default stylesheet available.
func HTMLReportCoverage(r io.Reader, css string) error {
func HTMLReportCoverage(r io.Reader, lowCoverageOnTop bool, css string) error {
report := newReport()

// Custom stylesheet?
Expand All @@ -279,6 +283,6 @@ func HTMLReportCoverage(r io.Reader, css string) error {
report.addPackage(pkg)
}
fmt.Println()
printReport(os.Stdout, report)
printReport(os.Stdout, lowCoverageOnTop, report)
return nil
}
5 changes: 3 additions & 2 deletions gocov-html.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package main

import (
"flag"
"github.com/matm/gocov-html/cov"
"github.com/Blackmage89/gocov-html/cov"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package name changed to github.com/Blackmage89/gocov-html/cov from github.com/matm/gocov-html/cov.

"io"
"log"
"os"
Expand All @@ -33,6 +33,7 @@ func main() {
log.SetFlags(0)

var s = flag.String("s", "", "path to custom CSS file")
var i = flag.Bool("i", false, "put low coverage functions on top")
flag.Parse()

switch flag.NArg() {
Expand All @@ -47,7 +48,7 @@ func main() {
log.Fatalf("Usage: %s data.json\n", os.Args[0])
}

if err := cov.HTMLReportCoverage(r, *s); err != nil {
if err := cov.HTMLReportCoverage(r, *i, *s); err != nil {
log.Fatal(err)
}
}