Add support for testing more than one PHP extension at once

pull/66/head
Michele Locati 2019-12-18 16:45:20 +01:00
parent 9d30d8806f
commit 2de4f3462d
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
3 changed files with 99 additions and 44 deletions

View File

@ -172,6 +172,16 @@ Improve the GD and ZIP extensions
Test: gd, zip Test: gd, zip
``` ```
Tests only check the installation of a single PHP extension at a time.
If you want to test installing more PHP extensions at the same time, use a commit message like this:
```
Improve the GD and ZIP extensions
Test: gd+zip
```
If your pull request contains multiple commits, we'll check the "Test:" message of every commit. If your pull request contains multiple commits, we'll check the "Test:" message of every commit.
If you want to stop parsing next commits, add `-STOP-` in the "Test:" line, for example: If you want to stop parsing next commits, add `-STOP-` in the "Test:" line, for example:

View File

@ -1,14 +1,17 @@
<?php <?php
$extension = isset($argv[1]) ? trim($argv[1]) : ''; $rc = 0;
$rc = 1; $numTestedExtensions = 0;
if ($extension === '') {
fprintf(STDERR, "Missing module handle.\n");
} else {
$nameMap = array( $nameMap = array(
'opcache' => 'Zend OPcache', 'opcache' => 'Zend OPcache',
); );
for ($index = 1, $count = isset($argv) ? count($argv) : 0; $index < $count; $index++) {
$numTestedExtensions++;
$rcThis = 1;
$extension = $argv[$index];
if ($extension === '') {
fprintf(STDERR, "Missing extension handle.\n");
} else {
$extensionLowerCase = strtolower($extension); $extensionLowerCase = strtolower($extension);
if (isset($nameMap[$extensionLowerCase])) { if (isset($nameMap[$extensionLowerCase])) {
$extension = $nameMap[$extensionLowerCase]; $extension = $nameMap[$extensionLowerCase];
@ -17,8 +20,16 @@ if ($extension === '') {
fprintf(STDERR, sprintf("Extension not loaded: %s\n", $extension)); fprintf(STDERR, sprintf("Extension not loaded: %s\n", $extension));
} else { } else {
fprintf(STDOUT, sprintf("Extension correctly loaded: %s\n", $extension)); fprintf(STDOUT, sprintf("Extension correctly loaded: %s\n", $extension));
$rc = 0; $rcThis = 0;
} }
} }
if ($rcThis !== 0) {
$rc = $rcThis;
}
}
if ($numTestedExtensions === 0) {
fprintf(STDERR, "No extension handles specified.\n");
$rc = 1;
}
exit($rc); exit($rc);

View File

@ -22,7 +22,7 @@ ALREADY_TESTED_EXTENSIONS=''
# Get the docker image ID for a PHP extension and a PHP version # Get the docker image ID for a PHP extension and a PHP version
# #
# Arguments: # Arguments:
# $1: the extension name # $1: space-separated list with the names of the PHP extensions
# $2: the PHP version # $2: the PHP version
# #
# Outputs: # Outputs:
@ -36,9 +36,12 @@ getDockerImageName () {
getDockerImageName_suffix='-cli' getDockerImageName_suffix='-cli'
getDockerImageName_reqs="${TRAVIS_BUILD_DIR}/data/special-requirements" getDockerImageName_reqs="${TRAVIS_BUILD_DIR}/data/special-requirements"
if test -f "${getDockerImageName_reqs}"; then if test -f "${getDockerImageName_reqs}"; then
if test -n "$(cat "${getDockerImageName_reqs}" | grep -E "^${1}[ \t]+zts[ \t]*$")"; then IFS=' '
for getDockerImageName_testExtension in $1; do
if test -n "$(cat "${getDockerImageName_reqs}" | grep -E "^${getDockerImageName_testExtension}[ \t]+zts[ \t]*$")"; then
getDockerImageName_suffix="-zts" getDockerImageName_suffix="-zts"
fi fi
done
fi fi
case "${DOCKER_DISTRO:-}" in case "${DOCKER_DISTRO:-}" in
alpine) alpine)
@ -55,7 +58,7 @@ getDockerImageName () {
# Test an extension # Test an extension
# #
# Arguments: # Arguments:
# $1: the extension name # $1: space-separated list with the names of the PHP extensions to be tested
# $2: the PHP version # $2: the PHP version
# #
# Return: # Return:
@ -70,7 +73,7 @@ testExtension () {
testExtension_Image="$(getDockerImageName "${1}" "${2}")" testExtension_Image="$(getDockerImageName "${1}" "${2}")"
printf ' - Docker image: %s\n' "${testExtension_Image}" printf ' - Docker image: %s\n' "${testExtension_Image}"
testExtension_out=`mktemp` testExtension_out=`mktemp`
if $(docker run --rm --volume "${TRAVIS_BUILD_DIR}:/app" --workdir /app "${testExtension_Image}" sh -c "./install-php-extensions '${1}' && php ./scripts/check-installed-extension.php '${1}'" >"${testExtension_out}" 2>&1); then if $(docker run --rm --volume "${TRAVIS_BUILD_DIR}:/app" --workdir /app "${testExtension_Image}" sh -c "./install-php-extensions ${1} && php ./scripts/check-installed-extension.php ${1}" >"${testExtension_out}" 2>&1); then
rm -rf "${testExtension_out}" rm -rf "${testExtension_out}"
printf ' - Passed\n' printf ' - Passed\n'
return 0 return 0
@ -120,36 +123,66 @@ testNewExtensionLine () {
# Get the list of all supported PHP versions # Get the list of all supported PHP versions
# #
# Arguments: # Arguments:
# $1: the extension name # $1: space-separated list with the names of the PHP extensions to be tested
# #
# Outputs: # Outputs:
# the space-separated list of supported PHP versions # the space-separated list of supported PHP versions
getAllPHPVersionsFor () { getAllPHPVersionsForExtensions () {
getAllPHPVersionsFor_result='' getAllPHPVersionsForExtensions_result=''
while IFS= read -r getAllPHPVersionsFor_line; do
getAllPHPVersionsFor_ok=
IFS=' ' IFS=' '
for getAllPHPVersionsFor_chunk in $getAllPHPVersionsFor_line; do for getAllPHPVersionsForExtensions_extension in $1; do
if test -z "$getAllPHPVersionsFor_ok"; then getAllPHPVersionsForExtensions_this="$(getAllPHPVersionsForExtension "$getAllPHPVersionsForExtensions_extension")"
if test "$getAllPHPVersionsFor_chunk" = "$1"; then if test -z "$getAllPHPVersionsForExtensions_this"; then
getAllPHPVersionsFor_ok=y return
fi
if test -z "$getAllPHPVersionsForExtensions_result"; then
getAllPHPVersionsForExtensions_result="$getAllPHPVersionsForExtensions_this"
else else
getAllPHPVersionsFor_ok=n getAllPHPVersionsForExtensions_tmp=''
for getAllPHPVersionsForExtensions_php1 in $getAllPHPVersionsForExtensions_this; do
if stringInList "$getAllPHPVersionsForExtensions_php1" "$getAllPHPVersionsForExtensions_result"; then
getAllPHPVersionsForExtensions_tmp="$getAllPHPVersionsForExtensions_tmp $getAllPHPVersionsForExtensions_php1"
fi
done
getAllPHPVersionsForExtensions_result="${getAllPHPVersionsForExtensions_tmp# }"
fi
done
printf '%s' "$getAllPHPVersionsForExtensions_result"
}
# Get the list of all supported PHP versions
#
# Arguments:
# $1: the names of a PHP extension to be tested
#
# Outputs:
# the space-separated list of supported PHP versions
getAllPHPVersionsForExtension () {
getAllPHPVersionsForExtension_result=''
while IFS= read -r getAllPHPVersionsForExtension_line; do
getAllPHPVersionsForExtension_ok=
IFS=' '
for getAllPHPVersionsForExtension_chunk in $getAllPHPVersionsForExtension_line; do
if test -z "$getAllPHPVersionsForExtension_ok"; then
if test "$getAllPHPVersionsForExtension_chunk" = "$1"; then
getAllPHPVersionsForExtension_ok=y
else
getAllPHPVersionsForExtension_ok=n
fi fi
else else
if test $getAllPHPVersionsFor_ok = 'y'; then if test $getAllPHPVersionsForExtension_ok = 'y'; then
if test -z "$getAllPHPVersionsFor_result"; then if test -z "$getAllPHPVersionsForExtension_result"; then
getAllPHPVersionsFor_result="$getAllPHPVersionsFor_chunk" getAllPHPVersionsForExtension_result="$getAllPHPVersionsForExtension_chunk"
else else
if ! stringInList "$getAllPHPVersionsFor_chunk" "$getAllPHPVersionsFor_result"; then if ! stringInList "$getAllPHPVersionsForExtension_chunk" "$getAllPHPVersionsForExtension_result"; then
getAllPHPVersionsFor_result="$getAllPHPVersionsFor_result $getAllPHPVersionsFor_chunk" getAllPHPVersionsForExtension_result="$getAllPHPVersionsForExtension_result $getAllPHPVersionsForExtension_chunk"
fi fi
fi fi
fi fi
fi fi
done done
done < "$TRAVIS_BUILD_DIR/data/supported-extensions" done < "$TRAVIS_BUILD_DIR/data/supported-extensions"
printf '%s' "${getAllPHPVersionsFor_result}" printf '%s' "${getAllPHPVersionsForExtension_result}"
} }
@ -207,8 +240,9 @@ testExtensionsFromMessage () {
for TEST_EXTENSION in $TEST_EXTENSIONS; do for TEST_EXTENSION in $TEST_EXTENSIONS; do
if ! stringInList "$TEST_EXTENSION" "$ALREADY_TESTED_EXTENSIONS"; then if ! stringInList "$TEST_EXTENSION" "$ALREADY_TESTED_EXTENSIONS"; then
ALREADY_TESTED_EXTENSIONS="$ALREADY_TESTED_EXTENSIONS $TEST_EXTENSION" ALREADY_TESTED_EXTENSIONS="$ALREADY_TESTED_EXTENSIONS $TEST_EXTENSION"
printf '### TESTING EXTENSION %s ###\n' "$TEST_EXTENSION" TEST_EXTENSION="$(printf '%s' "$TEST_EXTENSION" | sed 's/\+/ /g')"
for TEST_PHPVERSION in $(getAllPHPVersionsFor $TEST_EXTENSION); do printf '### TESTING EXTENSION(S) %s ###\n' "$TEST_EXTENSION"
for TEST_PHPVERSION in $(getAllPHPVersionsForExtensions "$TEST_EXTENSION"); do
if ! testExtension "$TEST_EXTENSION" "$TEST_PHPVERSION"; then if ! testExtension "$TEST_EXTENSION" "$TEST_PHPVERSION"; then
testExtensionsFromMessage_result=1 testExtensionsFromMessage_result=1
fi fi