OSDN Git Service

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