Adding tests, shellcheck cleanup, update docs, release 2.2.0

This commit is contained in:
Tyler Akins
2020-08-05 15:44:04 -05:00
parent 65f12277e6
commit dcd9d7738b
19 changed files with 285 additions and 194 deletions

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# This should display a message indicating that the file --help
# could not be found. It should not display a help messsage.
cd "${0%/*}"
cd "${0%/*}" || exit 1
../mo -- --help 2>&1

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
unset __NO_SUCH_VAR
POPULATED="words" EMPTY="" ../mo --fail-not-set ./fail-not-set-file.template 2>&1

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
unset __NO_SUCH_VAR
POPULATED="words" EMPTY="" ../mo --fail-not-set 2>&1 <<EOF
Populated: {{POPULATED}};

View File

@@ -0,0 +1 @@
Fail on function? Function 'failFunction' with args () failed with status code 1

18
tests/fail-on-function.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
cd "${0%/*}" || exit 1
failFunction() {
false
}
# Must be sourced to use functions
# shellcheck disable=SC1091
. ../mo
mo --fail-on-function 2>&1 <<EOF
Fail on function? {{failFunction}}
EOF
if [[ $? -ne 1 ]]; then
echo "Did not return 1"
fi

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
USER=j.doe ADMIN=false ../mo --false false-is-empty-arg.template

View File

@@ -9,9 +9,19 @@ Learn more about mustache templates at https://mustache.github.io/
Simple usage:
mo [--false] [--help] [--source=FILE] filenames...
mo [OPTIONS] filenames...
--fail-not-set - Fail upon expansion of an unset variable.
--false - Treat the string "false" as empty for conditionals.
--help - This message.
--source=FILE - Load FILE into the environment before processing templates.
Options:
-u, --fail-not-set
- Fail upon expansion of an unset variable.
-x, --fail-on-function
- Fail when a function returns a non-zero status code.
-e, --false
- Treat the string "false" as empty for conditionals.
-h, --help
- This message.
-s=FILE, --source=FILE
- Load FILE into the environment before processing templates.
MO_VERSION=2.2.0

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
../mo --help

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# This should display a message indicating that the file --something
# could not be found.
cd "${0%/*}"
cd "${0%/*}" || exit 1
../mo --something 2>&1

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
../mo partial-missing.template 2>&1
if [[ $? -ne 1 ]]; then

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
echo "Do not display this" | ../mo --source=invalid 2>&1
if [[ $? -ne 1 ]]; then

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
echo "Do not display this" | ../mo --source= 2>&1
if [[ $? -ne 1 ]]; then

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
cd "${0%/*}"
cd "${0%/*}" || exit 1
cat <<EOF | ../mo --source=source.vars
{{VAR}}
{{#ARR}}

View File

@@ -1,4 +1,5 @@
export VAR=value
export ARR=(1 2 3)
declare -A ASSOC_ARR
export ASSOC_ARR=([a]=AAA [b]=BBB)
# Can not export associative arrays, otherwise they turn into indexed arrays
ASSOC_ARR=([a]=AAA [b]=BBB)