diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..d48eca1f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*.sh] +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +charset = utf-8 + +trim_trailing_whitespace = true \ No newline at end of file diff --git a/README.md b/README.md index 239d04a5..cdb52244 100644 --- a/README.md +++ b/README.md @@ -49,5 +49,5 @@ To update a git-submodule is as simple as: ### Run test from the library ```bash -./bashunit ./tests/**/* +./bashunit ./tests/**/*.sh ``` \ No newline at end of file diff --git a/example/tools/bashunit b/example/tools/bashunit index c3b63b7a..bc35c410 160000 --- a/example/tools/bashunit +++ b/example/tools/bashunit @@ -1 +1 @@ -Subproject commit c3b63b7a97347a11318a0cc7fbbe1e2ec53df977 +Subproject commit bc35c4108b60102a7ea427762c6000bec3024467 diff --git a/src/assert.sh b/src/assert.sh index da6bdc4d..1c6ac611 100755 --- a/src/assert.sh +++ b/src/assert.sh @@ -3,6 +3,7 @@ export TEST=true export assertEquals +export assertContains TOTAL_TESTS=0 FAILED=false @@ -37,6 +38,23 @@ assertEquals() { printf "✔️ ${COLOR_PASSED}Passed${COLOR_DEFAULT}: %s\\n" "$label" fi } +assertContains() { + local expected="$1" + local actual="$2" + local label="${3:-$(transformTestFunctionName ${FUNCNAME[1]})}" + + case "$actual" in + *"$expected"*) + ((TOTAL_TESTS++)) + printf "✔️ ${COLOR_PASSED}Passed${COLOR_DEFAULT}: %s\\n" "$label" + ;; + *) + FAILED=true + printf "❌ ${COLOR_FAILED}Failed${COLOR_DEFAULT}: %s\\n Expected '%s'\\n to contain '%s'\\n" "$label" "$actual" "$expected" + exit 1 + ;; + esac +} renderResult() { echo "" diff --git a/tests/unit/assert_test.sh b/tests/unit/assert_test.sh index af04fd89..bbee63e8 100644 --- a/tests/unit/assert_test.sh +++ b/tests/unit/assert_test.sh @@ -13,3 +13,13 @@ function test_unsuccessful_assertEquals() { function testCamelCase() { assertEquals "$(printf "✔️ ${COLOR_PASSED}Passed${COLOR_DEFAULT}: CamelCase")" "$(assertEquals "1" "1")" } + +function test_successful_assertContains() { + assertEquals "$(printf "✔️ ${COLOR_PASSED}Passed${COLOR_DEFAULT}: Successful assertContains")" "$(assertContains "Linux" "GNU/Linux")" +} + +function test_unsuccessful_assertContains() { + assertEquals "$(printf "❌ ${COLOR_FAILED}Failed${COLOR_DEFAULT}: Unsuccessful assertContains + Expected 'GNU/Linux' + to contain 'Unix'")" "$(assertContains "Unix" "GNU/Linux")" +}