diff --git a/sys/Makefile.include b/sys/Makefile.include index de8b66de52..f2238f8b4e 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -81,5 +81,9 @@ ifneq (,$(filter embunit,$(USEMODULE))) CFLAGS += -DOUTPUT=OUTPUT_TEXT else ifeq ($(OUTPUT),COMPILER) CFLAGS += -DOUTPUT=OUTPUT_COMPILER + else ifeq ($(OUTPUT),COLORTEXT) + CFLAGS += -DOUTPUT=OUTPUT_COLORTEXT + else ifeq ($(OUTPUT),COLOR) + CFLAGS += -DOUTPUT=OUTPUT_COLOR endif endif diff --git a/sys/embunit/ColorOutputter.c b/sys/embunit/ColorOutputter.c new file mode 100644 index 0000000000..3c489e1562 --- /dev/null +++ b/sys/embunit/ColorOutputter.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2015 Janos Kutscherauer + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#include +#include "ColorOutputter.h" +#include "ColorTextColors.h" + +static void ColorOutputter_printHeader(OutputterRef self) +{ + (void) self; +} + +static void ColorOutputter_printStartTest(OutputterRef self, TestRef test) +{ + (void) self; + (void) test; +} + +static void ColorOutputter_printEndTest(OutputterRef self, TestRef test) +{ + (void) self; + (void) test; +} + +static void ColorOutputter_printSuccessful(OutputterRef self, TestRef test, int runCount) +{ + (void) self; + (void) test; + (void) runCount; + printf(CGREEN "." CDEFAULT); +} + +static void ColorOutputter_printFailure(OutputterRef self, TestRef test, char *msg, int line, + char *file, int runCount) +{ + (void) self; + (void) runCount; + printf("\n" CRED "FAILED %s (%s:%d) %s" CDEFAULT "\n", Test_name(test), file, line, msg); +} + +void ColorOutputter_printStatistics(OutputterRef self, TestResultRef result) +{ + (void) self; + if (result->failureCount) { + printf("\n" BGRED SBOLD "FAILED" SDEFAULT " (%d of %d failed)", result->failureCount, + result->runCount); + } + else { + printf("\n" BGGREEN SBOLD "OK" SDEFAULT " (%d tests)", result->runCount); + } + printf(LINEFILL BGDEFAULT "\n"); +} + +static const OutputterImplement ColorOutputterImplement = { + (OutputterPrintHeaderFunction) ColorOutputter_printHeader, + (OutputterPrintStartTestFunction) ColorOutputter_printStartTest, + (OutputterPrintEndTestFunction) ColorOutputter_printEndTest, + (OutputterPrintSuccessfulFunction) ColorOutputter_printSuccessful, + (OutputterPrintFailureFunction) ColorOutputter_printFailure, + (OutputterPrintStatisticsFunction) ColorOutputter_printStatistics +}; + +static const Outputter ColorOutputter = { + (OutputterImplementRef) &ColorOutputterImplement +}; + +OutputterRef ColorOutputter_outputter(void) +{ + return (OutputterRef) &ColorOutputter; +} diff --git a/sys/embunit/ColorTextColors.h b/sys/embunit/ColorTextColors.h new file mode 100644 index 0000000000..335dccc0ab --- /dev/null +++ b/sys/embunit/ColorTextColors.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2015 Janos Kutscherauer + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * + * @author Janos Kutscherauer + */ +#ifndef __COLORTEXTCOLORS_H__ +#define __COLORTEXTCOLORS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Terminal color definitions + * C: text color + * + * CDEFAULT: default text color + * + * BG: background color + * + * BGDEFAULT: default background color + * + * S