]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: test-event-filter-*: Hide details of tests unless they fail
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 21 May 2021 17:23:57 +0000 (19:23 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 25 May 2021 14:31:48 +0000 (14:31 +0000)
This removes ~14k lines of output from test-lib run.

src/lib/test-event-filter-expr.c
src/lib/test-event-filter-merge.c
src/lib/test-event-filter-parser.c

index 0af8a982ebdfc5bc9a9a461861489f94d16e1dc7..444f16f25245fcd5c5c6f4597582a17ead0f74e7 100644 (file)
@@ -13,7 +13,8 @@
 #define SOURCE_FILENAME "blah.c"
 #define SOURCE_LINE 123
 
-static void check_expr(struct event *event,
+static void check_expr(const char *test_name,
+                      struct event *event,
                       struct event_filter *filter,
                       enum event_filter_log_type log_type,
                       bool expected)
@@ -24,36 +25,39 @@ static void check_expr(struct event *event,
 
        /* get at the expr inside the filter */
        expr = event_filter_get_expr_for_testing(filter, &num_queries);
-       test_assert(num_queries == 1); /* should have only one query */
+       test_out_quiet(t_strdup_printf("%s:num_queries==1", test_name),
+                      num_queries == 1); /* should have only one query */
 
        got = event_filter_query_match_eval(expr, event,
                                            SOURCE_FILENAME, SOURCE_LINE,
                                            log_type);
-       test_assert(got == expected);
+       test_out_quiet(t_strdup_printf("%s:got=expected", test_name),
+                      got == expected);
 }
 
 static void do_test_expr(const char *filter_string, struct event *event,
                         enum event_filter_log_type log_type,
                         bool expected)
 {
-       const char *error;
+       const char *test_name, *error;
 
-       test_begin(t_strdup_printf("%.*s log type + event {a=%s, b=%s} + filter '%s' (exp %s)",
-                                  3, /* truncate the type name to avoid CI seeing 'warning' messages */
-                                  event_filter_category_from_log_type(log_type),
-                                  event_find_field_recursive_str(event, "a"),
-                                  event_find_field_recursive_str(event, "b"),
-                                  filter_string,
-                                  expected ? "true" : "false"));
+       test_name = t_strdup_printf(
+               "%.*s log type + event {a=%s, b=%s} + filter '%s' (exp %s)",
+               3, /* truncate the type name to avoid CI seeing 'warning' messages */
+               event_filter_category_from_log_type(log_type),
+               event_find_field_recursive_str(event, "a"),
+               event_find_field_recursive_str(event, "b"),
+               filter_string,
+               expected ? "true" : "false");
 
        /* set up the filter expression */
        struct event_filter *filter = event_filter_create();
-       test_assert(event_filter_parse(filter_string, filter, &error) == 0);
+       test_out_quiet(t_strdup_printf("%s:event_filter_parse()", test_name),
+                      event_filter_parse(filter_string, filter, &error) == 0);
 
-       check_expr(event, filter, log_type, expected);
+       check_expr(test_name, event, filter, log_type, expected);
 
        event_filter_unref(&filter);
-       test_end();
 }
 
 static void test_unary_expr(struct event *event,
@@ -239,6 +243,8 @@ void test_event_filter_expr(void)
        };
        unsigned int i;
 
+       test_begin("event filter expressions");
        for (i = 0; i < N_ELEMENTS(log_types); i++)
                test_event_filter_expr_fields(log_types[i]);
+       test_end();
 }
index c29e53352af401a6784fa3d0cebd7a290970eacf..b520cf920f413e6584b85aa7ae6a8952902d73c7 100644 (file)
@@ -7,22 +7,25 @@
 static void filter_merge(const char *parent_str, const char *child_str)
 {
        struct event_filter *parent, *child;
-       const char *error;
+       const char *test_name, *error;
        string_t *out = t_str_new(128);
 
-       test_begin(t_strdup_printf("parent %s, child %s",
-                                  (parent_str == NULL) ? "NULL" : parent_str,
-                                  (child_str == NULL) ? "NULL" : child_str));
+       test_name = t_strdup_printf("parent %s, child %s",
+                                   (parent_str == NULL) ? "NULL" : parent_str,
+                                   (child_str == NULL) ? "NULL" : child_str);
 
        parent = event_filter_create();
        child = event_filter_create();
 
        /* prime the filters with an expression */
-       if (parent_str != NULL)
-               test_assert(event_filter_parse(parent_str, parent, &error) == 0);
-       if (child_str != NULL)
-               test_assert(event_filter_parse(child_str, child, &error) == 0);
-
+       if (parent_str != NULL) {
+               test_out_quiet(t_strdup_printf("%s:parent", test_name),
+                              event_filter_parse(parent_str, parent, &error) == 0);
+       }
+       if (child_str != NULL) {
+               test_out_quiet(t_strdup_printf("%s:child", test_name),
+                              event_filter_parse(child_str, child, &error) == 0);
+       }
        /* merge */
        event_filter_merge(parent, child);
 
@@ -32,8 +35,6 @@ static void filter_merge(const char *parent_str, const char *child_str)
 
        event_filter_unref(&parent);
        event_filter_unref(&child);
-
-       test_end();
 }
 
 void test_event_filter_merge(void)
@@ -56,9 +57,11 @@ void test_event_filter_merge(void)
        };
        unsigned int i, j;
 
+       test_begin("event filter merge");
        for (i = 0; i < N_ELEMENTS(inputs); i++) {
                for (j = 0; j < N_ELEMENTS(inputs); j++) T_BEGIN {
                        filter_merge(inputs[i], inputs[j]);
                } T_END;
        }
+       test_end();
 }
index 3cfb7fe461b0a2623a72f53ccde2b1a610d2421b..3dd265881e18acb5485e7f3bae2efe05a86d8ab5 100644 (file)
@@ -223,12 +223,11 @@ static void testcase(const char *name, const char *input, const char *exp,
        const char *error;
        int ret;
 
-       test_begin(t_strdup_printf("event filter parser: %s", name));
-
        filter = event_filter_create();
        ret = event_filter_parse(input, filter, &error);
 
-       test_assert((ret != 0) == fails);
+       test_out_quiet(name != NULL ? name : "filter parser",
+                      (ret != 0) == fails);
 
        if (ret == 0) {
                string_t *tmp = t_str_new(128);
@@ -243,20 +242,19 @@ static void testcase(const char *name, const char *input, const char *exp,
        }
 
        event_filter_unref(&filter);
-
-       test_end();
 }
 
 static void test_event_filter_parser_table(void)
 {
        unsigned int i;
 
+       test_begin("event filter parser: table");
        for (i = 0; i < N_ELEMENTS(tests); i++) T_BEGIN {
-               testcase("table",
-                        tests[i].input,
+               testcase(NULL, tests[i].input,
                         tests[i].output,
                         tests[i].fails);
        } T_END;
+       test_end();
 }
 
 static void test_event_filter_parser_categories(void)
@@ -266,6 +264,7 @@ static void test_event_filter_parser_categories(void)
        };
        unsigned int i;
 
+       test_begin("event filter parser: log type category");
        for (i = 0; i < N_ELEMENTS(cat_names); i++) T_BEGIN {
                string_t *str = t_str_new(128);
 
@@ -273,8 +272,9 @@ static void test_event_filter_parser_categories(void)
                str_append(str, cat_names[i]);
                str_append(str, ")");
 
-               testcase("log type category", str_c(str), str_c(str), FALSE);
+               testcase(NULL, str_c(str), str_c(str), FALSE);
        } T_END;
+       test_end();
 }
 
 static void
@@ -309,7 +309,7 @@ test_event_filter_parser_simple_nesting_helper(bool not1, bool not2,
                              expr2,
                              not2 ? ")" : "");
 
-       testcase("simple nesting", in, exp, FALSE);
+       testcase(NULL, in, exp, FALSE);
 }
 
 static void test_event_filter_parser_simple_nesting(void)
@@ -325,6 +325,7 @@ static void test_event_filter_parser_simple_nesting(void)
        unsigned int loc;
        unsigned int not;
 
+       test_begin("event filter parser: simple nesting");
        for (i = 0; i < N_ELEMENTS(whitespace); i++) {
                for (not = 0; not < 4; not++) {
                        const bool not1 = (not & 0x2) != 0;
@@ -349,6 +350,7 @@ static void test_event_filter_parser_simple_nesting(void)
                        } T_END;
                }
        }
+       test_end();
 }
 
 /*
@@ -435,6 +437,8 @@ static void test_event_filter_parser_generated(bool parens)
 {
        unsigned int w, v;
 
+       test_begin(t_strdup_printf("event filter parser: parser generated parens=%s",
+                                  parens ? "yes" : "no"));
        /* check that non-field keys work */
        for (w = 0; w < N_ELEMENTS(what_special); w++) {
                for (v = 0; v < N_ELEMENTS(values_single); v++)
@@ -518,11 +522,14 @@ static void test_event_filter_parser_generated(bool parens)
                                                    QUOTE_MUST);
                }
        }
+       test_end();
 }
 
 static void test_event_filter_parser_simple_invalid(void)
 {
-       testcase("simple invalid", "a=b=c", "", TRUE);
+       test_begin("event filter parser: simple invalid");
+       testcase(NULL, "a=b=c", "", TRUE);
+       test_end();
 }
 
 void test_event_filter_parser(void)