From fb95f02af6f1274cfd34b8f671f22f42b80d379a Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 14 Jan 2015 21:36:33 +0100 Subject: [PATCH] Refactor testsuite --- Makefile | 34 +++++------------- cmd/restic/Makefile | 17 +++------ testsuite.sh | 17 +++++++++ {test => testsuite}/fake-data.tar.gz | Bin {test => testsuite}/run.sh | 29 ++++++++++----- .../test-backup-missing-file.sh | 0 {test => testsuite}/test-backup.sh | 0 {test => testsuite}/test-key-add-remove.sh | 0 wercker.yml | 4 +-- 9 files changed, 52 insertions(+), 49 deletions(-) create mode 100755 testsuite.sh rename {test => testsuite}/fake-data.tar.gz (100%) rename {test => testsuite}/run.sh (70%) rename {test => testsuite}/test-backup-missing-file.sh (100%) rename {test => testsuite}/test-backup.sh (100%) rename {test => testsuite}/test-key-add-remove.sh (100%) diff --git a/Makefile b/Makefile index 2b440959d..7ae540e78 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,15 @@ -.PHONY: clean all test release debug +.PHONY: clean all debug test -GOFLAGS= -#GOFLAGS+=-race - -all: release - -release: - for dir in cmd/* ; do \ - test -f "$$dir/Makefile" && \ - (GOFLAGS="$(GOFLAGS)" make -C "$$dir") \ +all: + for dir in ./cmd/* ; do \ + (echo "$$dir"; cd "$$dir"; go build) \ done debug: - for dir in cmd/* ; do \ - test -f "$$dir/Makefile" && \ - (GOFLAGS="$(GOFLAGS)" make -C "$$dir" debug) \ - done + (cd cmd/restic; go build -a -tags debug) -test: release debug - go test -v ./... - test/run.sh cmd/restic:cmd/dirdiff - -test-%: test/test-%.sh release debug - echo $* - test/run.sh cmd/restic:cmd/dirdiff "test/$@.sh" +test: + ./testsuite.sh clean: - go clean - for dir in cmd/* ; do \ - test -f "$$dir/Makefile" && \ - (make -C "$$dir" clean) \ - done + go clean ./... diff --git a/cmd/restic/Makefile b/cmd/restic/Makefile index 6e0e521c2..c1d2ba9ff 100644 --- a/cmd/restic/Makefile +++ b/cmd/restic/Makefile @@ -1,26 +1,17 @@ -# try to get version from git -VERSION = $(shell ./version.sh) -VERSION ?= "unknown version" -LDFLAGS = -X main.version $(VERSION) -LDFLAGS += -X github.com/restic/restic.Version $(VERSION) -TAGS = - -.PHONY: all both clean debug +.PHONY: all clean debug # include config file if it exists -include $(CURDIR)/config.mk all: restic -both: restic restic.debug - -debug: restic.debug +debug: restic.debug restic: $(wildcard *.go) $(wildcard ../../*.go) $(wildcard ../../*/*.go) - go build -tags "$(TAGS)" $(GOFLAGS) -ldflags "$(LDFLAGS)" + go build -a restic.debug: $(wildcard *.go) $(wildcard ../../*.go) $(wildcard ../../*/*.go) - go build -o restic.debug -tags "debug debug_cmd" $(GOFLAGS) -ldflags "$(LDFLAGS)" + go build -a -tags debug -o restic.debug clean: go clean diff --git a/testsuite.sh b/testsuite.sh new file mode 100755 index 000000000..79607e51f --- /dev/null +++ b/testsuite.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# tempdir for binaries +export BASEDIR="$(mktemp --tmpdir --directory restic-testsuite-XXXXXX)" +export BINDIR="${BASEDIR}/bin" +export PATH="${BINDIR}:$PATH" +export DEBUG_LOG="${BASEDIR}/restic.log" + +echo "restic testsuite basedir ${BASEDIR}" + +# build binaries +go build -a -o "${BINDIR}/restic" ./cmd/restic +go build -a -tags debug -o "${BINDIR}/restic.debug" ./cmd/restic +go build -a -o "${BINDIR}/dirdiff" ./cmd/dirdiff + +# run tests +testsuite/run.sh diff --git a/test/fake-data.tar.gz b/testsuite/fake-data.tar.gz similarity index 100% rename from test/fake-data.tar.gz rename to testsuite/fake-data.tar.gz diff --git a/test/run.sh b/testsuite/run.sh similarity index 70% rename from test/run.sh rename to testsuite/run.sh index a4ae89070..9356df0df 100755 --- a/test/run.sh +++ b/testsuite/run.sh @@ -30,20 +30,20 @@ cleanup() { } msg() { - printf "%s: %s\n" "$(basename "$0" .sh)" "$*" + printf "%s\n" "$*" } pass() { - printf "\e[32m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*" + printf "\e[32m%s\e[39m\n" "$*" } err() { - printf "\e[31m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*" + printf "\e[31m%s\e[39m\n" "$*" } debug() { if [ "$DEBUG" = "1" ]; then - printf "\e[33m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*" + printf "\e[33m%s\e[39m\n" "$*" fi } @@ -62,14 +62,23 @@ run() { export -f prepare cleanup msg debug pass err fail run -# first argument is restic path -export PATH="$1:$PATH"; shift +if [ -z "$BASEDIR" ]; then + echo "BASEDIR not set" >&2 + exit 2 +fi -which restic || fail "restic binary not found!" -which dirdiff || fail "dirdiff binary not found!" +which restic > /dev/null || fail "restic binary not found!" +which restic.debug > /dev/null || fail "restic.debug binary not found!" +which dirdiff > /dev/null || fail "dirdiff binary not found!" debug "restic path: $(which restic)" +debug "restic.debug path: $(which restic.debug)" debug "dirdiff path: $(which dirdiff)" +debug "path: $PATH" + +debug "restic versions:" +run restic version +run restic.debug version if [ "$#" -gt 0 ]; then testfiles="$1" @@ -81,6 +90,10 @@ echo "testfiles: ${testfiles[@]}" failed="" for testfile in "${testfiles[@]}"; do + msg "================================================================================" + msg "run test $testfile" + msg "" + current=$(basename "${testfile}" .sh) if [ "$DEBUG" = "1" ]; then diff --git a/test/test-backup-missing-file.sh b/testsuite/test-backup-missing-file.sh similarity index 100% rename from test/test-backup-missing-file.sh rename to testsuite/test-backup-missing-file.sh diff --git a/test/test-backup.sh b/testsuite/test-backup.sh similarity index 100% rename from test/test-backup.sh rename to testsuite/test-backup.sh diff --git a/test/test-key-add-remove.sh b/testsuite/test-key-add-remove.sh similarity index 100% rename from test/test-key-add-remove.sh rename to testsuite/test-key-add-remove.sh diff --git a/wercker.yml b/wercker.yml index aec9c09bc..9a74ba87e 100644 --- a/wercker.yml +++ b/wercker.yml @@ -13,7 +13,7 @@ build: code: | cd $WERCKER_SOURCE_DIR go version - go get -t ./... + go get -v -t ./... # Build the project - script: @@ -31,4 +31,4 @@ build: - script: name: integration test code: | - make test + ./testsuite.sh