Skip to content

Commit

Permalink
1. Fixed codecoverage
Browse files Browse the repository at this point in the history
  • Loading branch information
iasergunin committed Dec 9, 2023
1 parent 7dda220 commit 3e4301d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
- name: Code coverage data
run: |
set -x
COVERAGE_TOTAL=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
COVERAGE_TOTAL=`go tool covdata func -i=./coverage | grep total | grep -Eo '[0-9]+\.[0-9]+'`
echo "COVERAGE_TOTAL=$COVERAGE_TOTAL" >> $GITHUB_ENV
- uses: jandelgado/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ vendor/

# Code coverage
coverage.*
coverage/
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
GO_TEST=cd ./sh && sh ./go.test.sh
GO_TEST_WITH_REAL_DB=$(GO_TEST) --tags=with_real_db

DIR=$(PWD)
COVERAGE_FILE=`echo $(DIR)/coverage.out`

GO_TEST=cd ./sh && bash ./go.test.sh
GO_TEST_COVERAGE=cd ./sh && bash ./go.test.coverage.sh

GO_TEST_WITH_REAL_DB=--tags=with_real_db

test:
$(GO_TEST)

test.with_real_db:
$(GO_TEST_WITH_REAL_DB)
$(GO_TEST) $(GO_TEST_WITH_REAL_DB)

# TODO see in https://gist.github.com/skarllot/13ebe8220822bc19494c8b076aabe9fc
test.coverage:
$(GO_TEST) -covermode=atomic -coverprofile=$(COVERAGE_FILE)
$(GO_TEST_COVERAGE)

test.coverage.with_real_db:
$(GO_TEST_WITH_REAL_DB) -covermode=atomic -coverprofile=$(COVERAGE_FILE)
$(GO_TEST_COVERAGE) $(GO_TEST_WITH_REAL_DB)

fmt:
go fmt ./...
Expand Down
21 changes: 21 additions & 0 deletions internal/cover/nested/cover.build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cd ./module1/cmd

mkdir -p codecov

go build -cover -o run.exe .
GOCOVERDIR=./codecov ./run.exe

# go test ./... -covermode=atomic -coverprofile=coverage.out

cd ../../module2/cmd

mkdir -p codecov

go build -cover -o run.exe .
GOCOVERDIR=./codecov ./run.exe

# go test ./... -covermode=atomic -coverprofile=coverage.out

cd ../../

go tool covdata textfmt -i=module1/cmd/codecov,module2/cmd/codecov -o ./output.out
2 changes: 2 additions & 0 deletions sh/go.mod.tidy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

cd ../

ROOT=$(pwd)
Expand Down
2 changes: 2 additions & 0 deletions sh/go.mod.vendor.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

cd ../

ROOT=$(pwd)
Expand Down
14 changes: 14 additions & 0 deletions sh/go.test.coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

DIR=$(pwd)
ROOT="$(pwd)/.."

COVERAGE_TEST="-cover -covermode=atomic -test.gocoverdir=$ROOT/coverage"

drivers=("$($DIR/utils/drivers.sh)")

mkdir -p $ROOT/coverage

./go.test.sh $COVERAGE_TEST "$@"

go tool covdata textfmt -i="$ROOT/coverage" -o "$ROOT/coverage.out"
14 changes: 10 additions & 4 deletions sh/go.test.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/bin/bash

DIR=$(pwd)

drivers=("$($DIR/utils/drivers.sh)")

cd ../

ROOT=$(pwd)
Expand All @@ -9,16 +15,16 @@ golist() {
gotest() {
cd $driver

go test $(golist) -race "$@"
go test $(golist) "$@"

cd $ROOT
}

go test $(golist) -race "$@"
go test $(golist) $@ &

for driver in ./drivers/*; do
for driver in $drivers; do
if [ -d "$driver" ]; then
gotest "$@" &
gotest $@ &
fi
done

Expand Down
5 changes: 5 additions & 0 deletions sh/utils/drivers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd ../

echo drivers/*

0 comments on commit 3e4301d

Please sign in to comment.