Skip to content

test(utility): adopt canonical ReportTestSuite pattern for string_parse foundation test#840

Merged
Ravenwater merged 1 commit into
mainfrom
refactor/string-parse-foundation-test-pattern
May 16, 2026
Merged

test(utility): adopt canonical ReportTestSuite pattern for string_parse foundation test#840
Ravenwater merged 1 commit into
mainfrom
refactor/string-parse-foundation-test-pattern

Conversation

@Ravenwater

@Ravenwater Ravenwater commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-on cleanup for the Phase A foundation that landed via #838. The foundation test (static/utility/test_string_parse.cpp) used a homegrown g_total/g_failures bench instead of the ReportTestSuiteHeader / scope-block / ReportTestSuiteResults idiom that the rest of the regression suite (hundreds of tests in static/*/api/*) uses. PR #839 applied the same fix to the integer and fixpnt parse() tests; this PR brings the foundation in line.

Changes

  • static/utility/test_string_parse.cpp -- replaces the custom bench with the canonical pattern:
    • ReportTestSuiteHeader at entry, ReportTestSuiteResults at exit
    • One scope block per primitive (scan_prefix / scan_sign / parse_binary / parse_octal / parse_hex / scan_decimal_float), each with int start = nrOfFailedTestCases; at the top, per-assertion ++nrOfFailedTestCases, trailing if (nrOfFailedTestCases - start > 0) std::cout << "FAIL: <group>\n"; diagnostic.
    • Standard catch footer (ad-hoc / runtime / unknown).

The static_assert smoke tests at file scope (proving constexpr evaluation) are kept verbatim -- they verify a different invariant (compile-time evaluation) that no runtime block can.

Test coverage

Identical to the pre-refactor version:

  • scan_prefix: 0b/0B/0o/0O/0x/0X, decimal default, leading-0-without-prefix, empty
  • scan_sign: +/-, no sign, empty, double-sign
  • parse_binary/octal/hex: valid, partial-stop-at-invalid, 64-bit boundary, 65/17-digit overflow, empty -> invalid
  • scan_decimal_float: integer-only, fraction-only, signs, exponent variants, malformed (bare dot, trailing garbage, empty exponent), 50-digit fraction, int32 boundary exponents (INT32_MAX, INT32_MIN, INT32_MAX+1)

Test results

Target gcc build gcc run clang build clang run
utility_test_string_parse OK PASS OK PASS

Output now reads string_parse primitives (Phase A of #835) test suite: PASS matching the rest of the suite.

Test plan

  • Fast CI passes (gcc + clang CI_LITE)
  • CodeRabbit feedback addressed
  • Promote to ready: `gh pr ready `

Relates to #835

Generated with Claude Code

Summary by CodeRabbit

Release Notes

Tests

  • Improved internal test infrastructure and reporting for string parsing validation.
  • Enhanced test coverage with more comprehensive edge case verification.

Note: No user-facing changes in this release. This update focuses on test quality improvements.

Review Change Stack

…se foundation test

Follow-on cleanup for PR #838 (Phase A of #835). The foundation test
landed with a homegrown g_total/g_failures bench instead of the
ReportTestSuiteHeader / scope-block / ReportTestSuiteResults idiom used
by the rest of the Universal regression suite (and applied to the
integer/fixpnt parse() tests on PR #839).

Refactor mirrors that style:
  - ReportTestSuiteHeader at entry, ReportTestSuiteResults at exit
  - Each primitive (scan_prefix / scan_sign / parse_binary/octal/hex /
    scan_decimal_float) is one scope block: `int start = nrOfFailedTestCases`
    at the top, per-assertion `if (...) ++nrOfFailedTestCases`,
    trailing `if (nrOfFailedTestCases - start > 0) std::cout << "FAIL: ..."`
    diagnostic.
  - Standard catch footer (ad-hoc / runtime / ...)

Static_assert smoke tests at file scope (proving constexpr) are kept
verbatim -- they verify a different invariant (compile-time evaluation)
that the runtime block can't.

Same test matrix, same coverage. Output now reads:
  string_parse primitives (Phase A of #835) test suite: PASS

Relates to #835

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR refactors a string-parsing test file from an ad-hoc iostream-based bench to the project's sw::universal verification reporter framework, expands test coverage for parsing primitives with explicit edge cases (overflow, malformed input, boundary conditions), and updates exception handling.

Changes

Test Harness Refactoring and Coverage Expansion

Layer / File(s) Summary
Test harness integration and includes
static/utility/test_string_parse.cpp
Includes updated to use directives.hpp and verification/test_reporters.hpp; old iostream-backed scaffolding (g_failures, g_total, report()) removed.
Prefix and sign parsing tests
static/utility/test_string_parse.cpp
Main function rewritten to call ReportTestSuiteHeader(); scan_prefix and scan_sign tests structured inline with failure tracking via nrOfFailedTestCases.
Number base parsing tests
static/utility/test_string_parse.cpp
Inline test sections for parse_binary, parse_octal, and parse_hex replace prior standalone functions; coverage includes normal values, maximum widths, overflow cases, and stopping at invalid characters.
Decimal float parsing tests
static/utility/test_string_parse.cpp
Inline scan_decimal_float section replaces prior function with extensive edge-case validation: sign/integer/fraction/exponent structure, malformed rejection, long fractions, and INT32_MIN/INT32_MAX boundaries.
Test suite finalization and exception handling
static/utility/test_string_parse.cpp
Main calls ReportTestSuiteResults() and returns EXIT_FAILURE on failures; exception handling updated to distinguish const char*, std::runtime_error, and generic exceptions with distinct messages.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • stillwater-sc/universal#838: Main PR that refactors the same test file's harness and exception handling while exercising the same parsing primitives.

Suggested Labels

enhancement


🐰 A tale of tests renewed with care,
From old ad-hoc to frameworks fair!
Parsing primitives now shine so bright,
With edge cases caught in full sunlight. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and accurately reflects the main change: adopting the canonical ReportTestSuite pattern for the string_parse test file. It is concise, specific, and clearly conveys the primary refactoring objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/string-parse-foundation-test-pattern

Comment @coderabbitai help to get the list of available commands and usage tips.

@Ravenwater Ravenwater self-assigned this May 16, 2026
@Ravenwater Ravenwater moved this to In progress in Universal Number Library May 16, 2026
@Ravenwater Ravenwater added this to the V4 milestone May 16, 2026
@Ravenwater Ravenwater marked this pull request as ready for review May 16, 2026 12:46
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 25962300725

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.007%) to 83.936%

Details

  • Coverage increased (+0.007%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 2 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
include/sw/universal/number/posito/posito_impl.hpp 2 89.8%

Coverage Stats

Coverage Status
Relevant Lines: 54832
Covered Lines: 46024
Line Coverage: 83.94%
Coverage Strength: 6463351.12 hits per line

💛 - Coveralls

@Ravenwater Ravenwater merged commit 81bb1a4 into main May 16, 2026
41 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in Universal Number Library May 16, 2026
@Ravenwater Ravenwater deleted the refactor/string-parse-foundation-test-pattern branch May 16, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants