test.sh
· 977 B · Bash
Bruto
#!/usr/bin/env bash
# ============================================
# Test Framework
# ============================================
TEST_PASS=0
TEST_FAIL=0
TEST_WARN=0
function test::pass() {
local desc="$1"
printf " \033[1;32m✅\033[0m %s\n" "$desc"
(( TEST_PASS++ )) || true
}
function test::fail() {
local desc="$1"
printf " \033[1;31m❌\033[0m %s\n" "$desc"
(( TEST_FAIL++ )) || true
}
function test::warn() {
local desc="$1"
printf " \033[1;33m⚠️ \033[0m %s\n" "$desc"
(( TEST_WARN++ )) || true
}
function test::section() {
printf "\n \033[1;37m%s\033[0m\n" "$1"
printf " %s\n" "$(printf '─%.0s' {1..50})"
}
function test::reset() {
TEST_PASS=0
TEST_FAIL=0
TEST_WARN=0
}
function test::summary() {
printf "\n"
printf " \033[1;32m✅ %s passed\033[0m " "$TEST_PASS"
printf "\033[1;31m❌ %s failed\033[0m " "$TEST_FAIL"
printf "\033[1;33m⚠️ %s warnings\033[0m\n\n" "$TEST_WARN"
[[ "$TEST_FAIL" -eq 0 ]]
}
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # ============================================ |
| 4 | # Test Framework |
| 5 | # ============================================ |
| 6 | |
| 7 | TEST_PASS=0 |
| 8 | TEST_FAIL=0 |
| 9 | TEST_WARN=0 |
| 10 | |
| 11 | function test::pass() { |
| 12 | local desc="$1" |
| 13 | printf " \033[1;32m✅\033[0m %s\n" "$desc" |
| 14 | (( TEST_PASS++ )) || true |
| 15 | } |
| 16 | |
| 17 | function test::fail() { |
| 18 | local desc="$1" |
| 19 | printf " \033[1;31m❌\033[0m %s\n" "$desc" |
| 20 | (( TEST_FAIL++ )) || true |
| 21 | } |
| 22 | |
| 23 | function test::warn() { |
| 24 | local desc="$1" |
| 25 | printf " \033[1;33m⚠️ \033[0m %s\n" "$desc" |
| 26 | (( TEST_WARN++ )) || true |
| 27 | } |
| 28 | |
| 29 | function test::section() { |
| 30 | printf "\n \033[1;37m%s\033[0m\n" "$1" |
| 31 | printf " %s\n" "$(printf '─%.0s' {1..50})" |
| 32 | } |
| 33 | |
| 34 | function test::reset() { |
| 35 | TEST_PASS=0 |
| 36 | TEST_FAIL=0 |
| 37 | TEST_WARN=0 |
| 38 | } |
| 39 | |
| 40 | function test::summary() { |
| 41 | printf "\n" |
| 42 | printf " \033[1;32m✅ %s passed\033[0m " "$TEST_PASS" |
| 43 | printf "\033[1;31m❌ %s failed\033[0m " "$TEST_FAIL" |
| 44 | printf "\033[1;33m⚠️ %s warnings\033[0m\n\n" "$TEST_WARN" |
| 45 | [[ "$TEST_FAIL" -eq 0 ]] |
| 46 | } |