Skip to content

Improve test coverage for src/utils.jl #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025

Conversation

ChrisRackauckas
Copy link
Member

Summary

This PR addresses issue #868 by adding comprehensive unit tests for all functions in src/utils.jl, significantly improving test coverage from the current 30.77%.

Changes

  • New file: test/utils.jl - Comprehensive test suite for utils functions
  • Updated: test/runtests.jl - Added utils tests to the main test suite

Test Coverage Added

The new test suite covers all functions in src/utils.jl:

Core Functions

  • get_maxiters() - Tests iterator size handling (with error handling for existing implementation issue)
  • maybe_with_logger() - Tests logger wrapper functionality with and without loggers
  • default_logger() - Tests logger creation with different log levels
  • @withprogress - Tests progress logging macro behavior
  • decompose_trace() - Tests trace decomposition (passthrough function)

Validation Functions

  • _check_and_convert_maxiters() - Tests validation and conversion with positive values, error cases (≤0), and type conversion
  • _check_and_convert_maxtime() - Tests validation and conversion with positive values, error cases (≤0), and type conversion

Return Code Functions

  • deduce_retcode(::String) - Tests all regex patterns for mapping stop reason strings to ReturnCode values
  • deduce_retcode(::Symbol) - Tests symbolic return code mapping for all supported symbols
  • STOP_REASON_MAP validation - Tests specific regex patterns work correctly

Test Results

  • 116 tests pass covering normal operation, edge cases, and error conditions
  • Tests validate all regex patterns used for return code mapping
  • Comprehensive error handling tests for input validation functions
  • Mock testing for functions with external dependencies

Benefits

  • Significantly improves code reliability through comprehensive testing
  • Catches potential regressions in utility functions
  • Documents expected behavior through test cases
  • Validates all return code mapping patterns work correctly

Closes #868

🤖 Generated with Claude Code

Addresses issue #868 by adding comprehensive unit tests for all functions in src/utils.jl:

- get_maxiters: Tests iterator size handling (with error handling for existing bug)
- maybe_with_logger: Tests logger wrapper functionality
- default_logger: Tests logger creation with different log levels
- @withprogress: Tests progress logging macro with and without progress enabled
- decompose_trace: Tests trace decomposition (passthrough function)
- _check_and_convert_maxiters: Tests maxiters validation and conversion with edge cases
- _check_and_convert_maxtime: Tests maxtime validation and conversion with edge cases
- deduce_retcode (String): Tests return code deduction from stop reason strings
- deduce_retcode (Symbol): Tests return code deduction from symbolic return codes
- STOP_REASON_MAP: Tests specific regex patterns for return code mapping

The tests cover normal operation, edge cases, error conditions, and validate all the regex patterns used for return code mapping. This significantly improves test coverage for the utils.jl file from 30.77%.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit 597f249 into master Jul 23, 2025
24 of 29 checks passed
@ChrisRackauckas ChrisRackauckas deleted the improve-utils-test-coverage branch July 23, 2025 18:33
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.

test: test coverage needs improvement for the ./src/utils.jl file
1 participant