test.sh 3.4 KB

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