3 # Copyright 2014 Google Inc. All rights reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 pushd "$(dirname $0)" >/dev/null
19 go_path=${test_dir}/go_gen
22 # Emit Go code for the example schema in the test dir:
23 ../flatc -g --gen-object-api -I include_test monster_test.fbs
25 # Go requires a particular layout of files in order to link multiple packages.
26 # Copy flatbuffer Go files to their own package directories to compile the
28 mkdir -p ${go_src}/MyGame/Example
29 mkdir -p ${go_src}/MyGame/Example2
30 mkdir -p ${go_src}/github.com/google/flatbuffers/go
31 mkdir -p ${go_src}/flatbuffers_test
33 cp -a MyGame/*.go ./go_gen/src/MyGame/
34 cp -a MyGame/Example/*.go ./go_gen/src/MyGame/Example/
35 cp -a MyGame/Example2/*.go ./go_gen/src/MyGame/Example2/
36 # do not compile the gRPC generated files, which are not tested by go_test.go
37 # below, but have their own test.
38 rm ./go_gen/src/MyGame/Example/*_grpc.go
39 cp -a ../go/* ./go_gen/src/github.com/google/flatbuffers/go
40 cp -a ./go_test.go ./go_gen/src/flatbuffers_test/
42 # Run tests with necessary flags.
43 # Developers may wish to see more detail by appending the verbosity flag
44 # -test.v to arguments for this command, as in:
45 # go -test -test.v ...
46 # Developers may also wish to run benchmarks, which may be achieved with the
47 # flag -test.bench and the wildcard regexp ".":
48 # go -test -test.bench=. ...
49 GOPATH=${go_path} go test flatbuffers_test \
50 --test.coverpkg=github.com/google/flatbuffers/go \
51 --cpp_data=${test_dir}/monsterdata_test.mon \
52 --out_data=${test_dir}/monsterdata_go_wire.mon \
60 rm -rf ${go_path}/{pkg,src}
61 if [[ $GO_TEST_RESULT == 0 ]]; then
62 echo "OK: Go tests passed."
64 echo "KO: Go tests failed."
68 NOT_FMT_FILES=$(gofmt -l MyGame)
69 if [[ ${NOT_FMT_FILES} != "" ]]; then
70 echo "These files are not well gofmt'ed:"
72 echo "${NOT_FMT_FILES}"
73 # enable this when enums are properly formated