blob: 454cfd836564fbbe53c67142782325a1be72965b [file] [log] [blame]
Joe Tsai1bed4542018-08-03 19:13:55 -07001#!/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
6REPO_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.
10TEST_DIR=/tmp/golang-protobuf-test
11if [ ! -d $TEST_DIR ]; then
12 echo "mkdir $TEST_DIR"
13 mkdir -p $TEST_DIR
14fi
15cd $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.
20PROTOBUF_VERSION=3.6.1
21PROTOBUF_DIR="protobuf-$PROTOBUF_VERSION"
22if [ ! -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
26fi
27
28# Download each Go toolchain version.
29GO_VERSIONS=(1.9.7 1.10.3 1.11beta3)
30for 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
37done
38
39# Setup GOPATH for pre-module support.
40MODULE_PATH=$(grep '^module ' $REPO_ROOT/go.mod | cut -d " " -f 2)
41if [ ! -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))
44fi
45export GOPATH=$TEST_DIR/gopath
46
47# Run tests across every supported version of Go.
48FAIL=0
49for 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 ./...
64done
65exit $FAIL