-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
19 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
#!/bin/bash | ||
|
||
function test_redirect_error() { | ||
local result | ||
result="$(my_help)" | ||
assert_equals "BASH_SOURCE: redirect_error_test.sh" "$result" | ||
assert_successful_code | ||
} | ||
_ERROR_LOG=temp_error.log | ||
|
||
function my_help() { | ||
smth "BASH_SOURCE: ${BASH_SOURCE[0]}" | ||
exit 1 | ||
function tear_down() { | ||
rm $_ERROR_LOG | ||
} | ||
|
||
function smth(){ | ||
echo "$*" >&2 | ||
function test_redirect_error() { | ||
|
||
function render_into_error_fd_and_exit() { | ||
echo "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
exec 2>&3 2>$_ERROR_LOG | ||
|
||
local result | ||
result="$(render_into_error_fd_and_exit "arg1" "arg2")" | ||
assert_general_error | ||
|
||
local error_output | ||
error_output=$(<$_ERROR_LOG) | ||
assert_equals "arg1 arg2" "$error_output" | ||
} |