Browse Source

test elapsed time

main
pvincent 1 week ago
parent
commit
eb06c0e061
  1. 46
      README.md
  2. 40
      bin/miaou-bash
  3. 53
      test/miaou-bash.test.bash
  4. 2
      test/stub/extra/onemore.bash
  5. 10
      test/stub/scenario.bash

46
README.md

@ -1,19 +1,28 @@
MIAOU-BASH
===========
# MIAOU-BASH
MIAOU-BASH is a collection of settings and helpers aiming for leveraging BASH.
Developer-friendly, it may be used as a solo package or combined with other miaou-* utilities.
MIAOU-BASH is a mix of scripts and settings aiming for leveraging
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] git, lxd, 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)
* [x] smart prompt
* [x] git, failure aware
## 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
### by default
* 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
## extra bindkeys
* CTRL LEFT, RIGHT => move between words
* CTRL LEFT, RIGHT => move around words, back and forward
* 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

40
bin/miaou-bash

@ -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[@]}")
error_lineno=("${BASH_LINENO[@]}")
error_funcname=("${FUNCNAME[@]}")
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]'
error_funcname[-1]='<main>'
error_source=("${error_source[@]}")
error_lineno=("${error_lineno[@]}")
error_funcname=("${error_funcname[@]}")
failure_code=${1:-0}
failure_type="EXIT"
failure_payload="${error_funcname[0]}"
miaou_debug "<exit code=$failure_code overridden/>"
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}"
builtin exit "$failure_code"
code=${1:-0}
if [[ $code -gt 0 ]]; then
error_source=("${BASH_SOURCE[@]}")
error_lineno=("${BASH_LINENO[@]}")
error_funcname=("${FUNCNAME[@]}")
unset 'error_source[-1]' 'error_lineno[-1]' 'error_funcname[-1]'
unset 'error_source[0]' 'error_lineno[-1]' 'error_funcname[0]'
error_funcname[-1]='<main>'
error_source=("${error_source[@]}")
error_lineno=("${error_lineno[@]}")
error_funcname=("${error_funcname[@]}")
failure_code=${1:-0}
failure_type="EXIT"
failure_payload="${error_funcname[0]}"
miaou_debug "<overridden_exit code=$failure_code/>"
print_miaou_error "${BASH_SOURCE[1]}" "${BASH_LINENO[0]}" "${failure_code}" "${failure_type}" "${failure_payload}"
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}}>"

53
test/miaou-bash.test.bash

@ -6,13 +6,15 @@
function assert { function assert {
((test_count++)) ((test_count++))
if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null; then
echo -n .
else
echo -n F
failures+=("$1")
return 1
if miaou-bash ./test/stub/scenario.bash "$1" >/dev/null 2>/dev/null 3>_miaou; then
if [[ -s _miaou ]]; then
echo -n .
return
fi
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
assert_grep success_with_args 'count args: 2' -- 'A B' C
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'
TIMEFORMAT=$'\nelapsed: %Rs'
time {
assert success
assert exit_0
assert_grep success_with_args 'count args: 2' -- 'A B' C
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

2
test/stub/extra/onemore.bash

@ -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

10
test/stub/scenario.bash

@ -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 "b=${b}"
echo -n "content: "
echo -n "a=${a} b=${b}"
} }
function do_source_not_found { function do_source_not_found {

Loading…
Cancel
Save