tests: simplify shell code, skip YAML test if Ruby is too old
This commit is contained in:
committed by
James Shubin
parent
5ae5d364bb
commit
806d4660cf
@@ -1,6 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# check for any bash files that aren't properly formatted
|
# check for any bash files that aren't properly formatted
|
||||||
# TODO: this is hardly exhaustive
|
# TODO: this is hardly exhaustive
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
echo running test-bashfmt.sh
|
echo running test-bashfmt.sh
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
@@ -24,8 +27,5 @@ bad_files=$(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if [[ -n "${bad_files}" ]]; then
|
if [[ -n "${bad_files}" ]]; then
|
||||||
echo 'FAIL'
|
fail_test "The following bash files are not properly formatted: ${bad_files}"
|
||||||
echo 'The following bash files are not properly formatted:'
|
|
||||||
echo "${bad_files}"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# original version of this script from kubernetes project, under ALv2 license
|
# original version of this script from kubernetes project, under ALv2 license
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
echo running test-gofmt.sh
|
echo running test-gofmt.sh
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
@@ -10,8 +13,7 @@ ROOT=$(dirname "${BASH_SOURCE}")/..
|
|||||||
GO_VERSION=($(go version))
|
GO_VERSION=($(go version))
|
||||||
|
|
||||||
if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3|go1.4|go1.5|go1.6|go1.7|go1.8|devel') ]]; then
|
if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3|go1.4|go1.5|go1.6|go1.7|go1.8|devel') ]]; then
|
||||||
echo "Unknown go version '${GO_VERSION[2]}', failing gofmt."
|
fail_test "Unknown go version '${GO_VERSION[2]}', failing gofmt."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "${ROOT}"
|
cd "${ROOT}"
|
||||||
@@ -23,8 +25,5 @@ find_files() {
|
|||||||
GOFMT="gofmt" # we prefer to not use the -s flag, which is pretty annoying...
|
GOFMT="gofmt" # we prefer to not use the -s flag, which is pretty annoying...
|
||||||
bad_files=$(find_files | xargs $GOFMT -l)
|
bad_files=$(find_files | xargs $GOFMT -l)
|
||||||
if [[ -n "${bad_files}" ]]; then
|
if [[ -n "${bad_files}" ]]; then
|
||||||
echo 'FAIL'
|
fail_test "The following golang files are not properly formatted: ${bad_files}"
|
||||||
echo 'The following golang files are not properly formatted:'
|
|
||||||
echo "${bad_files}"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# check that go lint passes or doesn't get worse by some threshold
|
# check that go lint passes or doesn't get worse by some threshold
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
echo running test-golint.sh
|
echo running test-golint.sh
|
||||||
# TODO: output a diff of what has changed in the golint output
|
# TODO: output a diff of what has changed in the golint output
|
||||||
# FIXME: test a range of commits, since only the last patch is checked here
|
# FIXME: test a range of commits, since only the last patch is checked here
|
||||||
@@ -26,10 +29,10 @@ COUNT=`echo -e "$LINT" | wc -l` # number of golint problems in current branch
|
|||||||
echo "$LINT" # display the issues
|
echo "$LINT" # display the issues
|
||||||
|
|
||||||
T=`mktemp --tmpdir -d tmp.XXX`
|
T=`mktemp --tmpdir -d tmp.XXX`
|
||||||
[ "$T" = "" ] && exit 1
|
[ "$T" = "" ] && fail_test "Could not create tmpdir"
|
||||||
cd $T || exit 1
|
cd $T || fail_test "Could not change into tmpdir $T"
|
||||||
git clone --recursive "${ROOT}" 2>/dev/null # make a copy
|
git clone --recursive "${ROOT}" 2>/dev/null # make a copy
|
||||||
cd "`basename ${ROOT}`" >/dev/null || exit 1
|
cd "`basename ${ROOT}`" >/dev/null || fail_test "Could not determine basename for the repo root '$ROOT'"
|
||||||
if [ "$HACK" != "" ]; then
|
if [ "$HACK" != "" ]; then
|
||||||
# ensure master branch really exists when cloning from a branched repo!
|
# ensure master branch really exists when cloning from a branched repo!
|
||||||
git checkout master &>/dev/null && git checkout - &>/dev/null
|
git checkout master &>/dev/null && git checkout - &>/dev/null
|
||||||
@@ -62,7 +65,6 @@ echo "Curr. # of issues: $COUNT"
|
|||||||
echo "Issue count delta is: $DELTA %"
|
echo "Issue count delta is: $DELTA %"
|
||||||
if [ "$DELTA" -gt "$THRESHOLD" ]; then
|
if [ "$DELTA" -gt "$THRESHOLD" ]; then
|
||||||
echo "Maximum threshold is: $THRESHOLD %"
|
echo "Maximum threshold is: $THRESHOLD %"
|
||||||
echo '`golint` FAIL'
|
fail_test "`golint` - FAILED"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo PASS
|
echo PASS
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# check that go vet passes
|
# check that go vet passes
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
echo running test-govet.sh
|
echo running test-govet.sh
|
||||||
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
|
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
|
||||||
cd "${ROOT}"
|
cd "${ROOT}"
|
||||||
|
|
||||||
for file in `find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*'`; do
|
for file in `find . -maxdepth 3 -type f -name '*.go' -not -path './old/*' -not -path './tmp/*'`; do
|
||||||
go vet "$file" && echo PASS || exit 1 # since it doesn't output an ok message on pass
|
go vet "$file" && echo PASS || fail_test "go vet did not pass" # since it doesn't output an ok message on pass
|
||||||
grep 'log.' "$file" | grep '\\n"' && echo 'no \n needed in log.Printf()' && exit 1 || echo PASS # no \n needed in log.Printf()
|
grep 'log.' "$file" | grep '\\n"' && fail_test 'no \n needed in log.Printf()' || echo PASS # no \n needed in log.Printf()
|
||||||
grep 'case _ = <-' "$file" && echo 'case _ = <- can be simplified to: case <-' && exit 1 || echo PASS # this can be simplified
|
grep 'case _ = <-' "$file" && fail_test 'case _ = <- can be simplified to: case <-' || echo PASS # this can be simplified
|
||||||
grep -Ei "[\/]+[\/]+[ ]*+(FIXME[^:]|TODO[^:]|XXX[^:])" "$file" && echo 'Token is missing a colon' && exit 1 || echo PASS # tokens must end with a colon
|
grep -Ei "[\/]+[\/]+[ ]*+(FIXME[^:]|TODO[^:]|XXX[^:])" "$file" && fail_test 'Token is missing a colon' || echo PASS # tokens must end with a colon
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# check that headers are properly formatted
|
# check that headers are properly formatted
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
echo running test-headerfmt.sh
|
echo running test-headerfmt.sh
|
||||||
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
|
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" # dir!
|
||||||
FILE="${ROOT}/main.go" # file headers should match main.go
|
FILE="${ROOT}/main.go" # file headers should match main.go
|
||||||
@@ -23,8 +26,5 @@ bad_files=$(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if [[ -n "${bad_files}" ]]; then
|
if [[ -n "${bad_files}" ]]; then
|
||||||
echo 'FAIL'
|
fail_test "The following file headers are not properly formatted: ${bad_files}"
|
||||||
echo 'The following file headers are not properly formatted:'
|
|
||||||
echo "${bad_files}"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# simple test harness for testing mgmt
|
# simple test harness for testing mgmt
|
||||||
# NOTE: this will rm -rf /tmp/mgmt/
|
# NOTE: this will rm -rf /tmp/mgmt/
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
|
if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
|
||||||
echo -e "usage: ./"`basename $0`" [[--help] | <test>]"
|
echo -e "usage: ./"`basename $0`" [[--help] | <test>]"
|
||||||
echo -e "where: <test> is empty to run all tests, or <file>.sh from shell/ dir"
|
echo -e "where: <test> is empty to run all tests, or <file>.sh from shell/ dir"
|
||||||
@@ -65,9 +68,7 @@ rm -f "$MGMT"
|
|||||||
make clean
|
make clean
|
||||||
|
|
||||||
if [ "$count" = '0' ]; then
|
if [ "$count" = '0' ]; then
|
||||||
echo 'FAIL'
|
fail_test 'No tests were run!'
|
||||||
echo 'No tests were run!'
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# display errors
|
# display errors
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# check for any yaml files that aren't properly formatted
|
# check for any yaml files that aren't properly formatted
|
||||||
|
|
||||||
|
. test/util.sh
|
||||||
|
|
||||||
echo running test-yamlfmt.sh
|
echo running test-yamlfmt.sh
|
||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
@@ -14,14 +17,15 @@ ROOT=$(dirname "${BASH_SOURCE}")/..
|
|||||||
|
|
||||||
RUBY=`which ruby 2>/dev/null`
|
RUBY=`which ruby 2>/dev/null`
|
||||||
if [ -z $RUBY ]; then
|
if [ -z $RUBY ]; then
|
||||||
echo "The 'ruby' utility can't be found."
|
fail_test "The 'ruby' utility can't be found."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$RUBY -e "require 'yaml'" 2>/dev/null || (
|
$RUBY -e "require 'yaml'" 2>/dev/null || fail_test "The ruby 'yaml' library can't be found."
|
||||||
echo "The ruby 'yaml' library can't be found."
|
|
||||||
exit 1
|
if $RUBY -e "puts RUBY_VERSION" | grep -q ^1 ; then
|
||||||
)
|
echo "SKIPPING - cannot test YAML formatting with Ruby 1.x"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
cd "${ROOT}"
|
cd "${ROOT}"
|
||||||
|
|
||||||
@@ -38,8 +42,5 @@ bad_files=$(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if [[ -n "${bad_files}" ]]; then
|
if [[ -n "${bad_files}" ]]; then
|
||||||
echo 'FAIL'
|
fail_test "The following yaml files are not properly formatted: ${bad_files}"
|
||||||
echo 'The following yaml files are not properly formatted:'
|
|
||||||
echo "${bad_files}"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
7
test/util.sh
Normal file
7
test/util.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# common settings and functions for test scripts
|
||||||
|
|
||||||
|
fail_test()
|
||||||
|
{
|
||||||
|
echo "FAIL: $@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user