...

Text file src/github.com/google/flatbuffers/tests/GoTest.sh

Documentation: github.com/google/flatbuffers/tests

     1#!/bin/bash -eu
     2#
     3# Copyright 2014 Google Inc. All rights reserved.
     4#
     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
     8#
     9#     http://www.apache.org/licenses/LICENSE-2.0
    10#
    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.
    16
    17pushd "$(dirname $0)" >/dev/null
    18test_dir="$(pwd)"
    19go_path=${test_dir}/go_gen
    20go_src=${go_path}/src
    21
    22# Emit Go code for the example schemas in the test dir:
    23../flatc -g --gen-object-api -I include_test -o ${go_src} monster_test.fbs optional_scalars.fbs
    24../flatc -g --gen-object-api -I include_test/sub -o ${go_src} include_test/order.fbs
    25../flatc -g --gen-object-api -o ${go_src}/Pizza include_test/sub/no_namespace.fbs
    26
    27# Go requires a particular layout of files in order to link multiple packages.
    28# Copy flatbuffer Go files to their own package directories to compile the
    29# test binary:
    30mkdir -p ${go_src}/github.com/google/flatbuffers/go
    31mkdir -p ${go_src}/flatbuffers_test
    32
    33cp -a ../go/* ./go_gen/src/github.com/google/flatbuffers/go
    34cp -a ./go_test.go ./go_gen/src/flatbuffers_test/
    35
    36# https://stackoverflow.com/a/63545857/7024978
    37# We need to turn off go modules for this script
    38# to work.
    39go env -w  GO111MODULE=off
    40
    41# Run tests with necessary flags.
    42# Developers may wish to see more detail by appending the verbosity flag
    43# -test.v to arguments for this command, as in:
    44#   go -test -test.v ...
    45# Developers may also wish to run benchmarks, which may be achieved with the
    46# flag -test.bench and the wildcard regexp ".":
    47#   go -test -test.bench=. ...
    48GOPATH=${go_path} go test flatbuffers_test \
    49                     --coverpkg=github.com/google/flatbuffers/go \
    50                     --cpp_data=${test_dir}/monsterdata_test.mon \
    51                     --out_data=${test_dir}/monsterdata_go_wire.mon \
    52                     --bench=. \
    53                     --benchtime=3s \
    54                     --fuzz=true \
    55                     --fuzz_fields=4 \
    56                     --fuzz_objects=10000
    57
    58GO_TEST_RESULT=$?
    59rm -rf ${go_path}/{pkg,src}
    60if [[ $GO_TEST_RESULT  == 0 ]]; then
    61    echo "OK: Go tests passed."
    62else
    63    echo "KO: Go tests failed."
    64    exit 1
    65fi
    66
    67NOT_FMT_FILES=$(gofmt -l .)
    68if [[ ${NOT_FMT_FILES} != "" ]]; then
    69    echo "These files are not well gofmt'ed:"
    70    echo
    71    echo "${NOT_FMT_FILES}"
    72    # enable this when enums are properly formated
    73    # exit 1
    74fi
    75
    76# Re-enable go modules when done tests
    77go env -w  GO111MODULE=on

View as plain text