Browse Source

test elapsed time

main
pvincent 1 week ago
parent
commit
eb06c0e061
  1. 46
      README.md
  2. 10
      bin/miaou-bash
  3. 17
      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
* [x] miaou-bash
* [x] semver-git_tag
* [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
@ -40,20 +49,9 @@ Any feedback would be appreciated. [contact@artcode.re](mailto:contact@artcode.r
* 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
* ALT DELETE, BACKSPACE => delete line from cursor
* CTRL + SHIFT + / => undo

10
bin/miaou-bash

@ -85,6 +85,8 @@ function on_return {
# overridden function which permits backtracing of the original `exit` statement
function exit {
code=${1:-0}
if [[ $code -gt 0 ]]; then
error_source=("${BASH_SOURCE[@]}")
error_lineno=("${BASH_LINENO[@]}")
error_funcname=("${FUNCNAME[@]}")
@ -99,9 +101,10 @@ function exit {
failure_type="EXIT"
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}"
builtin exit "$failure_code"
fi
builtin exit "$code"
}
function tty_ansi {
@ -135,7 +138,8 @@ function add_miaou_error {
function on_error {
trap - RETURN
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}}>"

17
test/miaou-bash.test.bash

@ -6,13 +6,15 @@
function assert {
((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
if [[ -s _miaou ]]; then
echo -n .
else
return
fi
fi
echo -n F
failures+=("$1")
return 1
fi
}
# assert performing '$1:script' successfully + output must contain '$2:content'
@ -71,7 +73,11 @@ set -uo pipefail
test_count=0
failures=()
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
@ -86,17 +92,16 @@ 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[@]}
success=$((test_count - failed))
echo
if [[ $failed -gt 0 ]]; then
ratio=$((100 * success / test_count))
echo "${ratio}% passed, ${test_count} tests, ${failed} failed!"
echo failures:
for failure in "${failures[@]}"; do
echo -e "\t- $failure"
echo -e "\t- $failure => replay: ./test/stub/scenario.bash $failure"
done
exit 1
else

2
test/stub/extra/onemore.bash

@ -9,7 +9,7 @@ function onemore {
function do_next {
echo do_next
exit 10 # youpi
exit 13 # youpi
grep nope nope
echo $nope
command_not_found

10
test/stub/scenario.bash

@ -76,14 +76,20 @@ function do_success {
return
}
function do_exit_0 {
echo success
exit 0
echo SHOULD NOT APPEAR
}
function do_success_with_args {
echo "count args: $#"
}
function do_unbound_variable {
a=5
echo "a=${a}"
echo "b=${b}"
echo -n "content: "
echo -n "a=${a} b=${b}"
}
function do_source_not_found {

Loading…
Cancel
Save