Making --fail-not-set work with partials

The return code was not propagated through nested subshells in case
when files were passed in as arguments.
This commit is contained in:
Alexey Maslennikov 2017-06-15 21:47:12 +02:00
parent 50aa18e2a6
commit 2b611b8f90
4 changed files with 16 additions and 4 deletions

9
mo
View File

@ -696,7 +696,7 @@ moParse() {
# Returns nothing. # Returns nothing.
moPartial() { moPartial() {
# Namespace variables here to prevent conflicts. # Namespace variables here to prevent conflicts.
local moContent moFilename moIndent moPartial moStandalone local moContent moFilename moIndent moPartial moStandalone moUnindented
if moIsStandalone moStandalone "$2" "$4" "$5"; then if moIsStandalone moStandalone "$2" "$4" "$5"; then
moStandalone=( $moStandalone ) moStandalone=( $moStandalone )
@ -715,16 +715,17 @@ moPartial() {
( (
# TODO: Remove dirname and use a function instead # TODO: Remove dirname and use a function instead
cd "$(dirname -- "$moFilename")" || exit 1 cd "$(dirname -- "$moFilename")" || exit 1
moIndentLines moPartial "$moIndent" "$( moUnindented="$(
moLoadFile moPartial "${moFilename##*/}" moLoadFile moPartial "${moFilename##*/}"
moParse "${moPartial}" "$6" true moParse "${moPartial}" "$6" true
# Fix bash handling of subshells and keep trailing whitespace. # Fix bash handling of subshells and keep trailing whitespace.
# This is removed in moIndentLines. # This is removed in moIndentLines.
echo -n "." echo -n "."
)" )" || exit 1
moIndentLines moPartial "$moIndent" "$moUnindented"
echo -n "$moPartial" echo -n "$moPartial"
) ) || exit 1
local "$1" && moIndirect "$1" "$moContent" local "$1" && moIndirect "$1" "$moContent"
} }

View File

@ -0,0 +1 @@
Env variable not set: __NO_SUCH_VAR

9
tests/fail-not-set-file.sh Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
cd "${0%/*}"
unset __NO_SUCH_VAR
../mo --fail-not-set ./fail-not-set-file.template 2>&1
if [[ $? -ne 1 ]]; then
echo "Did not return 1"
fi

View File

@ -0,0 +1 @@
* {{__NO_SUCH_VAR}}