8787 **********************/
8888
8989/* The unit test files should not rely on anything below. */
90-
9190#include < stdarg.h>
9291#include < stdio.h>
9392#include < stdlib.h>
9493#include < string.h>
9594
96- #if defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__)
95+ #if ( defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__)) && !defined(__STRICT_ANSI__ )
9796 #define CUTEST_UNIX__ 1
9897 #include < errno.h>
9998 #include < unistd.h>
102101 #include < signal.h>
103102#endif
104103
105- #if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
104+ #if ( defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)) && !defined(__STRICT_ANSI__ )
106105 #define CUTEST_WIN__ 1
107106 #include < windows.h>
108107 #include < io.h>
109108#endif
110109
110+ #if defined(__STRICT_ANSI__)
111+ #define CUTEST_ANSI__ 1
112+ #endif
113+
111114#ifdef __cplusplus
112115 #include < exception>
113116#endif
@@ -162,16 +165,16 @@ test_print_in_color__(int color, const char* fmt, ...)
162165 {
163166 const char * col_str;
164167 switch (color) {
165- case CUTEST_COLOR_GREEN__: col_str = " \e [0;32m" ; break ;
166- case CUTEST_COLOR_RED__: col_str = " \e [0;31m" ; break ;
167- case CUTEST_COLOR_GREEN_INTENSIVE__: col_str = " \e [1;32m" ; break ;
168- case CUTEST_COLOR_RED_INTENSIVE__: col_str = " \e [1;30m" ; break ;
169- case CUTEST_COLOR_DEFAULT_INTENSIVE__: col_str = " \e [1m" ; break ;
170- default : col_str = " \e [0m" ; break ;
168+ case CUTEST_COLOR_GREEN__: col_str = " \033 [0;32m" ; break ;
169+ case CUTEST_COLOR_RED__: col_str = " \033 [0;31m" ; break ;
170+ case CUTEST_COLOR_GREEN_INTENSIVE__: col_str = " \033 [1;32m" ; break ;
171+ case CUTEST_COLOR_RED_INTENSIVE__: col_str = " \033 [1;30m" ; break ;
172+ case CUTEST_COLOR_DEFAULT_INTENSIVE__: col_str = " \033 [1m" ; break ;
173+ default : col_str = " \033 [0m" ; break ;
171174 }
172175 printf (" %s" , col_str);
173176 n = printf (" %s" , buffer);
174- printf (" \e [0m" );
177+ printf (" \033 [0m" );
175178 return n;
176179 }
177180#elif defined CUTEST_WIN__
@@ -352,9 +355,10 @@ test_do_run__(const struct test__* test)
352355 return (test_current_failures__ == 0 ) ? 0 : -1 ;
353356}
354357
358+ #if !defined(CUTEST_ANSI__)
355359/* Called if anything goes bad in cutest, or if the unit test ends in other
356360 * way then by normal returning from its function (e.g. exception or some
357- * abnormal child process termination). */
361+ * abnormal child process termination). On CUTEST_ANSI__ this is not used so we don't define it */
358362static void
359363test_error__ (const char * fmt, ...)
360364{
@@ -377,6 +381,7 @@ test_error__(const char* fmt, ...)
377381 printf (" \n " );
378382 }
379383}
384+ #endif
380385
381386/* Trigger the unit test. If possible (and not suppressed) it starts a child
382387 * process who calls test_do_run__(), otherwise it calls test_do_run__()
@@ -458,7 +463,7 @@ test_run__(const struct test__* test)
458463 failed = 1 ;
459464 }
460465
461- #else
466+ #else /* CUTEST_ANSI__ */
462467
463468 /* A platform where we don't know how to run child process. */
464469 failed = (test_do_run__ (test) != 0 );
@@ -650,4 +655,3 @@ main(int argc, char** argv)
650655
651656
652657#endif /* #ifndef CUTEST_H__ */
653-
0 commit comments