compatibility_test.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php well_known_test.php )
  87. sed -i.bak '/php_implementation_test.php/d' phpunit.xml
  88. sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml
  89. sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh
  90. sed -i.bak 's/generated_service_test.php//g' tests/test.sh
  91. sed -i.bak '/memory_leak_test.php/d' tests/test.sh
  92. sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php
  93. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php
  94. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php
  95. sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php
  96. for t in "${tests[@]}"
  97. do
  98. remove_error_test tests/$t
  99. done
  100. cd tests
  101. # Test A.1:
  102. # proto set 1: use old version
  103. # proto set 2 which may import protos in set 1: use old version
  104. generate_proto $OLD_PROTOC $OLD_PROTOC
  105. ./test.sh
  106. pushd ..
  107. ./vendor/bin/phpunit
  108. popd
  109. # Test A.2:
  110. # proto set 1: use new version
  111. # proto set 2 which may import protos in set 1: use old version
  112. generate_proto $NEW_PROTOC $OLD_PROTOC
  113. ./test.sh
  114. pushd ..
  115. ./vendor/bin/phpunit
  116. popd
  117. # Test A.3:
  118. # proto set 1: use old version
  119. # proto set 2 which may import protos in set 1: use new version
  120. generate_proto $OLD_PROTOC $NEW_PROTOC
  121. ./test.sh
  122. pushd ..
  123. ./vendor/bin/phpunit
  124. popd