Skip to content

Add comprehensive error handling tests for bash utilities#21

Merged
ooloth merged 13 commits intomainfrom
feature/error-handling-tests
Jul 11, 2025
Merged

Add comprehensive error handling tests for bash utilities#21
ooloth merged 13 commits intomainfrom
feature/error-handling-tests

Conversation

@ooloth
Copy link
Owner

@ooloth ooloth commented Jul 11, 2025

💪 What

  • Files Created: test/setup/test-error-handling-bash.bats with 15 comprehensive tests
  • Test Coverage: All functions in bin/lib/error-handling.bash fully tested
  • Test Categories: Input validation, success/failure scenarios, error code handling, retry logic
  • Quality: 15/15 tests passing, zero shellcheck warnings

🤔 Why

  • Missing Test Coverage: PR Add Dry-run and Error Handling Utilities Migration to Bash #19 merged error handling utilities but tests were identified as missing
  • Testing Gap: Critical infrastructure utilities needed comprehensive behavioral testing
  • Development Quality: Ensures error handling functions work correctly in all scenarios
  • Migration Support: Validates bash utilities before full setup.bash migration

👩‍🔬 How to validate

Run the test suite:

bats test/setup/test-error-handling-bash.bats

Expected output:

1..15
ok 1 capture_error returns error when no command provided
ok 2 capture_error executes successful command and returns 0
ok 3 capture_error handles failing command and provides context
ok 4 capture_error shows command output before error message
ok 5 retry_with_backoff returns error when no command provided
ok 6 retry_with_backoff succeeds on first attempt
ok 7 retry_with_backoff fails after exhausting max attempts
ok 8 handle_error returns error when no command provided
ok 9 handle_error displays error message and generic suggestion
ok 10 handle_error provides permission-specific suggestion for EACCES
ok 11 handle_error provides file-not-found suggestion for ENOENT
ok 12 handle_error provides network-specific suggestion for ECONNREFUSED
ok 13 handle_error provides disk-space suggestion for ENOSPC
ok 14 retry_with_backoff succeeds on second attempt after one failure
ok 15 capture_error uses default context when none provided

Verify shellcheck compliance:

shellcheck bin/lib/error-handling.bash

Test Functions Covered:

  • capture_error() - Command execution with error context (5 tests)
  • retry_with_backoff() - Retry logic with exponential backoff (3 tests)
  • handle_error() - User-friendly error messages with suggestions (7 tests)

🔗 Related links

Test Implementation Details

TDD Approach:

  • Followed strict TDD: one test case (red) → minimal implementation (green) → commit cycle
  • Each test validates specific behavior, not implementation details
  • Tests cover both success and failure scenarios comprehensively

Function Coverage:

  • capture_error(): Input validation, successful execution, error handling, output preservation
  • retry_with_backoff(): Input validation, immediate success, retry logic, failure after max attempts
  • handle_error(): Input validation, error formatting, error-code-specific suggestions

Quality Standards:

  • All tests pass consistently
  • Zero shellcheck warnings on tested script
  • Comprehensive edge case coverage
  • Clear, descriptive test names and assertions

@ooloth ooloth marked this pull request as ready for review July 11, 2025 23:09
@ooloth ooloth merged commit 356331b into main Jul 11, 2025
1 check passed
@ooloth ooloth deleted the feature/error-handling-tests branch July 11, 2025 23:10
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.

1 participant