From 152acd13ed3c8ab8e12571b342cb562f5a5c47a1 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Fri, 19 Jun 2020 17:57:06 +1000 Subject: [PATCH] test-unit: run all unit-tests in one shot This might make running the tests a little bit quicker (maybe even more so if we add t.Parallel() calls in the future), and it removes the need for collating cover-profile output for each unit test run. Signed-off-by: Aleksa Sarai --- hack/test-unit.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hack/test-unit.sh b/hack/test-unit.sh index 47e133ee0..7164ad07b 100755 --- a/hack/test-unit.sh +++ b/hack/test-unit.sh @@ -21,13 +21,13 @@ PROJECT="${PROJECT:-github.com/opencontainers/umoci}" # Set up the root and coverage directories. export ROOT="$(readlink -f "$(dirname "$(readlink -f "$BASH_SOURCE")")/..")" -export COVERAGE_DIR=$(mktemp --tmpdir -d umoci-coverage.XXXXXX) -# Run the tests and collate the results. -for pkg in $(go list $PROJECT/...); do - $GO test -v -cover -covermode=count -coverprofile="$(mktemp --tmpdir=$COVERAGE_DIR cov.XXXXX)" -coverpkg=$PROJECT/... $pkg 2>/dev/null -done -[ "$COVERAGE" ] && $ROOT/hack/collate.awk $COVERAGE_DIR/* $COVERAGE | sponge $COVERAGE - -# Clean up the coverage directory. -rm -rf "$COVERAGE_DIR" +# Run the tests. +extra_args=() +if [ -n "$COVERAGE" ] +then + # If we have to generate a coverage file, make sure the coverage covers the + # entire project and not just the package being tested. + extra_args+=("-covermode=count" "-coverprofile=$COVERAGE" "-coverpkg=$PROJECT/...") +fi +"$GO" test -v -cover "${extra_args[@]}" "$PROJECT/..." 2>/dev/null