Skip to content

Commit

Permalink
test: green redirect_error
Browse files Browse the repository at this point in the history
with the logic inside the test itself
  • Loading branch information
Chemaclass committed Jun 22, 2024
1 parent 10a5972 commit bc9a1cc
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions tests/unit/redirect_error_test.sh
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"
}

0 comments on commit bc9a1cc

Please sign in to comment.