test.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. set -ex
  3. # Change to the script's directory.
  4. cd $(dirname $0)
  5. # Version of the tests (i.e., the version of protobuf from where we extracted
  6. # these tests).
  7. TEST_VERSION=2.5.0
  8. # The old version of protobuf that we are testing compatibility against. This
  9. # is usually the same as TEST_VERSION (i.e., we use the tests extracted from
  10. # that version to test compatibility of the newest runtime against it), but it
  11. # is also possible to use this same test set to test the compatibiilty of the
  12. # latest version against other versions.
  13. case "$1" in
  14. ""|2.5.0)
  15. OLD_VERSION=2.5.0
  16. OLD_VERSION_PROTOC=https://github.com/xfxyjwf/protobuf-compiler-release/raw/master/v2.5.0/linux/protoc
  17. ;;
  18. 2.6.1)
  19. OLD_VERSION=2.6.1
  20. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_64.exe
  21. ;;
  22. 3.0.0-beta-1)
  23. OLD_VERSION=3.0.0-beta-1
  24. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_64.exe
  25. ;;
  26. 3.0.0-beta-2)
  27. OLD_VERSION=3.0.0-beta-2
  28. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_64.exe
  29. ;;
  30. 3.0.0-beta-3)
  31. OLD_VERSION=3.0.0-beta-3
  32. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_64.exe
  33. ;;
  34. 3.0.0-beta-4)
  35. OLD_VERSION=3.0.0-beta-4
  36. OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_64.exe
  37. ;;
  38. *)
  39. echo "[ERROR]: Unknown version number: $1"
  40. exit 1
  41. ;;
  42. esac
  43. # Extract the latest protobuf version number.
  44. VERSION_NUMBER=`grep "^__version__ = '.*'" ../../google/protobuf/__init__.py | sed "s|__version__ = '\(.*\)'|\1|"`
  45. echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
  46. # Check protoc
  47. [ -f ../../../src/protoc ] || {
  48. echo "[ERROR]: Please build protoc first."
  49. exit 1
  50. }
  51. # Test source compatibility. In these tests we recompile everything against
  52. # the new runtime (including old version generated code).
  53. rm google -f -r
  54. mkdir -p google/protobuf/internal
  55. # Build and copy the new runtime
  56. cd ../../
  57. python setup.py build
  58. cp google/protobuf/*.py compatibility_tests/v2.5.0/google/protobuf/
  59. cp google/protobuf/internal/*.py compatibility_tests/v2.5.0/google/protobuf/internal/
  60. cd compatibility_tests/v2.5.0
  61. cp tests/google/protobuf/internal/test_util.py google/protobuf/internal/
  62. cp google/protobuf/__init__.py google/
  63. # Download old version protoc compiler (for linux)
  64. wget $OLD_VERSION_PROTOC -O old_protoc
  65. chmod +x old_protoc
  66. # Test A.1:
  67. # proto set 1: use old version
  68. # proto set 2 which may import protos in set 1: use old version
  69. cp old_protoc protoc_1
  70. cp old_protoc protoc_2
  71. python setup.py build
  72. python setup.py test
  73. # Test A.2:
  74. # proto set 1: use new version
  75. # proto set 2 which may import protos in set 1: use old version
  76. cp ../../../src/protoc protoc_1
  77. cp old_protoc protoc_2
  78. python setup.py build
  79. python setup.py test
  80. # Test A.3:
  81. # proto set 1: use old version
  82. # proto set 2 which may import protos in set 1: use new version
  83. cp old_protoc protoc_1
  84. cp ../../../src/protoc protoc_2
  85. python setup.py build
  86. python setup.py test
  87. rm google -r -f
  88. rm build -r -f
  89. rm protoc_1
  90. rm protoc_2
  91. rm old_protoc