test elapsed time
This commit is contained in:
@@ -1,19 +1,28 @@
|
|||||||
MIAOU-BASH
|
# MIAOU-BASH
|
||||||
===========
|
|
||||||
|
|
||||||
MIAOU-BASH is a collection of settings and helpers aiming for leveraging BASH.
|
MIAOU-BASH is a mix of scripts and settings aiming for leveraging
|
||||||
Developer-friendly, it may be used as a solo package or combined with other miaou-* utilities.
|
your terminal experience. As the name suggests, it is based on Bash
|
||||||
|
and expect to work on any modern GNU/Linux.
|
||||||
|
|
||||||
|
Actually the installation process supports only 2 distros: Debian and Arch Linux.
|
||||||
|
This package works either standalone or as a core dependency of any other
|
||||||
|
miaou-* utilities.
|
||||||
|
|
||||||
|
Be aware (uppercase) MIAOU-BASH refer to a bunch of scripts and configuration settings.
|
||||||
|
Meanwhile (downcase) `miaou-bash` refer to one of these scripts,
|
||||||
|
maybe the most useful one!
|
||||||
|
|
||||||
|
This is free software and licensed as: Affero GPL v3 +
|
||||||
|
Any feedback would be appreciated.
|
||||||
|
[contact@artcode.re](mailto:contact@artcode.re)
|
||||||
|
|
||||||
## Featuring
|
## Featuring
|
||||||
|
|
||||||
|
* [x] miaou-bash
|
||||||
|
* [x] semver-git_tag
|
||||||
* [x] some aliases (l, ll, ltr, ...)
|
* [x] some aliases (l, ll, ltr, ...)
|
||||||
* [x] a smart prompt
|
* [x] smart prompt
|
||||||
* [x] git, lxd, failure aware
|
* [x] git, failure aware
|
||||||
* [x] simple vim and micro settings
|
|
||||||
* [x] Debian and Archlinux support
|
|
||||||
|
|
||||||
It's Free Software (AGPLv3), help yourself.
|
|
||||||
Any feedback would be appreciated. [contact@artcode.re](mailto:contact@artcode.re)
|
|
||||||
|
|
||||||
## install
|
## install
|
||||||
|
|
||||||
@@ -40,20 +49,9 @@ Any feedback would be appreciated. [contact@artcode.re](mailto:contact@artcode.r
|
|||||||
|
|
||||||
* source /opt/miaou-bash/lib/functions.bash
|
* source /opt/miaou-bash/lib/functions.bash
|
||||||
|
|
||||||
## bindkeys
|
## extra bindkeys
|
||||||
|
|
||||||
### by default
|
* CTRL LEFT, RIGHT => move around words, back and forward
|
||||||
|
|
||||||
* CTRL + C => stop program
|
|
||||||
* CTRL + V => display bindkey
|
|
||||||
* CTRL + Z => interrupt for background job (fg, bg)
|
|
||||||
|
|
||||||
* SHIFT + CTRL + C => copy
|
|
||||||
* SHIFT + CTRL + V => paste
|
|
||||||
|
|
||||||
### customized
|
|
||||||
|
|
||||||
* CTRL LEFT, RIGHT => move between words
|
|
||||||
* CTRL DELETE, BACKSPACE => delete word
|
* CTRL DELETE, BACKSPACE => delete word
|
||||||
* ALT DELETE, BACKSPACE => delete line from cursor
|
* ALT DELETE, BACKSPACE => delete line from cursor
|
||||||
* CTRL + SHIFT + / => undo
|
* CTRL + SHIFT + / => undo
|
||||||
|
|||||||
+20
-16
@@ -85,23 +85,26 @@ function on_return {
|
|||||||
|
|
||||||
# overridden function which permits backtracing of the original `exit` statement
|
# overridden function which permits backtracing of the original `exit` statement
|
||||||
function exit {
|
function exit {
|
||||||
error_source=("${BASH_SOURCE[@]}")
|
code=${1:-0}
|
||||||
error_lineno=("${BASH_LINENO[@]}")
|
if [[ $code -gt 0 ]]; then
|
||||||
error_funcname=("${FUNCNAME[@]}")
|
error_source=("${BASH_SOURCE[@]}")
|
||||||
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
|
error_lineno=("${BASH_LINENO[@]}")
|
||||||
unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]'
|
error_funcname=("${FUNCNAME[@]}")
|
||||||
error_funcname[-1]='<main>'
|
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
|
||||||
error_source=("${error_source[@]}")
|
unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]'
|
||||||
error_lineno=("${error_lineno[@]}")
|
error_funcname[-1]='<main>'
|
||||||
error_funcname=("${error_funcname[@]}")
|
error_source=("${error_source[@]}")
|
||||||
|
error_lineno=("${error_lineno[@]}")
|
||||||
|
error_funcname=("${error_funcname[@]}")
|
||||||
|
|
||||||
failure_code=${1:-0}
|
failure_code=${1:-0}
|
||||||
failure_type="EXIT"
|
failure_type="EXIT"
|
||||||
failure_payload="${error_funcname[0]}"
|
failure_payload="${error_funcname[0]}"
|
||||||
|
|
||||||
miaou_debug "<exit code=$failure_code overridden/>"
|
miaou_debug "<overridden_exit code=$failure_code/>"
|
||||||
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}"
|
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}"
|
||||||
builtin exit "$failure_code"
|
fi
|
||||||
|
builtin exit "$code"
|
||||||
}
|
}
|
||||||
|
|
||||||
function tty_ansi {
|
function tty_ansi {
|
||||||
@@ -135,7 +138,8 @@ function add_miaou_error {
|
|||||||
function on_error {
|
function on_error {
|
||||||
trap - RETURN
|
trap - RETURN
|
||||||
failure_code="${1:-200}"
|
failure_code="${1:-200}"
|
||||||
>&4 printf '\r' # TODO: force carriage return explicitly, is it really useful?
|
|
||||||
|
# >&4 printf '\r' # TODO: force carriage return explicitly, is it really useful?
|
||||||
|
|
||||||
miaou_debug "<on_error code=${failure_code} command={${BASH_COMMAND}}>"
|
miaou_debug "<on_error code=${failure_code} command={${BASH_COMMAND}}>"
|
||||||
|
|
||||||
|
|||||||
+27
-22
@@ -6,13 +6,15 @@
|
|||||||
|
|
||||||
function assert {
|
function assert {
|
||||||
((test_count++))
|
((test_count++))
|
||||||
if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null; then
|
if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null 2>/dev/null 3>_miaou; then
|
||||||
echo -n .
|
if [[ -s _miaou ]]; then
|
||||||
else
|
echo -n .
|
||||||
echo -n F
|
return
|
||||||
failures+=("$1")
|
fi
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
echo -n F
|
||||||
|
failures+=("$1")
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# assert performing '$1:script' successfully + output must contain '$2:content'
|
# assert performing '$1:script' successfully + output must contain '$2:content'
|
||||||
@@ -71,32 +73,35 @@ set -uo pipefail
|
|||||||
test_count=0
|
test_count=0
|
||||||
failures=()
|
failures=()
|
||||||
|
|
||||||
assert success
|
TIMEFORMAT=$'\nelapsed: %Rs'
|
||||||
assert_grep success_with_args 'count args: 2' -- 'A B' C
|
|
||||||
|
|
||||||
fail_type subshell_term SUBSHELL_ERROR
|
time {
|
||||||
fail_type unbound_variable UNBOUND_VARIABLE
|
assert success
|
||||||
fail_type unbound_associative UNBOUND_VARIABLE
|
assert exit_0
|
||||||
fail_type false FALSE
|
assert_grep success_with_args 'count args: 2' -- 'A B' C
|
||||||
fail_type last_false COMMAND_ERROR
|
|
||||||
fail_type command_error COMMAND_ERROR
|
|
||||||
fail_type subshell_term SUBSHELL_ERROR
|
|
||||||
fail_type exit EXIT
|
|
||||||
fail_type command_not_found COMMAND_NOT_FOUND
|
|
||||||
fail_type source_not_found SOURCE_NOT_FOUND
|
|
||||||
fail_type file_not_found FILE_NOT_FOUND
|
|
||||||
fail_type child_error CHILD_ERROR 'prefer source than child process'
|
|
||||||
|
|
||||||
|
fail_type subshell_term SUBSHELL_ERROR
|
||||||
|
fail_type unbound_variable UNBOUND_VARIABLE
|
||||||
|
fail_type unbound_associative UNBOUND_VARIABLE
|
||||||
|
fail_type false FALSE
|
||||||
|
fail_type last_false COMMAND_ERROR
|
||||||
|
fail_type command_error COMMAND_ERROR
|
||||||
|
fail_type subshell_term SUBSHELL_ERROR
|
||||||
|
fail_type exit EXIT
|
||||||
|
fail_type command_not_found COMMAND_NOT_FOUND
|
||||||
|
fail_type source_not_found SOURCE_NOT_FOUND
|
||||||
|
fail_type file_not_found FILE_NOT_FOUND
|
||||||
|
fail_type child_error CHILD_ERROR 'prefer source than child process'
|
||||||
|
}
|
||||||
failed=${#failures[@]}
|
failed=${#failures[@]}
|
||||||
success=$((test_count - failed))
|
success=$((test_count - failed))
|
||||||
|
|
||||||
echo
|
|
||||||
if [[ $failed -gt 0 ]]; then
|
if [[ $failed -gt 0 ]]; then
|
||||||
ratio=$((100 * success / test_count))
|
ratio=$((100 * success / test_count))
|
||||||
echo "${ratio}% passed, ${test_count} tests, ${failed} failed!"
|
echo "${ratio}% passed, ${test_count} tests, ${failed} failed!"
|
||||||
echo failures:
|
echo failures:
|
||||||
for failure in "${failures[@]}"; do
|
for failure in "${failures[@]}"; do
|
||||||
echo -e "\t- $failure"
|
echo -e "\t- $failure => replay: ./test/stub/scenario.bash $failure"
|
||||||
done
|
done
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function onemore {
|
|||||||
|
|
||||||
function do_next {
|
function do_next {
|
||||||
echo do_next
|
echo do_next
|
||||||
exit 10 # youpi
|
exit 13 # youpi
|
||||||
grep nope nope
|
grep nope nope
|
||||||
echo $nope
|
echo $nope
|
||||||
command_not_found
|
command_not_found
|
||||||
|
|||||||
@@ -76,14 +76,20 @@ function do_success {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function do_exit_0 {
|
||||||
|
echo success
|
||||||
|
exit 0
|
||||||
|
echo SHOULD NOT APPEAR
|
||||||
|
}
|
||||||
|
|
||||||
function do_success_with_args {
|
function do_success_with_args {
|
||||||
echo "count args: $#"
|
echo "count args: $#"
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_unbound_variable {
|
function do_unbound_variable {
|
||||||
a=5
|
a=5
|
||||||
echo "a=${a}"
|
echo -n "content: "
|
||||||
echo "b=${b}"
|
echo -n "a=${a} b=${b}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_source_not_found {
|
function do_source_not_found {
|
||||||
|
|||||||
Reference in New Issue
Block a user