mirror of
https://github.com/tests-always-included/mo.git
synced 2025-11-19 23:34:32 +01:00
Adding tests, shellcheck cleanup, update docs, release 2.2.0
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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}};
|
||||
|
||||
1
tests/fail-on-function.expected
Normal file
1
tests/fail-on-function.expected
Normal file
@@ -0,0 +1 @@
|
||||
Fail on function? Function 'failFunction' with args () failed with status code 1
|
||||
18
tests/fail-on-function.sh
Executable file
18
tests/fail-on-function.sh
Executable 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "${0%/*}"
|
||||
cd "${0%/*}" || exit 1
|
||||
../mo --help
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "${0%/*}"
|
||||
cd "${0%/*}" || exit 1
|
||||
../mo partial-missing.template 2>&1
|
||||
|
||||
if [[ $? -ne 1 ]]; then
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "${0%/*}"
|
||||
cd "${0%/*}" || exit 1
|
||||
cat <<EOF | ../mo --source=source.vars
|
||||
{{VAR}}
|
||||
{{#ARR}}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user