├── .github └── workflows │ └── go.yml ├── .gitignore ├── AUTHORS ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── build.mk ├── cmd ├── generator │ └── main.go └── gocov-html │ └── main.go ├── go.mod ├── go.sum ├── pkg ├── config │ └── version.go └── themes │ ├── default.go │ ├── default_gen.go │ ├── kit.go │ ├── kit_gen.go │ ├── report.go │ ├── theme.go │ └── theme_test.go ├── res ├── monero-symbol-on-white-96.png ├── qr-donate.png └── qr-donate.svg ├── themes ├── README.md ├── golang │ ├── index.html │ ├── screenshot.png │ └── style.css └── kit │ ├── app.css │ ├── app.js │ ├── index.html │ ├── kit.css │ └── screenshot.png └── version.mk /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a golang project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go 3 | 4 | name: Go 5 | 6 | on: 7 | push: 8 | branches: [ "master" ] 9 | pull_request: 10 | branches: [ "master" ] 11 | 12 | jobs: 13 | 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - name: Set up Go 20 | uses: actions/setup-go@v3 21 | with: 22 | go-version: 1.11 23 | 24 | - name: Build 25 | run: go build -v ./cmd/gocov-html 26 | 27 | - name: Test 28 | run: go test -v ./... 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /gocov-html 2 | /generator 3 | *.swp 4 | /*.css 5 | // Generated Go files 6 | /build 7 | /dist 8 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Mathias Monnerville 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | v 1.4.0 2 | - refac: remove pkg/types package. #51 3 | - Add CLI support for coverage thresholds. #43 4 | - refac: faster and cleaner code generator. #52 5 | 6 | v 1.3.1 7 | - Fix clean target in Makefile. #49 8 | - Version the generated files and restore the go install command. #47 9 | - Add reverse order CLI flag. #41 10 | - Add a tiny Dockerfile showing the build instructions. #44 11 | 12 | v 1.3.0 13 | - New kit theme. #28 14 | - refac: generate Go code to render themes. #38 15 | - doc: fix semver in README. #36 16 | 17 | v 1.2.0 18 | - Makefile: fix missing version info during build. #33 19 | - Provide binaries for a variety of os/arch. #31 20 | - Add support for themes. #24 21 | - Re-enable support for older Go compilers (1.11+). #29 22 | - New -d flag to output CSS content used in default theme. #22 23 | - Embbed custom stylesheet into final HTML document. #22 24 | 25 | v 1.1.1 26 | - Show a 100% coverage for empty functions/methods. #16 27 | - Update project layout and show program version. #17 28 | 29 | v 1.1 30 | - Skip packages missing test files (no report generation) 31 | 32 | v 1.0 33 | - First version 34 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.19-alpine3.16 2 | 3 | RUN apk update && apk add git 4 | RUN go install github.com/axw/gocov/gocov@latest 5 | RUN go install github.com/matm/gocov-html/cmd/gocov-html@latest 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Mathias Monnerville 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: gocov-html build dist linux darwin windows buildall cleardist clean 2 | 3 | 4 | BIN=gocov-html 5 | MAIN_CMD=github.com/matm/${BIN}/cmd/${BIN} 6 | 7 | GENERATOR_BIN=generator 8 | GENERATOR_CMD=github.com/matm/${BIN}/cmd/${GENERATOR_BIN} 9 | 10 | include version.mk 11 | include build.mk 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gocov HTML export 2 | 3 | [![go-recipes](https://raw.githubusercontent.com/nikolaydubina/go-recipes/main/badge.svg?raw=true)](https://github.com/nikolaydubina/go-recipes) 4 | 5 | This is a simple helper tool for generating HTML output from [axw/gocov](https://github.com/axw/gocov/). 6 | 7 | `gocov-html` has support for themes, you might want to have a [look at the screenshots](themes/README.md). 8 | 9 | ## Installation 10 | 11 | Binaries for most amd64 systems are built for every release. Please just [grab a binary version of the latest release](https://github.com/matm/gocov-html/releases). 12 | 13 | You can also build it from source. In this case, a working Go 1.11+ compiler is required: 14 | 15 | ```bash 16 | $ go install github.com/matm/gocov-html/cmd/gocov-html@latest 17 | ``` 18 | 19 | A [Dockerfile](Dockerfile) is also provided. 20 | 21 | ## Features Matrix 22 | 23 | Feature|CLI Flag|Version 24 | :---|:---|---: 25 | Use custom CSS file|`-s `|`1.0.0` 26 | Show program version|`-v`|`1.1.1` 27 | Write CSS of default theme to stdout|`-d`|`1.2.0` 28 | Embbed custom CSS into final HTML document|-|`1.2.0` 29 | List available themes|`-lt`|`1.2.0` 30 | Render with a specific theme|`-t `|`1.2.0` 31 | New `kit` theme |`-t kit`|`1.3.0` 32 | Put lower coverage functions on top|`-r`|`1.3.1` 33 | Only show functions whose coverage is smaller than a max threshold|`-cmax`|`1.4.0` 34 | Only show functions whose coverage is greater than a min threshold|`-cmin`|`1.4.0` 35 | 36 | ## Usage 37 | 38 | ``` 39 | Usage of gocov-html: 40 | -cmax uint 41 | only show functions whose coverage is less than cmax (default 100) 42 | -cmin uint 43 | only show functions whose coverage is more than cmin 44 | -d output CSS of default theme 45 | -lt 46 | list available themes 47 | -r put lower coverage functions on top 48 | -s string 49 | path to custom CSS file 50 | -t string 51 | theme to use for rendering (default "golang") 52 | -v show program version 53 | ``` 54 | 55 | ## Examples 56 | 57 | Generate code coverage for the `strings` package then generate an HTML report: 58 | ``` 59 | $ gocov test strings | gocov-html > strings.html 60 | ok strings 0.700s coverage: 98.1% of statements 61 | ``` 62 | 63 | Merge several coverage stats for different packages into a single report: 64 | ``` 65 | $ gocov test fmt math io | gocov-html > report.html 66 | ok fmt 0.045s coverage: 95.2% of statements 67 | ok math 0.006s coverage: 83.6% of statements 68 | ok io 0.024s coverage: 88.2% of statements 69 | ``` 70 | 71 | In this case, the generated report will have an *overview* section with stats per package along with the global coverage percentage. This section may be rendered depending on the theme used. The `golang` (default) theme displays it. 72 | 73 | List all available themes: 74 | ``` 75 | $ gocov-html -lt 76 | golang -- original golang theme (default) 77 | kit -- AdminKit theme 78 | ``` 79 | 80 | Generate a report using a specific theme with `-t`: 81 | ``` 82 | $ gocov test io | gocov-html -t kit > io.html 83 | ``` 84 | 85 | Only show functions whose code coverage is lower than 90% for the `strings` package: 86 | ``` 87 | $ gocov test strings|./gocov-html -cmax 90 > strings.html 88 | ``` 89 | In this example, only 5 matches are added to the report. 90 | 91 | ## Donate 92 | 93 | If you like this tool and want to support its development, a donation would be greatly appreciated! 94 | 95 | It's not about the amount at all: making a donation boosts the motivation to work on a project. Thank you very much if you can give anything. 96 | 97 | Monero address: 98 | `86S43wMDNPgNeUd6MkPEpiPUbBM6dS6DGdXBzc34uSw3Lxyg9p5tjmuGHESwmza3wGKfP2njUQdEd6kE3YPFRuaJFzP4Ger` 99 | 100 | ![My monero address](res/qr-donate.png) 101 | -------------------------------------------------------------------------------- /build.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Cross building for various operating systems (amd64) 3 | # 4 | WINDOWS_BIN=${BIN}.exe 5 | DISTDIR=dist 6 | BINDIR=${DISTDIR}/${BIN} 7 | BUILDDIR=build 8 | # 9 | BUILD_VERSION=${BIN}-${VERSION} 10 | BUILD_DARWIN_AMD64=${BUILD_VERSION}-darwin-amd64 11 | BUILD_FREEBSD_AMD64=${BUILD_VERSION}-freebsd-amd64 12 | BUILD_OPENBSD_AMD64=${BUILD_VERSION}-openbsd-amd64 13 | BUILD_LINUX_AMD64=${BUILD_VERSION}-linux-amd64 14 | BUILD_WINDOWS_AMD64=${BUILD_VERSION}-windows-amd64 15 | # 16 | GOBUILD64=GOARCH=amd64 go build -ldflags "all=$(GO_LDFLAGS)" 17 | 18 | all: build 19 | 20 | dist: cleardist buildall zip sourcearchive checksum 21 | 22 | checksum: 23 | @for f in ${DISTDIR}/*; do \ 24 | sha256sum $$f > $$f.sha256; \ 25 | sed -i 's,${DISTDIR}/,,' $$f.sha256; \ 26 | done 27 | 28 | zip: linux freebsd openbsd darwin windows 29 | @rm -rf ${BINDIR} 30 | 31 | linux: 32 | @cp ${BUILDDIR}/${BUILD_VERSION}-linux* ${BINDIR}/${BIN} && \ 33 | (cd ${DISTDIR} && zip -r ${BUILD_LINUX_AMD64}.zip ${BIN}) 34 | 35 | darwin: 36 | @cp ${BUILDDIR}/${BUILD_VERSION}-darwin* ${BINDIR}/${BIN} && \ 37 | (cd ${DISTDIR} && zip -r ${BUILD_DARWIN_AMD64}.zip ${BIN}) 38 | 39 | windows: 40 | @cp ${BUILDDIR}/${BUILD_VERSION}-windows* ${BINDIR}/${WINDOWS_BIN} && \ 41 | (cd ${DISTDIR} && rm ${BIN}/${BIN} && zip -r ${BUILD_WINDOWS_AMD64}.zip ${BIN}) 42 | 43 | freebsd: 44 | @cp ${BUILDDIR}/${BUILD_VERSION}-freebsd* ${BINDIR}/${BIN} && \ 45 | (cd ${DISTDIR} && zip -r ${BUILD_FREEBSD_AMD64}.zip ${BIN}) 46 | 47 | openbsd: 48 | @cp ${BUILDDIR}/${BUILD_VERSION}-openbsd* ${BINDIR}/${BIN} && \ 49 | (cd ${DISTDIR} && zip -r ${BUILD_OPENBSD_AMD64}.zip ${BIN}) 50 | 51 | buildall: 52 | @echo ">>>>>> OpenBSD build <<<<<<<" 53 | @GOOS=openbsd ${GOBUILD64} -v -o ${BUILDDIR}/${BUILD_OPENBSD_AMD64} ${MAIN_CMD} 54 | @echo ">>>>>> FreeBSD build <<<<<<<" 55 | @GOOS=freebsd ${GOBUILD64} -v -o ${BUILDDIR}/${BUILD_FREEBSD_AMD64} ${MAIN_CMD} 56 | @echo ">>>>>> Linux build <<<<<<<" 57 | @GOOS=linux ${GOBUILD64} -v -o ${BUILDDIR}/${BUILD_LINUX_AMD64} ${MAIN_CMD} 58 | @echo ">>>>>> MacOSX build <<<<<<<" 59 | @GOOS=darwin ${GOBUILD64} -v -o ${BUILDDIR}/${BUILD_DARWIN_AMD64} ${MAIN_CMD} 60 | @echo ">>>>>> Windows build <<<<<<<" 61 | @GOOS=windows ${GOBUILD64} -v -o ${BUILDDIR}/${BUILD_WINDOWS_AMD64} ${MAIN_CMD} 62 | 63 | sourcearchive: 64 | @git archive --format=zip -o ${DISTDIR}/${BUILD_VERSION}.zip ${VERSION} 65 | @echo ${DISTDIR}/${BUILD_VERSION}.zip 66 | @git archive -o ${DISTDIR}/${BUILD_VERSION}.tar ${VERSION} 67 | @gzip ${DISTDIR}/${BUILD_VERSION}.tar 68 | @echo ${DISTDIR}/${BUILD_VERSION}.tar.gz 69 | 70 | cleardist: 71 | @rm -rf ${DISTDIR} && mkdir -p ${BINDIR} && mkdir -p ${BUILDDIR} 72 | 73 | build: 74 | go build ${GENERATOR_CMD} && \ 75 | go generate ./... 76 | @echo "building ..." && \ 77 | go build -ldflags "all=$(GO_LDFLAGS)" ${MAIN_CMD} 78 | 79 | test: 80 | @go test ./... 81 | 82 | clean: 83 | @rm -rf ${BIN} ${GENERATOR_BIN} ${BUILDDIR} ${DISTDIR} 84 | -------------------------------------------------------------------------------- /cmd/generator/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "fmt" 7 | "go/ast" 8 | "go/parser" 9 | "go/token" 10 | "io" 11 | "io/ioutil" 12 | "log" 13 | "os" 14 | "path" 15 | "strings" 16 | "text/template" 17 | 18 | "github.com/matm/gocov-html/pkg/themes" 19 | ) 20 | 21 | const tmpl = `// Code generated by "go run generator.go". DO NOT EDIT. 22 | 23 | package themes 24 | 25 | import ( 26 | "text/template" 27 | "time" 28 | ) 29 | 30 | func (t {{.Type}}) Data() *templateData { 31 | td:= &templateData{ 32 | When: time.Now().Format(time.RFC1123), 33 | ProjectURL: ProjectURL, 34 | } 35 | {{if .Style}} 36 | td.Style = "{{.Style}}" 37 | {{end}} 38 | {{if .Script}} 39 | td.Script = "{{.Script}}" 40 | {{end}} 41 | return td 42 | } 43 | 44 | func (t {{.Type}}) Template() *template.Template { 45 | tmpl := {{.Template}} 46 | p := template.Must(template.New("theme").Parse(tmpl)) 47 | return p 48 | } 49 | ` 50 | 51 | func inspect(p *params) error { 52 | fset := token.NewFileSet() 53 | token, err := parser.ParseFile(fset, p.filename, nil, parser.ParseComments) 54 | if err != nil { 55 | return err 56 | } 57 | ast.Inspect(token, func(n ast.Node) bool { 58 | fn, ok := n.(*ast.FuncDecl) 59 | if ok { 60 | p.rtype = fn.Recv.List[0].Type.(*ast.Ident).Name 61 | switch fn.Name.Name { 62 | case "Name": 63 | p.theme = fn.Body.List[0].(*ast.ReturnStmt).Results[0].(*ast.BasicLit).Value 64 | p.theme = strings.Replace(p.theme, `"`, "", -1) 65 | case "Assets": 66 | es := fn.Body.List[0].(*ast.ReturnStmt).Results[0].(*ast.CompositeLit).Elts 67 | for _, e := range es { 68 | kv := e.(*ast.KeyValueExpr) 69 | id := kv.Key.(*ast.Ident) 70 | switch id.Name { 71 | case "Stylesheets": 72 | elems := kv.Value.(*ast.CompositeLit).Elts 73 | for _, elem := range elems { 74 | sheet := elem.(*ast.BasicLit).Value 75 | p.assets.Stylesheets = append(p.assets.Stylesheets, strings.Replace(sheet, `"`, "", -1)) 76 | } 77 | case "Index": 78 | tmplName := kv.Value.(*ast.BasicLit).Value 79 | p.assets.Index = strings.Replace(tmplName, `"`, "", -1) 80 | case "Scripts": 81 | elems := kv.Value.(*ast.CompositeLit).Elts 82 | for _, elem := range elems { 83 | script := elem.(*ast.BasicLit).Value 84 | p.assets.Scripts = append(p.assets.Scripts, strings.Replace(script, `"`, "", -1)) 85 | } 86 | } 87 | } 88 | } 89 | return false 90 | } 91 | return true 92 | }) 93 | return nil 94 | } 95 | 96 | func render(p *params) error { 97 | baseThemeDir := path.Join("..", "..", "themes", p.theme) 98 | out := strings.Replace(p.filename, ".go", "_gen.go", 1) 99 | outFile, err := os.Create(out) 100 | if err != nil { 101 | return err 102 | } 103 | defer outFile.Close() 104 | index, err := ioutil.ReadFile(path.Join(baseThemeDir, p.assets.Index)) 105 | if err != nil { 106 | return err 107 | } 108 | // Contains all stylesheets' data. 109 | var allStyles bytes.Buffer 110 | // Contains all scripts' data. 111 | var allScripts bytes.Buffer 112 | 113 | type static struct { 114 | buf *bytes.Buffer 115 | assets []string 116 | } 117 | 118 | for _, st := range []static{ 119 | {&allStyles, p.assets.Stylesheets}, 120 | {&allScripts, p.assets.Scripts}, 121 | } { 122 | var buf bytes.Buffer 123 | for _, asset := range st.assets { 124 | f, err := os.Open(path.Join(baseThemeDir, asset)) 125 | if err != nil { 126 | return err 127 | } 128 | defer f.Close() 129 | _, err = io.Copy(&buf, f) 130 | if err != nil { 131 | return err 132 | } 133 | } 134 | // Encode in base64 instead to prevent any invalid character escaping issues. 135 | fmt.Fprint(st.buf, base64.StdEncoding.EncodeToString(buf.Bytes())) 136 | } 137 | t, err := template.New("").Parse(tmpl) 138 | if err != nil { 139 | return err 140 | } 141 | type data struct { 142 | Script string 143 | Style string 144 | Template string 145 | Type string 146 | } 147 | err = t.Execute(outFile, &data{ 148 | Script: allScripts.String(), 149 | Style: allStyles.String(), 150 | Template: "`" + string(index) + "`", 151 | Type: p.rtype, 152 | }) 153 | return err 154 | } 155 | 156 | type params struct { 157 | filename string 158 | rtype string // Receiver type. 159 | theme string 160 | assets themes.StaticAssets 161 | } 162 | 163 | func main() { 164 | name := os.Getenv("GOFILE") 165 | if name == "" { 166 | fmt.Println("Must be run by the \"go generate\" tool, like \"go generate ./...\"") 167 | os.Exit(1) 168 | } 169 | p := ¶ms{filename: name} 170 | err := inspect(p) 171 | if err != nil { 172 | log.Fatal(err) 173 | } 174 | if err := render(p); err != nil { 175 | log.Fatal(err) 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /cmd/gocov-html/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2022 Mathias Monnerville 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to 5 | // deal in the Software without restriction, including without limitation the 6 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | // sell copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | // IN THE SOFTWARE. 20 | 21 | package main 22 | 23 | import ( 24 | "flag" 25 | "fmt" 26 | "io" 27 | "log" 28 | "os" 29 | "runtime" 30 | 31 | "github.com/matm/gocov-html/pkg/config" 32 | "github.com/matm/gocov-html/pkg/themes" 33 | ) 34 | 35 | func main() { 36 | var r io.Reader 37 | log.SetFlags(0) 38 | 39 | css := flag.String("s", "", "path to custom CSS file") 40 | showVersion := flag.Bool("v", false, "show program version") 41 | showDefaultCSS := flag.Bool("d", false, "output CSS of default theme") 42 | listThemes := flag.Bool("lt", false, "list available themes") 43 | theme := flag.String("t", "golang", "theme to use for rendering") 44 | reverseOrder := flag.Bool("r", false, "put lower coverage functions on top") 45 | maxCoverage := flag.Uint64("cmax", 100, "only show functions whose coverage is greater than cmax") 46 | minCoverage := flag.Uint64("cmin", 0, "only show functions whose coverage is smaller than cmin") 47 | 48 | flag.Parse() 49 | 50 | if *showVersion { 51 | fmt.Printf("Version: %s\n", config.Version) 52 | fmt.Printf("Git revision: %s\n", config.GitRev) 53 | fmt.Printf("Git branch: %s\n", config.GitBranch) 54 | fmt.Printf("Go version: %s\n", runtime.Version()) 55 | fmt.Printf("Built: %s\n", config.BuildDate) 56 | fmt.Printf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) 57 | return 58 | } 59 | 60 | if *listThemes { 61 | for _, th := range themes.List() { 62 | fmt.Printf("%-10s -- %s\n", th.Name(), th.Description()) 63 | } 64 | return 65 | } 66 | 67 | if *minCoverage > *maxCoverage { 68 | log.Fatal("error: empty report if cmin > cmax, please use a smaller cmin value.") 69 | } 70 | if *maxCoverage > 100 { 71 | *maxCoverage = 100 72 | } 73 | 74 | err := themes.Use(*theme) 75 | if err != nil { 76 | log.Fatalf("theme selection: %v", err) 77 | } 78 | 79 | if *showDefaultCSS { 80 | fmt.Println(themes.Current().Data().Style) 81 | return 82 | } 83 | 84 | switch flag.NArg() { 85 | case 0: 86 | r = os.Stdin 87 | case 1: 88 | var err error 89 | if r, err = os.Open(flag.Arg(0)); err != nil { 90 | log.Fatal(err) 91 | } 92 | default: 93 | log.Fatalf("Usage: %s data.json\n", os.Args[0]) 94 | } 95 | 96 | opts := themes.ReportOptions{ 97 | LowCoverageOnTop: *reverseOrder, 98 | Stylesheet: *css, 99 | CoverageMin: uint8(*minCoverage), 100 | CoverageMax: uint8(*maxCoverage), 101 | } 102 | if err := themes.HTMLReportCoverage(r, opts); err != nil { 103 | log.Fatal(err) 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/matm/gocov-html 2 | 3 | go 1.11 4 | 5 | require ( 6 | github.com/axw/gocov v1.1.0 7 | github.com/rotisserie/eris v0.5.4 8 | ) 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/axw/gocov v1.1.0 h1:y5U1krExoJDlb/kNtzxyZQmNRprFOFCutWbNjcQvmVM= 2 | github.com/axw/gocov v1.1.0/go.mod h1:H9G4tivgdN3pYSSVrTFBr6kGDCmAkgbJhtxFzAvgcdw= 3 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 5 | github.com/rotisserie/eris v0.5.4 h1:Il6IvLdAapsMhvuOahHWiBnl1G++Q0/L5UIkI5mARSk= 6 | github.com/rotisserie/eris v0.5.4/go.mod h1:Z/kgYTJiJtocxCbFfvRmO+QejApzG6zpyky9G1A4g9s= 7 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 8 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 9 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 10 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 11 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 12 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 13 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 14 | golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 15 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 16 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 17 | -------------------------------------------------------------------------------- /pkg/config/version.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | // Populated during build, don't touch! 4 | var ( 5 | Version = "undefined" 6 | GitRev = "undefined" 7 | GitBranch = "undefined" 8 | BuildDate = "undefined" 9 | ) 10 | -------------------------------------------------------------------------------- /pkg/themes/default.go: -------------------------------------------------------------------------------- 1 | package themes 2 | 3 | //go:generate ../../generator 4 | 5 | type defaultTheme struct{} 6 | 7 | func (t defaultTheme) Assets() StaticAssets { 8 | return StaticAssets{ 9 | Stylesheets: []string{"style.css"}, 10 | Index: "index.html", 11 | } 12 | } 13 | 14 | func (t defaultTheme) Name() string { 15 | return "golang" 16 | } 17 | 18 | func (t defaultTheme) Description() string { 19 | return "original golang theme (default)" 20 | } 21 | -------------------------------------------------------------------------------- /pkg/themes/default_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by "go run generator.go". DO NOT EDIT. 2 | 3 | package themes 4 | 5 | import ( 6 | "text/template" 7 | "time" 8 | ) 9 | 10 | func (t defaultTheme) Data() *templateData { 11 | td:= &templateData{ 12 | When: time.Now().Format(time.RFC1123), 13 | ProjectURL: ProjectURL, 14 | } 15 | 16 | td.Style = "Ym9keSB7CiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAjZmZmOwogICAgZm9udC1mYW1pbHk6ICJIZWx2ZXRpY2EgTmV1ZSIsIEhlbHZldGljYSwgQXJpYWwsIHNhbnMtc2VyaWY7Cn0KCnRhYmxlIHsKICAgIG1hcmdpbi1sZWZ0OiAxMHB4OwogICAgYm9yZGVyLWNvbGxhcHNlOiBjb2xsYXBzZTsKfQoKdGQgewogICAgYmFja2dyb3VuZC1jb2xvcjogI2ZmZjsKICAgIHBhZGRpbmc6IDJweDsKfQoKdGFibGUub3ZlcnZpZXcgdGQgewogICAgcGFkZGluZy1yaWdodDogMjBweDsKfQoKdGQucGVyY2VudCwKdGQubGluZWNvdW50IHsKICAgIHRleHQtYWxpZ246IHJpZ2h0Owp9CgpkaXYucGFja2FnZSwKI3RvdGFsY292IHsKICAgIGNvbG9yOiAjZmZmOwogICAgYmFja2dyb3VuZC1jb2xvcjogIzM3NWVhYjsKICAgIGZvbnQtc2l6ZTogMTZweDsKICAgIGZvbnQtd2VpZ2h0OiBib2xkOwogICAgcGFkZGluZzogMTBweDsKICAgIGJvcmRlci1yYWRpdXM6IDVweCA1cHggNXB4IDVweDsKfQoKZGl2LnBhY2thZ2UsCiN0b3RhbGNvdiB7CiAgICBmbG9hdDogcmlnaHQ7CiAgICByaWdodDogMTBweDsKfQoKI3RvdGFsY292IHsKICAgIHRvcDogMTBweDsKICAgIHBvc2l0aW9uOiByZWxhdGl2ZTsKICAgIGJhY2tncm91bmQtY29sb3I6ICNmZmY7CiAgICBjb2xvcjogIzAwMDsKICAgIGJvcmRlcjogMXB4IHNvbGlkICMzNzVlYWI7CiAgICBjbGVhcjogYm90aDsKfQoKI3N1bW1hcnlXcmFwcGVyIHsKICAgIHBvc2l0aW9uOiBmaXhlZDsKICAgIHRvcDogMTBweDsKICAgIGZsb2F0OiByaWdodDsKICAgIHJpZ2h0OiAxMHB4OwoKfQoKc3Bhbi5wYWNrYWdlVG90YWwgewogICAgZmxvYXQ6IHJpZ2h0OwogICAgY29sb3I6ICMwMDA7Cn0KCiNkb2N0aXRsZSB7CiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAjZmZmOwogICAgZm9udC1zaXplOiAyNHB4OwogICAgbWFyZ2luLXRvcDogMjBweDsKICAgIG1hcmdpbi1sZWZ0OiAxMHB4OwogICAgY29sb3I6ICMzNzVlYWI7CiAgICBmb250LXdlaWdodDogYm9sZDsKfQoKI2Fib3V0IHsKICAgIG1hcmdpbi1sZWZ0OiAxOHB4OwogICAgZm9udC1zaXplOiAxMHB4Owp9CgouZnVuY3RpdGxlLAouZnVuY25hbWUgewogICAgdGV4dC1hbGlnbjogY2VudGVyOwogICAgZm9udC1zaXplOiAyMHB4OwogICAgZm9udC13ZWlnaHQ6IGJvbGQ7CiAgICBjb2xvcjogIzM3NWVhYjsKfQoKLmZ1bmNuYW1lIHsKICAgIHRleHQtYWxpZ246IGxlZnQ7CiAgICBtYXJnaW4tdG9wOiAyMHB4OwogICAgbWFyZ2luLWxlZnQ6IDEwcHg7CiAgICBtYXJnaW4tYm90dG9tOiAyMHB4OwogICAgcGFkZGluZzogMnB4IDVweCA1cHg7CiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAjZTBlYmY1Owp9Cgp0YWJsZS5saXN0aW5nIHsKICAgIG1hcmdpbi1sZWZ0OiAxMHB4Owp9Cgp0YWJsZS5saXN0aW5nIHRkIHsKICAgIHBhZGRpbmc6IDBweDsKICAgIGZvbnQtc2l6ZTogMTJweDsKICAgIGJhY2tncm91bmQtY29sb3I6ICNlZWU7CiAgICB2ZXJ0aWNhbC1hbGlnbjogdG9wOwogICAgcGFkZGluZy1sZWZ0OiAxMHB4OwogICAgYm9yZGVyLWJvdHRvbTogMXB4IHNvbGlkICNmZmY7Cn0KCnRhYmxlLmxpc3RpbmcgdGQ6Zmlyc3QtY2hpbGQgewogICAgdGV4dC1hbGlnbjogcmlnaHQ7CiAgICBmb250LXdlaWdodDogYm9sZDsKICAgIHZlcnRpY2FsLWFsaWduOiBjZW50ZXI7Cn0KCnRhYmxlLmxpc3RpbmcgdHIubWlzcyB0ZCB7CiAgICBiYWNrZ3JvdW5kLWNvbG9yOiAjRkZCQkI4Owp9Cgp0YWJsZS5saXN0aW5nIHRyOmxhc3QtY2hpbGQgdGQgewogICAgZm9udC13ZWlnaHQ6IG5vcm1hbDsKICAgIGNvbG9yOiAjMDAwOwp9Cgp0YWJsZS5saXN0aW5nIHRyOmxhc3QtY2hpbGQgdGQ6Zmlyc3QtY2hpbGQgewogICAgZm9udC13ZWlnaHQ6IGJvbGQ7Cn0KCi5pbmZvIHsKICAgIG1hcmdpbi1sZWZ0OiAxMHB4Owp9CgouaW5mbyBjb2RlIHt9CgpwcmUgewogICAgbWFyZ2luOiAxcHg7Cn0KCnByZS5jbWQgewogICAgYmFja2dyb3VuZC1jb2xvcjogI2U5ZTllOTsKICAgIGJvcmRlci1yYWRpdXM6IDVweCA1cHggNXB4IDVweDsKICAgIHBhZGRpbmc6IDEwcHg7CiAgICBtYXJnaW46IDIwcHg7CiAgICBsaW5lLWhlaWdodDogMThweDsKICAgIGZvbnQtc2l6ZTogMTRweDsKfQoKYSB7CiAgICB0ZXh0LWRlY29yYXRpb246IG5vbmU7CiAgICBjb2xvcjogIzM3NWVhYjsKfQoKYTpob3ZlciB7CiAgICB0ZXh0LWRlY29yYXRpb246IHVuZGVybGluZTsKfQoKcCB7CiAgICBtYXJnaW4tbGVmdDogMTBweDsKfQ==" 17 | 18 | 19 | return td 20 | } 21 | 22 | func (t defaultTheme) Template() *template.Template { 23 | tmpl := `{{define "theme"}} 24 | 25 | 26 | Coverage Report 27 | 28 | {{if .Style}} 29 | 32 | {{end}} 33 | 34 | 35 |
Coverage Report
36 | {{if not .Packages}} 37 |

no test files in package.

" 38 | {{else}} 39 |
Generated on {{.When}} with gocov-html
40 | {{/* Report overview/summary available? */}} 41 | {{if .Overview}} 42 |
Report Overview
43 | 44 | {{range $k,$rp := .Packages}} 45 | 46 | 47 | 48 | 49 | 50 | {{end}} 51 |
{{$rp.Pkg.Name}}{{printf "%.1f%%" $rp.PercentageReached}}{{printf "%d" $rp.ReachedStatements}}/{{printf "%d" $rp.TotalStatements}}
52 |

53 | This coverage report has been generated with the following command: 54 |

55 |
{{.Command}}
56 | 57 | {{end}} 58 | {{range $k,$rp := .Packages}} 59 |
60 | Package Overview: {{$rp.Pkg.Name}} 61 | {{printf "%.1f%%" $rp.PercentageReached}} 62 |
63 |

Please select a function to see what's left for testing.

64 | 65 | 66 | {{range $k,$f := $rp.Functions}} 67 | 68 | 71 | 74 | 77 | 80 | 81 | {{end}} 82 |
69 | {{$f.Name}}(...) 70 | 72 | {{$rp.Pkg.Name}}/{{$f.ShortFileName}} 73 | 75 | {{printf "%.1f%%" $f.CoveragePercent}} 76 | 78 | {{$f.StatementsReached}}/{{len $f.Statements}} 79 |
83 | 84 | {{/* Functions source code here */}} 85 | {{range $k,$f := $rp.Functions}} 86 |
func {{$f.Name}}
87 |
88 | Back 89 |

In {{$f.File}}:

90 |
91 | 92 | {{range $p,$info := $f.Lines}} 93 | 94 | 95 | 98 | 99 | {{end}} 100 |
{{$info.LineNumber}} 96 |
{{$info.Code}}
97 |
101 | {{end}} {{/* range function lines */}} 102 | 103 | 106 | {{end}} {{/* range Packages end */}} 107 | 108 |
109 | {{if not .Overview}} 110 | {{$rp := index .Packages 0}} 111 |
{{$rp.Pkg.Name}}
112 |
{{printf "%.1f%%" $rp.PercentageReached}}
113 | {{else}} 114 |
{{.Overview.Pkg.Name}}
115 |
{{printf "%.1f%%" .Overview.PercentageReached}}
116 | {{end}} {{/* if overview end */}} 117 |
118 | {{end}} {{/* range if end */}} 119 | {{if .Script}} 120 | 123 | {{end}} 124 | 125 | 126 | {{end}}` 127 | p := template.Must(template.New("theme").Parse(tmpl)) 128 | return p 129 | } 130 | -------------------------------------------------------------------------------- /pkg/themes/kit.go: -------------------------------------------------------------------------------- 1 | package themes 2 | 3 | //go:generate ../../generator 4 | 5 | type kitTheme struct{} 6 | 7 | func (t kitTheme) Assets() StaticAssets { 8 | return StaticAssets{ 9 | Stylesheets: []string{ 10 | // From the official theme. 11 | "app.css", 12 | //"a.css", "b.css", 13 | // Custom rules. 14 | "kit.css", 15 | }, 16 | Scripts: []string{"app.js"}, 17 | Index: "index.html", 18 | } 19 | } 20 | 21 | func (t kitTheme) Name() string { 22 | return "kit" 23 | } 24 | 25 | func (t kitTheme) Description() string { 26 | return "AdminKit theme" 27 | } 28 | -------------------------------------------------------------------------------- /pkg/themes/report.go: -------------------------------------------------------------------------------- 1 | package themes 2 | 3 | import ( 4 | "encoding/base64" 5 | "encoding/json" 6 | "fmt" 7 | "go/token" 8 | "html" 9 | "io" 10 | "io/ioutil" 11 | "os" 12 | "path/filepath" 13 | "sort" 14 | "strings" 15 | "time" 16 | 17 | "github.com/axw/gocov" 18 | "github.com/rotisserie/eris" 19 | ) 20 | 21 | // ReportOptions holds various options used when generating the final 22 | // HTML report. 23 | type ReportOptions struct { 24 | // LowCoverageOnTop puts low coverage functions first. 25 | LowCoverageOnTop bool 26 | // Stylesheet is the path to a custom CSS file. 27 | Stylesheet string 28 | // CoverageMin filters out all functions whose code coverage is smaller than it is. 29 | CoverageMin uint8 30 | // CoverageMax filters out all functions whose code coverage is greater than it is. 31 | CoverageMax uint8 32 | } 33 | 34 | type report struct { 35 | ReportOptions 36 | packages []*gocov.Package 37 | } 38 | 39 | func unmarshalJSON(data []byte) (packages []*gocov.Package, err error) { 40 | result := &struct{ Packages []*gocov.Package }{} 41 | err = json.Unmarshal(data, result) 42 | if err == nil { 43 | packages = result.Packages 44 | } 45 | return 46 | } 47 | 48 | type reverse struct { 49 | sort.Interface 50 | } 51 | 52 | func (r reverse) Less(i, j int) bool { 53 | return r.Interface.Less(j, i) 54 | } 55 | 56 | // NewReport creates a new report. 57 | func newReport() (r *report) { 58 | r = &report{} 59 | return 60 | } 61 | 62 | // AddPackage adds a package's coverage information to the report. 63 | func (r *report) addPackage(p *gocov.Package) { 64 | i := sort.Search(len(r.packages), func(i int) bool { 65 | return r.packages[i].Name >= p.Name 66 | }) 67 | if i < len(r.packages) && r.packages[i].Name == p.Name { 68 | r.packages[i].Accumulate(p) 69 | } else { 70 | head := r.packages[:i] 71 | tail := append([]*gocov.Package{p}, r.packages[i:]...) 72 | r.packages = append(head, tail...) 73 | } 74 | } 75 | 76 | // Clear clears the coverage information from the report. 77 | func (r *report) clear() { 78 | r.packages = nil 79 | } 80 | 81 | func buildReportPackage(pkg *gocov.Package, r *report) reportPackage { 82 | rv := reportPackage{ 83 | Pkg: pkg, 84 | Functions: make(reportFunctionList, 0), 85 | } 86 | for _, fn := range pkg.Functions { 87 | reached := 0 88 | for _, stmt := range fn.Statements { 89 | if stmt.Reached > 0 { 90 | reached++ 91 | } 92 | } 93 | rf := reportFunction{Function: fn, StatementsReached: reached} 94 | covp := rf.CoveragePercent() 95 | if covp >= float64(r.CoverageMin) && covp <= float64(r.CoverageMax) { 96 | rv.Functions = append(rv.Functions, rf) 97 | } 98 | rv.TotalStatements += len(fn.Statements) 99 | rv.ReachedStatements += reached 100 | } 101 | if r.LowCoverageOnTop { 102 | sort.Sort(rv.Functions) 103 | } else { 104 | sort.Sort(reverse{rv.Functions}) 105 | } 106 | return rv 107 | } 108 | 109 | // printReport prints a coverage report to the given writer. 110 | func printReport(w io.Writer, r *report) error { 111 | data := curTheme.Data() 112 | 113 | // Base64 decoding of style data and script. 114 | s, err := base64.StdEncoding.DecodeString(data.Style) 115 | if err != nil { 116 | return eris.Wrap(err, "decode style") 117 | } 118 | css := string(s) 119 | // Decode the script also. 120 | sc, err := base64.StdEncoding.DecodeString(data.Script) 121 | if err != nil { 122 | return eris.Wrap(err, "decode script") 123 | } 124 | 125 | if len(r.Stylesheet) > 0 { 126 | // Inline CSS. 127 | f, err := os.Open(r.Stylesheet) 128 | if err != nil { 129 | return eris.Wrap(err, "print report") 130 | } 131 | style, err := ioutil.ReadAll(f) 132 | if err != nil { 133 | return eris.Wrap(err, "read style") 134 | } 135 | css = string(style) 136 | } 137 | reportPackages := make(reportPackageList, len(r.packages)) 138 | pkgNames := make([]string, len(r.packages)) 139 | for i, pkg := range r.packages { 140 | reportPackages[i] = buildReportPackage(pkg, r) 141 | pkgNames[i] = pkg.Name 142 | } 143 | 144 | data.Script = string(sc) 145 | data.Style = css 146 | data.Packages = reportPackages 147 | data.Command = fmt.Sprintf("gocov test %s | gocov-html %s", 148 | strings.Join(pkgNames, " "), 149 | strings.Join(os.Args[1:], " "), 150 | ) 151 | 152 | if len(reportPackages) > 1 { 153 | rv := reportPackage{ 154 | Pkg: &gocov.Package{Name: "Report Total"}, 155 | } 156 | for _, rp := range reportPackages { 157 | rv.ReachedStatements += rp.ReachedStatements 158 | rv.TotalStatements += rp.TotalStatements 159 | } 160 | data.Overview = &rv 161 | } 162 | err = curTheme.Template().Execute(w, data) 163 | return eris.Wrap(err, "execute template") 164 | } 165 | 166 | func exists(path string) (bool, error) { 167 | if _, err := os.Stat(path); err != nil { 168 | return false, err 169 | } 170 | return true, nil 171 | } 172 | 173 | // HTMLReportCoverage outputs an HTML report on stdout by 174 | // parsing JSON data generated by axw/gocov. The css parameter 175 | // is an absolute path to a custom stylesheet. Use an empty 176 | // string to use the default stylesheet available. 177 | func HTMLReportCoverage(r io.Reader, opts ReportOptions) error { 178 | t0 := time.Now() 179 | report := newReport() 180 | report.ReportOptions = opts 181 | 182 | // Custom stylesheet? 183 | stylesheet := "" 184 | if opts.Stylesheet != "" { 185 | if _, err := exists(opts.Stylesheet); err != nil { 186 | return eris.Wrap(err, "stylesheet") 187 | } 188 | stylesheet = opts.Stylesheet 189 | } 190 | report.Stylesheet = stylesheet 191 | 192 | data, err := ioutil.ReadAll(r) 193 | if err != nil { 194 | return eris.Wrap(err, "read coverage data") 195 | } 196 | 197 | packages, err := unmarshalJSON(data) 198 | if err != nil { 199 | return eris.Wrap(err, "unmarshal coverage data") 200 | } 201 | 202 | for _, pkg := range packages { 203 | report.addPackage(pkg) 204 | } 205 | fmt.Println() 206 | err = printReport(os.Stdout, report) 207 | fmt.Fprintf(os.Stderr, "Took %v\n", time.Since(t0)) 208 | return eris.Wrap(err, "HTML report") 209 | } 210 | 211 | // ProjectURL is the project's site on GitHub. 212 | const ProjectURL = "https://github.com/matm/gocov-html" 213 | 214 | const ( 215 | hitPrefix = " " 216 | missPrefix = "MISS" 217 | ) 218 | 219 | type reportPackageList []reportPackage 220 | 221 | type reportPackage struct { 222 | Pkg *gocov.Package 223 | Functions reportFunctionList 224 | TotalStatements int 225 | ReachedStatements int 226 | } 227 | 228 | // PercentageReached computes the percentage of reached statements by the tests 229 | // for a package. 230 | func (rp *reportPackage) PercentageReached() float64 { 231 | var rv float64 232 | if rp.TotalStatements > 0 { 233 | rv = float64(rp.ReachedStatements) / float64(rp.TotalStatements) * 100 234 | } 235 | return rv 236 | } 237 | 238 | // reportFunction is a gocov Function with some added stats. 239 | type reportFunction struct { 240 | *gocov.Function 241 | StatementsReached int 242 | } 243 | 244 | // functionLine holds the line of code, its line number in the source file 245 | // and whether the tests reached it. 246 | type functionLine struct { 247 | Code string 248 | LineNumber int 249 | Missed bool 250 | } 251 | 252 | // CoveragePercent is the percentage of code coverage for a function. Returns 100 253 | // if the function has no statement. 254 | func (f reportFunction) CoveragePercent() float64 { 255 | reached := f.StatementsReached 256 | var stmtPercent float64 = 0 257 | if len(f.Statements) > 0 { 258 | stmtPercent = float64(reached) / float64(len(f.Statements)) * 100 259 | } else if len(f.Statements) == 0 { 260 | stmtPercent = 100 261 | } 262 | return stmtPercent 263 | } 264 | 265 | // ShortFileName returns the base path of the function's file name. Provided for 266 | // convenience to be used in the HTML template of the theme. 267 | func (f reportFunction) ShortFileName() string { 268 | return filepath.Base(f.File) 269 | } 270 | 271 | // Lines returns information about all a function's Lines of code. 272 | func (f reportFunction) Lines() []functionLine { 273 | type annotator struct { 274 | fset *token.FileSet 275 | files map[string]*token.File 276 | } 277 | a := &annotator{} 278 | a.fset = token.NewFileSet() 279 | a.files = make(map[string]*token.File) 280 | 281 | // Load the file for line information. Probably overkill, maybe 282 | // just compute the lines from offsets in here. 283 | setContent := false 284 | file := a.files[f.File] 285 | if file == nil { 286 | info, err := os.Stat(f.File) 287 | if err != nil { 288 | panic(err) 289 | } 290 | file = a.fset.AddFile(f.File, a.fset.Base(), int(info.Size())) 291 | setContent = true 292 | } 293 | 294 | data, err := ioutil.ReadFile(f.File) 295 | if err != nil { 296 | panic(err) 297 | } 298 | 299 | if setContent { 300 | // This processes the content and records line number info. 301 | file.SetLinesForContent(data) 302 | } 303 | 304 | statements := f.Statements[:] 305 | lineno := file.Line(file.Pos(f.Start)) 306 | lines := strings.Split(string(data)[f.Start:f.End], "\n") 307 | fls := make([]functionLine, len(lines)) 308 | 309 | for i, line := range lines { 310 | lineno := lineno + i 311 | statementFound := false 312 | hit := false 313 | for j := 0; j < len(statements); j++ { 314 | start := file.Line(file.Pos(statements[j].Start)) 315 | if start == lineno { 316 | statementFound = true 317 | if !hit && statements[j].Reached > 0 { 318 | hit = true 319 | } 320 | statements = append(statements[:j], statements[j+1:]...) 321 | } 322 | } 323 | hitmiss := hitPrefix 324 | if statementFound && !hit { 325 | hitmiss = missPrefix 326 | } 327 | fls[i] = functionLine{ 328 | Missed: hitmiss == missPrefix, 329 | LineNumber: lineno, 330 | Code: html.EscapeString(strings.Replace(line, "\t", " ", -1)), 331 | } 332 | } 333 | return fls 334 | } 335 | 336 | // reportFunctionList is a list of functions for a report. 337 | type reportFunctionList []reportFunction 338 | 339 | func (l reportFunctionList) Len() int { 340 | return len(l) 341 | } 342 | 343 | // TODO make sort method configurable? 344 | func (l reportFunctionList) Less(i, j int) bool { 345 | var left, right float64 346 | if len(l[i].Statements) > 0 { 347 | left = float64(l[i].StatementsReached) / float64(len(l[i].Statements)) 348 | } 349 | if len(l[j].Statements) > 0 { 350 | right = float64(l[j].StatementsReached) / float64(len(l[j].Statements)) 351 | } 352 | if left < right { 353 | return true 354 | } 355 | return left == right && len(l[i].Statements) < len(l[j].Statements) 356 | } 357 | 358 | func (l reportFunctionList) Swap(i, j int) { 359 | l[i], l[j] = l[j], l[i] 360 | } 361 | -------------------------------------------------------------------------------- /pkg/themes/theme.go: -------------------------------------------------------------------------------- 1 | package themes 2 | 3 | import ( 4 | "text/template" 5 | 6 | "github.com/rotisserie/eris" 7 | ) 8 | 9 | // Beautifier defines a theme used for rendering the HTML coverage stats. 10 | type Beautifier interface { 11 | // Name is the name of the theme. 12 | Name() string 13 | // Description is a single line comment about the theme. 14 | Description() string 15 | Assets() StaticAssets 16 | // Template is the structure of the page that will be rendered. 17 | // This code is generated by pkg/theme/generator.go. 18 | Template() *template.Template 19 | // Data is the content used by the template. 20 | // This code is generated by pkg/theme/generator.go. 21 | Data() *templateData 22 | } 23 | 24 | // templateData has all the fields needed by the the HTML template for rendering. 25 | type templateData struct { 26 | // Command is the shell Command used to generate the HTML report. 27 | Command string 28 | // Style is the stylesheet content that will be embedded in the HTML page. 29 | Style string 30 | // Script is the javascript content that will be embedded in the HTML page. 31 | Script string 32 | // When is the date time of report generation. 33 | When string 34 | // Overview holds data used for an additional header in case of multiple Go packages 35 | // have been analysed. Can be used for a high level summary. Is nil if the report has 36 | // only one package. 37 | Overview *reportPackage 38 | // Packages is the list of all Go Packages analysed. 39 | Packages reportPackageList 40 | // ProjectURL is the project's site on GitHub. 41 | ProjectURL string 42 | } 43 | 44 | // StaticAssets sets all assets required for a theme. 45 | type StaticAssets struct { 46 | Stylesheets []string 47 | Scripts []string 48 | Index string 49 | } 50 | 51 | var availableThemes = []Beautifier{ 52 | defaultTheme{}, 53 | kitTheme{}, 54 | } 55 | 56 | // Theme to use for rendering. 57 | var curTheme Beautifier = defaultTheme{} 58 | 59 | // List returns all available themes. 60 | func List() []Beautifier { 61 | return availableThemes 62 | } 63 | 64 | // Get a theme by name. Returns nil if none found. 65 | func Get(name string) Beautifier { 66 | for _, t := range availableThemes { 67 | if t.Name() == name { 68 | return t 69 | } 70 | } 71 | return nil 72 | } 73 | 74 | // Use takes the name of the theme that will be used for rendering. 75 | // Returns an error for an unknown theme. 76 | func Use(name string) error { 77 | p := Get(name) 78 | if p == nil { 79 | return eris.Errorf("unknown theme %q", name) 80 | } 81 | curTheme = p 82 | return nil 83 | } 84 | 85 | // Current returns the theme to use for rendering HTML. 86 | func Current() Beautifier { 87 | return curTheme 88 | } 89 | -------------------------------------------------------------------------------- /pkg/themes/theme_test.go: -------------------------------------------------------------------------------- 1 | package themes 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func TestGet(t *testing.T) { 9 | tests := []struct { 10 | name string 11 | theme string 12 | want Beautifier 13 | }{ 14 | {"empty string", "", nil}, 15 | {"unknown", "bad", nil}, 16 | {"default", "golang", defaultTheme{}}, 17 | } 18 | for _, tt := range tests { 19 | t.Run(tt.name, func(t *testing.T) { 20 | if got := Get(tt.theme); !reflect.DeepEqual(got, tt.want) { 21 | t.Errorf("Get() = %v, want %v", got, tt.want) 22 | } 23 | }) 24 | } 25 | } 26 | 27 | func TestList(t *testing.T) { 28 | tests := []struct { 29 | name string 30 | after func([]Beautifier) 31 | }{ 32 | {"all themes", func(ts []Beautifier) { 33 | if len(ts) == 0 { 34 | t.Error("no theme") 35 | } 36 | for _, p := range ts { 37 | if p.Name() == "" { 38 | t.Error("empty name") 39 | } 40 | if p.Description() == "" { 41 | t.Error("empty description") 42 | } 43 | if p.Template() == nil { 44 | t.Errorf("missing template for %q theme", p.Name()) 45 | } 46 | } 47 | }}, 48 | } 49 | for _, tt := range tests { 50 | t.Run(tt.name, func(t *testing.T) { 51 | got := List() 52 | if tt.after != nil { 53 | tt.after(got) 54 | } 55 | }) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /res/monero-symbol-on-white-96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matm/gocov-html/84704c21cb6d41b92670a111e656a51822b3c627/res/monero-symbol-on-white-96.png -------------------------------------------------------------------------------- /res/qr-donate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matm/gocov-html/84704c21cb6d41b92670a111e656a51822b3c627/res/qr-donate.png -------------------------------------------------------------------------------- /res/qr-donate.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | 1109 | 1110 | 1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | 1284 | 1285 | 1286 | 1287 | 1288 | 1289 | 1290 | 1291 | 1292 | 1293 | 1294 | 1295 | 1296 | 1297 | 1298 | 1299 | 1300 | 1301 | 1302 | 1303 | 1304 | 1305 | 1306 | 1307 | 1308 | 1309 | 1310 | 1311 | 1312 | 1313 | 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 1321 | 1322 | 1323 | 1324 | 1325 | 1326 | 1327 | 1328 | 1329 | 1330 | 1331 | 1332 | 1333 | 1334 | 1335 | 1336 | 1337 | 1338 | 1339 | 1340 | 1341 | 1342 | 1343 | 1344 | 1345 | 1346 | 1347 | 1348 | 1349 | 1350 | 1351 | 1352 | 1353 | 1354 | 1355 | 1356 | 1357 | 1358 | 1359 | 1360 | 1361 | 1362 | 1363 | 1364 | 1365 | 1366 | 1367 | 1368 | 1369 | 1370 | 1371 | 1372 | 1373 | 1374 | 1375 | 1376 | 1377 | 1378 | 1379 | 1380 | 1381 | 1382 | 1383 | 1384 | 1385 | 1386 | 1387 | 1388 | 1389 | 1390 | 1391 | 1392 | 1393 | 1394 | 1395 | 1396 | 1397 | 1398 | 1399 | 1400 | 1401 | 1402 | 1403 | 1404 | 1405 | 1406 | 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1414 | 1415 | 1416 | 1417 | 1418 | 1419 | 1420 | 1421 | 1422 | 1423 | 1424 | 1425 | 1426 | 1427 | 1428 | 1429 | 1430 | 1431 | 1432 | 1433 | 1434 | 1435 | 1436 | 1437 | 1438 | 1439 | 1440 | 1441 | 1442 | 1443 | 1444 | 1445 | 1446 | 1447 | 1448 | 1449 | 1450 | 1451 | 1452 | 1453 | 1454 | 1455 | 1456 | 1457 | 1458 | 1459 | 1460 | 1461 | 1462 | 1463 | 1464 | 1465 | 1466 | 1467 | 1468 | 1469 | 1470 | 1471 | 1472 | 1473 | 1474 | 1475 | 1476 | 1477 | 1478 | 1479 | 1480 | 1481 | 1482 | 1483 | 1484 | 1485 | 1486 | 1487 | 1488 | 1489 | 1490 | 1491 | 1492 | 1493 | 1494 | 1495 | 1496 | 1497 | 1498 | 1499 | 1500 | 1501 | 1502 | 1503 | 1504 | 1505 | 1506 | 1507 | 1508 | 1509 | 1510 | 1511 | 1512 | 1513 | 1514 | 1515 | 1516 | 1517 | 1518 | 1519 | 1520 | 1521 | 1522 | 1523 | 1524 | 1525 | 1526 | 1527 | 1528 | 1529 | 1530 | 1531 | 1532 | 1533 | 1534 | 1535 | 1536 | 1537 | 1538 | 1539 | 1540 | 1541 | 1542 | 1543 | 1544 | 1545 | 1546 | 1547 | 1548 | 1549 | 1550 | 1551 | 1552 | 1553 | 1554 | 1555 | 1556 | 1557 | 1558 | 1559 | 1560 | 1561 | 1562 | 1563 | 1564 | 1565 | 1566 | 1567 | 1568 | 1569 | 1570 | 1571 | 1572 | 1573 | 1574 | 1575 | 1576 | 1577 | 1578 | 1579 | 1580 | 1581 | 1582 | 1583 | 1584 | 1585 | 1586 | 1587 | 1588 | 1589 | 1590 | 1591 | 1592 | 1593 | 1594 | 1595 | 1596 | 1597 | 1598 | 1599 | 1600 | 1601 | 1602 | 1603 | 1604 | 1605 | 1606 | 1607 | 1608 | 1609 | 1610 | 1611 | 1612 | 1613 | 1614 | 1615 | 1616 | 1617 | 1618 | 1619 | 1620 | 1621 | 1622 | 1623 | 1624 | 1625 | 1626 | 1627 | 1628 | 1629 | 1630 | 1631 | 1632 | 1633 | 1634 | 1635 | 1636 | 1637 | 1638 | 1639 | 1640 | 1641 | 1642 | 1643 | 1644 | 1645 | 1646 | 1647 | 1648 | 1649 | 1650 | 1651 | 1652 | 1653 | 1654 | 1655 | 1656 | 1657 | 1658 | 1659 | 1660 | 1661 | 1662 | 1663 | 1664 | 1665 | 1666 | 1667 | 1668 | 1669 | 1670 | 1671 | 1672 | 1673 | 1674 | 1675 | 1676 | 1677 | 1678 | 1679 | 1680 | 1681 | 1682 | 1683 | 1684 | 1685 | 1686 | 1687 | 1688 | 1689 | 1690 | 1691 | 1692 | 1693 | 1694 | 1695 | 1696 | 1697 | 1698 | 1699 | 1700 | 1701 | 1702 | 1703 | 1704 | 1705 | 1706 | 1707 | 1708 | 1709 | 1710 | 1711 | 1712 | 1713 | 1714 | 1715 | 1716 | 1717 | 1718 | 1719 | 1720 | 1721 | 1722 | 1723 | 1724 | 1725 | 1726 | 1727 | 1728 | 1729 | 1730 | 1731 | 1732 | 1733 | 1734 | 1735 | 1736 | 1737 | 1738 | 1739 | 1740 | 1741 | 1742 | 1743 | 1744 | 1745 | 1746 | 1747 | 1748 | 1749 | 1750 | 1751 | 1752 | 1753 | 1754 | 1755 | 1756 | 1757 | 1758 | 1759 | 1760 | 1761 | 1762 | 1763 | 1764 | 1765 | 1766 | 1767 | 1768 | 1769 | 1770 | 1771 | 1772 | 1773 | 1774 | 1775 | 1776 | 1777 | 1778 | 1779 | 1780 | 1781 | 1782 | 1783 | 1784 | 1785 | 1786 | 1787 | 1788 | 1789 | 1790 | 1791 | 1792 | 1793 | 1794 | 1795 | 1796 | 1797 | 1798 | 1799 | 1800 | 1801 | 1802 | 1803 | 1804 | 1805 | 1806 | 1807 | 1808 | 1809 | 1810 | 1811 | 1812 | 1813 | 1814 | 1815 | 1816 | 1817 | 1818 | 1819 | 1820 | 1821 | 1822 | 1823 | 1824 | 1825 | 1826 | 1827 | 1828 | 1829 | 1830 | 1831 | 1832 | 1833 | 1834 | 1835 | 1836 | 1837 | 1838 | 1839 | 1840 | 1841 | 1842 | 1843 | 1844 | 1845 | 1846 | 1847 | 1848 | 1849 | 1850 | 1851 | 1852 | 1853 | 1854 | 1855 | 1856 | 1857 | 1858 | 1859 | 1860 | 1861 | 1862 | 1863 | 1864 | 1865 | 1866 | 1867 | 1868 | 1869 | 1870 | 1871 | 1872 | 1873 | 1874 | 1875 | 1876 | 1877 | 1878 | 1879 | 1880 | 1881 | 1882 | 1883 | 1884 | 1885 | 1886 | 1887 | 1888 | 1889 | 1890 | 1891 | 1892 | 1893 | 1894 | 1895 | 1896 | 1897 | 1898 | 1899 | 1900 | 1901 | 1902 | 1903 | 1904 | 1905 | 1906 | 1907 | 1908 | 1909 | 1910 | 1911 | 1912 | 1913 | 1914 | 1915 | 1916 | 1917 | 1918 | 1919 | 1920 | 1921 | 1922 | 1923 | 1924 | 1925 | 1926 | 1927 | 1928 | 1929 | 1930 | 1931 | 1932 | 1933 | 1934 | 1935 | 1936 | 1937 | 1938 | 1939 | 1940 | 1941 | 1942 | 1943 | 1944 | 1945 | 1946 | 1947 | 1948 | 1949 | 1950 | 1951 | 1952 | 1953 | 1954 | 1955 | 1956 | 1957 | 1958 | 1959 | 1960 | 1961 | 1962 | 1963 | 1964 | 1965 | 1966 | 1967 | 1968 | 1969 | 1970 | 1971 | 1972 | 1973 | 1974 | 1975 | 1976 | 1977 | 1978 | 1979 | 1980 | 1981 | 1982 | 1983 | 1984 | 1985 | 1986 | 1987 | 1988 | 1989 | 1990 | 1991 | 1992 | 1993 | 1994 | 1995 | 1996 | 1997 | 1998 | 1999 | 2000 | 2001 | 2002 | 2003 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 2010 | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | 2026 | 2027 | 2028 | 2029 | 2030 | 2031 | 2032 | 2033 | 2034 | 2035 | 2036 | 2037 | 2038 | 2039 | 2040 | 2041 | 2042 | 2043 | 2044 | 2045 | 2046 | 2047 | 2048 | 2049 | 2050 | 2051 | 2052 | 2053 | 2054 | 2055 | 2056 | 2057 | 2058 | 2059 | 2060 | 2061 | 2062 | 2063 | 2064 | 2065 | 2066 | 2067 | 2068 | 2069 | 2070 | 2071 | 2072 | 2073 | 2074 | 2075 | 2076 | 2077 | 2078 | 2079 | 2080 | 2081 | 2082 | 2083 | 2084 | 2085 | 2086 | 2087 | 2088 | 2089 | 2090 | 2091 | 2092 | 2093 | 2094 | 2095 | 2096 | 2097 | 2098 | 2099 | 2100 | 2101 | 2102 | 2103 | 2104 | 2105 | 2106 | 2107 | 2108 | 2109 | 2110 | 2111 | 2112 | 2113 | 2114 | 2115 | 2116 | 2117 | 2118 | 2119 | 2120 | 2121 | 2122 | 2123 | 2124 | 2125 | 2126 | 2127 | 2128 | 2129 | 2130 | 2131 | 2132 | 2133 | 2134 | 2135 | 2136 | 2137 | 2138 | 2139 | 2140 | 2141 | 2142 | 2143 | 2144 | 2145 | 2146 | 2147 | 2148 | 2149 | 2150 | 2151 | 2152 | 2153 | 2154 | 2155 | 2156 | 2157 | 2158 | 2159 | 2160 | 2161 | 2162 | 2163 | 2164 | 2165 | 2166 | 2167 | 2168 | 2169 | 2170 | 2171 | 2172 | 2173 | 2174 | 2175 | 2176 | 2177 | 2178 | 2179 | 2180 | 2181 | 2182 | 2183 | 2184 | 2185 | 2186 | 2187 | 2188 | 2189 | 2190 | 2191 | 2192 | 2193 | 2194 | 2195 | 2196 | 2197 | 2198 | -------------------------------------------------------------------------------- /themes/README.md: -------------------------------------------------------------------------------- 1 | # Available Themes 2 | 3 | ## golang 4 | 5 | This is the default theme: 6 | 7 | ```shell 8 | $ gocov test strings | gocov-html -t golang > strings.html 9 | ``` 10 | 11 | ![golang theme screenshot](golang/screenshot.png) 12 | 13 | ## kit 14 | 15 | Uses the [AdminKit](https://adminkit.io) theme: 16 | 17 | ```shell 18 | $ gocov test encoding/csv strings | gocov-html -t kit > strings.html 19 | ``` 20 | 21 | ![kit theme screenshot](kit/screenshot.png) -------------------------------------------------------------------------------- /themes/golang/index.html: -------------------------------------------------------------------------------- 1 | {{define "theme"}} 2 | 3 | 4 | Coverage Report 5 | 6 | {{if .Style}} 7 | 10 | {{end}} 11 | 12 | 13 |
Coverage Report
14 | {{if not .Packages}} 15 |

no test files in package.

" 16 | {{else}} 17 |
Generated on {{.When}} with gocov-html
18 | {{/* Report overview/summary available? */}} 19 | {{if .Overview}} 20 |
Report Overview
21 | 22 | {{range $k,$rp := .Packages}} 23 | 24 | 25 | 26 | 27 | 28 | {{end}} 29 |
{{$rp.Pkg.Name}}{{printf "%.1f%%" $rp.PercentageReached}}{{printf "%d" $rp.ReachedStatements}}/{{printf "%d" $rp.TotalStatements}}
30 |

31 | This coverage report has been generated with the following command: 32 |

33 |
{{.Command}}
34 | 35 | {{end}} 36 | {{range $k,$rp := .Packages}} 37 |
38 | Package Overview: {{$rp.Pkg.Name}} 39 | {{printf "%.1f%%" $rp.PercentageReached}} 40 |
41 |

Please select a function to see what's left for testing.

42 | 43 | 44 | {{range $k,$f := $rp.Functions}} 45 | 46 | 49 | 52 | 55 | 58 | 59 | {{end}} 60 |
47 | {{$f.Name}}(...) 48 | 50 | {{$rp.Pkg.Name}}/{{$f.ShortFileName}} 51 | 53 | {{printf "%.1f%%" $f.CoveragePercent}} 54 | 56 | {{$f.StatementsReached}}/{{len $f.Statements}} 57 |
61 | 62 | {{/* Functions source code here */}} 63 | {{range $k,$f := $rp.Functions}} 64 |
func {{$f.Name}}
65 |
66 | Back 67 |

In {{$f.File}}:

68 |
69 | 70 | {{range $p,$info := $f.Lines}} 71 | 72 | 73 | 76 | 77 | {{end}} 78 |
{{$info.LineNumber}} 74 |
{{$info.Code}}
75 |
79 | {{end}} {{/* range function lines */}} 80 | 81 | 84 | {{end}} {{/* range Packages end */}} 85 | 86 |
87 | {{if not .Overview}} 88 | {{$rp := index .Packages 0}} 89 |
{{$rp.Pkg.Name}}
90 |
{{printf "%.1f%%" $rp.PercentageReached}}
91 | {{else}} 92 |
{{.Overview.Pkg.Name}}
93 |
{{printf "%.1f%%" .Overview.PercentageReached}}
94 | {{end}} {{/* if overview end */}} 95 |
96 | {{end}} {{/* range if end */}} 97 | {{if .Script}} 98 | 101 | {{end}} 102 | 103 | 104 | {{end}} -------------------------------------------------------------------------------- /themes/golang/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matm/gocov-html/84704c21cb6d41b92670a111e656a51822b3c627/themes/golang/screenshot.png -------------------------------------------------------------------------------- /themes/golang/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #fff; 3 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | table { 7 | margin-left: 10px; 8 | border-collapse: collapse; 9 | } 10 | 11 | td { 12 | background-color: #fff; 13 | padding: 2px; 14 | } 15 | 16 | table.overview td { 17 | padding-right: 20px; 18 | } 19 | 20 | td.percent, 21 | td.linecount { 22 | text-align: right; 23 | } 24 | 25 | div.package, 26 | #totalcov { 27 | color: #fff; 28 | background-color: #375eab; 29 | font-size: 16px; 30 | font-weight: bold; 31 | padding: 10px; 32 | border-radius: 5px 5px 5px 5px; 33 | } 34 | 35 | div.package, 36 | #totalcov { 37 | float: right; 38 | right: 10px; 39 | } 40 | 41 | #totalcov { 42 | top: 10px; 43 | position: relative; 44 | background-color: #fff; 45 | color: #000; 46 | border: 1px solid #375eab; 47 | clear: both; 48 | } 49 | 50 | #summaryWrapper { 51 | position: fixed; 52 | top: 10px; 53 | float: right; 54 | right: 10px; 55 | 56 | } 57 | 58 | span.packageTotal { 59 | float: right; 60 | color: #000; 61 | } 62 | 63 | #doctitle { 64 | background-color: #fff; 65 | font-size: 24px; 66 | margin-top: 20px; 67 | margin-left: 10px; 68 | color: #375eab; 69 | font-weight: bold; 70 | } 71 | 72 | #about { 73 | margin-left: 18px; 74 | font-size: 10px; 75 | } 76 | 77 | .functitle, 78 | .funcname { 79 | text-align: center; 80 | font-size: 20px; 81 | font-weight: bold; 82 | color: #375eab; 83 | } 84 | 85 | .funcname { 86 | text-align: left; 87 | margin-top: 20px; 88 | margin-left: 10px; 89 | margin-bottom: 20px; 90 | padding: 2px 5px 5px; 91 | background-color: #e0ebf5; 92 | } 93 | 94 | table.listing { 95 | margin-left: 10px; 96 | } 97 | 98 | table.listing td { 99 | padding: 0px; 100 | font-size: 12px; 101 | background-color: #eee; 102 | vertical-align: top; 103 | padding-left: 10px; 104 | border-bottom: 1px solid #fff; 105 | } 106 | 107 | table.listing td:first-child { 108 | text-align: right; 109 | font-weight: bold; 110 | vertical-align: center; 111 | } 112 | 113 | table.listing tr.miss td { 114 | background-color: #FFBBB8; 115 | } 116 | 117 | table.listing tr:last-child td { 118 | font-weight: normal; 119 | color: #000; 120 | } 121 | 122 | table.listing tr:last-child td:first-child { 123 | font-weight: bold; 124 | } 125 | 126 | .info { 127 | margin-left: 10px; 128 | } 129 | 130 | .info code {} 131 | 132 | pre { 133 | margin: 1px; 134 | } 135 | 136 | pre.cmd { 137 | background-color: #e9e9e9; 138 | border-radius: 5px 5px 5px 5px; 139 | padding: 10px; 140 | margin: 20px; 141 | line-height: 18px; 142 | font-size: 14px; 143 | } 144 | 145 | a { 146 | text-decoration: none; 147 | color: #375eab; 148 | } 149 | 150 | a:hover { 151 | text-decoration: underline; 152 | } 153 | 154 | p { 155 | margin-left: 10px; 156 | } -------------------------------------------------------------------------------- /themes/kit/index.html: -------------------------------------------------------------------------------- 1 | {{define "theme"}} 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Coverage Report 14 | {{if .Style}} 15 | 18 | {{end}} 19 | 20 | 21 | 22 | 23 |
24 | 48 | 49 |
50 | 55 |
56 |
57 |

Dashboard

58 |
59 | {{range $k,$rp := .Packages}} 60 |
61 |
62 |
63 |
64 |
65 |
{{$rp.Pkg.Name}}
66 |
67 | 68 |
69 |
70 | 71 |
72 |
73 |
74 |

{{printf "%.1f%%" $rp.PercentageReached}}

75 |
76 | {{printf "%d" $rp.ReachedStatements}}/{{printf "%d" $rp.TotalStatements}} 77 | statements reached 78 |
79 |
80 |
81 |
82 | {{end}} 83 | {{if .Overview}} 84 |
85 |
86 |
87 |
88 |
89 |
TOTAL
90 |
91 |
92 |
93 | 94 |
95 |
96 |
97 |

{{printf "%.1f%%" .Overview.PercentageReached}}

98 |
99 | covered for those {{len .Packages}} packages 100 |
101 |
102 |
103 |
104 | {{end}} 105 | 106 |
107 |
108 |
109 |
110 |
111 |
Generated With
112 |
113 |
114 |
115 | 116 |
117 |
118 |
119 |
120 | $ {{.Command}} 121 |
122 |
123 |
124 |
125 |
126 | 127 | {{range $k,$rp := .Packages}} 128 |

Package {{$rp.Pkg.Name}}

129 |
130 |
131 |
132 |
133 |
134 |
135 |
Coverage
136 |
137 |
138 |
139 | 140 |
141 |
142 |
143 |

{{printf "%.1f%%" $rp.PercentageReached}}

144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
Functions
153 |
154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | {{range $k,$f := $rp.Functions}} 165 | 166 | 167 | 168 | 169 | 170 | 171 | {{end}} 172 | 173 |
NameFileCoverageStatements
{{$f.Name}}(...){{$f.ShortFileName}}{{printf "%.1f%%" $f.CoveragePercent}}{{$f.StatementsReached}}/{{len $f.Statements}}
174 |
175 |
176 |
177 | {{/* Functions source code here */}} 178 |
179 | {{range $k,$f := $rp.Functions}} 180 |
181 |
182 |
183 |
func {{$f.Name}}(...) 184 | 185 | 186 | 187 |
188 |
189 |

{{$f.File}}

190 | 191 | 192 | {{range $p,$info := $f.Lines}} 193 | 194 | 195 | 197 | {{end}} 198 | 199 |
{{$info.LineNumber}}
{{$info.Code}}
196 |
200 |
201 |
202 | {{end}} 203 |
204 | {{end}} 205 |
206 |
207 | 208 |
209 |
210 |
211 |
212 |

213 | gocov-html - Generated on {{.When}} 214 |

215 |
216 |
217 | 225 |
226 |
227 |
228 |
229 |
230 |
231 | {{if .Script}} 232 | 253 | {{end}} 254 | 255 | 256 | {{end}} -------------------------------------------------------------------------------- /themes/kit/kit.css: -------------------------------------------------------------------------------- 1 | .codex { 2 | word-wrap: break-word; 3 | font-size: 100%; 4 | } 5 | 6 | .loc { 7 | word-wrap: break-word; 8 | font-size: 110%; 9 | margin: 0px; 10 | } 11 | -------------------------------------------------------------------------------- /themes/kit/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matm/gocov-html/84704c21cb6d41b92670a111e656a51822b3c627/themes/kit/screenshot.png -------------------------------------------------------------------------------- /version.mk: -------------------------------------------------------------------------------- 1 | VERSION = $(shell git describe --tags) 2 | GITREV = $(shell git rev-parse --verify --short HEAD) 3 | GITBRANCH = $(shell git rev-parse --abbrev-ref HEAD) 4 | DATE = $(shell LANG=US date +"%a, %d %b %Y %X %z") 5 | 6 | GO_LDFLAGS += -X 'github.com/matm/gocov-html/pkg/config.Version=$(VERSION)' 7 | GO_LDFLAGS += -X 'github.com/matm/gocov-html/pkg/config.GitRev=$(GITREV)' 8 | GO_LDFLAGS += -X 'github.com/matm/gocov-html/pkg/config.GitBranch=$(GITBRANCH)' 9 | GO_LDFLAGS += -X 'github.com/matm/gocov-html/pkg/config.BuildDate=$(DATE)' 10 | --------------------------------------------------------------------------------