Enlightenment CVS committal Author : ningerso Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/bin Modified Files: Ewl_Test.h main.c Log Message: Add a quiet flag to unit tests to suppress stderr. Test for quiet flag and temporarily redirect stderr to /dev/null. Allow disabling the stderr redirect by passing the -d arg. Re-order unit test fields to eliminate holes. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/bin/Ewl_Test.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- Ewl_Test.h 5 Sep 2007 18:33:25 -0000 1.10 +++ Ewl_Test.h 11 Nov 2007 08:03:39 -0000 1.11 @@ -31,8 +31,9 @@ const char *name; /**< The test name */ int (*func)(char *buf, int len); /**< The test function */ - short status; /**< Test status */ char *failure_reason; /**< Test failure reason */ + short status; /**< Test status */ + unsigned int quiet: 1; /**< Boolean to disable stderr */ }; /** =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/bin/main.c,v retrieving revision 1.80 retrieving revision 1.81 diff -u -3 -r1.80 -r1.81 --- main.c 10 Nov 2007 19:17:23 -0000 1.80 +++ main.c 11 Nov 2007 08:03:39 -0000 1.81 @@ -18,6 +18,7 @@ #include <limits.h> #include <fcntl.h> #include <ctype.h> +#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <Ecore.h> @@ -26,6 +27,8 @@ #include <Ecore_Str.h> #include <zlib.h> +#define NULL_PATH "/dev/null" + #define MAIN_WIDTH 640 #define MAIN_HEIGHT 320 @@ -46,6 +49,8 @@ static void ewl_test_free(Ewl_Test *test); static int ewl_test_compare(Ewl_Test *test1, Ewl_Test *test2); static void ewl_test_print_tests(void); +static void ewl_test_stderr_enable(); +static void ewl_test_stderr_disable(); static void run_test_boxed(Ewl_Test *t); static void run_unit_test_boxed(Ewl_Test *t); @@ -87,6 +92,9 @@ static int window_count = 0; static int current_unit_test = 0; static int hide_passed = 0; +static int show_debug = 0; +static int saved_stderr = -1; + static Ecore_Timer *unit_test_timer = NULL; static Ewl_Test *current_test = NULL; @@ -121,6 +129,8 @@ } else if (!strncmp(argv[i], "-p", 2)) hide_passed = 1; + else if (!strncmp(argv[i], "-d", 2)) + show_debug = 1; else if (!strncmp(argv[i], "-all", 4)) all_tests = 1; else if (!strncmp(argv[i], "-unit", 5)) @@ -198,6 +208,49 @@ return ret; } +static void +ewl_test_stderr_disable() +{ + static int null_fd = -1; + + /* + * If stderr is already disabled, bail out early. + */ + if (show_debug || saved_stderr >= 0) + return; + + /* + * Open /dev/null the first time it's necessary, and maintain a + * reference to it for the lifetime of the test app. + */ + if (null_fd < 0) + null_fd = open(NULL_PATH, O_RDONLY); + + if (null_fd >= 0) + { + saved_stderr = dup(fileno(stderr)); + + if (dup2(null_fd, fileno(stderr)) < 0) + { + close(saved_stderr); + saved_stderr = -1; + } + } +} + +static void +ewl_test_stderr_enable() +{ + /* + * Return early if stderr is not disabled. + */ + if (show_debug || saved_stderr < 0) + return; + + dup2(saved_stderr, fileno(stderr)); + saved_stderr = -1; +} + static int ewl_test_cb_unit_test_timer(void *data) { @@ -214,7 +267,11 @@ stat = ewl_widget_name_find("statusbar"); ewl_statusbar_push(EWL_STATUSBAR(stat), (char *)unit_tests[current_unit_test].name); + if (unit_tests[current_unit_test].quiet) + ewl_test_stderr_disable(); val = unit_tests[current_unit_test].func(buf, sizeof(buf)); + if (unit_tests[current_unit_test].quiet) + ewl_test_stderr_enable(); ewl_statusbar_pop(EWL_STATUSBAR(stat)); tree = ewl_widget_name_find("unit_test_tree"); @@ -308,6 +365,9 @@ { int ret; + if (test->unit_tests[i].quiet) + ewl_test_stderr_disable(); + ret = test->unit_tests[i].func(buf, sizeof(buf)); if (!ret || !hide_passed) { @@ -318,6 +378,9 @@ buf[0] = '\0'; if (!ret) failures++; + + if (test->unit_tests[i].quiet) + ewl_test_stderr_enable(); } return failures; @@ -1274,6 +1337,3 @@ return i; } - - - ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs