2023-04-08 00:35:25 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
cd "${0%/*}" || exit 1
|
|
|
|
. ../run-tests
|
|
|
|
|
|
|
|
testArgs() {
|
2023-04-10 13:10:14 +00:00
|
|
|
local args
|
|
|
|
# shellcheck disable=SC2031
|
|
|
|
args=$(declare -p MO_FUNCTION_ARGS)
|
|
|
|
echo -n "${args#*=}"
|
2023-04-08 00:35:25 +00:00
|
|
|
}
|
|
|
|
template() {
|
|
|
|
cat <<EOF
|
2023-04-08 04:10:47 +00:00
|
|
|
No args: {{testArgs}} - done
|
|
|
|
One arg: {{testArgs 'one'}} - done
|
|
|
|
Multiple arguments: {{testArgs 'aa' 'bb' 'cc' 'x' "" '!' '{[_.|' }} - done
|
|
|
|
Evil: {{testArgs bla; cat /etc/issue}} - done
|
2023-04-08 00:35:25 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
expected() {
|
|
|
|
cat <<EOF
|
2023-04-08 04:10:47 +00:00
|
|
|
No args: () - done
|
|
|
|
One arg: ([0]="one") - done
|
|
|
|
Multiple arguments: ([0]="aa" [1]="bb" [2]="cc" [3]="x" [4]="" [5]="!" [6]="{[_.|") - done
|
|
|
|
Evil: ([0]="" [1]="" [2]="") - done
|
2023-04-08 00:35:25 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
runTest
|