From 3a58ee390e9781d0cd0bbb316cb5fed13cbfb448 Mon Sep 17 00:00:00 2001 From: Tyler Akins Date: Mon, 10 Apr 2023 11:39:47 -0500 Subject: [PATCH] More bugfixes and shellcheck tweaks --- demo/associative-arrays | 2 +- demo/embedded-template | 1 + demo/function-args | 10 ++++++---- mo | 9 +++++---- run-spec.js | 43 +++++++++++++++++++++++++++++++---------- tests/invalid-option | 2 +- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/demo/associative-arrays b/demo/associative-arrays index bc66117..f0d8950 100755 --- a/demo/associative-arrays +++ b/demo/associative-arrays @@ -3,7 +3,7 @@ cd "$(dirname "$0")" # Go to the script's directory declare -A DATA -DATA=([one]=111 [two]=222) +export DATA=([one]=111 [two]=222) . ../mo cat < Escaping": { skip: "HTML escaping is not supported" }, + "Lambdas -> Inverted Section": { + // This one passed mostly by accident. Correcting so the test still + // tests what is was designed to illustrate. + data: { + static: "static", + lambda: { + __tag__: 'code', + bash: 'false' + } + } + }, + "Lambdas -> Section - Alternate Delimiters": { + data: { + lambda: { + __tag__: 'code', + bash: 'content=$(cat); echo -n "$content{{planet}}=>|planet|$content"' + } + } + }, + "Lambdas -> Section - Multiple Calls": { + data: { + lambda: { + __tag__: 'code', + bash: 'echo -n "__$(cat)__"' + } + } + }, "Partials -> Recursion": { skip: "Complex objects are not supported and context is reset to the global level, so the recursion will loop forever" }, @@ -158,14 +185,8 @@ function addToEnvironmentObject(name, value) { return `#${name} is null`; } - // Sometimes the __tag__ property of the code in the lambdas may be - // missing. Compensate by detecting commonly defined languages. - if (value.__tag__ === "code" || (value.ruby && value.php && value.perl)) { - if (value.bash) { - return `${name}() { ${value.bash}; }`; - } - - return `${name}() { perl -e 'print ((${value.perl})->("'"$1"'"))'; }`; + if (value.__tag__ === "code") { + return `${name}() { ${value.bash || 'echo "NO BASH VERSION OF CODE"'}; }`; } return addToEnvironmentObjectConvertedToAssociativeArray(name, value); @@ -288,12 +309,12 @@ function runTest(testSet, test) { test.script = buildScript(test); if (test.skip) { - debug("Skipping test:", testSet.fullName, `$(${test.skip})`); + debug("Skipping test:", test.fullName, `(${test.skip})`); return Promise.resolve(); } - debug("Running test:", testSet.fullName); + debug("Running test:", test.fullName); return setupEnvironment(test) .then(() => executeScript(test)) @@ -303,6 +324,8 @@ function runTest(testSet, test) { if (test.isFailure) { showFailureDetails(test); + } else { + debug('Test pass:', test.fullName); } }); } diff --git a/tests/invalid-option b/tests/invalid-option index bba194e..8817896 100755 --- a/tests/invalid-option +++ b/tests/invalid-option @@ -6,6 +6,6 @@ export person="" export template="" export returnCode=1 export arguments=(--something) -export expected=$'ERROR: Unknown option: --something (See --help for options)\n' +export expected=$'ERROR: Unknown option: --something (See --help for options)\n' runTest