From 9531465410778e77f7d3f1105c77f87f7e148ec3 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Fri, 2 Jun 2017 03:32:53 -0400 Subject: [PATCH] test: Make sure our examples build Since there are occasional API changes, I'd like to at least remember to keep the examples building, so we now have a test to remind us! --- test.sh | 1 + test/test-examples.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 test/test-examples.sh diff --git a/test.sh b/test.sh index c399f7ae..5a502abc 100755 --- a/test.sh +++ b/test.sh @@ -23,6 +23,7 @@ run-test ./test/test-bashfmt.sh run-test ./test/test-headerfmt.sh run-test ./test/test-commit-message.sh run-test ./test/test-govet.sh +run-test ./test/test-examples.sh run-test ./test/test-gotest.sh # do these longer tests only when running on ci diff --git a/test/test-examples.sh b/test/test-examples.sh new file mode 100755 index 00000000..6017e3c3 --- /dev/null +++ b/test/test-examples.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# check that our examples still build, even if we don't run them here + +. test/util.sh + +echo running test-examples.sh + +failures='' +function run-test() +{ + $@ || failures=$( [ -n "$failures" ] && echo "$failures\\n$@" || echo "$@" ) +} + +ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir! +cd "${ROOT}" + +buildout='test-examples.out' +# make symlink to outside of package +linkto="`pwd`/examples/lib/" +tmpdir="`mktemp --tmpdir -d tmp.XXX`" # get a dir outside of the main package +cd "$tmpdir" +ln -s "$linkto" # symlink outside of dir +cd `basename "$linkto"` + +# loop through individual *.go files in working dir +for file in `find . -maxdepth 3 -type f -name '*.go'`; do + #echo "running test on: $file" + run-test go build -i -o "$buildout" "$file" || fail_test "could not build: $file" +done +rm "$buildout" || true # clean up build mess + +cd - # back to tmp dir +rm `basename "$linkto"` +cd .. +rmdir "$tmpdir" # cleanup + +if [[ -n "$failures" ]]; then + echo 'FAIL' + echo 'The following tests have failed:' + echo -e "$failures" + exit 1 +fi +echo 'PASS'