success_with_args
This commit is contained in:
@@ -13,9 +13,29 @@ function assert {
|
||||
failures+=("$1")
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# assert performing '$1:script' successfully + output must contain '$2:content'
|
||||
# in case of extra args (4th position or more) must be provided after -- (3rd position)
|
||||
# 1: script
|
||||
# 2: content
|
||||
# 3: --
|
||||
# 4..: extra args
|
||||
function assert_grep {
|
||||
((test_count++))
|
||||
local script="$1" content="$2" extra_args=()
|
||||
[[ $# -gt 3 ]] && shift 3 && extra_args=("$@")
|
||||
|
||||
if miaou-bash ./test/stub/scenario.bash "$script" "${extra_args[@]}" >_stdout 2>/dev/null 3>/dev/null; then
|
||||
if grep -q "$content" _stdout; then
|
||||
echo -n .
|
||||
return
|
||||
fi
|
||||
fi
|
||||
echo -n F
|
||||
failures+=("$script")
|
||||
return 1
|
||||
}
|
||||
function fail_type {
|
||||
((test_count++))
|
||||
local success regex hint_message
|
||||
@@ -52,6 +72,8 @@ test_count=0
|
||||
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
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
# CONSTANTS
|
||||
|
||||
BASEDIR=$(dirname "$0")
|
||||
# readonly BASEDIR
|
||||
|
||||
# SCENARII
|
||||
|
||||
@@ -71,11 +70,16 @@ function do_false {
|
||||
}
|
||||
|
||||
function do_success {
|
||||
echo "count args: $#"
|
||||
[[ true==true ]] && echo true
|
||||
! false && echo unfalse
|
||||
return
|
||||
}
|
||||
|
||||
function do_success_with_args {
|
||||
echo "count args: $#"
|
||||
}
|
||||
|
||||
function do_unbound_variable {
|
||||
a=5
|
||||
echo "a=${a}"
|
||||
@@ -203,5 +207,5 @@ if test_contain_item SCENARII "$scenario"; then
|
||||
shift
|
||||
"do_${scenario}" "$@"
|
||||
else
|
||||
(>&2 echo "scenario <${scenario}> not found!" && usage && exit 2)
|
||||
(>&2 echo "scenario '${scenario}' not found!" && usage && exit 2)
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user