Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 4.27 KB

File metadata and controls

65 lines (45 loc) · 4.27 KB

Code Coverage Analysis for src/json.c

The code coverage analysis of src/json.c reveals that 44 out of 767 lines are not covered by the current test suite. This document details the uncovered lines and provides an analysis of why they are not being executed.

Summary of Uncovered Lines

The uncovered lines are primarily in error handling branches of the parsing functions and in some specific conditions of the stringify and equality functions.

parse_number

  • Line 175: return false;
    • Reason: This line is executed when a non-digit character is found after the first digit of a number (e.g., "1a"). The tests do not include such a case.
  • Line 183: return false;
    • Reason: This line is executed when a . is not followed by a digit (e.g., "1."). The tests do not include this specific malformed number.

parse_string

  • Line 212: return false;
    • Reason: This is the default case in the escape sequence switch, which is triggered by an invalid escape sequence (e.g., "\\z"). This is not tested.

parse_array_value

  • Lines 261, 262: free_array_node(array_node); v->u.array.items = NULL;
    • Reason: This is an error path taken when parse_value_build fails while parsing an array element. It's a hard-to-reach case that would require a malformed value inside an array that does not trigger other error conditions first.
  • Line 264: if (*s == end) return false;
    • Reason: This checks for an unexpected end of input after an array element and a comma. The test suite does not seem to have a test case for this.
  • Lines 267, 268: return false;
    • Reason: These lines are executed when a character other than a comma or a closing bracket is found after an array element.
  • Lines 270, 271: return false;
    • Reason: This is the final return false; of the function, and it is not clear how to reach this code path.

parse_object_value

  • Line 283: if (*s == end) return false;
    • Reason: Unexpected end of input after a key-value pair and a comma in an object.
  • Line 287: return false;
    • Reason: After a value in an object, there is no } or ,.

parse_value_build

  • Lines 324, 328: return false;
    • Reason: These lines handle unexpected end of input after [ and after whitespace.
  • Line 340, 341: return false;
    • Reason: Error in number parsing.
  • Line 345: return false;
    • Reason: Default case in parse_value_build, when the character does not match any known value type.

Printing Functions (print_value_compact, print_value, buffer_write_indent, buffer_write_object_indent, buffer_write_value_indent, buffer_write_value)

  • Lines 546, 553, 554, 556, 647, 649, 651, 693, 694, 718, 723, 724, 725:
    • Reason: These are mostly error conditions related to the underlying buffer operations (e.g. realloc failing) or specific uncovered cases in the printing logic (e.g. printing a null value with print_value_compact).

json_stringify, json_array_equal, json_object_equal

  • Lines 730, 735, 784, 786, 789, 790, 799, 800, 803, 804, 827, 828:
    • Reason: These are error conditions, such as realloc failing during stringification, or specific edge cases in the equality comparison functions that are not currently tested (e.g., comparing an object with a different number of keys).

Recommendations

To improve code coverage, the following actions are recommended:

  1. Add tests for malformed JSON: Create new test cases that specifically target the identified uncovered error-handling branches. This includes invalid numbers, invalid escape sequences, and truncated JSON structures.
  2. Test printing of all value types: Ensure that the printing functions are tested with all possible JSON value types, including empty objects and arrays.
  3. Simulate allocation failures: To test the error handling of realloc failures, it might be necessary to use a custom memory allocation function that can be configured to fail on demand. This is an advanced testing technique.
  4. Review complex logic: The uncovered lines in parse_array_value and parse_object_value suggest that some complex parsing scenarios are not fully tested. A review of these functions and the creation of targeted tests would be beneficial.