Skip to content

Commit 054a72f

Browse files
authored
feat: Add color to tests (#82)
1 parent b1dc726 commit 054a72f

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

test/TestFunction.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class TestFunction
3131
std::cout << "[";
3232
if (0 == (result = tests_[i]()))
3333
{
34-
std::cout << "passed";
34+
std::cout << "\33[32mpassed\33[0m";
3535
}
3636
else
3737
{
38-
std::cout << "FAILED";
38+
std::cout << "\33[31mFAILED\33[0m";
3939
}
4040

4141
std::cout << "] " << tests_[i].name << std::endl;

test/run_all_tests.sh

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/bin/sh
22

3+
GREEN='\x1B[0;32m'
4+
RED='\x1B[0;31m'
5+
YELLOW='\x1B[0;33m'
6+
DEFAULT='\x1B[0;0m'
7+
38
all_tests_result=0
49

510
if [ 0 -eq $all_tests_result ]; then
6-
echo && echo 'Compiling and running Notecard Test Suite...'
11+
echo && echo -e "${YELLOW}Compiling and running Notecard Test Suite...${DEFAULT}"
712
g++ -fprofile-arcs -ftest-coverage -Wall -Wextra -Werror -Wpedantic -std=c++11 -O0 -g \
813
src/Notecard.cpp \
914
test/Notecard.test.cpp \
@@ -19,9 +24,9 @@ if [ 0 -eq $all_tests_result ]; then
1924
valgrind --leak-check=full --error-exitcode=66 ./a.out
2025
tests_result=$?
2126
if [ 0 -eq ${tests_result} ]; then
22-
echo 'Notecard tests passed!'
27+
echo -e "${GREEN}Notecard tests passed!${DEFAULT}"
2328
else
24-
echo "Notecard tests failed!"
29+
echo -e "${RED}Notecard tests failed!${DEFAULT}"
2530
fi
2631
all_tests_result=$((all_tests_result+tests_result))
2732
else
@@ -30,7 +35,7 @@ if [ 0 -eq $all_tests_result ]; then
3035
fi
3136

3237
if [ 0 -eq $all_tests_result ]; then
33-
echo && echo 'Compiling and running NoteI2c_Arduino Test Suite (no flags)...'
38+
echo && echo -e "${YELLOW}Compiling and running NoteI2c_Arduino Test Suite (no flags)...${DEFAULT}"
3439
g++ -fprofile-arcs -ftest-coverage -Wall -Wextra -Werror -Wpedantic -std=c++11 -O0 -g \
3540
src/NoteI2c_Arduino.cpp \
3641
test/NoteI2c_Arduino.test.cpp \
@@ -43,9 +48,9 @@ if [ 0 -eq $all_tests_result ]; then
4348
valgrind --leak-check=full --error-exitcode=66 ./a.out
4449
tests_result=$?
4550
if [ 0 -eq ${tests_result} ]; then
46-
echo 'NoteI2c_Arduino tests passed!'
51+
echo -e "${GREEN}NoteI2c_Arduino tests passed!${DEFAULT}"
4752
else
48-
echo "NoteI2c_Arduino tests failed!"
53+
echo -e "${RED}NoteI2c_Arduino tests failed!${DEFAULT}"
4954
fi
5055
all_tests_result=$((all_tests_result+tests_result))
5156
else
@@ -54,7 +59,7 @@ if [ 0 -eq $all_tests_result ]; then
5459
fi
5560

5661
if [ 0 -eq $all_tests_result ]; then
57-
echo && echo 'Compiling and running NoteI2c_Arduino Test Suite (-DWIRE_HAS_END)...'
62+
echo && echo -e "${YELLOW}Compiling and running NoteI2c_Arduino Test Suite (-DWIRE_HAS_END)...${DEFAULT}"
5863
g++ -fprofile-arcs -ftest-coverage -Wall -Wextra -Werror -Wpedantic -std=c++11 -O0 -g \
5964
src/NoteI2c_Arduino.cpp \
6065
test/NoteI2c_Arduino.test.cpp \
@@ -68,9 +73,9 @@ if [ 0 -eq $all_tests_result ]; then
6873
valgrind --leak-check=full --error-exitcode=66 ./a.out
6974
tests_result=$?
7075
if [ 0 -eq ${tests_result} ]; then
71-
echo 'NoteI2c_Arduino tests passed! (-DWIRE_HAS_END)'
76+
echo -e "${GREEN}NoteI2c_Arduino tests passed! (-DWIRE_HAS_END)${DEFAULT}"
7277
else
73-
echo "NoteI2c_Arduino tests failed!"
78+
echo -e "${RED}NoteI2c_Arduino tests failed!${DEFAULT}"
7479
fi
7580
all_tests_result=$((all_tests_result+tests_result))
7681
else
@@ -79,7 +84,7 @@ if [ 0 -eq $all_tests_result ]; then
7984
fi
8085

8186
if [ 0 -eq $all_tests_result ]; then
82-
echo && echo 'Compiling and running NoteLog_Arduino Test Suite...'
87+
echo && echo -e "${YELLOW}Compiling and running NoteLog_Arduino Test Suite...${DEFAULT}"
8388
g++ -fprofile-arcs -ftest-coverage -Wall -Wextra -Werror -Wpedantic -std=c++11 -O0 -g \
8489
src/NoteLog_Arduino.cpp \
8590
test/NoteLog_Arduino.test.cpp \
@@ -91,9 +96,9 @@ if [ 0 -eq $all_tests_result ]; then
9196
valgrind --leak-check=full --error-exitcode=66 ./a.out
9297
tests_result=$?
9398
if [ 0 -eq ${tests_result} ]; then
94-
echo 'NoteLog_Arduino tests passed!'
99+
echo -e "${GREEN}NoteLog_Arduino tests passed!${DEFAULT}"
95100
else
96-
echo "NoteLog_Arduino tests failed!"
101+
echo -e "${RED}NoteLog_Arduino tests failed!${DEFAULT}"
97102
fi
98103
all_tests_result=$((all_tests_result+tests_result))
99104
else
@@ -102,7 +107,7 @@ if [ 0 -eq $all_tests_result ]; then
102107
fi
103108

104109
if [ 0 -eq $all_tests_result ]; then
105-
echo && echo 'Compiling and running NoteSerial_Arduino Test Suite...'
110+
echo && echo -e "${YELLOW}Compiling and running NoteSerial_Arduino Test Suite...${DEFAULT}"
106111
g++ -fprofile-arcs -ftest-coverage -Wall -Wextra -Werror -Wpedantic -std=c++11 -O0 -g \
107112
src/NoteSerial_Arduino.cpp \
108113
test/NoteSerial_Arduino.test.cpp \
@@ -114,9 +119,9 @@ if [ 0 -eq $all_tests_result ]; then
114119
valgrind --leak-check=full --error-exitcode=66 ./a.out
115120
tests_result=$?
116121
if [ 0 -eq ${tests_result} ]; then
117-
echo 'NoteSerial_Arduino tests passed!'
122+
echo -e "${GREEN}NoteSerial_Arduino tests passed!${DEFAULT}"
118123
else
119-
echo "NoteSerial_Arduino tests failed!"
124+
echo -e "${RED}NoteSerial_Arduino tests failed!${DEFAULT}"
120125
fi
121126
all_tests_result=$((all_tests_result+tests_result))
122127
else
@@ -126,7 +131,7 @@ fi
126131

127132
# Print summary statement
128133
if [ 0 -eq ${all_tests_result} ]; then
129-
echo && echo 'All tests have passed!' && echo
134+
echo && echo -e "${GREEN}All tests have passed!${DEFAULT}" && echo
130135

131136
# Run coverage if available
132137
if [ $(which lcov) ]; then
@@ -140,14 +145,14 @@ if [ 0 -eq ${all_tests_result} ]; then
140145
--output-file ./coverage/lcov.info \
141146
--rc lcov_branch_coverage=1
142147
if [ ! -f "./coverage/lcov.info" ]; then
143-
echo "COVERAGE REPORT NOT PRODUCED!!!";
148+
echo -e "${YELLOW}COVERAGE REPORT NOT PRODUCED!!!${DEFAULT}";
144149
all_tests_result=998
145150
else
146151
lcov --summary ./coverage/lcov.info
147152
fi
148153
fi
149154
else
150-
echo && echo 'TESTS FAILED!!!'
155+
echo && echo -e "${RED}TESTS FAILED!!!${DEFAULT}"
151156
fi
152157

153158
# Clean testing artifacts

0 commit comments

Comments
 (0)