test.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # fail out of the script if anything here fails
  3. set -e
  4. set -o pipefail
  5. # set the path to the present working directory
  6. export GOPATH=`pwd`
  7. function git_clone() {
  8. path=$1
  9. branch=$2
  10. version=$3
  11. if [ ! -d "src/$path" ]; then
  12. mkdir -p src/$path
  13. git clone https://$path.git src/$path
  14. fi
  15. pushd src/$path
  16. git checkout "$branch"
  17. git reset --hard "$version"
  18. popd
  19. }
  20. # Remove potential previous runs
  21. rm -rf src test_program_bin toml-test
  22. go get github.com/davecgh/go-spew/spew
  23. go get gopkg.in/yaml.v2
  24. go get github.com/BurntSushi/toml
  25. # get code for BurntSushi TOML validation
  26. git_clone github.com/BurntSushi/toml master a368813
  27. git_clone github.com/BurntSushi/toml-test master 39e37e6
  28. # build the BurntSushi test application
  29. go build -o toml-test github.com/BurntSushi/toml-test
  30. # vendorize the current lib for testing
  31. # NOTE: this basically mocks an install without having to go back out to github for code
  32. mkdir -p src/github.com/pelletier/go-toml/cmd
  33. mkdir -p src/github.com/pelletier/go-toml/query
  34. cp *.go *.toml src/github.com/pelletier/go-toml
  35. cp -R cmd/* src/github.com/pelletier/go-toml/cmd
  36. cp -R query/* src/github.com/pelletier/go-toml/query
  37. go build -o test_program_bin src/github.com/pelletier/go-toml/cmd/test_program.go
  38. # Run basic unit tests
  39. go test github.com/pelletier/go-toml -race -coverprofile=coverage.txt -covermode=atomic
  40. go test github.com/pelletier/go-toml/cmd/tomljson
  41. go test github.com/pelletier/go-toml/query
  42. # run the entire BurntSushi test suite
  43. if [[ $# -eq 0 ]] ; then
  44. echo "Running all BurntSushi tests"
  45. ./toml-test ./test_program_bin | tee test_out
  46. else
  47. # run a specific test
  48. test=$1
  49. test_path='src/github.com/BurntSushi/toml-test/tests'
  50. valid_test="$test_path/valid/$test"
  51. invalid_test="$test_path/invalid/$test"
  52. if [ -e "$valid_test.toml" ]; then
  53. echo "Valid Test TOML for $test:"
  54. echo "===="
  55. cat "$valid_test.toml"
  56. echo "Valid Test JSON for $test:"
  57. echo "===="
  58. cat "$valid_test.json"
  59. echo "Go-TOML Output for $test:"
  60. echo "===="
  61. cat "$valid_test.toml" | ./test_program_bin
  62. fi
  63. if [ -e "$invalid_test.toml" ]; then
  64. echo "Invalid Test TOML for $test:"
  65. echo "===="
  66. cat "$invalid_test.toml"
  67. echo "Go-TOML Output for $test:"
  68. echo "===="
  69. echo "go-toml Output:"
  70. cat "$invalid_test.toml" | ./test_program_bin
  71. fi
  72. fi