mirror of
https://github.com/tests-always-included/mo.git
synced 2024-12-18 16:27:52 +00:00
Fixing empty variable failure for --fail-not-set
This commit is contained in:
parent
2b611b8f90
commit
31b2faf135
12
mo
12
mo
@ -758,7 +758,7 @@ moShow() {
|
|||||||
echo -n "$moJoined"
|
echo -n "$moJoined"
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2031
|
# shellcheck disable=SC2031
|
||||||
if [[ -z "$MO_FAIL_ON_UNSET" ]] || moTest "$1"; then
|
if [[ -z "$MO_FAIL_ON_UNSET" ]] || moTestVarSet "$1"; then
|
||||||
echo -n "${!1}"
|
echo -n "${!1}"
|
||||||
else
|
else
|
||||||
echo "Env variable not set: $1" >&2
|
echo "Env variable not set: $1" >&2
|
||||||
@ -880,6 +880,16 @@ moTest() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Internal: Determine if a variable is assigned, even if it is assigned an empty
|
||||||
|
# value.
|
||||||
|
#
|
||||||
|
# $1 - Variable name to check.
|
||||||
|
#
|
||||||
|
# Returns true (0) if the variable is set, 1 if the variable is unset.
|
||||||
|
moTestVarSet() {
|
||||||
|
[[ "${!1-a}" == "${!1-b}" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Internal: Trim the leading whitespace only.
|
# Internal: Trim the leading whitespace only.
|
||||||
#
|
#
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
cd "${0%/*}"
|
cd "${0%/*}"
|
||||||
unset __NO_SUCH_VAR
|
unset __NO_SUCH_VAR
|
||||||
../mo --fail-not-set ./fail-not-set-file.template 2>&1
|
POPULATED="words" EMPTY="" ../mo --fail-not-set ./fail-not-set-file.template 2>&1
|
||||||
|
|
||||||
if [[ $? -ne 1 ]]; then
|
if [[ $? -ne 1 ]]; then
|
||||||
echo "Did not return 1"
|
echo "Did not return 1"
|
||||||
|
@ -1 +1,3 @@
|
|||||||
* {{__NO_SUCH_VAR}}
|
Populated: {{POPULATED}};
|
||||||
|
Empty: {{EMPTY}};
|
||||||
|
Unset: {{__NO_SUCH_VAR}};
|
||||||
|
@ -1 +1,3 @@
|
|||||||
This will fail: Env variable not set: __NO_SUCH_VAR
|
Populated: words;
|
||||||
|
Empty: ;
|
||||||
|
Unset: Env variable not set: __NO_SUCH_VAR
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
|
|
||||||
cd "${0%/*}"
|
cd "${0%/*}"
|
||||||
unset __NO_SUCH_VAR
|
unset __NO_SUCH_VAR
|
||||||
echo "This will fail: {{__NO_SUCH_VAR}}" | ../mo --fail-not-set 2>&1
|
POPULATED="words" EMPTY="" ../mo --fail-not-set 2>&1 <<EOF
|
||||||
|
Populated: {{POPULATED}};
|
||||||
|
Empty: {{EMPTY}};
|
||||||
|
Unset: {{__NO_SUCH_VAR}};
|
||||||
|
EOF
|
||||||
|
|
||||||
if [[ $? -ne 1 ]]; then
|
if [[ $? -ne 1 ]]; then
|
||||||
echo "Did not return 1"
|
echo "Did not return 1"
|
||||||
|
Loading…
Reference in New Issue
Block a user