feat: Add run() wrapper with command output assertions #146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_testassert_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:
Usage Examples
Simple one-liners:
run my_script && assert_run_successrun my_command && assert_run_output_equals "expected"run failing_cmd && assert_run_status_code 42Multiple assertions:
run my_script.sh input.txtassert_run_successassert_run_output_matches "^Processed.*successfully"assert_run_error_equals ""