最後活躍 1 month ago

修訂 9dfc760fa7dc7e6b2d3a1e5db3f19bc82de92021

test.sh 原始檔案
1#!/usr/bin/env bash
2
3# ============================================
4# Test Framework
5# ============================================
6
7TEST_PASS=0
8TEST_FAIL=0
9TEST_WARN=0
10
11function test::pass() {
12 local desc="$1"
13 printf " \033[1;32m✅\033[0m %s\n" "$desc"
14 (( TEST_PASS++ )) || true
15}
16
17function test::fail() {
18 local desc="$1"
19 printf " \033[1;31m❌\033[0m %s\n" "$desc"
20 (( TEST_FAIL++ )) || true
21}
22
23function test::warn() {
24 local desc="$1"
25 printf " \033[1;33m⚠️ \033[0m %s\n" "$desc"
26 (( TEST_WARN++ )) || true
27}
28
29function test::section() {
30 printf "\n \033[1;37m%s\033[0m\n" "$1"
31 printf " %s\n" "$(printf '─%.0s' {1..50})"
32}
33
34function test::reset() {
35 TEST_PASS=0
36 TEST_FAIL=0
37 TEST_WARN=0
38}
39
40function 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}