Skip to content

Commit 6e37702

Browse files
committed
Add test summary
1 parent 6be90b0 commit 6e37702

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

beginner/tests/test_helpers.sh

+26-13
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@ fi
1313

1414
source "$HELPERS_PATH"
1515

16+
# Array to store test results
17+
declare -a TEST_RESULTS
18+
1619
# Function to handle test failures
1720
fail_test() {
18-
echo -e "\033[31m\033[1m$1: FAIL\033[0m"
19-
exit 1
21+
TEST_RESULTS+=("$1: \033[31m\033[1mFAIL\033[0m")
22+
}
23+
24+
# Function to handle test successes
25+
pass_test() {
26+
TEST_RESULTS+=("$1: \033[32m\033[1mPASS\033[0m")
2027
}
2128

2229
# Test reset function
2330
echo "Testing reset function..."
2431
reset_output=$(reset)
25-
if [[ "$reset_output" == *"restore clean working directory"* ]]; then
26-
echo -e "\033[32m\033[1mreset function: PASS\033[0m"
32+
if [[ "$reset_output" == *"Here we go again!"* ]]; then
33+
pass_test "reset function"
2734
else
2835
fail_test "reset function"
2936
fi
@@ -32,7 +39,7 @@ fi
3239
echo "Testing get_default_branch_name function..."
3340
default_branch=$(get_default_branch_name)
3441
if [[ "$default_branch" == "main" || "$default_branch" == "master" ]]; then
35-
echo -e "\033[32m\033[1mget_default_branch_name function: PASS\033[0m"
42+
pass_test "get_default_branch_name function"
3643
else
3744
fail_test "get_default_branch_name function"
3845
fi
@@ -41,7 +48,7 @@ fi
4148
echo "Testing init_exercise function..."
4249
init_exercise
4350
if [[ -d "$SCRIPT_DIR/../../../beginners_git" ]]; then
44-
echo -e "\033[32m\033[1minit_exercise function: PASS\033[0m"
51+
pass_test "init_exercise function"
4552
else
4653
fail_test "init_exercise function"
4754
fi
@@ -50,7 +57,7 @@ fi
5057
echo "Testing init_repo_empty_schedule function..."
5158
init_repo_empty_schedule
5259
if [[ -f "$SCRIPT_DIR/../../../beginners_git/conference_planning/conference_schedule.txt" ]]; then
53-
echo -e "\033[32m\033[1minit_repo_empty_schedule function: PASS\033[0m"
60+
pass_test "init_repo_empty_schedule function"
5461
else
5562
fail_test "init_repo_empty_schedule function"
5663
fi
@@ -59,7 +66,7 @@ fi
5966
echo "Testing init_simple_repo function..."
6067
init_simple_repo
6168
if [[ -d "$SCRIPT_DIR/../../../beginners_git/conference_planning/.git" ]]; then
62-
echo -e "\033[32m\033[1minit_simple_repo function: PASS\033[0m"
69+
pass_test "init_simple_repo function"
6370
else
6471
fail_test "init_simple_repo function"
6572
fi
@@ -68,7 +75,7 @@ fi
6875
echo "Testing init_simple_repo_remote function..."
6976
init_simple_repo_remote
7077
if [[ -d "$SCRIPT_DIR/../../../beginners_git/conference_planning_remote/.git" ]]; then
71-
echo -e "\033[32m\033[1minit_simple_repo_remote function: PASS\033[0m"
78+
pass_test "init_simple_repo_remote function"
7279
else
7380
fail_test "init_simple_repo_remote function"
7481
fi
@@ -77,7 +84,7 @@ fi
7784
echo "Testing init_repo function..."
7885
init_repo
7986
if [[ -d "$SCRIPT_DIR/../../../beginners_git/conference_planning/.git" ]]; then
80-
echo -e "\033[32m\033[1minit_repo function: PASS\033[0m"
87+
pass_test "init_repo function"
8188
else
8289
fail_test "init_repo function"
8390
fi
@@ -86,7 +93,7 @@ fi
8693
echo "Testing init_repo_remote function..."
8794
init_repo_remote
8895
if [[ -d "$SCRIPT_DIR/../../../beginners_git/conference_planning/.git" && -d "$SCRIPT_DIR/../../../beginners_git/conference_planning_remote/" ]]; then
89-
echo -e "\033[32m\033[1minit_repo_remote function: PASS\033[0m"
96+
pass_test "init_repo_remote function"
9097
else
9198
fail_test "init_repo_remote function"
9299
fi
@@ -95,7 +102,13 @@ fi
95102
echo "Testing commit_to_remote_by_third_party function..."
96103
commit_to_remote_by_third_party
97104
if [[ -d "$SCRIPT_DIR/../../../beginners_git/conference_planning/.git" && -d "$SCRIPT_DIR/../../../beginners_git/conference_planning_remote/" ]]; then
98-
echo -e "\033[32m\033[1mcommit_to_remote_by_third_party function: PASS\033[0m"
105+
pass_test "commit_to_remote_by_third_party function"
99106
else
100107
fail_test "commit_to_remote_by_third_party function"
101-
fi
108+
fi
109+
110+
# Print summary
111+
echo -e "\n\033[1mTest Summary:\033[0m"
112+
for result in "${TEST_RESULTS[@]}"; do
113+
echo -e "$result"
114+
done

0 commit comments

Comments
 (0)