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