Skip to content

Commit 2b253d0

Browse files
committed
Split log output from stacktrace output in bash_unit.
1 parent eb4253a commit 2b253d0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

bash_unit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ BLUE="${ESCAPE}[94m"
2929
# OUT -> all code under test outputs relevant in the context
3030
# ERR -> all code under test error outputs relevant in the context
3131
exec {LOG}>&1
32+
exec {STACK}>&1
3233
exec {OUT}>&1
3334
exec {ERR}>&1
3435

@@ -42,7 +43,7 @@ fail() {
4243
[[ ! -z $stdout ]] && [ -s $stdout ] && cat $stdout | sed 's:^:out> :' | format $GREEN >&$OUT
4344
[[ ! -z $stderr ]] && [ -s $stderr ] && cat $stderr | sed 's:^:err> :' | format $RED >&$ERR
4445

45-
print_stack | grep -v ^$BASH_SOURCE | format "$YELLOW" >&$LOG
46+
print_stack | grep -v ^$BASH_SOURCE | format "$YELLOW" >&$STACK
4647
exit 1
4748
}
4849

tests/test_bash_unit.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test_fail_prints_failure_message() {
6666

6767
test_fail_prints_where_is_error() {
6868
assert_equals "${BASH_SOURCE}:${LINENO}:${FUNCNAME}()" \
69-
"$(with_bash_unit_log fail | last_line)"
69+
"$(with_bash_unit_stack fail | last_line)"
7070
}
7171

7272
test_assert_status_code_succeeds() {
@@ -253,18 +253,26 @@ with_bash_unit_log() {
253253
with_bash_unit_redirected -l '&1' "$@"
254254
}
255255

256+
with_bash_unit_stack() {
257+
with_bash_unit_redirected -s '&1' "$@"
258+
}
259+
256260
with_bash_unit_redirected() {
257261
local log=/dev/null
262+
local stack=/dev/null
258263
local out=/dev/null
259264
local err=/dev/null
260265

261266
unset OPTIND
262-
while getopts "l:o:e:" option
267+
while getopts "l:s:o:e:" option
263268
do
264269
case "$option" in
265270
l)
266271
log=$OPTARG
267272
;;
273+
s)
274+
stack=$OPTARG
275+
;;
268276
o)
269277
out=$OPTARG
270278
;;
@@ -277,6 +285,7 @@ with_bash_unit_redirected() {
277285

278286
(
279287
eval "exec {LOG}>$log"
288+
eval "exec {STACK}>$stack"
280289
eval "exec {OUT}>$out"
281290
eval "exec {ERR}>$err"
282291
"$@"

0 commit comments

Comments
 (0)