Refactored testing approach to use 'vendorized' libraries at test time.
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# fail out of the script if anything here fails
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# clear out stuff generated by test.sh
|
||||||
|
rm -rf src test_program_bin toml-test
|
||||||
@@ -40,6 +40,12 @@ func translate(tomlData interface{}) interface{} {
|
|||||||
return typed
|
return typed
|
||||||
case *toml.TomlTree:
|
case *toml.TomlTree:
|
||||||
return translate((map[string]interface{})(*orig))
|
return translate((map[string]interface{})(*orig))
|
||||||
|
case []*toml.TomlTree:
|
||||||
|
typed := make([]map[string]interface{}, len(orig))
|
||||||
|
for i, v := range orig {
|
||||||
|
typed[i] = translate(v).(map[string]interface{})
|
||||||
|
}
|
||||||
|
return typed
|
||||||
case []map[string]interface{}:
|
case []map[string]interface{}:
|
||||||
typed := make([]map[string]interface{}, len(orig))
|
typed := make([]map[string]interface{}, len(orig))
|
||||||
for i, v := range orig {
|
for i, v := range orig {
|
||||||
@@ -1,11 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# fail out of the script if anything here fails
|
||||||
|
set -e
|
||||||
|
|
||||||
# Run basic go unit tests
|
# set the path to the present working directory
|
||||||
go test -v ./...
|
export GOPATH=`pwd`
|
||||||
result=$?
|
|
||||||
|
|
||||||
# Run example-based toml tests
|
# Vendorize the BurntSushi test suite
|
||||||
cd test_program && ./go-test.sh
|
# NOTE: this gets a specific release to avoid versioning issues
|
||||||
result="$(( result || $? ))"
|
if [ ! -d 'src/github.com/BurntSushi/toml-test' ]; then
|
||||||
|
mkdir -p src/github.com/BurntSushi
|
||||||
|
git clone https://github.com/BurntSushi/toml-test.git src/github.com/BurntSushi/toml-test
|
||||||
|
fi
|
||||||
|
pushd src/github.com/BurntSushi/toml-test
|
||||||
|
git reset --hard '0.2.0' # use the released version, NOT tip
|
||||||
|
popd
|
||||||
|
go build -o toml-test github.com/BurntSushi/toml-test
|
||||||
|
|
||||||
exit $result
|
# vendorize the current lib for testing
|
||||||
|
# NOTE: this basically mocks an install without having to go back out to github for code
|
||||||
|
mkdir -p src/github.com/pelletier/go-toml/cmd
|
||||||
|
cp *.go *.toml src/github.com/pelletier/go-toml
|
||||||
|
cp cmd/*.go src/github.com/pelletier/go-toml/cmd
|
||||||
|
go build -o test_program_bin src/github.com/pelletier/go-toml/cmd/test_program.go
|
||||||
|
|
||||||
|
# Run basic unit tests and then the BurntSushi test suite
|
||||||
|
go test -v github.com/pelletier/go-toml
|
||||||
|
./toml-test ./test_program_bin | tee test_out
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
go get github.com/BurntSushi/toml-test # install test suite
|
|
||||||
go build -o test_program_bin github.com/pelletier/go-toml/test_program
|
|
||||||
|
|
||||||
toml_test_wrapper() {
|
|
||||||
ret=0
|
|
||||||
if hash toml-test 2>/dev/null; then # test availability in $PATH
|
|
||||||
toml-test "$@"
|
|
||||||
ret=$?
|
|
||||||
else
|
|
||||||
p="$HOME/gopath/bin/toml-test" # try in Travi's place
|
|
||||||
if [ -f "$p" ]; then
|
|
||||||
"$p" "$@"
|
|
||||||
ret=$?
|
|
||||||
else
|
|
||||||
"$GOPATH/bin/toml-test" "$@"
|
|
||||||
ret=$?
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
toml_test_wrapper ./test_program_bin | tee test_out
|
|
||||||
ret="$([ `tail -n 1 test_out | sed -E 's/^.+([0-9]+) failed$/\1/'` -eq 0 ])"
|
|
||||||
exit $ret
|
|
||||||
Reference in New Issue
Block a user