diff --git a/src/summary.sh b/src/summary.sh index 95f15637..3d8a3c36 100644 --- a/src/summary.sh +++ b/src/summary.sh @@ -92,7 +92,7 @@ link_to_results () { local push_link="https://github.com/${GITHUB_REPOSITORY}/security/code-scanning?query=tool%3A${SCANNING_TOOL:-"shellcheck"}+branch%3A${GITHUB_REF_NAME:-"main"}+is%3Aopen" local pull_request_link="https://github.com/${GITHUB_REPOSITORY}/security/code-scanning?query=pr%3A${pull_number}+tool%3A${SCANNING_TOOL:-"shellcheck"}+is%3Aopen" - case ${INPUT_TRIGGERING_EVENT:-${GITHUB_EVENT_NAME}} in + case ${INPUT_TRIGGERING_EVENT-${GITHUB_EVENT_NAME}} in "push") echo -e "${push_link}" ;; diff --git a/test/diff_scan_summary.bats b/test/diff_scan_summary.bats new file mode 100644 index 00000000..9c21b68e --- /dev/null +++ b/test/diff_scan_summary.bats @@ -0,0 +1,87 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +setup_file () { + load 'test_helper/common-setup' + _common_setup +} + +setup () { + load 'test_helper/bats-assert/load' + load 'test_helper/bats-support/load' +} + +@test "diff_scan_summary()" { + source "${PROJECT_ROOT}/src/summary.sh" + + export only_changed_scripts=("1.sh" "\$2.sh" "3 .sh") + INPUT_TRIGGERING_EVENT="" + + echo -e \ +"Error: SHELLCHECK_WARNING: +src/index.sh:53:10: warning[SC2154]: MAIN_HEADING is referenced but not assigned. + +Error: SHELLCHECK_WARNING: +src/index.sh:56:14: warning[SC2154]: WHITE is referenced but not assigned. + +Error: SHELLCHECK_WARNING: +src/index.sh:56:56: warning[SC2154]: NOCOLOR is referenced but not assigned. +" > ../defects.log + + echo -e \ +"Error: SHELLCHECK_WARNING: +src/index.sh:7:3: note[SC1091]: Not following: functions.sh: openBinaryFile: does not exist (No such file or directory) +" > ../fixes.log + + run diff_scan_summary + assert_success + assert_output \ +"Changed scripts: \`3\` + +| | ❌ Added | ✅ Fixed | +|:------------------:|:------------------------:|:------------------------:| +| ⚠️ Errors / Warnings / Notes | **3** | **1** |" +} + +@test "diff_scan_summary() - no fixes or defects" { + source "${PROJECT_ROOT}/src/summary.sh" + + export only_changed_scripts=("1.sh" "\$2.sh" "3 .sh") + INPUT_TRIGGERING_EVENT="" + + touch ../defects.log ../fixes.log + + run diff_scan_summary + assert_success + assert_output \ +"Changed scripts: \`3\` + +| | ❌ Added | ✅ Fixed | +|:------------------:|:------------------------:|:------------------------:| +| ⚠️ Errors / Warnings / Notes | **0** | **0** |" +} + +@test "diff_scan_summary() - no changed shell scripts" { + source "${PROJECT_ROOT}/src/summary.sh" + + export only_changed_scripts=() + INPUT_TRIGGERING_EVENT="" + + touch ../defects.log ../fixes.log + + run diff_scan_summary + assert_success + assert_output \ +"Changed scripts: \`0\` + +| | ❌ Added | ✅ Fixed | +|:------------------:|:------------------------:|:------------------------:| +| ⚠️ Errors / Warnings / Notes | **0** | **0** |" +} + +teardown () { + rm -f ../defects.log ../fixes.log + + export \ + only_changed_scripts="" \ + INPUT_TRIGGERING_EVENT="" +}