diff --git a/Makefile b/Makefile index c998fd25..3825005c 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,12 @@ PKG := github.com/btcsuite/btcd LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint -GOACC_PKG := github.com/ory/go-acc GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports GO_BIN := ${GOPATH}/bin LINT_BIN := $(GO_BIN)/golangci-lint -GOACC_BIN := $(GO_BIN)/go-acc LINT_COMMIT := v1.18.0 -GOACC_COMMIT := 80342ae2e0fcf265e99e76bcc4efd022c7c3811b DEPGET := cd /tmp && go install -v GOBUILD := go build -v @@ -17,6 +14,7 @@ GOINSTALL := go install -v DEV_TAGS := rpctest GOTEST_DEV = go test -v -tags=$(DEV_TAGS) GOTEST := go test -v +COVER_FLAGS = -coverprofile=coverage.txt -covermode=atomic -coverpkg=$(PKG)/... GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*") @@ -53,10 +51,6 @@ $(LINT_BIN): @$(call print, "Fetching linter") $(DEPGET) $(LINT_PKG)@$(LINT_COMMIT) -$(GOACC_BIN): - @$(call print, "Fetching go-acc") - $(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT) - #? goimports: Install goimports goimports: @$(call print, "Installing goimports.") @@ -106,17 +100,17 @@ unit: cd btcutil/psbt; $(GOTEST_DEV) ./... -test.timeout=20m #? unit-cover: Run unit coverage tests -unit-cover: $(GOACC_BIN) +unit-cover: @$(call print, "Running unit coverage tests.") - $(GOACC_BIN) ./... - + $(GOTEST) $(COVER_FLAGS) ./... # We need to remove the /v2 pathing from the module to have it work - # nicely with the CI tool we use to render live code coverage. - cd btcec; $(GOACC_BIN) ./...; sed -i.bak 's/v2\///g' coverage.txt + # nicely with the CI tool we use to render live code coverage. + cd btcec; $(GOTEST) $(COVER_FLAGS) ./...; \ + sed -i.bak 's/v2\///g' coverage.txt - cd btcutil; $(GOACC_BIN) ./... + cd btcutil; $(GOTEST) $(COVER_FLAGS) ./... - cd btcutil/psbt; $(GOACC_BIN) ./... + cd btcutil/psbt; $(GOTEST) $(COVER_FLAGS) ./... #? unit-race: Run unit race tests unit-race: diff --git a/addrmgr/cov_report.sh b/addrmgr/cov_report.sh old mode 100644 new mode 100755 index 307f05b7..e41c9282 --- a/addrmgr/cov_report.sh +++ b/addrmgr/cov_report.sh @@ -1,17 +1,9 @@ #!/bin/sh -# This script uses gocov to generate a test coverage report. -# The gocov tool my be obtained with the following command: -# go get github.com/axw/gocov/gocov -# -# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH. +# This script uses the standard Go test coverage tools to generate a test coverage report. -# Check for gocov. -type gocov >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo >&2 "This script requires the gocov tool." - echo >&2 "You may obtain it with the following command:" - echo >&2 "go get github.com/axw/gocov/gocov" - exit 1 -fi -gocov test | gocov report +# Run tests with coverage enabled and generate coverage profile. +go test -cover -coverprofile=coverage.txt ./... + +# Display function-level coverage statistics. +go tool cover -func=coverage.txt diff --git a/btcutil/base58/cov_report.sh b/btcutil/base58/cov_report.sh index 307f05b7..e41c9282 100644 --- a/btcutil/base58/cov_report.sh +++ b/btcutil/base58/cov_report.sh @@ -1,17 +1,9 @@ #!/bin/sh -# This script uses gocov to generate a test coverage report. -# The gocov tool my be obtained with the following command: -# go get github.com/axw/gocov/gocov -# -# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH. +# This script uses the standard Go test coverage tools to generate a test coverage report. -# Check for gocov. -type gocov >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo >&2 "This script requires the gocov tool." - echo >&2 "You may obtain it with the following command:" - echo >&2 "go get github.com/axw/gocov/gocov" - exit 1 -fi -gocov test | gocov report +# Run tests with coverage enabled and generate coverage profile. +go test -cover -coverprofile=coverage.txt ./... + +# Display function-level coverage statistics. +go tool cover -func=coverage.txt diff --git a/btcutil/bloom/cov_report.sh b/btcutil/bloom/cov_report.sh index 307f05b7..e41c9282 100644 --- a/btcutil/bloom/cov_report.sh +++ b/btcutil/bloom/cov_report.sh @@ -1,17 +1,9 @@ #!/bin/sh -# This script uses gocov to generate a test coverage report. -# The gocov tool my be obtained with the following command: -# go get github.com/axw/gocov/gocov -# -# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH. +# This script uses the standard Go test coverage tools to generate a test coverage report. -# Check for gocov. -type gocov >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo >&2 "This script requires the gocov tool." - echo >&2 "You may obtain it with the following command:" - echo >&2 "go get github.com/axw/gocov/gocov" - exit 1 -fi -gocov test | gocov report +# Run tests with coverage enabled and generate coverage profile. +go test -cover -coverprofile=coverage.txt ./... + +# Display function-level coverage statistics. +go tool cover -func=coverage.txt diff --git a/btcutil/coinset/cov_report.sh b/btcutil/coinset/cov_report.sh index 307f05b7..01dd7457 100644 --- a/btcutil/coinset/cov_report.sh +++ b/btcutil/coinset/cov_report.sh @@ -1,17 +1,8 @@ #!/bin/sh -# This script uses gocov to generate a test coverage report. -# The gocov tool my be obtained with the following command: -# go get github.com/axw/gocov/gocov -# -# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH. +# This script uses the standard Go test coverage tools to generate a test coverage report. +# Run tests with coverage enabled and generate coverage profile. +go test -cover -coverprofile=coverage.txt ./... -# Check for gocov. -type gocov >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo >&2 "This script requires the gocov tool." - echo >&2 "You may obtain it with the following command:" - echo >&2 "go get github.com/axw/gocov/gocov" - exit 1 -fi -gocov test | gocov report +# Display function-level coverage statistics. +go tool cover -func=coverage.txt diff --git a/btcutil/cov_report.sh b/btcutil/cov_report.sh index 307f05b7..e41c9282 100644 --- a/btcutil/cov_report.sh +++ b/btcutil/cov_report.sh @@ -1,17 +1,9 @@ #!/bin/sh -# This script uses gocov to generate a test coverage report. -# The gocov tool my be obtained with the following command: -# go get github.com/axw/gocov/gocov -# -# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH. +# This script uses the standard Go test coverage tools to generate a test coverage report. -# Check for gocov. -type gocov >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo >&2 "This script requires the gocov tool." - echo >&2 "You may obtain it with the following command:" - echo >&2 "go get github.com/axw/gocov/gocov" - exit 1 -fi -gocov test | gocov report +# Run tests with coverage enabled and generate coverage profile. +go test -cover -coverprofile=coverage.txt ./... + +# Display function-level coverage statistics. +go tool cover -func=coverage.txt diff --git a/btcutil/hdkeychain/cov_report.sh b/btcutil/hdkeychain/cov_report.sh index 307f05b7..e41c9282 100644 --- a/btcutil/hdkeychain/cov_report.sh +++ b/btcutil/hdkeychain/cov_report.sh @@ -1,17 +1,9 @@ #!/bin/sh -# This script uses gocov to generate a test coverage report. -# The gocov tool my be obtained with the following command: -# go get github.com/axw/gocov/gocov -# -# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH. +# This script uses the standard Go test coverage tools to generate a test coverage report. -# Check for gocov. -type gocov >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo >&2 "This script requires the gocov tool." - echo >&2 "You may obtain it with the following command:" - echo >&2 "go get github.com/axw/gocov/gocov" - exit 1 -fi -gocov test | gocov report +# Run tests with coverage enabled and generate coverage profile. +go test -cover -coverprofile=coverage.txt ./... + +# Display function-level coverage statistics. +go tool cover -func=coverage.txt