Created
July 22, 2011 10:49
-
-
Save mpapis/1099240 to your computer and use it in GitHub Desktop.
log with levels
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
#!/usr/bin/env bash | |
export LEVEL=0 | |
function log() { | |
printf "%$(( LEVEL * 2 ))s$*\n" "" | |
} | |
function fail() { | |
local ret=$1 | |
shift | |
printf "FAIL: $*\n" | |
exit $ret | |
} | |
function cf() | |
{ | |
"$@" | |
local ret=$? | |
if (( $ret == 0 )) | |
then | |
return $ret | |
else | |
fail $ret "$@" | |
fi | |
} | |
function go() | |
{ | |
: $(( LEVEL++ )) | |
"$@" | |
local ret=$? | |
: $(( LEVEL-- )) | |
return $ret | |
} | |
test2() | |
{ | |
log 'a 2nd level' | |
go test3 x | |
log 'b 2nd level' | |
cf go test3 y | |
log 'c 2nd level' | |
} | |
test3() | |
{ | |
log "$1 a 3nd level" | |
log "$1 b 3nd level" | |
return 1 | |
} | |
log '1st level' | |
go test2 | |
log 'finish' |
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
1st level | |
a 2nd level | |
x a 3nd level | |
x b 3nd level | |
b 2nd level | |
y a 3nd level | |
y b 3nd level | |
FAIL: go test3 y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment