Skip to content

Conversation

@aarvio
Copy link

@aarvio aarvio commented Jan 25, 2026

Add a new test pattern for asserting command outputs and exit status through a run() wrapper function and corresponding assertion functions.

Addresses issue: #134

User story suggested pipe syntax:
command_under_test | should_display "${expected_pattern}"
command_under_test | err_should_contain "${expected_pattern}"

Implemented wrapper pattern:
run command_under_test && assert_run_output_matches "${expected_pattern}"
run command_under_test && assert_run_error_matches "${expected_pattern}"

Works also as separate lines:
run command_under_test
assert_run_output_matches "${expected_pattern}"
assert_run_error_matches "${expected_pattern}"

The wrapper pattern achieves the same readability while providing more flexibility and reliability.

Problem with pipes:

  • pipes carry only stdout
  • harder to resolve exit status if needed
  • can't verify multiple conditions independently

Usage Examples

Simple one-liners:
run my_script && assert_run_success
run my_command && assert_run_output_equals "expected"
run failing_cmd && assert_run_status_code 42

Multiple assertions:
run my_script.sh input.txt
assert_run_success
assert_run_output_matches "^Processed.*successfully"
assert_run_error_equals ""

Aki Arvio added 2 commits January 25, 2026 18:20
Add a new test pattern for asserting command outputs and exit status
through a run() wrapper function and corresponding assertion functions.

Addresses issue: bash-unit#134
--------------------------------------
User story suggested pipe syntax:
  command_under_test | should_display "${expected_pattern}"
  command_under_test | err_should_contain "${expected_pattern}"

Implemented wrapper pattern:
  run command_under_test && assert_run_output_matches "${expected_pattern}"
  run command_under_test && assert_run_error_matches "${expected_pattern}"

Works also as separate lines:
  run command_under_test
  assert_run_output_matches "${expected_pattern}"
  assert_run_error_matches "${expected_pattern}"

The wrapper pattern achieves the same readability while providing more
flexibility and reliability.

Problem with pipes:
- pipes carry only stdout
- harder to resolve exit status if needed
- can't verify multiple conditions independently

Usage Examples
--------------
Simple one-liners:
  run my_script && assert_run_success
  run my_command && assert_run_output_equals "expected"
  run failing_cmd && assert_run_status_code 42

Multiple assertions:
  run my_script.sh input.txt
  assert_run_success
  assert_run_output_matches "^Processed.*successfully"
  assert_run_error_equals ""
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