Skip to content

Achieve 100% branch coverage through targeted tests and defensive code marking#92

Merged
nanonyme merged 2 commits intomainfrom
copilot/fix-branch-coverage
Feb 19, 2026
Merged

Achieve 100% branch coverage through targeted tests and defensive code marking#92
nanonyme merged 2 commits intomainfrom
copilot/fix-branch-coverage

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

Branch coverage was at 98% with several testable paths uncovered. Per project requirements, defensive code that cannot be reached through streaming C input should be marked pragma: no cover.

Tests Added

  • Unicode string includes: u8", u", U", L" prefixed includes (core.py:406)
  • Nested elif conditionals: Parent condition state propagation (core.py:344-345)
  • Whitespace-only pragma: Empty pragma directive handling (core.py:224)
  • Invalid include formats: Malformed string and angle bracket includes
  • Empty line handling: Tokenizer StopIteration path

Example of added unicode string include test:

def test_include_u8_string():
    """Test include with u8 prefix (UTF-8 string literal)."""
    f_obj = FakeFile("header.h", ['#include u8"other.h"\n'])
    handler = FakeHandler({"other.h": ["1\n"]})
    ret = preprocess(f_obj, header_handler=handler)
    assert "".join(ret) == "1\n"

Defensive Code Marked

Four branches marked pragma: no cover - unreachable due to tokenizer guarantees:

  • core.py:410-414: Invalid STRING token format (tokenizer ensures well-formed strings)
  • core.py:442-446: Iterator exhaustion without NEWLINE (chunks always end with NEWLINE)
  • tokens.py:227: Unrecognized input (scanner \W pattern catches all)
  • tokens.py:241-242: Empty line with zero tokens (scanner always produces NEWLINE)

Coverage: 98% → 100% (320 branches → 314 branches, 0 partial)

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix branch coverage for existing code</issue_title>
<issue_description>1. Where failure branches exist and functionality can be covered by streaming input C test code even invalid one, add tests. No direct invariant tests.
2. Where branches marked as no cover can in fact be covered by rules from 1, add coverage and remove pragma no cover.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ed0673d) to head (a21f2c7).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main       #92      +/-   ##
===========================================
+ Coverage   97.90%   100.00%   +2.09%     
===========================================
  Files           7         7              
  Lines         763       755       -8     
  Branches      160       157       -3     
===========================================
+ Hits          747       755       +8     
+ Misses         10         0      -10     
+ Partials        6         0       -6     
Files with missing lines Coverage Δ
simplecpreprocessor/core.py 100.00% <ø> (+3.59%) ⬆️
simplecpreprocessor/tokens.py 100.00% <ø> (+2.19%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…over

Co-authored-by: nanonyme <348449+nanonyme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix branch coverage for existing code Achieve 100% branch coverage through targeted tests and defensive code marking Feb 19, 2026
Copilot AI requested a review from nanonyme February 19, 2026 09:39
Copilot AI requested a review from nanonyme February 19, 2026 09:46
@nanonyme nanonyme marked this pull request as ready for review February 19, 2026 09:50
@nanonyme nanonyme merged commit a1eeba4 into main Feb 19, 2026
7 checks passed
@nanonyme nanonyme deleted the copilot/fix-branch-coverage branch February 19, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix branch coverage for existing code

2 participants