Joe Tsai | 1bed454 | 2018-08-03 19:13:55 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2018 The Go Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style |
| 4 | # license that can be found in the LICENSE file. |
| 5 | |
| 6 | REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 7 | |
| 8 | # Create a test directory. |
| 9 | # The Go and protobuf toolchains used for testing will be cached here. |
| 10 | TEST_DIR=/tmp/golang-protobuf-test |
| 11 | if [ ! -d $TEST_DIR ]; then |
| 12 | echo "mkdir $TEST_DIR" |
| 13 | mkdir -p $TEST_DIR |
| 14 | fi |
| 15 | cd $TEST_DIR |
| 16 | |
| 17 | # Download and build the protobuf toolchain. |
| 18 | # We avoid downloading the pre-compiled binaries since they do not contain |
| 19 | # the conformance test runner. |
| 20 | PROTOBUF_VERSION=3.6.1 |
| 21 | PROTOBUF_DIR="protobuf-$PROTOBUF_VERSION" |
| 22 | if [ ! -d $PROTOBUF_DIR ]; then |
| 23 | echo "download and build $PROTOBUF_DIR" |
| 24 | (curl -s -L https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/protobuf-all-$PROTOBUF_VERSION.tar.gz | tar -zxf -) || exit 1 |
| 25 | (cd $PROTOBUF_DIR && ./configure && make && cd conformance && make) || exit 1 |
| 26 | fi |
| 27 | |
| 28 | # Download each Go toolchain version. |
| 29 | GO_VERSIONS=(1.9.7 1.10.3 1.11beta3) |
| 30 | for GO_VERSION in ${GO_VERSIONS[@]}; do |
| 31 | GO_DIR=go$GO_VERSION |
| 32 | if [ ! -d $GO_DIR ]; then |
| 33 | echo "download $GO_DIR" |
| 34 | GOOS=$(uname | tr '[:upper:]' '[:lower:]') |
| 35 | (mkdir $GO_DIR && curl -s -L https://dl.google.com/go/$GO_DIR.$GOOS-amd64.tar.gz | tar -zxf - -C $GO_DIR --strip-components 1) || exit 1 |
| 36 | fi |
| 37 | done |
| 38 | |
| 39 | # Setup GOPATH for pre-module support. |
| 40 | MODULE_PATH=$(grep '^module ' $REPO_ROOT/go.mod | cut -d " " -f 2) |
| 41 | if [ ! -d gopath/src/$MODULE_PATH ]; then |
| 42 | mkdir -p gopath/src/$(dirname $MODULE_PATH) |
| 43 | (cd gopath/src/$(dirname $MODULE_PATH) && ln -s $REPO_ROOT $(basename $MODULE_PATH)) |
| 44 | fi |
| 45 | export GOPATH=$TEST_DIR/gopath |
| 46 | |
| 47 | # Run tests across every supported version of Go. |
| 48 | FAIL=0 |
| 49 | for GO_VERSION in ${GO_VERSIONS[@]}; do |
| 50 | export GOROOT=$TEST_DIR/go$GO_VERSION |
| 51 | GO_BIN=go$GO_VERSION/bin/go |
| 52 | function go_build() { |
| 53 | echo "$GO_BIN build $@" |
| 54 | (cd $GOPATH/src/$MODULE_PATH && $TEST_DIR/$GO_BIN build $@) || FAIL=1 |
| 55 | } |
| 56 | function go_test() { |
| 57 | echo "$GO_BIN test $@" |
| 58 | (cd $GOPATH/src/$MODULE_PATH && $TEST_DIR/$GO_BIN test $@) || FAIL=1 |
| 59 | } |
| 60 | |
| 61 | go_build ./... |
| 62 | go_test -race ./... |
| 63 | go_test -race -tags proto1_legacy ./... |
| 64 | done |
| 65 | exit $FAIL |