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=
#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 ./...

View file

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

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() {
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

View file

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