From f49f66f61e3b4135059ff086698466e090f7d817 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Tue, 22 Nov 2016 10:57:47 -0500 Subject: [PATCH] cli.test: fail on cli tests This cleans up the Makefile target, and drops the dependency to point to the $root path of the repo. Fixes https://github.com/vbatts/go-mtree/issues/98 Reported-by: Aleksa Sarai Signed-off-by: Vincent Batts --- Makefile | 4 +--- test/cli.go | 26 ++++++++++++++++++++++++++ test/cli/0001.sh | 2 +- test/cli/0002.sh | 2 +- test/cli/0004.sh | 2 +- test/cli/0005.sh | 2 +- test/cli/0006.sh | 2 +- 7 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 test/cli.go diff --git a/Makefile b/Makefile index a428984..220cdbb 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,7 @@ vet: .vet cli.test: .cli.test .cli.test: $(BUILD) $(wildcard ./test/cli/*.sh) - @ for test in ./test/cli/*.sh ; do \ - bash $$test $(CWD) ; \ - done && touch $@ + @go run ./test/cli.go ./test/cli/*.sh && touch $@ .PHONY: build build: $(BUILD) diff --git a/test/cli.go b/test/cli.go new file mode 100644 index 0000000..286dd7f --- /dev/null +++ b/test/cli.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" + "fmt" + "os" + "os/exec" +) + +func main() { + flag.Parse() + + failed := 0 + for _, arg := range flag.Args() { + cmd := exec.Command("bash", arg) + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stdout + if err := cmd.Run(); err != nil { + failed++ + } + } + if failed > 0 { + fmt.Printf("%d FAILED tests\n", failed) + os.Exit(1) + } +} diff --git a/test/cli/0001.sh b/test/cli/0001.sh index 5119c1b..47162fe 100644 --- a/test/cli/0001.sh +++ b/test/cli/0001.sh @@ -2,7 +2,7 @@ set -e name=$(basename $0) -root=$1 +root="$(dirname $(dirname $(dirname $0)))" gomtree=$(readlink -f ${root}/gomtree) t=$(mktemp -d /tmp/go-mtree.XXXXXX) diff --git a/test/cli/0002.sh b/test/cli/0002.sh index 5bf9a40..c474103 100644 --- a/test/cli/0002.sh +++ b/test/cli/0002.sh @@ -2,7 +2,7 @@ set -e name=$(basename $0) -root=$1 +root="$(dirname $(dirname $(dirname $0)))" gomtree=$(readlink -f ${root}/gomtree) t=$(mktemp -d /tmp/go-mtree.XXXXXX) diff --git a/test/cli/0004.sh b/test/cli/0004.sh index b538285..1488ef0 100644 --- a/test/cli/0004.sh +++ b/test/cli/0004.sh @@ -3,7 +3,7 @@ set -e #set -x name=$(basename $0) -root=$1 +root="$(dirname $(dirname $(dirname $0)))" gomtree=$(readlink -f ${root}/gomtree) t=$(mktemp -d /tmp/go-mtree.XXXXXX) diff --git a/test/cli/0005.sh b/test/cli/0005.sh index 48e025b..a4732d6 100644 --- a/test/cli/0005.sh +++ b/test/cli/0005.sh @@ -2,7 +2,7 @@ set -e name=$(basename $0) -root=$1 +root="$(dirname $(dirname $(dirname $0)))" gomtree=$(readlink -f ${root}/gomtree) t=$(mktemp -d /tmp/go-mtree.XXXXXX) diff --git a/test/cli/0006.sh b/test/cli/0006.sh index 611353a..70b0770 100644 --- a/test/cli/0006.sh +++ b/test/cli/0006.sh @@ -2,7 +2,7 @@ set -e name=$(basename $0) -root=$1 +root="$(dirname $(dirname $(dirname $0)))" gomtree=$(readlink -f ${root}/gomtree) t=$(mktemp -d /tmp/go-mtree.XXXXXX)