Permalink
Browse files

*: make coverage optional

This makes the hack/test-* scripts work in a non-coverage mode that
allows users to run hack/test-integration with a regular umoci binary.

Signed-off-by: Aleksa Sarai <asarai@suse.com>
  • Loading branch information...
1 parent 5dc557b commit 0fc2f762688eda358f05223fa3c3aed19e96eb9d @cyphar committed Dec 30, 2016
Showing with 27 additions and 14 deletions.
  1. +2 −2 Makefile
  2. +3 −2 cmd/umoci/main_test.go
  3. +15 −7 hack/test-integration.sh
  4. +1 −0 hack/test-unit.sh
  5. +6 −3 test/helpers.bash
View
@@ -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
@@ -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
@@ -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
@@ -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)
}
@@ -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"
View
@@ -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")")/..")"
View
@@ -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).
@@ -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

0 comments on commit 0fc2f76

Please sign in to comment.