From 70d0065158e25c8216cd0611bdf5740122c87159 Mon Sep 17 00:00:00 2001 From: Jakob Jensen Date: Sun, 28 Apr 2024 14:52:39 +0200 Subject: [PATCH] Report exit code for failing tests (#24) --- .../shell-run-github-workflow-tests/test.yaml | 14 ++++++++++++-- .github/workflows/tests.yaml | 17 +++++++++++++++++ lane.d/shell-run-github-workflow-tests/help.md | 2 +- lane.d/shell-run-github-workflow-tests/run.sh | 5 ++++- version | 2 +- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/test-resources/shell-run-github-workflow-tests/test.yaml b/.github/test-resources/shell-run-github-workflow-tests/test.yaml index 5885de4..1df2aab 100644 --- a/.github/test-resources/shell-run-github-workflow-tests/test.yaml +++ b/.github/test-resources/shell-run-github-workflow-tests/test.yaml @@ -8,8 +8,8 @@ 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 @@ -17,3 +17,13 @@ jobs: - 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 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 238e8fb..fcab269 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -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 diff --git a/lane.d/shell-run-github-workflow-tests/help.md b/lane.d/shell-run-github-workflow-tests/help.md index faf9a05..1d9369f 100644 --- a/lane.d/shell-run-github-workflow-tests/help.md +++ b/lane.d/shell-run-github-workflow-tests/help.md @@ -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 ``` diff --git a/lane.d/shell-run-github-workflow-tests/run.sh b/lane.d/shell-run-github-workflow-tests/run.sh index a2bc6f2..220d437 100755 --- a/lane.d/shell-run-github-workflow-tests/run.sh +++ b/lane.d/shell-run-github-workflow-tests/run.sh @@ -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)) @@ -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!' diff --git a/version b/version index 42045ac..c2c0004 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.3.4 +0.3.5