Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ jobs:
run: go mod download

- name: Build and Test
working-directory: ${{ github.workspace }}
run: |
scripts/build.sh
scripts/unit_test.sh
env:
CGO_CFLAGS: "-O -D__BLST_PORTABLE__" # Set the CGO flags to use the portable version of BLST

- name: Check Code Coverage
run: |
scripts/check_coverage_unit_test.sh
4 changes: 3 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ then
fi
if [ "${COVERAGE_MODE:-}" == true ]
then
extra_build_args+=" -cover -race"
# coverage mode has to be 'set' to merge with ut coverage which is 'set'
# i.e. -race cannot be added here.
extra_build_args+=" -cover"
fi

go build -v -ldflags="-X 'github.com/ava-labs/avalanche-cli/cmd.Version=$VERSION' -X github.com/ava-labs/avalanche-cli/pkg/metrics.telemetryToken=$AVALANCHE_CLI_METRICS_TOKEN" $extra_build_args -o $BIN
21 changes: 0 additions & 21 deletions scripts/check_coverage_unit_test.sh

This file was deleted.

27 changes: 27 additions & 0 deletions scripts/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

if ! [[ "$0" =~ scripts/coverage.sh ]]; then
echo "script must be run from the repository root"
exit 1
fi

coverage_dir=$(PWD)/coverage
merged_coverage_dir=$coverage_dir/merged
merged_coverage_file=$merged_coverage_dir/merged.txt

echo "Recreating merged coverage directory..."
rm -rf ${merged_coverage_dir}
mkdir -p ${merged_coverage_dir}

echo "Generating coverage report in text format..."
included_packages=$(go list ./... | grep -v /tests/ | grep -v '/sdk/') # not including 'tests' and 'sdk'
go tool covdata merge -i=$coverage_dir/e2e,$coverage_dir/ut -o=$merged_coverage_dir -pkg=${included_packages//$'\n'/,}
go tool covdata textfmt -i=$merged_coverage_dir -o $merged_coverage_file
go tool cover -func $merged_coverage_file

echo "Checking total coverage..."

# TODO: coverage details will be output as a comment in the PR

go tool cover -func=$merged_coverage_file | grep -e "total" | \
awk '{print "Total Coverage:", $3}'
14 changes: 6 additions & 8 deletions scripts/run.e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

if ! [[ "$0" =~ scripts/run.e2e.sh ]]; then
echo "script must be run from repository root"
exit 1
fi

description_filter=""
if [ "$1" = "--filter" ]
then
Expand Down Expand Up @@ -60,7 +65,7 @@ ACK_GINKGO_RC=true ~/go/bin/ginkgo build $extra_build_args ./tests/e2e

if [ "${COVERAGE_MODE:-}" == true ]
then
export GOCOVERDIR=coverage/e2e
export GOCOVERDIR=$(PWD)/coverage/e2e
echo 'Coverage mode enabled - re-creating coverage dir $GOCOVERDIR'
echo 'It requires the CLI binary to be built by build.sh with COVERAGE_MODE=true too'
rm -rf ${GOCOVERDIR}
Expand All @@ -76,11 +81,4 @@ if [[ ${EXIT_CODE} -gt 0 ]]; then
exit ${EXIT_CODE}
else
echo "ALL SUCCESS!"

if [ "${COVERAGE_MODE:-}" == true ]
then
echo "Generating coverage report: ${GOCOVERDIR}/profile.txt"
go tool covdata textfmt -i=${GOCOVERDIR} -o ${GOCOVERDIR}/profile.txt
# go tool cover -func ${GOCOVERDIR}/profile.txt
fi
fi
17 changes: 15 additions & 2 deletions scripts/unit_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
#!/usr/bin/env bash

go test -v -coverprofile=coverage.out $(go list ./... | grep -v /tests/ | grep -v '/sdk/')
#go tool cover -func=coverage.out
set -ex

if ! [[ "$0" =~ scripts/unit_test.sh ]]; then
echo "script must be run from repository root"
exit 1
fi

coverage_dir=$PWD/coverage/ut # should be under the same parent folder as e2e coverage dir

echo "Re-creating unit test coverage directory: $coverage_dir"
rm -rf $coverage_dir
mkdir -p $coverage_dir

go test -cover -v $(go list ./... | grep -v /tests/ | grep -v '/sdk/') -args -test.gocoverdir=$coverage_dir

Loading