From ef0b7645cb8e7a91fbc886045cf0d495e4f02c17 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 13 May 2024 16:28:02 +0200 Subject: [PATCH] Better integration tests, with correct exit status checks --- .github/workflows/phpcs.yml | 38 +++++++++++++++---- moodle/Tests/fixtures/integration_test_ci.php | 3 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 277d046..ce65e81 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -63,18 +63,42 @@ jobs: run: ./vendor/bin/phpunit-coverage-check -t 80 clover.xml - name: Integration tests - if: ${{ (!cancelled()) && (runner.os == 'ubuntu-latest') }} + if: ${{ !cancelled() && matrix.os == 'ubuntu-latest' }} run: | - # There is one failure (exit with error) - vendor/bin/phpcs --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt || [[ $? = 1 ]] + # There is one failure (exit with error 2, because some are fixable). + expectedcode=2 + vendor/bin/phpcs --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt + exitcode="${PIPESTATUS[0]}" + if [[ "${exitcode}" = "${expectedcode}" ]]; then + echo "Ok, got expected ${exitcode} exit code." + else + echo "Error: Expected ${expectedcode}, got ${exitcode} exit code." + exit 1 + fi grep -q "PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY" output.txt - # The failure is fixed (exit with error) - vendor/bin/phpcbf --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt || [[ $? = 1 ]] + # The failure is fixed (exit with error 1, because all fixable ones were fixed). + expectedcode=1 + vendor/bin/phpcbf --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt + exitcode="${PIPESTATUS[0]}" + if [[ "${exitcode}" = "${expectedcode}" ]]; then + echo "Ok, got expected ${exitcode} exit code." + else + echo "Error: Expected ${expectedcode}, got ${exitcode} exit code." + exit 1 + fi grep -q "A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE" output.txt - # So, there isn't any failure any more (exit without error) - vendor/bin/phpcs --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt && [[ $? = 0 ]] + # So, there isn't any failure any more (exit without error, aka, 0) + expectedcode=0 + vendor/bin/phpcs --standard=moodle moodle/Tests/fixtures/integration_test_ci.php | tee output.txt + exitcode="${PIPESTATUS[0]}" + if [[ "${exitcode}" = "${expectedcode}" ]]; then + echo "Ok, got expected ${exitcode} exit code." + else + echo "Error: Expected ${expectedcode}, got ${exitcode} exit code." + exit 1 + fi - name: Mark cancelled jobs as failed if: ${{ cancelled() }} diff --git a/moodle/Tests/fixtures/integration_test_ci.php b/moodle/Tests/fixtures/integration_test_ci.php index fdd4434..c6d85c9 100644 --- a/moodle/Tests/fixtures/integration_test_ci.php +++ b/moodle/Tests/fixtures/integration_test_ci.php @@ -1,4 +1,3 @@ -