From 2176805be108e0cd93badb9af148494f7e8e5d9d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 6 Oct 2025 15:23:11 +0200 Subject: [PATCH 01/15] Update install-wp-tests script --- templates/install-wp-tests.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index d2605fe0..63bd1854 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# See https://raw.githubusercontent.com/wp-cli/scaffold-command/master/templates/install-wp-tests.sh + if [ $# -lt 3 ]; then echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" exit 1 @@ -66,15 +68,15 @@ set -ex install_wp() { - if [ -d $WP_CORE_DIR ]; then + if [ -f $WP_CORE_FILE ]; then return; fi + rm -rf $WP_CORE_DIR mkdir -p $WP_CORE_DIR if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then mkdir -p $TMPDIR/wordpress-trunk - rm -rf $TMPDIR/wordpress-trunk/* check_svn_installed svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR @@ -103,8 +105,6 @@ install_wp() { download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR fi - - download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } install_test_suite() { @@ -115,11 +115,11 @@ install_test_suite() { local ioption='-i' fi - # set up testing suite if it doesn't yet exist - if [ ! -d $WP_TESTS_DIR ]; then + # set up testing suite if it doesn't yet exist or only partially exists + if [ ! -f $WP_TESTS_FILE ]; then # set up testing suite + rm -rf $WP_TESTS_DIR mkdir -p $WP_TESTS_DIR - rm -rf $WP_TESTS_DIR/{includes,data} check_svn_installed svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data @@ -130,7 +130,6 @@ install_test_suite() { # remove all forward slashes in the end WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s:__DIR__ . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php @@ -153,7 +152,11 @@ recreate_db() { } create_db() { - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + if [ `which mariadb-admin` ]; then + mariadb-admin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + else + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA + fi } install_db() { From f84721327dc241dccccb087b3ff640aeb69609d4 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 6 Oct 2025 15:40:13 +0200 Subject: [PATCH 02/15] remove svn usage props Gemini CLI --- templates/install-wp-tests.sh | 43 ++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index 63bd1854..062ebdb6 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -30,14 +30,6 @@ download() { fi } -# Check if svn is installed -check_svn_installed() { - if ! command -v svn > /dev/null; then - echo "Error: svn is not installed. Please install svn and try again." - exit 1 - fi -} - if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then WP_BRANCH=${WP_VERSION%\-*} WP_TESTS_TAG="branches/$WP_BRANCH" @@ -76,10 +68,7 @@ install_wp() { mkdir -p $WP_CORE_DIR if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - mkdir -p $TMPDIR/wordpress-trunk - check_svn_installed - svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress - mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR + download https://github.com/WordPress/wordpress-develop/archive/refs/heads/master.tar.gz $WP_CORE_DIR else if [ $WP_VERSION == 'latest' ]; then local ARCHIVE_NAME='latest' @@ -120,13 +109,35 @@ install_test_suite() { # set up testing suite rm -rf $WP_TESTS_DIR mkdir -p $WP_TESTS_DIR - check_svn_installed - svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes - svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data + + if [[ $WP_TESTS_TAG == 'trunk' ]]; then + ref=master + archive_url="https://github.com/WordPress/wordpress-develop/archive/refs/heads/${ref}.tar.gz" + elif [[ $WP_TESTS_TAG == branches/* ]]; then + ref=${WP_TESTS_TAG#branches/} + archive_url="https://github.com/WordPress/wordpress-develop/archive/refs/heads/${ref}.tar.gz" + else + ref=${WP_TESTS_TAG#tags/} + archive_url="https://github.com/WordPress/wordpress-develop/archive/refs/tags/${ref}.tar.gz" + fi + + download ${archive_url} $TMPDIR/wordpress-develop.tar.gz + tar -zxmf $TMPDIR/wordpress-develop.tar.gz -C $TMPDIR + mv $TMPDIR/wordpress-develop-${ref}/tests/phpunit/includes $WP_TESTS_DIR/ + mv $TMPDIR/wordpress-develop-${ref}/tests/phpunit/data $WP_TESTS_DIR/ + rm -rf $TMPDIR/wordpress-develop-${ref} + rm $TMPDIR/wordpress-develop.tar.gz fi if [ ! -f wp-tests-config.php ]; then - download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php + if [[ $WP_TESTS_TAG == 'trunk' ]]; then + ref=master + elif [[ $WP_TESTS_TAG == branches/* ]]; then + ref=${WP_TESTS_TAG#branches/} + else + ref=${WP_TESTS_TAG#tags/} + fi + download https://raw.githubusercontent.com/WordPress/wordpress-develop/${ref}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php # remove all forward slashes in the end WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php From a4e6950de03b92ab49f81d2667324c8802c8f81c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 6 Oct 2025 15:41:39 +0200 Subject: [PATCH 03/15] more mariadb checks --- templates/install-wp-tests.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index 062ebdb6..bc3d74b9 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -153,7 +153,11 @@ recreate_db() { shopt -s nocasematch if [[ $1 =~ ^(y|yes)$ ]] then - mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA + if [ `which mariadb-admin` ]; then + mariadb-admin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA + else + mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA + fi create_db echo "Recreated the database ($DB_NAME)." else @@ -193,7 +197,12 @@ install_db() { fi # create database - if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ] + if [ `which mariadb` ]; then + local DB_CLIENT='mariadb' + else + local DB_CLIENT='mysql' + fi + if [ $($DB_CLIENT --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ] then echo "Reinstalling will delete the existing test database ($DB_NAME)" read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB From 8746658ada4070880915bdef67e2a31b0193e831 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 6 Oct 2025 15:44:55 +0200 Subject: [PATCH 04/15] Add update check --- templates/install-wp-tests.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index bc3d74b9..3c46dc4c 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -30,6 +30,40 @@ download() { fi } +check_for_updates() { + local remote_url="https://raw.githubusercontent.com/wp-cli/scaffold-command/main/templates/install-wp-tests.sh" + local tmp_script="$TMPDIR/install-wp-tests.sh.latest" + + download "$remote_url" "$tmp_script" + + if [ ! -f "$tmp_script" ]; then + echo "Warning: Could not download the latest version of the script for update check." + return + fi + + local local_hash="" + local remote_hash="" + + if command -v shasum > /dev/null; then + local_hash=$(shasum -a 256 "$0" | awk '{print $1}') + remote_hash=$(shasum -a 256 "$tmp_script" | awk '{print $1}') + elif command -v sha256sum > /dev/null; then + local_hash=$(sha256sum "$0" | awk '{print $1}') + remote_hash=$(sha256sum "$tmp_script" | awk '{print $1}') + else + echo "Warning: Could not find shasum or sha256sum to check for script updates." + rm "$tmp_script" + return + fi + + rm "$tmp_script" + + if [ "$local_hash" != "$remote_hash" ]; then + echo "Warning: A newer version of this script is available at $remote_url" + fi +} +check_for_updates + if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then WP_BRANCH=${WP_VERSION%\-*} WP_TESTS_TAG="branches/$WP_BRANCH" From 4f19c42179b9f4074fee88f7fd3bf3394dba3200 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 7 Oct 2025 10:15:40 +0200 Subject: [PATCH 05/15] Add missing vars --- templates/install-wp-tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index 3c46dc4c..d49037f3 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -17,7 +17,9 @@ SKIP_DB_CREATE=${6-false} TMPDIR=${TMPDIR-/tmp} TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} +WP_TESTS_FILE="$WP_TESTS_DIR"/includes/functions.php WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress} +WP_CORE_FILE="$WP_CORE_DIR"/wp-settings.php download() { if [ `which curl` ]; then From a05593f7a4a40bd5d4e7848511c22406ac21051a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 7 Oct 2025 10:32:09 +0200 Subject: [PATCH 06/15] Fix conditional check --- templates/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index d49037f3..a6925842 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -165,7 +165,7 @@ install_test_suite() { rm $TMPDIR/wordpress-develop.tar.gz fi - if [ ! -f wp-tests-config.php ]; then + if [ ! -f "$WP_TESTS_DIR"/wp-tests-config.php ]; then if [[ $WP_TESTS_TAG == 'trunk' ]]; then ref=master elif [[ $WP_TESTS_TAG == branches/* ]]; then From 49792b738977b3661a8b0d513009b18fa078a0fa Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 7 Oct 2025 10:32:13 +0200 Subject: [PATCH 07/15] Follow redirects --- templates/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index a6925842..e1484465 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -23,7 +23,7 @@ WP_CORE_FILE="$WP_CORE_DIR"/wp-settings.php download() { if [ `which curl` ]; then - curl -s "$1" > "$2"; + curl -L -s "$1" > "$2"; elif [ `which wget` ]; then wget -nv -O "$2" "$1" else From 2b5b25ac0421f8ab399b103557b7786df6d40749 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 7 Oct 2025 17:58:28 +0200 Subject: [PATCH 08/15] Update templates/install-wp-tests.sh Co-authored-by: Gary Jones --- templates/install-wp-tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index e1484465..9a5fc637 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -104,7 +104,8 @@ install_wp() { mkdir -p $WP_CORE_DIR if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - download https://github.com/WordPress/wordpress-develop/archive/refs/heads/master.tar.gz $WP_CORE_DIR + download https://github.com/WordPress/wordpress-develop/archive/refs/heads/master.tar.gz $TMPDIR/wordpress.tar.gz + tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR else if [ $WP_VERSION == 'latest' ]; then local ARCHIVE_NAME='latest' From 7859375a8b357a251cd314a63074ed331e2a2925 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 7 Oct 2025 21:40:09 +0200 Subject: [PATCH 09/15] Use built files --- templates/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index 9a5fc637..8f51612b 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -104,7 +104,7 @@ install_wp() { mkdir -p $WP_CORE_DIR if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - download https://github.com/WordPress/wordpress-develop/archive/refs/heads/master.tar.gz $TMPDIR/wordpress.tar.gz + download https://github.com/WordPress/wordpress/archive/refs/heads/master.tar.gz $TMPDIR/wordpress.tar.gz tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR else if [ $WP_VERSION == 'latest' ]; then From 634d3f68bfaea9e17a44a0bcc2341e0f6892e929 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 7 Oct 2025 21:54:49 +0200 Subject: [PATCH 10/15] use correct trunk branch --- templates/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index 8f51612b..8c390082 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -148,7 +148,7 @@ install_test_suite() { mkdir -p $WP_TESTS_DIR if [[ $WP_TESTS_TAG == 'trunk' ]]; then - ref=master + ref=trunk archive_url="https://github.com/WordPress/wordpress-develop/archive/refs/heads/${ref}.tar.gz" elif [[ $WP_TESTS_TAG == branches/* ]]; then ref=${WP_TESTS_TAG#branches/} From 428275b6df0d4d0e70af1b684468dfb58061612b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 8 Oct 2025 10:39:24 +0200 Subject: [PATCH 11/15] Add some coloring and logging Incorporating changes from #346 --- templates/install-wp-tests.sh | 44 ++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index 8c390082..e08d2d60 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -2,6 +2,13 @@ # See https://raw.githubusercontent.com/wp-cli/scaffold-command/master/templates/install-wp-tests.sh +# Set up colors for output +RED=$(tput setaf 1) +GREEN=$(tput setaf 2) +YELLOW=$(tput setaf 3) +CYAN=$(tput setaf 6) +RESET=$(tput sgr0) + if [ $# -lt 3 ]; then echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" exit 1 @@ -27,7 +34,7 @@ download() { elif [ `which wget` ]; then wget -nv -O "$2" "$1" else - echo "Error: Neither curl nor wget is installed." + echo "${RED}Error: Neither curl nor wget is installed.${RESET}" exit 1 fi } @@ -39,7 +46,7 @@ check_for_updates() { download "$remote_url" "$tmp_script" if [ ! -f "$tmp_script" ]; then - echo "Warning: Could not download the latest version of the script for update check." + echo "${YELLOW}Warning: Could not download the latest version of the script for update check.${RESET}" return fi @@ -53,7 +60,7 @@ check_for_updates() { local_hash=$(sha256sum "$0" | awk '{print $1}') remote_hash=$(sha256sum "$tmp_script" | awk '{print $1}') else - echo "Warning: Could not find shasum or sha256sum to check for script updates." + echo "${YELLOW}Warning: Could not find shasum or sha256sum to check for script updates.${RESET}" rm "$tmp_script" return fi @@ -61,7 +68,7 @@ check_for_updates() { rm "$tmp_script" if [ "$local_hash" != "$remote_hash" ]; then - echo "Warning: A newer version of this script is available at $remote_url" + echo "${YELLOW}Warning: A newer version of this script is available at $remote_url${RESET}" fi } check_for_updates @@ -69,7 +76,6 @@ check_for_updates if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then WP_BRANCH=${WP_VERSION%\-*} WP_TESTS_TAG="branches/$WP_BRANCH" - elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then WP_TESTS_TAG="branches/$WP_VERSION" elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then @@ -84,10 +90,9 @@ elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then else # http serves a single offer, whereas https serves multiple. we only want one download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json - grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json - LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') + LATEST_VERSION=$(grep -oE '"version":"[^"]*' /tmp/wp-latest.json | head -n 1 | sed 's/"version":"//') if [[ -z "$LATEST_VERSION" ]]; then - echo "Latest WordPress version could not be found" + echo "${RED}Error: Latest WordPress version could not be found.${RESET}" exit 1 fi WP_TESTS_TAG="tags/$LATEST_VERSION" @@ -97,9 +102,12 @@ set -ex install_wp() { if [ -f $WP_CORE_FILE ]; then + echo "${CYAN}WordPress is already installed.${RESET}" return; fi + echo "${CYAN}Installing WordPress...${RESET}" + rm -rf $WP_CORE_DIR mkdir -p $WP_CORE_DIR @@ -131,6 +139,7 @@ install_wp() { download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR fi + echo "${GREEN}WordPress installed successfully.${RESET}" } install_test_suite() { @@ -143,6 +152,7 @@ install_test_suite() { # set up testing suite if it doesn't yet exist or only partially exists if [ ! -f $WP_TESTS_FILE ]; then + echo "${CYAN}Installing test suite...${RESET}" # set up testing suite rm -rf $WP_TESTS_DIR mkdir -p $WP_TESTS_DIR @@ -164,9 +174,13 @@ install_test_suite() { mv $TMPDIR/wordpress-develop-${ref}/tests/phpunit/data $WP_TESTS_DIR/ rm -rf $TMPDIR/wordpress-develop-${ref} rm $TMPDIR/wordpress-develop.tar.gz + echo "${GREEN}Test suite installed.${RESET}" + else + echo "${CYAN}Test suite is already installed.${RESET}" fi if [ ! -f "$WP_TESTS_DIR"/wp-tests-config.php ]; then + echo "${CYAN}Configuring test suite...${RESET}" if [[ $WP_TESTS_TAG == 'trunk' ]]; then ref=master elif [[ $WP_TESTS_TAG == branches/* ]]; then @@ -182,6 +196,9 @@ install_test_suite() { sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + echo "${GREEN}Test suite configured.${RESET}" + else + echo "${CYAN}Test suite is already configured.${RESET}" fi } @@ -190,15 +207,16 @@ recreate_db() { shopt -s nocasematch if [[ $1 =~ ^(y|yes)$ ]] then + echo "${CYAN}Recreating the database ($DB_NAME)...${RESET}" if [ `which mariadb-admin` ]; then mariadb-admin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA else mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA fi create_db - echo "Recreated the database ($DB_NAME)." + echo "${GREEN}Database ($DB_NAME) recreated.${RESET}" else - echo "Leaving the existing database ($DB_NAME) in place." + echo "${YELLOW}Leaving the existing database ($DB_NAME) in place.${RESET}" fi shopt -u nocasematch } @@ -214,6 +232,7 @@ create_db() { install_db() { if [ ${SKIP_DB_CREATE} = "true" ]; then + echo "${YELLOW}Skipping database creation.${RESET}" return 0 fi @@ -241,14 +260,17 @@ install_db() { fi if [ $($DB_CLIENT --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ] then - echo "Reinstalling will delete the existing test database ($DB_NAME)" + echo "${YELLOW}Reinstalling will delete the existing test database ($DB_NAME)${RESET}" read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB recreate_db $DELETE_EXISTING_DB else + echo "${CYAN}Creating database ($DB_NAME)...${RESET}" create_db + echo "${GREEN}Database ($DB_NAME) created.${RESET}" fi } install_wp install_test_suite install_db +echo "${GREEN}Done.${RESET}" From cd80f8b55a029a8ecad8928488269b2e3479fa76 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 8 Oct 2025 11:07:19 +0200 Subject: [PATCH 12/15] No tput --- templates/install-wp-tests.sh | 57 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index e08d2d60..c22beae5 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -3,14 +3,14 @@ # See https://raw.githubusercontent.com/wp-cli/scaffold-command/master/templates/install-wp-tests.sh # Set up colors for output -RED=$(tput setaf 1) -GREEN=$(tput setaf 2) -YELLOW=$(tput setaf 3) -CYAN=$(tput setaf 6) -RESET=$(tput sgr0) +RED="\033[0;31m" +GREEN="\033[0;32m" +YELLOW="\033[0;33m" +CYAN="\033[0;36m" +RESET="\033[0m" if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + echo -e "${YELLOW}Usage:${RESET} $0 [db-host] [wp-version] [skip-database-creation]" exit 1 fi @@ -34,7 +34,7 @@ download() { elif [ `which wget` ]; then wget -nv -O "$2" "$1" else - echo "${RED}Error: Neither curl nor wget is installed.${RESET}" + echo -e "${RED}Error: Neither curl nor wget is installed.${RESET}" exit 1 fi } @@ -46,7 +46,7 @@ check_for_updates() { download "$remote_url" "$tmp_script" if [ ! -f "$tmp_script" ]; then - echo "${YELLOW}Warning: Could not download the latest version of the script for update check.${RESET}" + echo -e "${YELLOW}Warning: Could not download the latest version of the script for update check.${RESET}" return fi @@ -60,7 +60,7 @@ check_for_updates() { local_hash=$(sha256sum "$0" | awk '{print $1}') remote_hash=$(sha256sum "$tmp_script" | awk '{print $1}') else - echo "${YELLOW}Warning: Could not find shasum or sha256sum to check for script updates.${RESET}" + echo -e "${YELLOW}Warning: Could not find shasum or sha256sum to check for script updates.${RESET}" rm "$tmp_script" return fi @@ -68,7 +68,7 @@ check_for_updates() { rm "$tmp_script" if [ "$local_hash" != "$remote_hash" ]; then - echo "${YELLOW}Warning: A newer version of this script is available at $remote_url${RESET}" + echo -e "${YELLOW}Warning: A newer version of this script is available at $remote_url${RESET}" fi } check_for_updates @@ -92,21 +92,20 @@ else download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json LATEST_VERSION=$(grep -oE '"version":"[^"]*' /tmp/wp-latest.json | head -n 1 | sed 's/"version":"//') if [[ -z "$LATEST_VERSION" ]]; then - echo "${RED}Error: Latest WordPress version could not be found.${RESET}" + echo -e "${RED}Error: Latest WordPress version could not be found.${RESET}" exit 1 fi WP_TESTS_TAG="tags/$LATEST_VERSION" fi -set -ex install_wp() { if [ -f $WP_CORE_FILE ]; then - echo "${CYAN}WordPress is already installed.${RESET}" + echo -e "${CYAN}WordPress is already installed.${RESET}" return; fi - echo "${CYAN}Installing WordPress...${RESET}" + echo -e "${CYAN}Installing WordPress...${RESET}" rm -rf $WP_CORE_DIR mkdir -p $WP_CORE_DIR @@ -139,7 +138,7 @@ install_wp() { download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR fi - echo "${GREEN}WordPress installed successfully.${RESET}" + echo -e "${GREEN}WordPress installed successfully.${RESET}" } install_test_suite() { @@ -152,7 +151,7 @@ install_test_suite() { # set up testing suite if it doesn't yet exist or only partially exists if [ ! -f $WP_TESTS_FILE ]; then - echo "${CYAN}Installing test suite...${RESET}" + echo -e "${CYAN}Installing test suite...${RESET}" # set up testing suite rm -rf $WP_TESTS_DIR mkdir -p $WP_TESTS_DIR @@ -174,13 +173,13 @@ install_test_suite() { mv $TMPDIR/wordpress-develop-${ref}/tests/phpunit/data $WP_TESTS_DIR/ rm -rf $TMPDIR/wordpress-develop-${ref} rm $TMPDIR/wordpress-develop.tar.gz - echo "${GREEN}Test suite installed.${RESET}" + echo -e "${GREEN}Test suite installed.${RESET}" else - echo "${CYAN}Test suite is already installed.${RESET}" + echo -e "${CYAN}Test suite is already installed.${RESET}" fi if [ ! -f "$WP_TESTS_DIR"/wp-tests-config.php ]; then - echo "${CYAN}Configuring test suite...${RESET}" + echo -e "${CYAN}Configuring test suite...${RESET}" if [[ $WP_TESTS_TAG == 'trunk' ]]; then ref=master elif [[ $WP_TESTS_TAG == branches/* ]]; then @@ -196,9 +195,9 @@ install_test_suite() { sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php - echo "${GREEN}Test suite configured.${RESET}" + echo -e "${GREEN}Test suite configured.${RESET}" else - echo "${CYAN}Test suite is already configured.${RESET}" + echo -e "${CYAN}Test suite is already configured.${RESET}" fi } @@ -207,16 +206,16 @@ recreate_db() { shopt -s nocasematch if [[ $1 =~ ^(y|yes)$ ]] then - echo "${CYAN}Recreating the database ($DB_NAME)...${RESET}" + echo -e "${CYAN}Recreating the database ($DB_NAME)...${RESET}" if [ `which mariadb-admin` ]; then mariadb-admin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA else mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA fi create_db - echo "${GREEN}Database ($DB_NAME) recreated.${RESET}" + echo -e "${GREEN}Database ($DB_NAME) recreated.${RESET}" else - echo "${YELLOW}Leaving the existing database ($DB_NAME) in place.${RESET}" + echo -e "${YELLOW}Leaving the existing database ($DB_NAME) in place.${RESET}" fi shopt -u nocasematch } @@ -232,7 +231,7 @@ create_db() { install_db() { if [ ${SKIP_DB_CREATE} = "true" ]; then - echo "${YELLOW}Skipping database creation.${RESET}" + echo -e "${YELLOW}Skipping database creation.${RESET}" return 0 fi @@ -260,17 +259,17 @@ install_db() { fi if [ $($DB_CLIENT --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ] then - echo "${YELLOW}Reinstalling will delete the existing test database ($DB_NAME)${RESET}" + echo -e "${YELLOW}Reinstalling will delete the existing test database ($DB_NAME)${RESET}" read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB recreate_db $DELETE_EXISTING_DB else - echo "${CYAN}Creating database ($DB_NAME)...${RESET}" + echo -e "${CYAN}Creating database ($DB_NAME)...${RESET}" create_db - echo "${GREEN}Database ($DB_NAME) created.${RESET}" + echo -e "${GREEN}Database ($DB_NAME) created.${RESET}" fi } install_wp install_test_suite install_db -echo "${GREEN}Done.${RESET}" +echo -e "${GREEN}Done.${RESET}" From a961ecae01637817cb8441562fac221ed329c82b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 8 Oct 2025 11:23:45 +0200 Subject: [PATCH 13/15] Add back stmt --- templates/install-wp-tests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/install-wp-tests.sh b/templates/install-wp-tests.sh index c22beae5..87c8075b 100644 --- a/templates/install-wp-tests.sh +++ b/templates/install-wp-tests.sh @@ -98,6 +98,8 @@ else WP_TESTS_TAG="tags/$LATEST_VERSION" fi +set -ex + install_wp() { if [ -f $WP_CORE_FILE ]; then From dca43ccef4860641db86ce0da768035829efd1f8 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 8 Oct 2025 11:36:29 +0200 Subject: [PATCH 14/15] Adjust test --- features/install-wp-tests.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index 73c69c67..f2ab360f 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -119,7 +119,7 @@ Feature: Scaffold install-wp-tests.sh tests """ And STDOUT should contain: """ - Recreated the database (wp_cli_test_scaffold) + Database (wp_cli_test_scaffold) recreated. """ When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < negative-response` @@ -250,7 +250,7 @@ Feature: Scaffold install-wp-tests.sh tests """ And STDOUT should contain: """ - Recreated the database (wp_cli_test_scaffold) + Database (wp_cli_test_scaffold) recreated. """ When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < negative-response` @@ -369,7 +369,7 @@ Feature: Scaffold install-wp-tests.sh tests """ And STDOUT should contain: """ - Recreated the database (wp_cli_test_scaffold) + Database (wp_cli_test_scaffold) recreated. """ When I try `WP_TESTS_DIR={RUN_DIR}/wordpress-tests-lib WP_CORE_DIR={RUN_DIR}/wordpress /usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh wp_cli_test_scaffold {DB_USER} {DB_PASSWORD} {DB_HOST} latest < negative-response` From 6f17adf33028eee757e2907e7c9eacff6d4ca156 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 8 Oct 2025 13:15:01 +0200 Subject: [PATCH 15/15] Update test --- features/install-wp-tests.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/install-wp-tests.feature b/features/install-wp-tests.feature index f2ab360f..d5bc3a36 100644 --- a/features/install-wp-tests.feature +++ b/features/install-wp-tests.feature @@ -10,7 +10,7 @@ Feature: Scaffold install-wp-tests.sh tests When I try `/usr/bin/env bash {PLUGIN_DIR}/hello-world/bin/install-wp-tests.sh` Then STDOUT should contain: """ - usage: + Usage: """ And the return code should be 1