diff --git a/tests/mods/01-test-modules.sh b/tests/mods/01-test-modules.sh new file mode 100755 index 0000000..e52138b --- /dev/null +++ b/tests/mods/01-test-modules.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + +IMAGE="${1}" +VERSION="${2}" +FLAVOUR="${3}" + + +# shellcheck disable=SC1090 +. "${CWD}/../.lib.sh" + + +# ------------------------------------------------------------------------------------------------- +# Testing +# ------------------------------------------------------------------------------------------------- + +ERROR=0 +for dir in $( ls -1 "${CWD}/modules/" ); do + if ! "${CWD}/modules.sh" "${IMAGE}" "${VERSION}" "${FLAVOUR}" "${dir}"; then + ERROR="$(( ERROR + 1 ))" + fi +done + +exit "${ERROR}" diff --git a/tests/mods/modules.sh b/tests/mods/modules.sh new file mode 100755 index 0000000..b293576 --- /dev/null +++ b/tests/mods/modules.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + +CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" + +if [ "${#}" != "4" ]; then + >&2 echo "Error, requires 4 arguments: " + exit 1 +fi + +IMAGE="${1}" +VERSION="${2}" +FLAVOUR="${3}" +MODULE="${4}" + +# shellcheck disable=SC1090 +. "${CWD}/../.lib.sh" + + +SKIP_GD=("") + + +echo +echo "# ------------------------------------------------------------" +echo "# Testing: ${MODULE}" +echo "# ------------------------------------------------------------" +echo + + +# ------------------------------------------------------------------------------------------------- +# Check skipping +# ------------------------------------------------------------------------------------------------- + +if [[ ${SKIP_GD[*]} =~ ${VERSION} ]]; then + echo "Skipping '${MODULE}' checks for PHP ${VERSION}" + exit 0 +fi + + +# ------------------------------------------------------------------------------------------------- +# Testing +# ------------------------------------------------------------------------------------------------- + +WORKDIR="/tmp/${MODULE}" +docker run \ + --rm \ + -e DEBUG_ENTRYPOINT=0 \ + -e NEW_UID="$(id -u)" \ + -e NEW_GID="$(id -g)" \ + -v "${CWD}/modules/${MODULE}:${WORKDIR}" \ + --entrypoint=sh \ + --workdir="${WORKDIR}" \ + "${IMAGE}:${VERSION}-${FLAVOUR}" \ + -c 'find . -name "*.php" -type f -print0 | xargs -0 -n1 sh -c " + set -e + set -u + if [ -f \"\${1:-}\" ]; then + fail=0 + printf \"[TEST] %s\" \"\${1}\" + + if script -e -c \"php \${1}\" /dev/null 2>&1 | grep -Ei \"core|segmentation|fatal|except|err|warn|notice\" 2>&1 >/dev/null; then + fail=1 + fi + if ! php \"\${1}\" 2>&1 | grep -E \"^OK$\" 2>&1 >/dev/null; then + fail=1 + fi + + if [ \"\${fail}\" != \"0\" ]; then + printf \"\\r[FAIL] %s\\n\" \"\${1}\" + php \"\${1}\" || true + exit 1 + else + printf \"\\r[OK] %s\\n\" \"\${1}\" + fi + fi + + " --' diff --git a/tests/mods/modules/bcmath/bcmath.php b/tests/mods/modules/bcmath/bcmath.php new file mode 100644 index 0000000..0e318e6 --- /dev/null +++ b/tests/mods/modules/bcmath/bcmath.php @@ -0,0 +1,26 @@ +newImage($width, $height, new ImagickPixel('transparent')) !== TRUE) { + echo 'FAIL: imagecreatetruecolor()'; + exit(1); +} + +/* New ImagickDraw instance for ellipse draw */ +$draw = new ImagickDraw(); +/* Set purple fill color for ellipse */ +$draw->setFillColor('#777bb4'); +/* Set ellipse dimensions */ +$draw->ellipse($width / 2, $height / 2, $width / 2, $height / 2, 0, 360); +/* Draw ellipse onto the canvas */ +$img->drawImage($draw); + +/* Reset fill color from purple to black for text (note: we are reusing ImagickDraw object) */ +$draw->setFillColor('black'); + +if ($img->setImageFormat('png') !== TRUE) { + echo 'FAIL: imagecreatetruecolor()'; + exit(1); +} + + +echo 'OK';