Refactor testsuite

This commit is contained in:
Alexander Neumann 2015-01-14 21:36:33 +01:00
parent 25a214809b
commit fb95f02af6
9 changed files with 52 additions and 49 deletions

View File

@ -1,33 +1,15 @@
.PHONY: clean all test release debug .PHONY: clean all debug test
GOFLAGS= all:
#GOFLAGS+=-race for dir in ./cmd/* ; do \
(echo "$$dir"; cd "$$dir"; go build) \
all: release
release:
for dir in cmd/* ; do \
test -f "$$dir/Makefile" && \
(GOFLAGS="$(GOFLAGS)" make -C "$$dir") \
done done
debug: debug:
for dir in cmd/* ; do \ (cd cmd/restic; go build -a -tags debug)
test -f "$$dir/Makefile" && \
(GOFLAGS="$(GOFLAGS)" make -C "$$dir" debug) \
done
test: release debug test:
go test -v ./... ./testsuite.sh
test/run.sh cmd/restic:cmd/dirdiff
test-%: test/test-%.sh release debug
echo $*
test/run.sh cmd/restic:cmd/dirdiff "test/$@.sh"
clean: clean:
go clean go clean ./...
for dir in cmd/* ; do \
test -f "$$dir/Makefile" && \
(make -C "$$dir" clean) \
done

View File

@ -1,26 +1,17 @@
# try to get version from git .PHONY: all clean debug
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
# include config file if it exists # include config file if it exists
-include $(CURDIR)/config.mk -include $(CURDIR)/config.mk
all: restic all: restic
both: restic restic.debug debug: restic.debug
debug: restic.debug
restic: $(wildcard *.go) $(wildcard ../../*.go) $(wildcard ../../*/*.go) 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) 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: clean:
go clean go clean

17
testsuite.sh Executable file
View File

@ -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

View File

@ -30,20 +30,20 @@ cleanup() {
} }
msg() { msg() {
printf "%s: %s\n" "$(basename "$0" .sh)" "$*" printf "%s\n" "$*"
} }
pass() { pass() {
printf "\e[32m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*" printf "\e[32m%s\e[39m\n" "$*"
} }
err() { err() {
printf "\e[31m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*" printf "\e[31m%s\e[39m\n" "$*"
} }
debug() { debug() {
if [ "$DEBUG" = "1" ]; then if [ "$DEBUG" = "1" ]; then
printf "\e[33m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*" printf "\e[33m%s\e[39m\n" "$*"
fi fi
} }
@ -62,14 +62,23 @@ run() {
export -f prepare cleanup msg debug pass err fail run export -f prepare cleanup msg debug pass err fail run
# first argument is restic path if [ -z "$BASEDIR" ]; then
export PATH="$1:$PATH"; shift echo "BASEDIR not set" >&2
exit 2
fi
which restic || fail "restic binary not found!" which restic > /dev/null || fail "restic binary not found!"
which dirdiff || fail "dirdiff 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 path: $(which restic)"
debug "restic.debug path: $(which restic.debug)"
debug "dirdiff path: $(which dirdiff)" debug "dirdiff path: $(which dirdiff)"
debug "path: $PATH"
debug "restic versions:"
run restic version
run restic.debug version
if [ "$#" -gt 0 ]; then if [ "$#" -gt 0 ]; then
testfiles="$1" testfiles="$1"
@ -81,6 +90,10 @@ echo "testfiles: ${testfiles[@]}"
failed="" failed=""
for testfile in "${testfiles[@]}"; do for testfile in "${testfiles[@]}"; do
msg "================================================================================"
msg "run test $testfile"
msg ""
current=$(basename "${testfile}" .sh) current=$(basename "${testfile}" .sh)
if [ "$DEBUG" = "1" ]; then if [ "$DEBUG" = "1" ]; then

View File

@ -13,7 +13,7 @@ build:
code: | code: |
cd $WERCKER_SOURCE_DIR cd $WERCKER_SOURCE_DIR
go version go version
go get -t ./... go get -v -t ./...
# Build the project # Build the project
- script: - script:
@ -31,4 +31,4 @@ build:
- script: - script:
name: integration test name: integration test
code: | code: |
make test ./testsuite.sh