[gjs: 1/6] tests: Use assertions in coverage tests



commit cdf89118a39354a6f3415a149995fa217e7a67a3
Author: Philip Chimento <philip chimento gmail com>
Date:   Tue Oct 3 21:11:40 2017 -0700

    tests: Use assertions in coverage tests
    
    This gives better messages when trying to debug failing tests, since GLib
    will print out the expected and actual values in its assertion messages.
    Otherwise you have to use a debugger to find which values are incorrect.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788166

 test/gjs-test-coverage.cpp | 399 +++++++++++++++++++--------------------------
 1 file changed, 168 insertions(+), 231 deletions(-)
---
diff --git a/test/gjs-test-coverage.cpp b/test/gjs-test-coverage.cpp
index 5ce5d57..171a1c4 100644
--- a/test/gjs-test-coverage.cpp
+++ b/test/gjs-test-coverage.cpp
@@ -40,7 +40,7 @@
 
 #include "gjs/coverage.h"
 #include "gjs/coverage-internal.h"
-
+#include "gjs/jsapi-util.h"
 #include "gjs-test-utils.h"
 
 typedef struct _GjsCoverageFixture {
@@ -215,72 +215,41 @@ eval_script_and_get_coverage_data(GjsContext  *context,
                                                   coverage_data_length_return);
 }
 
-static bool
-coverage_data_contains_value_for_key(const char *data,
-                                     const char *key,
-                                     const char *value)
+static void
+assert_coverage_data_contains_value_for_key(const char *data,
+                                            const char *key,
+                                            const char *value)
 {
     const char *sf_line = line_starting_with(data, key);
 
-    if (!sf_line)
-        return false;
+    g_assert_nonnull(sf_line);
 
-    return strncmp(&sf_line[strlen(key)],
-                   value,
-                   strlen(value)) == 0;
+    GjsAutoChar actual = g_strndup(&sf_line[strlen(key)], strlen(value));
+    g_assert_cmpstr(value, ==, actual);
 }
 
-typedef bool (*CoverageDataMatchFunc) (const char *value,
-                                       gpointer    user_data);
-
-static bool
-coverage_data_matches_value_for_key_internal(const char            *line,
-                                             const char            *key,
-                                             CoverageDataMatchFunc  match,
-                                             gpointer               user_data)
-{
-    return (*match)(line, user_data);
-}
+using CoverageDataMatchFunc = void (*)(const char *value,
+                                       const void *user_data);
 
-static bool
-coverage_data_matches_value_for_key(const char            *data,
-                                    const char            *key,
-                                    CoverageDataMatchFunc  match,
-                                    gpointer               user_data)
+static void
+assert_coverage_data_matches_value_for_key(const char            *data,
+                                           const char            *key,
+                                           CoverageDataMatchFunc  match,
+                                           const void            *user_data)
 {
     const char *line = line_starting_with(data, key);
 
-    if (!line)
-        return false;
-
-    return coverage_data_matches_value_for_key_internal(line, key, match, user_data);
-}
-
-static bool
-coverage_data_matches_any_value_for_key(const char            *data,
-                                        const char            *key,
-                                        CoverageDataMatchFunc  match,
-                                        gpointer               user_data)
-{
-    data = line_starting_with(data, key);
-
-    while (data) {
-        if (coverage_data_matches_value_for_key_internal(data, key, match, user_data))
-            return true;
-
-        data = line_starting_with(data + 1, key);
-    }
-
-    return false;
+    g_assert_nonnull(line);
+    (*match)(line, user_data);
 }
 
-static bool
-coverage_data_matches_values_for_key(const char            *data,
-                                     const char            *key,
-                                     gsize                  n,
-                                     CoverageDataMatchFunc  match,
-                                     gpointer               user_data,
-                                     gsize                  data_size)
+static void
+assert_coverage_data_matches_values_for_key(const char            *data,
+                                            const char            *key,
+                                            size_t                 n,
+                                            CoverageDataMatchFunc  match,
+                                            const void            *user_data,
+                                            size_t                 data_size)
 {
     const char *line = line_starting_with (data, key);
     /* Keep matching. If we fail to match one of them then
@@ -288,8 +257,7 @@ coverage_data_matches_values_for_key(const char            *data,
     char *data_iterator = (char *) user_data;
 
     while (line && n > 0) {
-        if (!coverage_data_matches_value_for_key_internal(line, key, match, (gpointer) data_iterator))
-            return false;
+        (*match)(line, data_iterator);
 
         line = line_starting_with(line + 1, key);
         --n;
@@ -297,10 +265,7 @@ coverage_data_matches_values_for_key(const char            *data,
     }
 
     /* If n is zero then we've found all available matches */
-    if (n == 0)
-        return true;
-
-    return false;
+    g_assert_cmpuint(n, ==, 0);
 }
 
 /* A simple wrapper around gjs_coverage_new */
@@ -480,9 +445,8 @@ test_expected_source_file_name_written_to_coverage_data(gpointer      fixture_da
     char *expected_source_filename =
         get_output_path_for_script_on_disk(fixture->tmp_js_script, fixture->lcov_output_dir);
 
-    g_assert(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                  "SF:",
-                                                  expected_source_filename));
+    assert_coverage_data_contains_value_for_key(coverage_data_contents, "SF:",
+                                                expected_source_filename);
 
     g_free(expected_source_filename);
     g_free(coverage_data_contents);
@@ -526,9 +490,8 @@ test_expected_entry_not_written_for_nonexistent_file(gpointer      fixture_data,
     g_log_set_always_fatal(old_flags);
     g_log_set_default_handler(old_log_func, NULL);
 
-    g_assert(!(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                    "SF:",
-                                                    "doesnotexist")));
+    const char *sf_line = line_starting_with(coverage_data_contents, "SF:");
+    g_assert_null(sf_line);
 
     g_free(coverage_data_contents);
     g_object_unref(doesnotexist);
@@ -546,11 +509,11 @@ typedef struct _BranchLineData {
     BranchTaken taken;
 } BranchLineData;
 
-static bool
+static void
 branch_at_line_should_be_taken(const char *line,
-                               gpointer user_data)
+                               const void *user_data)
 {
-    BranchLineData *branch_data = (BranchLineData *) user_data;
+    auto branch_data = static_cast<const BranchLineData *>(user_data);
     int line_no, branch_id, block_no, hit_count_num, nmatches;
     char hit_count[20];  /* can hold maxint64 (19 digits) + nul terminator */
 
@@ -558,12 +521,7 @@ branch_at_line_should_be_taken(const char *line,
     line += 5;
 
     nmatches = sscanf(line, "%i,%i,%i,%19s", &line_no, &block_no, &branch_id, hit_count);
-    if (nmatches != 4) {
-        if (errno != 0)
-            g_error("sscanf: %s", strerror(errno));
-        else
-            g_error("sscanf: only matched %i", nmatches);
-    }
+    g_assert_cmpint(nmatches, ==, 4);
 
     /* Determine the branch hit count. It will be either:
      * > -1 if the line containing the branch was never executed, or
@@ -576,30 +534,22 @@ branch_at_line_should_be_taken(const char *line,
     else
         hit_count_num = atoi(hit_count);
 
-    const bool hit_correct_branch_line =
-        branch_data->expected_branch_line == line_no;
-    const bool hit_correct_branch_id =
-        branch_data->expected_id == branch_id;
-    bool branch_correctly_taken_or_not_taken;
+    g_assert_cmpint(line_no, ==, branch_data->expected_branch_line);
+    g_assert_cmpint(branch_id, ==, branch_data->expected_id);
 
     switch (branch_data->taken) {
     case NOT_EXECUTED:
-        branch_correctly_taken_or_not_taken = hit_count_num == -1;
+        g_assert_cmpint(hit_count_num, ==, -1);
         break;
     case NOT_TAKEN:
-        branch_correctly_taken_or_not_taken = hit_count_num == 0;
+        g_assert_cmpint(hit_count_num, ==, 0);
         break;
     case TAKEN:
-        branch_correctly_taken_or_not_taken = hit_count_num > 0;
+        g_assert_cmpint(hit_count_num, >, 0);
         break;
     default:
         g_assert_not_reached();
     };
-
-    return hit_correct_branch_line &&
-           hit_correct_branch_id &&
-           branch_correctly_taken_or_not_taken;
-
 }
 
 static void
@@ -632,19 +582,16 @@ test_single_branch_coverage_written_to_coverage_data(gpointer      fixture_data,
 
     /* There are two possible branches here, the second should be taken
      * and the first should not have been */
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "BRDA:",
-                                                  expected_branches_len,
-                                                  branch_at_line_should_be_taken,
-                                                  (gpointer) expected_branches,
-                                                  sizeof(BranchLineData)));
-
-    g_assert(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                  "BRF:",
-                                                  "2"));
-    g_assert(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                  "BRH:",
-                                                  "1"));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "BRDA:",
+                                                expected_branches_len,
+                                                branch_at_line_should_be_taken,
+                                                expected_branches,
+                                                sizeof(BranchLineData));
+
+    assert_coverage_data_contains_value_for_key(coverage_data_contents,
+                                                "BRF:", "2");
+    assert_coverage_data_contains_value_for_key(coverage_data_contents,
+                                                "BRH:", "1");
     g_free(coverage_data_contents);
 }
 
@@ -688,12 +635,11 @@ test_multiple_branch_coverage_written_to_coverage_data(gpointer      fixture_dat
 
     /* There are two possible branches here, the second should be taken
      * and the first should not have been */
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "BRDA:",
-                                                  expected_branches_len,
-                                                  branch_at_line_should_be_taken,
-                                                  (gpointer) expected_branches,
-                                                  sizeof(BranchLineData)));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "BRDA:",
+                                                expected_branches_len,
+                                                branch_at_line_should_be_taken,
+                                                expected_branches,
+                                                sizeof(BranchLineData));
     g_free(coverage_data_contents);
 }
 
@@ -738,16 +684,40 @@ test_branches_for_multiple_case_statements_fallthrough(gpointer      fixture_dat
 
     /* There are two possible branches here, the second should be taken
      * and the first should not have been */
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "BRDA:",
-                                                  expected_branches_len,
-                                                  branch_at_line_should_be_taken,
-                                                  (gpointer) expected_branches,
-                                                  sizeof(BranchLineData)));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "BRDA:",
+                                                expected_branches_len,
+                                                branch_at_line_should_be_taken,
+                                                expected_branches,
+                                                sizeof(BranchLineData));
     g_free(coverage_data_contents);
 }
 
 static void
+any_line_matches_not_executed_branch(const char *data)
+{
+    const char *line = line_starting_with(data, "BRDA:");
+
+    while (line) {
+        int line_no, branch_id, block_no;
+        char hit_count;
+
+        /* Advance past "BRDA:" */
+        line += 5;
+
+        int nmatches = sscanf(line, "%i,%i,%i,%c", &line_no, &block_no,
+                              &branch_id, &hit_count);
+        g_assert_cmpint(nmatches, ==, 4);
+
+        if (line_no == 3 && branch_id == 0 && hit_count == '-')
+            return;
+
+        line = line_starting_with(line + 1, "BRDA:");
+    }
+
+    g_assert_not_reached();
+}
+
+static void
 test_branch_not_hit_written_to_coverage_data(gpointer      fixture_data,
                                              gconstpointer user_data)
 {
@@ -771,23 +741,15 @@ test_branch_not_hit_written_to_coverage_data(gpointer      fixture_data,
                                           fixture->lcov_output,
                                           NULL);
 
-    const BranchLineData expected_branch = {
-        3, 0, NOT_EXECUTED
-    };
-
-    g_assert(coverage_data_matches_any_value_for_key(coverage_data_contents,
-                                                     "BRDA:",
-                                                     branch_at_line_should_be_taken,
-                                                     (gpointer) &expected_branch));
+    any_line_matches_not_executed_branch(coverage_data_contents);
     g_free(coverage_data_contents);
 }
 
-static bool
+static void
 has_function_name(const char *line,
-                  gpointer    user_data)
+                  const void *user_data)
 {
-    /* User data is const char ** */
-    const char *expected_function_name = *((const char **) user_data);
+    const char *expected_function_name = *(static_cast<const char * const *>(user_data));
 
     /* Advance past "FN:" */
     line += 3;
@@ -796,9 +758,8 @@ has_function_name(const char *line,
     while (*(line - 1) != ',')
         ++line;
 
-    return strncmp(line,
-                   expected_function_name,
-                   strlen(expected_function_name)) == 0;
+    GjsAutoChar actual = g_strndup(line, strlen(expected_function_name));
+    g_assert_cmpstr(actual, ==, expected_function_name);
 }
 
 static void
@@ -829,28 +790,25 @@ test_function_names_written_to_coverage_data(gpointer      fixture_data,
     const gsize expected_function_names_len = G_N_ELEMENTS(expected_function_names);
 
     /* Just expect that we've got an FN matching out expected function names */
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "FN:",
-                                                  expected_function_names_len,
-                                                  has_function_name,
-                                                  (gpointer) expected_function_names,
-                                                  sizeof(const char *)));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "FN:",
+                                                expected_function_names_len,
+                                                has_function_name,
+                                                expected_function_names,
+                                                sizeof(const char *));
     g_free(coverage_data_contents);
 }
 
-static bool
+static void
 has_function_line(const char *line,
-                  gpointer    user_data)
+                  const void *user_data)
 {
-    /* User data is const char ** */
-    const char *expected_function_line = *((const char **) user_data);
+    const char *expected_function_line = *(static_cast<const char * const *>(user_data));
 
     /* Advance past "FN:" */
     line += 3;
 
-    return strncmp(line,
-                   expected_function_line,
-                   strlen(expected_function_line)) == 0;
+    GjsAutoChar actual = g_strndup(line, strlen(expected_function_line));
+    g_assert_cmpstr(actual, ==, expected_function_line);
 }
 
 static void
@@ -872,18 +830,17 @@ test_function_lines_written_to_coverage_data(gpointer      fixture_data,
                                           fixture->tmp_js_script,
                                           fixture->lcov_output,
                                           NULL);
-    const char * expected_function_lines[] = {
+    const char * const expected_function_lines[] = {
         "1",
         "3"
     };
     const gsize expected_function_lines_len = G_N_ELEMENTS(expected_function_lines);
 
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "FN:",
-                                                  expected_function_lines_len,
-                                                  has_function_line,
-                                                  (gpointer) expected_function_lines,
-                                                  sizeof(const char *)));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "FN:",
+                                                expected_function_lines_len,
+                                                has_function_line,
+                                                expected_function_lines,
+                                                sizeof(const char *));
     g_free(coverage_data_contents);
 }
 
@@ -892,11 +849,11 @@ typedef struct _FunctionHitCountData {
     unsigned int hit_count_minimum;
 } FunctionHitCountData;
 
-static bool
+static void
 hit_count_is_more_than_for_function(const char *line,
-                                    gpointer   user_data)
+                                    const void *user_data)
 {
-    FunctionHitCountData *data = (FunctionHitCountData *) user_data;
+    auto data = static_cast<const FunctionHitCountData *>(user_data);
     char                 *detected_function = NULL;
     unsigned int         hit_count;
     size_t max_buf_size;
@@ -908,20 +865,12 @@ hit_count_is_more_than_for_function(const char *line,
     max_buf_size = strcspn(line, "\n");
     detected_function = g_new(char, max_buf_size + 1);
     nmatches = sscanf(line, "%u,%s", &hit_count, detected_function);
-    if (nmatches != 2) {
-        if (errno != 0)
-            g_error("sscanf: %s", strerror(errno));
-        else
-            g_error("sscanf: only matched %d", nmatches);
-    }
+    g_assert_cmpint(nmatches, ==, 2);
 
-    const bool function_name_match = g_strcmp0(data->function, detected_function) == 0;
-    const bool hit_count_more_than = hit_count >= data->hit_count_minimum;
+    g_assert_cmpstr(data->function, ==, detected_function);
+    g_assert_cmpuint(hit_count, >=, data->hit_count_minimum);
 
     g_free(detected_function);
-
-    return function_name_match &&
-           hit_count_more_than;
 }
 
 /* For functions with whitespace between their definition and
@@ -955,7 +904,7 @@ test_function_hit_counts_for_big_functions_written_to_coverage_data(gpointer
 
     /* The internal hash table is sorted in alphabetical order
      * so the function names need to be in this order too */
-    FunctionHitCountData expected_hit_counts[] = {
+    const FunctionHitCountData expected_hit_counts[] = {
         { "(anonymous):6:0", 1 },
         { "f:1:0", 1 }
     };
@@ -964,12 +913,11 @@ test_function_hit_counts_for_big_functions_written_to_coverage_data(gpointer
 
     /* There are two possible branches here, the second should be taken
      * and the first should not have been */
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "FNDA:",
-                                                  expected_hit_count_len,
-                                                  hit_count_is_more_than_for_function,
-                                                  (gpointer) expected_hit_counts,
-                                                  sizeof(FunctionHitCountData)));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "FNDA:",
+                                                expected_hit_count_len,
+                                                hit_count_is_more_than_for_function,
+                                                expected_hit_counts,
+                                                sizeof(FunctionHitCountData));
 
     g_free(coverage_data_contents);
 }
@@ -1001,7 +949,7 @@ test_function_hit_counts_for_little_functions_written_to_coverage_data(gpointer
 
     /* The internal hash table is sorted in alphabetical order
      * so the function names need to be in this order too */
-    FunctionHitCountData expected_hit_counts[] = {
+    const FunctionHitCountData expected_hit_counts[] = {
         { "(anonymous):2:0", 0 },
         { "(anonymous):4:0", 1 },
         { "f:1:0", 1 }
@@ -1011,12 +959,11 @@ test_function_hit_counts_for_little_functions_written_to_coverage_data(gpointer
 
     /* There are two possible branches here, the second should be taken
      * and the first should not have been */
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "FNDA:",
-                                                  expected_hit_count_len,
-                                                  hit_count_is_more_than_for_function,
-                                                  (gpointer) expected_hit_counts,
-                                                  sizeof(FunctionHitCountData)));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "FNDA:",
+                                                expected_hit_count_len,
+                                                hit_count_is_more_than_for_function,
+                                                expected_hit_counts,
+                                                sizeof(FunctionHitCountData));
 
     g_free(coverage_data_contents);
 }
@@ -1044,7 +991,7 @@ test_function_hit_counts_written_to_coverage_data(gpointer      fixture_data,
 
     /* The internal hash table is sorted in alphabetical order
      * so the function names need to be in this order too */
-    FunctionHitCountData expected_hit_counts[] = {
+    const FunctionHitCountData expected_hit_counts[] = {
         { "(anonymous):2:0", 1 },
         { "f:1:0", 1 }
     };
@@ -1053,12 +1000,11 @@ test_function_hit_counts_written_to_coverage_data(gpointer      fixture_data,
 
     /* There are two possible branches here, the second should be taken
      * and the first should not have been */
-    g_assert(coverage_data_matches_values_for_key(coverage_data_contents,
-                                                  "FNDA:",
-                                                  expected_hit_count_len,
-                                                  hit_count_is_more_than_for_function,
-                                                  (gpointer) expected_hit_counts,
-                                                  sizeof(FunctionHitCountData)));
+    assert_coverage_data_matches_values_for_key(coverage_data_contents, "FNDA:",
+                                                expected_hit_count_len,
+                                                hit_count_is_more_than_for_function,
+                                                expected_hit_counts,
+                                                sizeof(FunctionHitCountData));
 
     g_free(coverage_data_contents);
 }
@@ -1084,12 +1030,10 @@ test_total_function_coverage_written_to_coverage_data(gpointer      fixture_data
                                           NULL);
 
     /* More than one assert per test is bad, but we are testing interlinked concepts */
-    g_assert(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                  "FNF:",
-                                                  "2"));
-    g_assert(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                  "FNH:",
-                                                  "1"));
+    assert_coverage_data_contains_value_for_key(coverage_data_contents,
+                                                "FNF:", "2");
+    assert_coverage_data_contains_value_for_key(coverage_data_contents,
+                                                "FNH:", "1");
     g_free(coverage_data_contents);
 }
 
@@ -1098,11 +1042,11 @@ typedef struct _LineCountIsMoreThanData {
     unsigned int expected_to_be_more_than;
 } LineCountIsMoreThanData;
 
-static bool
+static void
 line_hit_count_is_more_than(const char *line,
-                            gpointer    user_data)
+                            const void *user_data)
 {
-    LineCountIsMoreThanData *data = (LineCountIsMoreThanData *) user_data;
+    auto data = static_cast<const LineCountIsMoreThanData *>(user_data);
 
     const char *coverage_line = &line[3];
     char *comma_ptr = NULL;
@@ -1118,8 +1062,8 @@ line_hit_count_is_more_than(const char *line,
     g_assert(end_ptr[0] == '\0' ||
              end_ptr[0] == '\n');
 
-    return data->expected_lineno == lineno &&
-           value > data->expected_to_be_more_than;
+    g_assert_cmpuint(lineno, ==, data->expected_lineno);
+    g_assert_cmpuint(value, >, data->expected_to_be_more_than);
 }
 
 static void
@@ -1135,15 +1079,14 @@ test_single_line_hit_written_to_coverage_data(gpointer      fixture_data,
                                           fixture->lcov_output,
                                           NULL);
 
-    LineCountIsMoreThanData data = {
+    const LineCountIsMoreThanData data = {
         1,
         0
     };
 
-    g_assert(coverage_data_matches_value_for_key(coverage_data_contents,
-                                                 "DA:",
-                                                 line_hit_count_is_more_than,
-                                                 &data));
+    assert_coverage_data_matches_value_for_key(coverage_data_contents, "DA:",
+                                               line_hit_count_is_more_than,
+                                               &data);
     g_free(coverage_data_contents);
 }
 
@@ -1170,17 +1113,16 @@ test_hits_on_multiline_if_cond(gpointer      fixture_data,
                                           NULL);
 
     /* Hits on all lines, including both lines with a condition (3 and 4) */
-    LineCountIsMoreThanData data[] = {
+    const LineCountIsMoreThanData data[] = {
         { 1, 0 },
         { 2, 0 },
         { 3, 0 },
         { 4, 0 }
     };
 
-    g_assert(coverage_data_matches_value_for_key(coverage_data_contents,
-                                                 "DA:",
-                                                 line_hit_count_is_more_than,
-                                                 data));
+    assert_coverage_data_matches_value_for_key(coverage_data_contents, "DA:",
+                                               line_hit_count_is_more_than,
+                                               data);
     g_free(coverage_data_contents);
 }
 
@@ -1198,12 +1140,10 @@ test_full_line_tally_written_to_coverage_data(gpointer      fixture_data,
                                           NULL);
 
     /* More than one assert per test is bad, but we are testing interlinked concepts */
-    g_assert(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                  "LF:",
-                                                  "1"));
-    g_assert(coverage_data_contains_value_for_key(coverage_data_contents,
-                                                  "LH:",
-                                                  "1"));
+    assert_coverage_data_contains_value_for_key(coverage_data_contents,
+                                                "LF:", "1");
+    assert_coverage_data_contains_value_for_key(coverage_data_contents,
+                                                "LH:", "1");
     g_free(coverage_data_contents);
 }
 
@@ -1341,34 +1281,31 @@ typedef struct _ExpectedSourceFileCoverageData {
     const char              expected_lines_found_character;
 } ExpectedSourceFileCoverageData;
 
-static bool
-check_coverage_data_for_source_file(ExpectedSourceFileCoverageData *expected,
-                                    const gsize                     expected_size,
-                                    const char                     *section_start)
+static void
+assert_coverage_data_for_source_file(ExpectedSourceFileCoverageData *expected,
+                                     const size_t                    expected_size,
+                                     const char                     *section_start)
 {
     gsize i;
     for (i = 0; i < expected_size; ++i) {
         if (strncmp(&section_start[3],
                     expected[i].source_file_path,
                     strlen (expected[i].source_file_path)) == 0) {
-            const bool line_hits_match = coverage_data_matches_values_for_key(section_start,
-                                                                              "DA:",
-                                                                              
expected[i].n_more_than_matchers,
-                                                                              line_hit_count_is_more_than,
-                                                                              expected[i].more_than,
-                                                                              sizeof 
(LineCountIsMoreThanData));
+            assert_coverage_data_matches_values_for_key(section_start, "DA:",
+                                                        expected[i].n_more_than_matchers,
+                                                        line_hit_count_is_more_than,
+                                                        expected[i].more_than,
+                                                        sizeof (LineCountIsMoreThanData));
             const char *total_hits_record = line_starting_with(section_start, "LH:");
-            const bool total_hits_match = total_hits_record[3] == expected[i].expected_lines_hit_character;
+            g_assert_cmpint(total_hits_record[3], ==, expected[i].expected_lines_hit_character);
             const char *total_found_record = line_starting_with(section_start, "LF:");
-            const bool total_found_match = total_found_record[3] == 
expected[i].expected_lines_found_character;
+            g_assert_cmpint(total_found_record[3], ==, expected[i].expected_lines_found_character);
 
-            return line_hits_match &&
-                   total_hits_match &&
-                   total_found_match;
+            return;
         }
     }
 
-    return false;
+    g_assert_not_reached();
 }
 
 static void
@@ -1427,10 +1364,10 @@ test_correct_line_coverage_data_written_for_both_source_file_sectons(gpointer
     const gsize expected_len = G_N_ELEMENTS(expected);
 
     const char *first_sf_record = line_starting_with(coverage_data_contents, "SF:");
-    g_assert(check_coverage_data_for_source_file(expected, expected_len, first_sf_record));
+    assert_coverage_data_for_source_file(expected, expected_len, first_sf_record);
 
     const char *second_sf_record = line_starting_with(first_sf_record + 3, "SF:");
-    g_assert(check_coverage_data_for_source_file(expected, expected_len, second_sf_record));
+    assert_coverage_data_for_source_file(expected, expected_len, second_sf_record);
 
     g_free(first_script_output_path);
     g_free(second_script_output_path);
@@ -1843,7 +1780,7 @@ test_coverage_cache_invalidation(gpointer      fixture_data,
 
     const gsize expected_len = G_N_ELEMENTS(expected);
     const char *record = line_starting_with(coverage_data_contents, "SF:");
-    g_assert(check_coverage_data_for_source_file(expected, expected_len, record));
+    assert_coverage_data_for_source_file(expected, expected_len, record);
 
     g_free(script_output_path);
     g_free(coverage_data_contents);
@@ -1951,7 +1888,7 @@ test_coverage_cache_invalidation_resource(gpointer      fixture_data,
 
     const gsize expected_len = G_N_ELEMENTS(expected);
     const char *record = line_starting_with(coverage_data_contents, "SF:");
-    g_assert(check_coverage_data_for_source_file(expected, expected_len, record));
+    assert_coverage_data_for_source_file(expected, expected_len, record);
 
     g_free(script_output_path);
     g_free(coverage_data_contents);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]