Overriding some tests so they work with mo + bugfix

This commit is contained in:
Tyler Akins 2023-04-09 10:20:17 -05:00
parent 47e10012ee
commit a1e4398547
No known key found for this signature in database
GPG Key ID: 8F3B8C432F4393BD
3 changed files with 77 additions and 25 deletions

2
mo
View File

@ -1513,7 +1513,7 @@ mo::evaluateVariable() {
fi
else
if mo::isArray "${moNameParts[0]}"; then
eval "moResult=\"\${${moNameParts[0]}[${moNameParts[1]%%.*}]}\""
eval "set +u;moResult=\"\${${moNameParts[0]}[${moNameParts[1]%%.*}]}\""
else
mo::error "Unable to index a scalar as an array: $moArg"
fi

View File

@ -11,14 +11,28 @@ const fsPromises = require("fs").promises;
//
// To override any test property, just define that property.
const testOverrides = {
'Lambdas -> Escaping': {
'Interpolation -> HTML Escaping': {
skip: 'HTML escaping is not supported'
},
'Interpolation -> Implicit Iterators - HTML Escaping': {
skip: 'HTML escaping is not supported'
},
'Interpolation -> HTML Escaping': {
'Lambdas -> Escaping': {
skip: 'HTML escaping is not supported'
},
'Sections -> Dotted Names - Broken Chains': {
// Complex objects are not supported
template: `"{{#a.b}}Here{{/a.b}}" == ""`
},
'Sections -> Dotted Names - Falsey': {
// Complex objects are not supported
data: { a: { b: false } },
template: `"{{#a.b}}Here{{/a.b}}" == ""`
},
'Sections -> Dotted Names - Truthy': {
// Complex objects are not supported
data: { a: { b: true } },
template: `"{{#a.b}}Here{{/a.b}}" == "Here"`
}
};
@ -61,6 +75,10 @@ function debug(...args) {
}
function makeShellString(value) {
if (typeof value === "boolean") {
return value ? '"true"' : '""';
}
if (typeof value === "string") {
// Newlines are tricky
return value
@ -88,10 +106,34 @@ function addToEnvironmentArray(name, value) {
return name + "=" + result.join(" ");
}
function addToEnvironmentObjectConvertedToAssociativeArray(name, value) {
const values = [];
for (const [k, v] of Object.entries(value)) {
if (typeof v === 'object') {
if (v) {
// An object - abort
return `# ${name}.${k} is an object that can not be converted to an associative array`;
}
// null
values.push(`[${k}]=`);
} else {
values.push(`[${k}]=${makeShellString(v)}`);
}
}
return `declare -A ${name}\n${name}=(${values.join(' ')})`;
}
function addToEnvironmentObject(name, value) {
if (value) {
if (!value) {
// null
return `#${name} is null`;
}
// Sometimes the __tag__ property of the code in the lambdas may be
// missing. :-(
// missing. Compensate by detecting commonly defined languages.
if (
(value.__tag__ === "code") ||
(value.ruby && value.php && value.perl)
@ -103,11 +145,8 @@ function addToEnvironmentObject(name, value) {
return `${name}() { perl -e 'print ((${value.perl})->("'"$1"'"))'; }`;
}
return `#${name} is an object and will not work in Bash`;
}
// null
return `#${name} is null`;
return addToEnvironmentObjectConvertedToAssociativeArray(name, value);
}
function addToEnvironment(name, value) {
@ -119,10 +158,6 @@ function addToEnvironment(name, value) {
return addToEnvironmentObject(name, value);
}
if (typeof value === "boolean") {
return `${name}="${value ? "true" : ""}"`;
}
return `${name}=${makeShellString(value)}`;
}
@ -204,19 +239,26 @@ function showFailureDetails(test) {
}
function applyTestOverrides(test) {
const overrides = testOverrides[test.fullName] || {};
const overrides = testOverrides[test.fullName];
const originals = {};
if (!overrides) {
return;
}
for (const [key, value] of Object.entries(overrides)) {
originals[key] = test[key];
test[key] = value;
}
test.valuesBeforeOverride = originals;
}
function runTest(testSet, test) {
test.script = buildScript(test);
test.partials = test.partials || {};
test.fullName = `${testSet.name} -> ${test.name}`;
applyTestOverrides(test);
test.script = buildScript(test);
if (test.skip) {
debug('Skipping test:', testSet.fullName, `$(${test.skip})`);

10
tests/unbound-variable Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
cd "${0%/*}" || exit 1
. ../run-tests
declare -A a
a=()
template="o{{#a.b}}WRONG{{/a.b}}k"
expected="ok"
runTest