Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PARALLEL_RUN=

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Added `assertCommandNotFound`
- Added `assertArrayContains`
- Added `assertArrayNotContains`
- Added `assertEmpty`
- Added `assertNotEmpty`
- Improved the readability of the assert by using guard clause
- Update documentation
- Add support for the static analysis on MacOS
Expand Down
26 changes: 26 additions & 0 deletions src/assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ function assertEquals() {
((_ASSERTIONS_PASSED++))
}

function assertEmpty() {
local expected="$1"
local label="${3:-$(normalizeTestFunctionName "${FUNCNAME[1]}")}"

if [[ "$expected" != "" ]]; then
((_ASSERTIONS_FAILED++))
printFailedTest "${label}" "to be empty" "but got" "${expected}"
return
fi

((_ASSERTIONS_PASSED++))
}

function assertNotEmpty() {
local expected="$1"
local label="${3:-$(normalizeTestFunctionName "${FUNCNAME[1]}")}"

if [[ "$expected" == "" ]]; then
((_ASSERTIONS_FAILED++))
printFailedTest "${label}" "to not be empty" "but got" "${expected}"
return
fi

((_ASSERTIONS_PASSED++))
}

function assertNotEquals() {
local expected="$1"
local actual="$2"
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/assert_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ function test_unsuccessful_assertEquals() {
"$(assertEquals "1" "2")"
}

function test_successful_assertEmpty() {
assertEquals "$SUCCESSFUL_EMPTY_MESSAGE" "$(assertEmpty "")"
}

function test_unsuccessful_assertEmpty() {
assertEquals\
"$(printFailedTest "Unsuccessful assertEmpty" "to be empty" "but got" "1")"\
"$(assertEmpty "1")"
}

function test_successful_assertNotEmpty() {
assertEquals "$SUCCESSFUL_EMPTY_MESSAGE" "$(assertNotEmpty "a_random_string")"
}

function test_unsuccessful_assertNotEmpty() {
assertEquals\
"$(printFailedTest "Unsuccessful assertNotEmpty" "to not be empty" "but got" "")"\
"$(assertNotEmpty "")"
}

function test_successful_assertNotEquals() {
assertEquals "$SUCCESSFUL_EMPTY_MESSAGE" "$(assertNotEquals "1" "2")"
}
Expand Down