From 192cd5f8edb809ac0667b02c63358c34412f6a8a Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Wed, 4 Oct 2023 12:40:00 +0200 Subject: [PATCH] fix: incorrect log about fixed issues --- src/summary.sh | 5 ++++- src/validation.sh | 7 +++++-- test/get_number_of.bats | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/summary.sh b/src/summary.sh index 5ec1765f..f1aaf2b0 100644 --- a/src/summary.sh +++ b/src/summary.sh @@ -72,7 +72,10 @@ Scanned/Changed scripts: \`${#list_of_changed_scripts[@]}\` get_number_of () { [[ $# -le 0 ]] && return 1 - jq '.defects | length' "../${1}.log" + file="../${1}.log" + [[ -s "${file}" ]] || return 1 + + jq '.defects | length' "${file}" } # Create full Markdown style link to results diff --git a/src/validation.sh b/src/validation.sh index 8d1667e7..1b96c9b3 100644 --- a/src/validation.sh +++ b/src/validation.sh @@ -19,7 +19,10 @@ get_fixes () { # It expects file '../fixes.log' to contain fixes # $? - return value is always 0 evaluate_and_print_fixes () { - if [[ -s ../fixes.log ]]; then + gather_statistics "../fixes.log" + + num_of_fixes=$(get_number_of fixes) + if [[ "${num_of_fixes}" -gt 0 ]]; then echo -e "✅ ${GREEN}Fixed defects${NOCOLOR}" csgrep --embed-context 2 ../fixes.log else @@ -45,7 +48,7 @@ evaluate_and_print_defects () { gather_statistics "../defects.log" num_of_defects=$(get_number_of defects) - if [[ -s ../defects.log ]] && [[ "${num_of_defects}" -gt 0 ]] ; then + if [[ "${num_of_defects}" -gt 0 ]] ; then print_statistics echo -e "✋ ${YELLOW}Defects, NEEDS INSPECTION${NOCOLOR}" diff --git a/test/get_number_of.bats b/test/get_number_of.bats index eb997a5d..dd4c6028 100644 --- a/test/get_number_of.bats +++ b/test/get_number_of.bats @@ -17,6 +17,13 @@ setup () { assert_failure 1 } +@test "get_number_of() - No such file or directory" { + source "${PROJECT_ROOT}/src/summary.sh" + + run get_number_of "asdfsghdfadshgfadsdshgfadsfghfjdsdf.log" + assert_failure 1 +} + @test "get_number_of() - defects" { source "${PROJECT_ROOT}/src/summary.sh"