Skip to content

Commit

Permalink
maintain shell tests
Browse files Browse the repository at this point in the history
fix phar test after upgrade of symfony-yml for php 7.4 forward compatible
symfony/yaml in 1bcf107

fix services test 1 2 run per run.sh. only the first operand was effective.

polish variable use by removal of superfluous curly brackets.

ref: 1bcf107
  • Loading branch information
ktomk committed Dec 31, 2020
1 parent 89197af commit eb169c6
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 78 deletions.
49 changes: 29 additions & 20 deletions test/shell/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,43 @@
# the test-case/drivers' test-plan, any number greater
# than zero runs that test number of the driver
#
# example: ./test/shell/run.sh test-phar.sh 1 2
# example: ./test/shell/run.sh phar 1 2
#
set -euo pipefail
IFS=$'\n\t'

cd "${0%/*}"

##
# optional: <case> (test-*.sh) [<test>..] as positional parameters
if [[ -f "./${1:-}" ]] && [[ -x "./${1:-}" ]]; then
test="./${1}"
if [[ "$#" -eq 1 ]]; then
"${test}"
exit
# run <case> (test->>*<<.sh) [<test>..] as positional parameters
run() {
local test
test="./test-${1:-}.sh"
if [[ -f "$test" ]] && [[ -x "$test" ]]; then
if [[ "$#" -eq 1 ]]; then
"$test"
return
fi
while [[ "$#" -gt 1 ]]; do
shift 1
echo "## $test $1"
"$test" "$1"
done
return
fi
while [[ "$#" -gt 1 ]]; do
shift 1
"${test}" "${1}"
done
if [[ "$#" -gt 1 ]]; then
>&2 echo "fatal: not a test-case: '$1'"
retrun 1
fi
}

if [ $# -gt 0 ]; then
run "$@"
exit
fi
if [[ "$#" -gt 1 ]]; then
>&2 echo "fatal: not a test-case: '${1}'"
exit 1
fi

./test-smoke.sh
./test-artifacts.sh
./test-schema-validate.sh
./test-services.sh 1 2
./test-pip.sh
run smoke
run artifacts
run schema-validate
run services 1 2
run pip
12 changes: 6 additions & 6 deletions test/shell/test-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ PROJECT_DIR=../..
TEST_BUILD_DIR=build/artifacts-test

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 1
0 ) echo "# 0: $0 run"
run_test "$0" 1
exit
;;
1 ) echo "# 1: pipeline with artifacts"
cd "${PROJECT_DIR}"
rm -rf -- "${TEST_BUILD_DIR}"
cd "$PROJECT_DIR"
rm -rf -- "$TEST_BUILD_DIR"
bin/pipelines --file test/data/yml/artifacts.yml
ls -al -- "${TEST_BUILD_DIR}"
ls -al -- "$TEST_BUILD_DIR"
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
14 changes: 7 additions & 7 deletions test/shell/test-phar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ IFS=$'\n\t'
PROJECT_DIR=../..

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 1 2
0 ) echo "# 0: $0 run"
run_test "$0" 1 2
exit
;;
1 ) echo "# 1: build pipelines phar"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
rm -f build/pipelines.phar
"${PHP_BINARY-php}" -d phar.readonly=0 -f lib/build/build.php | grep 'signature:'
build/pipelines.phar --version
exit
;;
2 ) echo "# 2: check last file by checksum"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
<<'EOD' "${PHP_BINARY-php}" -f /dev/stdin -- \
build/pipelines.phar \
vendor/symfony/yaml/Symfony/Component/Yaml/Yaml.php
vendor/ktomk/symfony-yaml/Symfony/Component/Yaml/Yaml.php
<?php
$pharFile = $argv[1];
$path = $argv[2];
Expand All @@ -40,7 +40,7 @@ function chk_file($label, $path) {
$buffer = file_get_contents($path);
$lenBuffer = strlen($buffer);
$fileSize = filesize($path);
printf(" %'.-4s: %d %d %s %s\n"
printf(" %'.-4s: %d %d %s \"%s\"\n"
, $label, $fileSize, $lenBuffer, md5_file($path)
, addcslashes(substr($buffer, -1), "\0..\37!@\177..\377")
);
Expand All @@ -52,7 +52,7 @@ chk_file('phar', $phar);
EOD
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
16 changes: 8 additions & 8 deletions test/shell/test-php74.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ IFS=$'\n\t'
PROJECT_DIR=../..

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 1 2 3
0 ) echo "# 0: $0 run"
run_test "$0" 1 2 3
exit
;;
1 ) echo "# 1: require phpunit 8"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
"${PHP_BIN-php}" -f "$(composer which 2>/dev/null)" -- -n require --dev phpunit/phpunit ^8 --update-with-dependencies --no-suggest
exit
;;
2 ) echo "# 2: patch for phpunit 8"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
./lib/script/ppconf.sh patch-phpunit-tests
exit
;;
-2 ) echo "# -2: patch from phpunit 8"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
./lib/script/ppconf.sh downpatch-phpunit-tests
exit
;;
3 ) echo "# 3: run phpunit tests"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
"${PHP_BIN-php}" -f "$(composer which 2>/dev/null)" -- phpunit-test
exit
;;
4 ) echo "# 4: reset phpunit to project baseline, checkout test-suite"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
git checkout -- composer.* test/TestCase.php test/unit
"${PHP_BIN-php}" -f "$(composer which 2>/dev/null)" -- install
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
6 changes: 3 additions & 3 deletions test/shell/test-phpunit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ IFS=$'\n\t'
#

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 1 2
0 ) echo "# 0: $0 run"
run_test "$0" 1 2
exit
;;
1 ) echo "# 1: phpunit on php 7.0"
Expand All @@ -28,7 +28,7 @@ case ${1-0} in
../../bin/pipelines --pipeline custom/unit-tests-php-5.3
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
8 changes: 4 additions & 4 deletions test/shell/test-pip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ IFS=$'\n\t'
#

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 8 1 6 5 4 2 3 7
0 ) echo "# 0: $0 run"
run_test "$0" 8 1 6 5 4 2 3 7
exit
;;
1 ) echo "# 1: build pipelines phar"
prj=../..
cd "${prj}" \
cd "$prj" \
; assert lib/build/build.php | grep 'signature:' \
; build/pipelines.phar --version \
; cd -
Expand Down Expand Up @@ -88,7 +88,7 @@ case ${1-0} in
../../bin/pipelines --pipeline custom/recursion-pip-happy
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
6 changes: 3 additions & 3 deletions test/shell/test-polish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ IFS=$'\n\t'
#

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 3 2 1
0 ) echo "# 0: $0 run"
run_test "$0" 3 2 1
exit
;;
1 ) echo "# 1: run w/ script generation and verbose output"
Expand All @@ -39,7 +39,7 @@ case ${1-0} in
docker ps | grep -v 'pipelines-1.pipeline-features-and-introspection.default.pipelines'
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
12 changes: 6 additions & 6 deletions test/shell/test-schema-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ IFS=$'\n\t'
PROJECT_DIR=../..

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 1 2 3
0 ) echo "# 0: $0 run"
run_test "$0" 1 2 3
exit
;;
1 ) echo "# 1: build pipelines phar (validate with phar)"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
if [ -z "${CI-}" ]; then # skip building the phar-file in CI
rm -f build/pipelines.phar
"${PHP_BINARY-php}" -d phar.readonly=0 -f lib/build/build.php | grep 'signature:'
Expand All @@ -31,18 +31,18 @@ case ${1-0} in
exit
;;
2 ) echo "# 2: validate valid files"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
build/pipelines.phar --validate --file bitbucket-pipelines.yml
build/pipelines.phar --validate --file test/data/yml/clone.yml
build/pipelines.phar --validate --file test/data/yml/condition.yml
exit
;;
3 ) echo "# 3: validate on syntax error file"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
{ 2>&1 build/pipelines.phar --validate --file test/data/yml/error.yml || true; } | grep 'YAML error:'
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
16 changes: 8 additions & 8 deletions test/shell/test-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ IFS=$'\n\t'
PROJECT_DIR=../..

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 1 2 3
0 ) echo "# 0: $0 run"
run_test "$0" 1 2 3
exit
;;
1 ) echo "# 1: redis service (kept)"
"${PROJECT_DIR}/bin/pipelines" --pipeline custom/redis-service --keep --verbatim | grep PONG
"${PROJECT_DIR}/bin/pipelines" --docker-list | grep pipelines-1.redis-service.custom-redis-service.pipelines
"$PROJECT_DIR/bin/pipelines" --pipeline custom/redis-service --keep --verbatim | grep PONG
"$PROJECT_DIR/bin/pipelines" --docker-list | grep pipelines-1.redis-service.custom-redis-service.pipelines
exit
;;
2 ) echo "# 2: redis service (clean)"
"${PROJECT_DIR}/bin/pipelines" --pipeline custom/redis-service --verbatim | grep PONG
"${PROJECT_DIR}/bin/pipelines" --docker-list | grep -v pipelines-1.redis-service.custom-redis-service.pipelines
"$PROJECT_DIR/bin/pipelines" --pipeline custom/redis-service --verbatim | grep PONG
"$PROJECT_DIR/bin/pipelines" --docker-list | grep -v pipelines-1.redis-service.custom-redis-service.pipelines
exit
;;
3 ) echo "# 3: mysql service"
"${PROJECT_DIR}/bin/pipelines" --pipeline custom/mysql-service
"$PROJECT_DIR/bin/pipelines" --pipeline custom/mysql-service
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
10 changes: 5 additions & 5 deletions test/shell/test-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ IFS=$'\n\t'
PROJECT_DIR=../..

case ${1-0} in
0 ) echo "# 0: ${0} run"
run_test "${0}" 1 2
0 ) echo "# 0: $0 run"
run_test "$0" 1 2
exit
;;
1 ) echo "# 1: composer 2 must not have written lock"
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
if grep -cq '"plugin-api-version": "2\..*"' composer.lock; then exit 1; fi;
exit
;;
2 ) echo "# 2: composer which"
# composer which script must work, there was a regression using composer 2 (Nov 2020)
# fixed in composer 2.0.7 <https://github.com/composer/composer/issues/9454>
# fixed in pipelines 0.0.52
cd "${PROJECT_DIR}"
cd "$PROJECT_DIR"
echo "--$(composer which 2>/dev/null)--" | grep -qv -- '----' >/dev/null
exit
;;
* ) >&2 echo "unknown step ${1}"
* ) >&2 echo "unknown step $1"
exit 1
;;
esac
Loading

0 comments on commit eb169c6

Please sign in to comment.