Skip to content

Commit

Permalink
Report exit code for failing tests (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeReaper authored Apr 28, 2024
1 parent 2b07851 commit 70d0065
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
14 changes: 12 additions & 2 deletions .github/test-resources/shell-run-github-workflow-tests/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ on:
- main

jobs:
test-inner-test-run:
name: Test inner test run
passing-tests:
name: Passing tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Test that passes
run: |
echo 'Test-in-tests'
failing-tests:
name: Failing tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Test that fails
run: |
exit 2
17 changes: 17 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,26 @@ jobs:
set +e
sh lane.d/shell-run-github-workflow-tests/run.sh -i ./non-existing-file > /dev/null
[ $? -eq 111 ] || exit 1
- name: Test running tests
run: |
set +e
sh lane.d/shell-run-github-workflow-tests/run.sh -i .github/test-resources/shell-run-github-workflow-tests/test.yaml
[ $? -eq 1 ] || exit 1
- name: Test running unknown test section (has no tests and thus no errors)
run: |
sh lane.d/shell-run-github-workflow-tests/run.sh -i .github/test-resources/shell-run-github-workflow-tests/test.yaml -j unknown-tests
- name: Test running passing tests
run: |
sh lane.d/shell-run-github-workflow-tests/run.sh -i .github/test-resources/shell-run-github-workflow-tests/test.yaml -j passing-tests
- name: Test running failing tests
run: |
set +e
sh lane.d/shell-run-github-workflow-tests/run.sh -i .github/test-resources/shell-run-github-workflow-tests/test.yaml -j failing-tests
[ $? -eq 1 ] || exit 1
shell-github-action-semver-compare:
name: Test Shell Github Action Semver Compare
Expand Down
2 changes: 1 addition & 1 deletion lane.d/shell-run-github-workflow-tests/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The output would be:
Test run (test-run)
- Test that passes: Pass
- Test that fails: Fail
- Test that fails: Failed with exit code 1
Tests; Total: 2 Passes: 1 Fails: 1
```
5 changes: 4 additions & 1 deletion lane.d/shell-run-github-workflow-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ yq -o json "$file" | jq -rc '.jobs | to_entries[] | [{group: .key, groupName: .v
{
echo "printf ' - ${step_name}: '"
echo "set +e; sh '${DIR}/${group}.${I}.sh' > messages 2>&1"
printf "if [ \$? -eq 0 ]; then printf \${GREEN}'Pass\n'\${NC}; PASS=\$((PASS+1)); else printf \${RED}'Fail\n'\${NC}; FAIL=\$((FAIL+1)); cat messages; fi;\n"
echo "ERROR=\$?"
printf "if [ \$ERROR -eq 0 ]; then printf \${GREEN}'Pass\n'\${NC}; PASS=\$((PASS+1)); else printf \${RED}'Failed with exit code %%s\n'\${NC} \$ERROR; FAIL=\$((FAIL+1)); cat messages; fi;\n"
} >>"${DIR}/${group}.sh"

I=$((I + 1))
Expand All @@ -86,6 +87,8 @@ done
echo 'TOTAL=$((TOTAL_PASS+TOTAL_FAIL))'
# shellcheck disable=SC2016
printf 'echo; printf "Tests; Total: \033[1m${TOTAL}\033[0m Passes: \033[1m${TOTAL_PASS}\033[0m Fails: \033[1m${TOTAL_FAIL}\033[0m\n"\n'
# shellcheck disable=SC2016
echo 'if [ $TOTAL_FAIL -ne 0 ]; then exit 1; fi'
} >>"$DIR/runner.sh"

echo ' done!'
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.4
0.3.5

0 comments on commit 70d0065

Please sign in to comment.