Skip to content

Commit a11af6f

Browse files
committed
Clean up tests with better output
1 parent fcb11b4 commit a11af6f

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

callable.sh

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
#!/bin/bash
2+
13
Test__MODULE_TEST_FILE="test.sh"
24

35
##################################################
4-
# This function is an alias for `ash self:help`.
6+
# This function will run the test.sh file located
7+
# in the module passed in
8+
#
9+
# @param $1: The name of the module to test. This
10+
# can either be the alias, or the full package
11+
# name.
512
#
6-
# @param $1: The name of the module to test
13+
# @returns $?: A 1 if any test has failed,
14+
# or a 0 if all tests have succeeded.
715
##################################################
816
Test__callable_main() {
917
# Params
@@ -13,7 +21,7 @@ Test__callable_main() {
1321
local module_directory="$(Ash__find_module_directory "$module_to_test" "1")"
1422
if [[ "$module_directory" = "" ]]; then
1523
Logger__error "Module $module_to_test does not exist"
16-
return
24+
return 1
1725
fi
1826

1927
# Loading in name of module, as if Ash core loaded it
@@ -24,15 +32,15 @@ Test__callable_main() {
2432
local test_file="$module_directory/$Test__MODULE_TEST_FILE"
2533
if [[ ! -f "$test_file" ]]; then
2634
Logger__error "There is no $Test__MODULE_TEST_FILE file in $module_to_test"
27-
return
35+
return 1
2836
fi
2937
. $test_file
3038

3139
# Loading in config
3240
local config="$module_directory/$Ash__CONFIG_FILENAME"
3341
if [[ ! -f "$config" ]]; then
3442
Logger__error "There is no $Ash__CONFIG_FILENAME file in $module_to_test"
35-
return
43+
return 1
3644
fi
3745
eval $(YamlParse__parse "$config" "Test_module_config_")
3846

@@ -45,27 +53,29 @@ Test__callable_main() {
4553

4654
# Call all methods
4755
local success="$Ash__TRUE"
48-
local to_find="$test_prefix"__
4956
for t in $tests
5057
do
58+
local to_find="$test_prefix"__
5159
local test_name=$(echo "$t" | sed "s/$to_find//g")
52-
Logger__alert "Running $test_name... " -n
53-
54-
test_output=$($t) # Can't make this local, as I need to capture the exit status!
60+
# Can't make this local, as I need to capture the exit status...
61+
# local itself has an exit status!
62+
test_output=$($t)
5563
if [[ $? -eq 0 ]]; then
5664
Test__print_green_check
65+
echo " $test_name"
5766
else
5867
success="$Ash__FALSE"
5968
Test__print_red_x
69+
echo " $test_name"
6070

6171
# Log output, if any
6272
if [[ "$test_output" != "" ]]; then
63-
echo -n " "
64-
Test__print_red_rightwards_arrow
65-
echo -n " "
66-
echo -ne '\033[1;31m'
67-
echo "${test_output}"
68-
echo -ne '\033[1;0m'
73+
local red="\033[1;31m"
74+
local clear="\033[1;0m"
75+
test_output="$(Test__print_red_rightwards_arrow) $red$test_output$clear"
76+
test_output="$(echo "${test_output}" | sed "s/^/ /g")"
77+
test_output="$(echo "${test_output}" | awk '/^/{if (M!=""){sub(""," ")}else{M=1}}{print}')"
78+
echo -e "$test_output"
6979
fi
7080
fi
7181
done

lib/util.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
##################################################
44
Test__print_green_check() {
55
echo -ne '\033[0;32m'
6-
echo -e '\xe2\x9c\x94'
6+
echo -ne '\xe2\x9c\x94'
77
echo -ne '\033[1;0m'
88
}
99

@@ -12,11 +12,13 @@ Test__print_green_check() {
1212
##################################################
1313
Test__print_red_x() {
1414
echo -ne '\033[1;31m'
15-
echo -e "\xe2\x9c\x98"
15+
echo -ne "\xe2\x9c\x98"
1616
echo -ne '\033[1;0m'
1717
}
1818

19-
# RIGHTWARDS ARROW
19+
##################################################
20+
# Returns a unicode 'RIGHTWARDS ARROW'
21+
##################################################
2022
Test__print_red_rightwards_arrow() {
2123
echo -ne '\033[1;31m'
2224
echo -ne "\xe2\x86\x92"

0 commit comments

Comments
 (0)