Skip to content

Commit

Permalink
wip: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Aug 21, 2023
1 parent f994631 commit 00a47fb
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get_fixes () {
evaluate_and_print_fixes () {
if [[ -s ../fixes.log ]]; then
echo -e "${GREEN}Fixed defects${NOCOLOR}"
csgrep ../fixes.log
csgrep --embed-context 2 ../fixes.log
else
echo -e "ℹ️ ${YELLOW}No Fixes!${NOCOLOR}"
fi
Expand All @@ -45,7 +45,7 @@ evaluate_and_print_defects () {
print_statistics

echo -e "${YELLOW}Defects, NEEDS INSPECTION${NOCOLOR}"
csgrep ../defects.log
csgrep --embed-context 4 ../defects.log
return 1
fi

Expand Down
18 changes: 5 additions & 13 deletions test/evaluate_and_print_defects.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@ setup () {

run evaluate_and_print_defects
assert_failure 1
assert_output "\
assert_output --partial "\
::group::📊 Statistics of defects
Error: 0
Warning: 3
Warning: 2
Note: 0
Style: 0
::endgroup::
✋ Defects, NEEDS INSPECTION
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."
::endgroup::"
assert_line --partial "innocent-script.sh:7: warning[SC2034]: UNUSED_VAR2 appears unused. Verify use (or export if used externally)."
assert_line --partial 'innocent-script.sh:11: warning[SC2115]: Use "${var:?}" to ensure this never expands to / .'
}

@test "evaluate_and_print_defects() - no defects" {
Expand Down
5 changes: 2 additions & 3 deletions test/evaluate_and_print_fixes.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ setup () {

run evaluate_and_print_fixes
assert_success
assert_output "\
✅ Fixed defects
assert_output --partial "✅ Fixed defects
Error: SHELLCHECK_WARNING:
src/index.sh:7:3: note[SC1091]: Not following: functions.sh: openBinaryFile: does not exist (No such file or directory)"
innocent-script.sh:6: warning[SC2034]: UNUSED_VAR appears unused. Verify use (or export if used externally)."
}

@test "evaluate_and_print_fixes() - no fixes" {
Expand Down
21 changes: 16 additions & 5 deletions test/fixtures/evaluate_and_print_defects/defects.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
Error: SHELLCHECK_WARNING:
src/index.sh:53:10: warning[SC2154]: MAIN_HEADING is referenced but not assigned.
innocent-script.sh:7: warning[SC2034]: UNUSED_VAR2 appears unused. Verify use (or export if used externally).
# 4|
# 5| DIR_SUFFIX="*"
# 6| UNUSED_VAR=""
# 7|-> UNUSED_VAR2=""
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|

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.
innocent-script.sh:11: warning[SC2115]: Use "${var:?}" to ensure this never expands to / .
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|
# 11|-> rm -rf $1/$2/$DIR_SUFFIX
# 12|
# 13| #! FIXME - Call rm -rf $1/$DIR_SUFFIX
# 14|
5 changes: 4 additions & 1 deletion test/fixtures/evaluate_and_print_fixes/fixes.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Error: SHELLCHECK_WARNING:
src/index.sh:7:3: note[SC1091]: Not following: functions.sh: openBinaryFile: does not exist (No such file or directory)
innocent-script.sh:6: warning[SC2034]: UNUSED_VAR appears unused. Verify use (or export if used externally).
# 5| DIR_SUFFIX="*"
# 6|-> UNUSED_VAR=""
# 7| UNUSED_VAR2=""
21 changes: 16 additions & 5 deletions test/fixtures/gather_statistics/defects.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
Error: SHELLCHECK_WARNING:
src/index.sh:53:10: warning[SC2154]: MAIN_HEADING is referenced but not assigned.
innocent-script.sh:7: warning[SC2034]: UNUSED_VAR2 appears unused. Verify use (or export if used externally).
# 4|
# 5| DIR_SUFFIX="*"
# 6| UNUSED_VAR=""
# 7|-> UNUSED_VAR2=""
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|

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.
innocent-script.sh:11: warning[SC2115]: Use "${var:?}" to ensure this never expands to / .
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|
# 11|-> rm -rf $1/$2/$DIR_SUFFIX
# 12|
# 13| #! FIXME - Call rm -rf $1/$DIR_SUFFIX
# 14|
19 changes: 15 additions & 4 deletions test/fixtures/get_defects/base.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
src/index.sh:7:3: note: Not following: functions.sh: openBinaryFile: does not exist (No such file or directory) [SC1091]
src/index.sh:39:42: warning: BASE is referenced but not assigned. [SC2154]
src/index.sh:39:53: warning: HEAD is referenced but not assigned. [SC2154]
src/index.sh:50:10: warning: VERSIONS_HEADING is referenced but not assigned. [SC2154]
{
"comments": [
{
"file": "innocent-script.sh",
"line": 6,
"endLine": 6,
"column": 1,
"endColumn": 11,
"level": "warning",
"code": 2034,
"message": "UNUSED_VAR appears unused. Verify use (or export if used externally).",
"fix": null
}
]
}
42 changes: 34 additions & 8 deletions test/fixtures/get_defects/defects.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
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": [
{
"checker": "SHELLCHECK_WARNING",
"language": "shell",
"tool": "shellcheck",
"key_event_idx": 0,
"events": [
{
"file_name": "innocent-script.sh",
"line": 7,
"event": "warning[SC2034]",
"message": "UNUSED_VAR2 appears unused. Verify use (or export if used externally).",
"verbosity_level": 0
}
]
},
{
"checker": "SHELLCHECK_WARNING",
"language": "shell",
"tool": "shellcheck",
"key_event_idx": 0,
"events": [
{
"file_name": "innocent-script.sh",
"line": 11,
"event": "warning[SC2115]",
"message": "Use \"${var:?}\" to ensure this never expands to / .",
"verbosity_level": 0
}
]
}
]
}
32 changes: 26 additions & 6 deletions test/fixtures/get_defects/head.err
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
src/index.sh:39:42: warning: BASE is referenced but not assigned. [SC2154]
src/index.sh:39:53: warning: HEAD is referenced but not assigned. [SC2154]
src/index.sh:50:10: warning: VERSIONS_HEADING is referenced but not assigned. [SC2154]
src/index.sh:53:10: warning: MAIN_HEADING is referenced but not assigned. [SC2154]
src/index.sh:56:14: warning: WHITE is referenced but not assigned. [SC2154]
src/index.sh:56:56: warning: NOCOLOR is referenced but not assigned. [SC2154]
{
"comments": [
{
"file": "innocent-script.sh",
"line": 7,
"endLine": 7,
"column": 1,
"endColumn": 12,
"level": "warning",
"code": 2034,
"message": "UNUSED_VAR2 appears unused. Verify use (or export if used externally).",
"fix": null
},
{
"file": "innocent-script.sh",
"line": 11,
"endLine": 11,
"column": 8,
"endColumn": 25,
"level": "warning",
"code": 2115,
"message": "Use \"${var:?}\" to ensure this never expands to / .",
"fix": null
}
]
}
22 changes: 15 additions & 7 deletions test/fixtures/get_fixes/base.err
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
src/index.sh:7:3: note: Not following: functions.sh: openBinaryFile: does not exist (No such file or directory) [SC1091]
src/index.sh:39:42: warning: BASE is referenced but not assigned. [SC2154]
src/index.sh:39:53: warning: HEAD is referenced but not assigned. [SC2154]
src/index.sh:50:10: warning: VERSIONS_HEADING is referenced but not assigned. [SC2154]
src/index.sh:53:10: warning: MAIN_HEADING is referenced but not assigned. [SC2154]
src/index.sh:56:14: warning: WHITE is referenced but not assigned. [SC2154]
src/index.sh:56:56: warning: NOCOLOR is referenced but not assigned. [SC2154]
{
"comments": [
{
"file": "innocent-script.sh",
"line": 6,
"endLine": 6,
"column": 1,
"endColumn": 11,
"level": "warning",
"code": 2034,
"message": "UNUSED_VAR appears unused. Verify use (or export if used externally).",
"fix": null
}
]
}
21 changes: 19 additions & 2 deletions test/fixtures/get_fixes/fixes.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
Error: SHELLCHECK_WARNING:
src/index.sh:7:3: note[SC1091]: Not following: functions.sh: openBinaryFile: does not exist (No such file or directory)
{
"defects": [
{
"checker": "SHELLCHECK_WARNING",
"language": "shell",
"tool": "shellcheck",
"key_event_idx": 0,
"events": [
{
"file_name": "innocent-script.sh",
"line": 6,
"event": "warning[SC2034]",
"message": "UNUSED_VAR appears unused. Verify use (or export if used externally).",
"verbosity_level": 0
}
]
}
]
}
32 changes: 26 additions & 6 deletions test/fixtures/get_fixes/head.err
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
src/index.sh:39:42: warning: BASE is referenced but not assigned. [SC2154]
src/index.sh:39:53: warning: HEAD is referenced but not assigned. [SC2154]
src/index.sh:50:10: warning: VERSIONS_HEADING is referenced but not assigned. [SC2154]
src/index.sh:53:10: warning: MAIN_HEADING is referenced but not assigned. [SC2154]
src/index.sh:56:14: warning: WHITE is referenced but not assigned. [SC2154]
src/index.sh:56:56: warning: NOCOLOR is referenced but not assigned. [SC2154]
{
"comments": [
{
"file": "innocent-script.sh",
"line": 7,
"endLine": 7,
"column": 1,
"endColumn": 12,
"level": "warning",
"code": 2034,
"message": "UNUSED_VAR2 appears unused. Verify use (or export if used externally).",
"fix": null
},
{
"file": "innocent-script.sh",
"line": 11,
"endLine": 11,
"column": 8,
"endColumn": 25,
"level": "warning",
"code": 2115,
"message": "Use \"${var:?}\" to ensure this never expands to / .",
"fix": null
}
]
}
27 changes: 24 additions & 3 deletions test/fixtures/get_number_of_defects_by_severity/defects.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
Error: SHELLCHECK_WARNING:
src/index.sh:53:10: warning[SC2154]: MAIN_HEADING is referenced but not assigned.
innocent-script.sh:6: warning[SC2034]: UNUSED_VAR appears unused. Verify use (or export if used externally).
# 3| echo "I'm innocent script, just pass the name of the directory as parameter and I'll remove it for you..."
# 4|
# 5| DIR_SUFFIX="*"
# 6|-> UNUSED_VAR=""
# 7| UNUSED_VAR2=""
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"

Error: SHELLCHECK_WARNING:
src/index.sh:56:14: warning[SC2154]: WHITE is referenced but not assigned.
innocent-script.sh:7: warning[SC2034]: UNUSED_VAR2 appears unused. Verify use (or export if used externally).
# 4|
# 5| DIR_SUFFIX="*"
# 6| UNUSED_VAR=""
# 7|-> UNUSED_VAR2=""
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|

Error: SHELLCHECK_WARNING:
src/index.sh:56:56: warning[SC2154]: NOCOLOR is referenced but not assigned.
innocent-script.sh:11: warning[SC2115]: Use "${var:?}" to ensure this never expands to / .
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|
# 11|-> rm -rf $1/$2/$DIR_SUFFIX
# 12|
# 13| #! FIXME - Call rm -rf $1/$DIR_SUFFIX
# 14|
27 changes: 24 additions & 3 deletions test/fixtures/print_statistics/defects.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
Error: SHELLCHECK_WARNING:
src/index.sh:53:10: warning[SC2154]: MAIN_HEADING is referenced but not assigned.
innocent-script.sh:6: warning[SC2034]: UNUSED_VAR appears unused. Verify use (or export if used externally).
# 3| echo "I'm innocent script, just pass the name of the directory as parameter and I'll remove it for you..."
# 4|
# 5| DIR_SUFFIX="*"
# 6|-> UNUSED_VAR=""
# 7| UNUSED_VAR2=""
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"

Error: SHELLCHECK_WARNING:
src/index.sh:56:14: warning[SC2154]: WHITE is referenced but not assigned.
innocent-script.sh:7: warning[SC2034]: UNUSED_VAR2 appears unused. Verify use (or export if used externally).
# 4|
# 5| DIR_SUFFIX="*"
# 6| UNUSED_VAR=""
# 7|-> UNUSED_VAR2=""
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|

Error: SHELLCHECK_WARNING:
src/index.sh:56:56: warning[SC2154]: NOCOLOR is referenced but not assigned.
innocent-script.sh:11: warning[SC2115]: Use "${var:?}" to ensure this never expands to / .
# 8|
# 9| echo "I'm going to remove directory $1/$DIR_SUFFIX"
# 10|
# 11|-> rm -rf $1/$2/$DIR_SUFFIX
# 12|
# 13| #! FIXME - Call rm -rf $1/$DIR_SUFFIX
# 14|
2 changes: 1 addition & 1 deletion test/get_defects.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setup () {
load 'test_helper/bats-file/load'
}

@test "get_defects()" {
@test "get_defects() - general" {
source "${PROJECT_ROOT}/src/validation.sh"

run get_defects
Expand Down

0 comments on commit 00a47fb

Please sign in to comment.