From 76db0cbe5e81bf8e04a2d63bd55c24ab4f2d0243 Mon Sep 17 00:00:00 2001 From: iasergunin Date: Sat, 9 Dec 2023 06:34:47 +0300 Subject: [PATCH] 1. Fixed codecoverage --- .gitignore | 1 + Makefile | 16 ++++++++-------- internal/cover/nested/cover.build.sh | 21 +++++++++++++++++++++ sh/go.mod.tidy.sh | 2 ++ sh/go.mod.vendor.sh | 2 ++ sh/go.test.coverage.sh | 15 +++++++++++++++ sh/go.test.sh | 14 ++++++++++---- sh/utils/drivers.sh | 5 +++++ 8 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 internal/cover/nested/cover.build.sh mode change 100644 => 100755 sh/go.mod.tidy.sh mode change 100644 => 100755 sh/go.mod.vendor.sh create mode 100755 sh/go.test.coverage.sh mode change 100644 => 100755 sh/go.test.sh create mode 100755 sh/utils/drivers.sh diff --git a/.gitignore b/.gitignore index 3bb6dc3..6e206e7 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ vendor/ # Code coverage coverage.* +coverage/ diff --git a/Makefile b/Makefile index be253c4..eeacff7 100644 --- a/Makefile +++ b/Makefile @@ -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 ./... diff --git a/internal/cover/nested/cover.build.sh b/internal/cover/nested/cover.build.sh new file mode 100644 index 0000000..0d55b8b --- /dev/null +++ b/internal/cover/nested/cover.build.sh @@ -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 \ No newline at end of file diff --git a/sh/go.mod.tidy.sh b/sh/go.mod.tidy.sh old mode 100644 new mode 100755 index 5a402ad..2bdf7e4 --- a/sh/go.mod.tidy.sh +++ b/sh/go.mod.tidy.sh @@ -1,3 +1,5 @@ +#!/bin/bash + cd ../ ROOT=$(pwd) diff --git a/sh/go.mod.vendor.sh b/sh/go.mod.vendor.sh old mode 100644 new mode 100755 index 9797e77..180b8fc --- a/sh/go.mod.vendor.sh +++ b/sh/go.mod.vendor.sh @@ -1,3 +1,5 @@ +#!/bin/bash + cd ../ ROOT=$(pwd) diff --git a/sh/go.test.coverage.sh b/sh/go.test.coverage.sh new file mode 100755 index 0000000..d27bf60 --- /dev/null +++ b/sh/go.test.coverage.sh @@ -0,0 +1,15 @@ +#!/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 "$@" + +drivers_i="${drivers// //coverage,}" +go tool covdata textfmt -i="$ROOT/coverage" -o "$ROOT/coverage.out" diff --git a/sh/go.test.sh b/sh/go.test.sh old mode 100644 new mode 100755 index d14c676..9d9723e --- a/sh/go.test.sh +++ b/sh/go.test.sh @@ -1,3 +1,9 @@ +#!/bin/bash + +DIR=$(pwd) + +drivers=("$($DIR/utils/drivers.sh)") + cd ../ ROOT=$(pwd) @@ -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 diff --git a/sh/utils/drivers.sh b/sh/utils/drivers.sh new file mode 100755 index 0000000..2f63581 --- /dev/null +++ b/sh/utils/drivers.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cd ../ + +echo drivers/*