-
Notifications
You must be signed in to change notification settings - Fork 48
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
add option to show diff in assert_output and assert_equal #65
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
# Options: | ||
# -p, --partial Match if `expected` is a substring of `$output` | ||
# -e, --regexp Treat `expected` as an extended regular expression | ||
# -d, --diff Show diff between `expected` and `$output` | ||
# -, --stdin Read `expected` value from STDIN | ||
# <expected> The expected value, substring or regular expression | ||
# | ||
|
@@ -57,6 +58,8 @@ | |
# -- | ||
# ``` | ||
# | ||
# If the `--diff` option is set, a diff between the expected and actual output is shown. | ||
# | ||
# ## Existence | ||
# | ||
# To assert that any output exists at all, omit the `expected` argument. | ||
|
@@ -126,6 +129,7 @@ assert_output() { | |
local -i is_mode_regexp=0 | ||
local -i is_mode_nonempty=0 | ||
local -i use_stdin=0 | ||
local -i show_diff=0 | ||
: "${output?}" | ||
|
||
# Handle options. | ||
|
@@ -137,6 +141,7 @@ assert_output() { | |
case "$1" in | ||
-p|--partial) is_mode_partial=1; shift ;; | ||
-e|--regexp) is_mode_regexp=1; shift ;; | ||
-d|--diff) show_diff=1; shift ;; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
-|--stdin) use_stdin=1; shift ;; | ||
--) shift; break ;; | ||
*) break ;; | ||
|
@@ -187,11 +192,17 @@ assert_output() { | |
fi | ||
else | ||
if [[ $output != "$expected" ]]; then | ||
batslib_print_kv_single_or_multi 8 \ | ||
'expected' "$expected" \ | ||
'actual' "$output" \ | ||
| batslib_decorate 'output differs' \ | ||
| fail | ||
if (( show_diff )); then | ||
diff <(echo "$expected") <(echo "$output") \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unified file format is more common than the so called normal format. It would be better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea, done |
||
| batslib_decorate 'output differs' \ | ||
| fail | ||
else | ||
batslib_print_kv_single_or_multi 8 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps batslib_print_kv_single_or_multi` could grow support for diffing expected and actual? For instance it could use |
||
'expected' "$expected" \ | ||
'actual' "$output" \ | ||
| batslib_decorate 'output differs' \ | ||
| fail | ||
fi | ||
fi | ||
fi | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a breaking change for some users that want to check if something is
-d
/--diff
Unfortunately, we don't have a
--
interface established here. I think at minimum we should check that there are still (at least) two parameters left after the shift.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done