Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: make coverage optional #69

Merged
merged 1 commit into from
Dec 30, 2016
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test-unit: umociimage

.PHONY: local-test-unit
local-test-unit:
GO=$(GO) PROJECT=$(PROJECT) hack/test-unit.sh
GO=$(GO) COVER=1 hack/test-unit.sh

.PHONY: test-integration
test-integration: umociimage
Expand All @@ -105,7 +105,7 @@ test-integration: umociimage

.PHONY: local-test-integration
local-test-integration: umoci.cover
hack/test-integration.sh
COVER=1 hack/test-integration.sh

shell: umociimage
docker run --rm -it -v $(PWD):/go/src/$(PROJECT) $(UMOCI_IMAGE) bash
Expand Down
5 changes: 3 additions & 2 deletions cmd/umoci/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// -cover -coverpkg=github.com/cyphar/umoci/... \
// github.com/cyphar/umoci/cmd/umoci
// Run:
// $ ./umoci --i-heard-you-like-tests -test.coverprofile [file] [args]...
// $ ./umoci __DEVEL--i-heard-you-like-tests -test.coverprofile [file] [args]...

// TestUmoci is a hack that allows us to figure out what the coverage is during
// integration tests. I would not recommend that you use a binary built using
Expand All @@ -41,9 +41,10 @@ func TestUmoci(t *testing.T) {

for _, arg := range os.Args {
switch {
case arg == "~~i-heard-you-like-tests":
case arg == "__DEVEL--i-heard-you-like-tests":
run = true
case strings.HasPrefix(arg, "-test"):
case strings.HasPrefix(arg, "__DEVEL"):
default:
args = append(args, arg)
}
Expand Down
22 changes: 15 additions & 7 deletions hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@

set -ex

export COVER="${COVER:-0}"

# 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)
if [ "$COVER" -eq 1 ]; then
export COVERAGE_DIR=$(mktemp --tmpdir -d umoci-coverage.XXXXXX)
fi

# Create a temporary symlink for umoci, since the --help tests require the
# binary have the name "umoci". This is all just to make the Makefile nicer.
UMOCI_DIR="$(mktemp --tmpdir -d umoci.XXXXXX)"
export UMOCI="$UMOCI_DIR/umoci"
ln -s "$ROOT/umoci.cover" "$UMOCI"
if [ "$COVER" -eq 1 ]; then
# Create a temporary symlink for umoci, since the --help tests require the
# binary have the name "umoci". This is all just to make the Makefile nicer.
UMOCI_DIR="$(mktemp --tmpdir -d umoci.XXXXXX)"
export UMOCI="$UMOCI_DIR/umoci"
ln -s "$ROOT/umoci.cover" "$UMOCI"
fi

# Run the tests and collate the results.
bats -t $ROOT/test/*.bats
[ "$COVERAGE" ] && $ROOT/hack/collate.awk $COVERAGE_DIR/* $COVERAGE | sponge $COVERAGE
if [ "$COVER" -eq 1 ]; then
[ "$COVERAGE" ] && $ROOT/hack/collate.awk $COVERAGE_DIR/* $COVERAGE | sponge $COVERAGE
fi

# Clean up the coverage directory.
rm -rf "$COVERAGE_DIR"
1 change: 1 addition & 0 deletions hack/test-unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
set -ex

GO="${GO:-go}"
PROJECT="${PROJECT:-github.com/cyphar/umoci}"

# Set up the root and coverage directories.
export ROOT="$(readlink -f "$(dirname "$(readlink -f "$BASH_SOURCE")")/..")"
Expand Down
9 changes: 6 additions & 3 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ function bundle-verify() {

function umoci() {
local args=()
if [ "$COVERAGE_DIR" ]; then
args+=("-test.coverprofile=$(mktemp -p "$COVERAGE_DIR" umoci.cov.XXXXXX)" "~~i-heard-you-like-tests")
if [ "$COVER" -eq 1 ]; then
if [ "$COVERAGE_DIR" ]; then
args+=("-test.coverprofile=$(mktemp -p "$COVERAGE_DIR" umoci.cov.XXXXXX)")
fi
args+=("__DEVEL--i-heard-you-like-tests")
fi

# Set the first argument (the subcommand).
Expand All @@ -84,7 +87,7 @@ function umoci() {
args+=("$@")
sane_run "$UMOCI" "${args[@]}"

if [ "$COVERAGE_DIR" ]; then
if [ "$COVER" -eq 1 ]; then
# Because this is running as a -test.cover test, we need to remove the last
# two lines.
if [ "$status" -eq 0 ]; then
Expand Down