compatibility_test.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. function generate_proto() {
  3. PROTOC1=$1
  4. PROTOC2=$2
  5. rm -rf generated
  6. mkdir generated
  7. $PROTOC1 --php_out=generated proto/test_include.proto
  8. $PROTOC2 --php_out=generated \
  9. -I../../src -I. \
  10. proto/empty/echo.proto \
  11. proto/test.proto \
  12. proto/test_no_namespace.proto \
  13. proto/test_prefix.proto \
  14. proto/test_php_namespace.proto \
  15. proto/test_empty_php_namespace.proto \
  16. proto/test_reserved_enum_lower.proto \
  17. proto/test_reserved_enum_upper.proto \
  18. proto/test_reserved_enum_value_lower.proto \
  19. proto/test_reserved_enum_value_upper.proto \
  20. proto/test_reserved_message_lower.proto \
  21. proto/test_reserved_message_upper.proto \
  22. proto/test_service.proto \
  23. proto/test_service_namespace.proto \
  24. proto/test_wrapper_type_setters.proto \
  25. proto/test_descriptors.proto
  26. pushd ../../src
  27. $PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto
  28. popd
  29. }
  30. # Remove tests to expect error. These were added to API tests by mistake.
  31. function remove_error_test() {
  32. local TEMPFILE=`tempfile`
  33. cat $1 | \
  34. awk -v file=`basename $1` -v dir=`basename $(dirname $1)` '
  35. BEGIN {
  36. show = 1
  37. }
  38. /@expectedException PHPUnit_Framework_Error/ { show = 0; next; }
  39. / *\*\// { print; next; }
  40. / *}/ {
  41. if (!show) {
  42. show = 1;
  43. next;
  44. }
  45. }
  46. show { print }
  47. ' > $TEMPFILE
  48. cp $TEMPFILE $1
  49. }
  50. set -ex
  51. # Change to the script's directory.
  52. cd $(dirname $0)
  53. OLD_VERSION=$1
  54. OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe
  55. # Extract the latest protobuf version number.
  56. VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"`
  57. echo "Running compatibility tests between current $VERSION_NUMBER and released $OLD_VERSION"
  58. # Check protoc
  59. [ -f ../../src/protoc ] || {
  60. echo "[ERROR]: Please build protoc first."
  61. exit 1
  62. }
  63. # Download old test.
  64. rm -rf protobuf
  65. git clone https://github.com/protocolbuffers/protobuf.git
  66. pushd protobuf
  67. git checkout v$OLD_VERSION
  68. popd
  69. # Build and copy the new runtime
  70. pushd ../ext/google/protobuf
  71. make clean || true
  72. phpize && ./configure && make
  73. popd
  74. rm -rf protobuf/php/ext
  75. rm -rf protobuf/php/src
  76. cp -r ../ext protobuf/php/ext/
  77. cp -r ../src protobuf/php/src/
  78. # Download old version protoc compiler (for linux)
  79. wget $OLD_VERSION_PROTOC -O old_protoc
  80. chmod +x old_protoc
  81. NEW_PROTOC=`pwd`/../../src/protoc
  82. OLD_PROTOC=`pwd`/old_protoc
  83. cd protobuf/php
  84. composer install
  85. # Remove implementation detail tests.
  86. # TODO(teboring): Temporarily disable encode_decode_test.php. In 3.13.0-rc1,
  87. # repeated primitive field encoding is changed to packed, which is a bug fix.
  88. # However, this fails the compatibility test which hard coded old encoding.
  89. # Will re-enable the test after making a release. After the version bump, the
  90. # compatibility test will use the updated test code.
  91. tests=( array_test.php generated_class_test.php map_field_test.php well_known_test.php )
  92. sed -i.bak '/php_implementation_test.php/d' phpunit.xml
  93. sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml
  94. sed -i.bak '/encode_decode_test.php/d' phpunit.xml
  95. sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh
  96. sed -i.bak 's/generated_service_test.php//g' tests/test.sh
  97. sed -i.bak 's/encode_decode_test.php//g' tests/test.sh
  98. sed -i.bak '/memory_leak_test.php/d' tests/test.sh
  99. sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php
  100. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php
  101. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php
  102. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php
  103. for t in "${tests[@]}"
  104. do
  105. remove_error_test tests/$t
  106. done
  107. cd tests
  108. # Test A.1:
  109. # proto set 1: use old version
  110. # proto set 2 which may import protos in set 1: use old version
  111. generate_proto $OLD_PROTOC $OLD_PROTOC
  112. ./test.sh
  113. pushd ..
  114. ./vendor/bin/phpunit
  115. popd
  116. # Test A.2:
  117. # proto set 1: use new version
  118. # proto set 2 which may import protos in set 1: use old version
  119. generate_proto $NEW_PROTOC $OLD_PROTOC
  120. ./test.sh
  121. pushd ..
  122. ./vendor/bin/phpunit
  123. popd
  124. # Test A.3:
  125. # proto set 1: use old version
  126. # proto set 2 which may import protos in set 1: use new version
  127. generate_proto $OLD_PROTOC $NEW_PROTOC
  128. ./test.sh
  129. pushd ..
  130. ./vendor/bin/phpunit
  131. popd