compatibility_test.sh 4.69 KB
Newer Older
1 2
#!/bin/bash

3
function use_php() {
4
  VERSION=$1
5 6 7 8 9 10 11 12

  OLD_PATH=$PATH
  OLD_CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH
  OLD_C_INCLUDE_PATH=$C_INCLUDE_PATH

  export PATH=/usr/local/php-${VERSION}/bin:$OLD_PATH
  export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$OLD_CPLUS_INCLUDE_PATH
  export C_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$OLD_C_INCLUDE_PATH
13 14
}

15
function generate_proto() {
16 17 18 19 20 21 22
  PROTOC1=$1
  PROTOC2=$2

  rm -rf generated
  mkdir generated

  $PROTOC1 --php_out=generated proto/test_include.proto
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  $PROTOC2 --php_out=generated                 \
    proto/test.proto                           \
    proto/test_no_namespace.proto              \
    proto/test_prefix.proto                    \
    proto/test_php_namespace.proto             \
    proto/test_empty_php_namespace.proto       \
    proto/test_reserved_enum_lower.proto       \
    proto/test_reserved_enum_upper.proto       \
    proto/test_reserved_enum_value_lower.proto \
    proto/test_reserved_enum_value_upper.proto \
    proto/test_reserved_message_lower.proto    \
    proto/test_reserved_message_upper.proto    \
    proto/test_service.proto                   \
    proto/test_service_namespace.proto         \
    proto/test_descriptors.proto

39 40 41 42 43
  pushd ../../src
  $PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto
  popd
}

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
# Remove tests to expect error. These were added to API tests by mistake.
function remove_error_test() {
  local TEMPFILE=`tempfile`
  cat $1 | \
  awk -v file=`basename $1` -v dir=`basename $(dirname $1)` '
    BEGIN {
      show = 1
    }
    /@expectedException PHPUnit_Framework_Error/ { show = 0; next; }
    / *\*\//                                     { print; next; }
    / *}/ {
      if (!show) {
        show = 1;
        next;
      }
    }
    show { print }
  ' > $TEMPFILE
  cp $TEMPFILE $1
}

65 66 67 68 69 70 71
set -ex

# Change to the script's directory.
cd $(dirname $0)

# The old version of protobuf that we are testing compatibility against.
case "$1" in
72 73 74
  ""|3.5.0)
    OLD_VERSION=3.5.0
    OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    ;;
  *)
    echo "[ERROR]: Unknown version number: $1"
    exit 1
    ;;
esac

# Extract the latest protobuf version number.
VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"`

echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"

# Check protoc
[ -f ../../src/protoc ] || {
  echo "[ERROR]: Please build protoc first."
  exit 1
}

# Download old test.
rm -rf protobuf
Feng Xiao's avatar
Feng Xiao committed
95
git clone https://github.com/protocolbuffers/protobuf.git
96 97 98 99 100
pushd protobuf
git checkout v$OLD_VERSION
popd

# Build and copy the new runtime
101
use_php 7.1
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
pushd ../ext/google/protobuf
make clean || true
phpize && ./configure && make
popd

rm -rf protobuf/php/ext
rm -rf protobuf/php/src
cp -r ../ext protobuf/php/ext/
cp -r ../src protobuf/php/src/

# Download old version protoc compiler (for linux)
wget $OLD_VERSION_PROTOC -O old_protoc
chmod +x old_protoc

NEW_PROTOC=`pwd`/../../src/protoc
OLD_PROTOC=`pwd`/old_protoc
cd protobuf/php
119
composer install
120 121 122 123

# Remove implementation detail tests.
tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php well_known_test.php )
sed -i.bak '/php_implementation_test.php/d' phpunit.xml
124
sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml
Bo Yang's avatar
Bo Yang committed
125
sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh
Paul Yang's avatar
Paul Yang committed
126
sed -i.bak 's/generated_service_test.php//g' tests/test.sh
Bo Yang's avatar
Bo Yang committed
127
sed -i.bak '/memory_leak_test.php/d' tests/test.sh
128
sed -i.bak '/^    public function testTimestamp()$/,/^    }$/d' tests/well_known_test.php
Paul Yang's avatar
Paul Yang committed
129 130 131
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php
132 133 134 135 136
for t in "${tests[@]}"
do
  remove_error_test tests/$t
done

137 138 139 140 141 142 143 144
cd tests

# Test A.1:
#   proto set 1: use old version
#   proto set 2 which may import protos in set 1: use old version
generate_proto $OLD_PROTOC $OLD_PROTOC
./test.sh
pushd ..
145
./vendor/bin/phpunit
146 147 148 149 150 151 152 153
popd

# Test A.2:
#   proto set 1: use new version
#   proto set 2 which may import protos in set 1: use old version
generate_proto $NEW_PROTOC $OLD_PROTOC
./test.sh
pushd ..
154
./vendor/bin/phpunit
155 156 157 158 159 160 161 162
popd

# Test A.3:
#   proto set 1: use old version
#   proto set 2 which may import protos in set 1: use new version
generate_proto $OLD_PROTOC $NEW_PROTOC
./test.sh
pushd ..
163
./vendor/bin/phpunit
164
popd