Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better integration tests, with correct exit status checks #161

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Expand Down
3 changes: 1 addition & 2 deletions moodle/Tests/fixtures/integration_test_ci.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?php
// phpcs:disable moodle.Files
<?php // phpcs:disable moodle.Files,moodle.Commenting
defined('MOODLE_INTERNAL') || die(); // Make this always the 1st line in all CS fixtures.
$arr ['wrong'] = $value;