1*1b3f573fSAndroid Build Coastguard Worker#!/bin/bash 2*1b3f573fSAndroid Build Coastguard Worker 3*1b3f573fSAndroid Build Coastguard Workerfunction run_test() { 4*1b3f573fSAndroid Build Coastguard Worker # Generate test proto files. 5*1b3f573fSAndroid Build Coastguard Worker $1 -Iprotos/src -I../../../src/ --csharp_out=src/Google.Protobuf.Test \ 6*1b3f573fSAndroid Build Coastguard Worker --csharp_opt=base_namespace=Google.Protobuf \ 7*1b3f573fSAndroid Build Coastguard Worker protos/src/google/protobuf/unittest_import_proto3.proto \ 8*1b3f573fSAndroid Build Coastguard Worker protos/src/google/protobuf/unittest_import_public_proto3.proto \ 9*1b3f573fSAndroid Build Coastguard Worker protos/src/google/protobuf/unittest_well_known_types.proto 10*1b3f573fSAndroid Build Coastguard Worker 11*1b3f573fSAndroid Build Coastguard Worker $1 -Iprotos/csharp --csharp_out=src/Google.Protobuf.Test \ 12*1b3f573fSAndroid Build Coastguard Worker --csharp_opt=base_namespace=UnitTest.Issues \ 13*1b3f573fSAndroid Build Coastguard Worker protos/csharp/protos/unittest_issues.proto 14*1b3f573fSAndroid Build Coastguard Worker 15*1b3f573fSAndroid Build Coastguard Worker $2 -Iprotos/src --csharp_out=src/Google.Protobuf.Test \ 16*1b3f573fSAndroid Build Coastguard Worker --csharp_opt=base_namespace=Google.Protobuf \ 17*1b3f573fSAndroid Build Coastguard Worker protos/src/google/protobuf/unittest_proto3.proto \ 18*1b3f573fSAndroid Build Coastguard Worker protos/src/google/protobuf/map_unittest_proto3.proto 19*1b3f573fSAndroid Build Coastguard Worker 20*1b3f573fSAndroid Build Coastguard Worker # Build and test. 21*1b3f573fSAndroid Build Coastguard Worker dotnet restore src/Google.Protobuf/Google.Protobuf.csproj 22*1b3f573fSAndroid Build Coastguard Worker dotnet restore src/Google.Protobuf.Test/Google.Protobuf.Test.csproj 23*1b3f573fSAndroid Build Coastguard Worker dotnet build -c Release src/Google.Protobuf/Google.Protobuf.csproj 24*1b3f573fSAndroid Build Coastguard Worker dotnet build -c Release src/Google.Protobuf.Test/Google.Protobuf.Test.csproj 25*1b3f573fSAndroid Build Coastguard Worker dotnet run -c Release -f netcoreapp3.1 -p src/Google.Protobuf.Test/Google.Protobuf.Test.csproj 26*1b3f573fSAndroid Build Coastguard Worker} 27*1b3f573fSAndroid Build Coastguard Worker 28*1b3f573fSAndroid Build Coastguard Workerset -ex 29*1b3f573fSAndroid Build Coastguard Worker 30*1b3f573fSAndroid Build Coastguard Worker# Change to the script's directory. 31*1b3f573fSAndroid Build Coastguard Workercd $(dirname $0) 32*1b3f573fSAndroid Build Coastguard Worker 33*1b3f573fSAndroid Build Coastguard Worker# Version of the tests (i.e., the version of protobuf from where we extracted 34*1b3f573fSAndroid Build Coastguard Worker# these tests). 35*1b3f573fSAndroid Build Coastguard WorkerTEST_VERSION=3.0.0 36*1b3f573fSAndroid Build Coastguard Worker 37*1b3f573fSAndroid Build Coastguard Worker# The old version of protobuf that we are testing compatibility against. This 38*1b3f573fSAndroid Build Coastguard Worker# is usually the same as TEST_VERSION (i.e., we use the tests extracted from 39*1b3f573fSAndroid Build Coastguard Worker# that version to test compatibility of the newest runtime against it), but it 40*1b3f573fSAndroid Build Coastguard Worker# is also possible to use this same test set to test the compatibility of the 41*1b3f573fSAndroid Build Coastguard Worker# latest version against other versions. 42*1b3f573fSAndroid Build Coastguard WorkerOLD_VERSION=$1 43*1b3f573fSAndroid Build Coastguard WorkerOLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe 44*1b3f573fSAndroid Build Coastguard Worker 45*1b3f573fSAndroid Build Coastguard Workerecho "Running compatibility tests with $OLD_VERSION" 46*1b3f573fSAndroid Build Coastguard Worker 47*1b3f573fSAndroid Build Coastguard Worker# Check protoc 48*1b3f573fSAndroid Build Coastguard Worker[ -f ../../../src/protoc ] || { 49*1b3f573fSAndroid Build Coastguard Worker echo "[ERROR]: Please build protoc first." 50*1b3f573fSAndroid Build Coastguard Worker exit 1 51*1b3f573fSAndroid Build Coastguard Worker} 52*1b3f573fSAndroid Build Coastguard Worker 53*1b3f573fSAndroid Build Coastguard Worker# Download old version protoc compiler (for linux). 54*1b3f573fSAndroid Build Coastguard Workerwget $OLD_VERSION_PROTOC -O old_protoc 55*1b3f573fSAndroid Build Coastguard Workerchmod +x old_protoc 56*1b3f573fSAndroid Build Coastguard Worker 57*1b3f573fSAndroid Build Coastguard Worker# Test source compatibility. In these tests we recompile everything against 58*1b3f573fSAndroid Build Coastguard Worker# the new runtime (including old version generated code). 59*1b3f573fSAndroid Build Coastguard Worker# Copy the new runtime and keys. 60*1b3f573fSAndroid Build Coastguard Workercp ../../src/Google.Protobuf src/Google.Protobuf -r 61*1b3f573fSAndroid Build Coastguard Workercp ../../keys . -r 62*1b3f573fSAndroid Build Coastguard Worker 63*1b3f573fSAndroid Build Coastguard Worker# Test A.1: 64*1b3f573fSAndroid Build Coastguard Worker# proto set 1: use old version 65*1b3f573fSAndroid Build Coastguard Worker# proto set 2 which may import protos in set 1: use old version 66*1b3f573fSAndroid Build Coastguard Workerrun_test "./old_protoc" "./old_protoc" 67*1b3f573fSAndroid Build Coastguard Worker 68*1b3f573fSAndroid Build Coastguard Worker# Test A.2: 69*1b3f573fSAndroid Build Coastguard Worker# proto set 1: use new version 70*1b3f573fSAndroid Build Coastguard Worker# proto set 2 which may import protos in set 1: use old version 71*1b3f573fSAndroid Build Coastguard Workerrun_test "../../../src/protoc" "./old_protoc" 72*1b3f573fSAndroid Build Coastguard Worker 73*1b3f573fSAndroid Build Coastguard Worker# Test A.3: 74*1b3f573fSAndroid Build Coastguard Worker# proto set 1: use old version 75*1b3f573fSAndroid Build Coastguard Worker# proto set 2 which may import protos in set 1: use new version 76*1b3f573fSAndroid Build Coastguard Workerrun_test "./old_protoc" "../../../src/protoc" 77*1b3f573fSAndroid Build Coastguard Worker 78*1b3f573fSAndroid Build Coastguard Workerrm old_protoc 79*1b3f573fSAndroid Build Coastguard Workerrm keys -r 80*1b3f573fSAndroid Build Coastguard Workerrm src/Google.Protobuf -r 81