Skip to content

Commit

Permalink
Test exit codes in steps' if: clause
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Jul 29, 2024
1 parent 347906d commit a3a6ffa
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions .github/workflows/test-working-directory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ jobs:
revision: HEAD

- name: Check that test.py was not found
if: always() && steps.no-work-dir.outputs.exitcode != '2'
run: |
if [ "${{ steps.no-work-dir.outputs.exitcode }}" != "2" ]; then
echo "::error::Darker should have failed with exit code 2"
exit 1
fi
echo "::error::Darker should have failed with exit code 2"
exit 1
- name: Run Darker with correct working-directory
id: right-workdir
Expand All @@ -50,19 +49,17 @@ jobs:
src: test.py
revision: HEAD

- name: Verify file was reformatted
if: always()
- name: Verify exit code 1 when reformatting is needed
if: always() && steps.right-workdir.outputs.exitcode != '1'
run: |
echo "::error::Darker should have exited with code 1"
exit 1
- name: Verify diff output
if: always() && !contains(steps.right-workdir.outputs.stdout, '@@')
run: |
if [ "${{ steps.right-workdir.outputs.exitcode }}" != "1" ]; then
echo "::error::Darker should have exited with code 1"
exit 1
fi
if [[ "${{ steps.right-workdir.outputs.stdout }}" == *"@@"* ]]; then
echo "Darker correctly output a reformatting diff"
else
echo "::error::Darker did not output a diff as expected"
exit 1
fi
echo "::error::Darker did not output a diff as expected"
exit 1
- name: Run Darker with incorrect working-directory (should not reformat)
if: always()
Expand All @@ -77,12 +74,10 @@ jobs:
revision: HEAD

- name: Check that Darker failed with a non-existing working-directory
if: always()
if: always() && steps.wrong-work-dir.outputs.exitcode != '21'
run: |
if [ "${{ steps.wrong-work-dir.outputs.exitcode }}" != "21" ]; then
echo "::error::Darker should have exited with code 21"
exit 1
fi
echo "::error::Darker should have exited with code 21"
exit 1
- name: Test file not found error
id: file-not-found
Expand All @@ -96,12 +91,10 @@ jobs:
src: non_existent_file.py

- name: Check file not found error code
if: always()
if: always() && steps.file-not-found.outputs.exitcode != '2'
run: |
if [ "${{ steps.file-not-found.outputs.exitcode }}" != "2" ]; then
echo "::error::Darker should have exited with code 2"
exit 1
fi
echo "::error::Darker should have exited with code 2"
exit 1
- name: Test invalid arguments error
id: invalid-arguments
Expand All @@ -113,12 +106,10 @@ jobs:
options: --invalid-option

- name: Check invalid arguments error code
if: always()
if: always() && steps.invalid-arguments.outputs.exitcode != '3'
run: |
if [ "${{ steps.invalid-arguments.outputs.exitcode }}" != "3" ]; then
echo "::error::Darker should have exited with code 3"
exit 1
fi
echo "::error::Darker should have exited with code 3"
exit 1
- name: Test missing dependencies error
id: missing-deps
Expand All @@ -131,9 +122,7 @@ jobs:
src: test.py

- name: Check missing dependencies error code
if: always()
if: always() && steps.missing-deps.outputs.exitcode != '4'
run: |
if [ "${{ steps.missing-deps.outputs.exitcode }}" != "4" ]; then
echo "::error::Darker should have exited with code 4"
exit 1
fi
echo "::error::Darker should have exited with code 4"
exit 1

0 comments on commit a3a6ffa

Please sign in to comment.