Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gkampitakis committed Jan 15, 2023
0 parents commit 087f099
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

**/.DS_Store
.vscode
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Georgios Kampitakis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.PHONY: install-tools lint test test-verbose format help

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

install-tools: ## Install linting tools
go install github.com/golangci/golangci-lint/cmd/[email protected]
go install mvdan.cc/gofumpt@latest
go install github.com/segmentio/golines@latest

lint: ## Run golangci linter
golangci-lint run -c ./golangci.yml ./...

format: ## Format code
gofumpt -l -w -extra .
golines . -w

test: ## Run tests
go test -race -count=1 -cover ./...

test-verbose: ## Run tests with verbose output
go test -race -count=1 -v -cover ./...
Empty file added README.md
Empty file.
45 changes: 45 additions & 0 deletions coverage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package coverage

import (
"fmt"
"os"
"runtime"
"strings"
"testing"
)

func Run(t *testing.M, c float64, callbacks ...func(t *testing.M)) {
var code int
defer func() {
os.Exit(code)
}()

code = t.Run()

if testing.CoverMode() == "" {
fmt.Printf("\nFAIL coverage is not enabled. You can enable by using `-cover`\n\n")
code = 1
} else {
coverage := testing.Coverage()
if coverage*100 < c {
code = 1
fmt.Printf("\nFAIL Coverage threshold not met %.1f >= %.1f for %s\n\n", c, coverage*100, packageName())
}
}

for _, callback := range callbacks {
callback(t)
}
}

func packageName() string {
pc, _, _, _ := runtime.Caller(2)
funcName := runtime.FuncForPC(pc).Name()
lastSlash := strings.LastIndexByte(funcName, '/')
if lastSlash < 0 {
lastSlash = 0
}
lastDot := strings.LastIndexByte(funcName[lastSlash:], '.') + lastSlash

return funcName[:lastDot]
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module coverage

go 1.19
21 changes: 21 additions & 0 deletions golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
linters:
enable:
- unconvert
- stylecheck
- lll
- unparam
- goimports
- unparam
- gofumpt
- revive
- unconvert
- gocognit

disable:
- errcheck

linters-settings:
lll:
line-length: 130
gofumpt:
extra-rules: true

0 comments on commit 087f099

Please sign in to comment.