mirror of
https://github.com/tests-always-included/mo.git
synced 2024-12-18 16:27:52 +00:00
Overriding some tests so they work with mo + bugfix
This commit is contained in:
parent
47e10012ee
commit
a1e4398547
2
mo
2
mo
@ -1513,7 +1513,7 @@ mo::evaluateVariable() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if mo::isArray "${moNameParts[0]}"; then
|
if mo::isArray "${moNameParts[0]}"; then
|
||||||
eval "moResult=\"\${${moNameParts[0]}[${moNameParts[1]%%.*}]}\""
|
eval "set +u;moResult=\"\${${moNameParts[0]}[${moNameParts[1]%%.*}]}\""
|
||||||
else
|
else
|
||||||
mo::error "Unable to index a scalar as an array: $moArg"
|
mo::error "Unable to index a scalar as an array: $moArg"
|
||||||
fi
|
fi
|
||||||
|
72
run-spec.js
72
run-spec.js
@ -11,14 +11,28 @@ const fsPromises = require("fs").promises;
|
|||||||
//
|
//
|
||||||
// To override any test property, just define that property.
|
// To override any test property, just define that property.
|
||||||
const testOverrides = {
|
const testOverrides = {
|
||||||
'Lambdas -> Escaping': {
|
'Interpolation -> HTML Escaping': {
|
||||||
skip: 'HTML escaping is not supported'
|
skip: 'HTML escaping is not supported'
|
||||||
},
|
},
|
||||||
'Interpolation -> Implicit Iterators - HTML Escaping': {
|
'Interpolation -> Implicit Iterators - HTML Escaping': {
|
||||||
skip: 'HTML escaping is not supported'
|
skip: 'HTML escaping is not supported'
|
||||||
},
|
},
|
||||||
'Interpolation -> HTML Escaping': {
|
'Lambdas -> Escaping': {
|
||||||
skip: 'HTML escaping is not supported'
|
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) {
|
function makeShellString(value) {
|
||||||
|
if (typeof value === "boolean") {
|
||||||
|
return value ? '"true"' : '""';
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
// Newlines are tricky
|
// Newlines are tricky
|
||||||
return value
|
return value
|
||||||
@ -88,10 +106,34 @@ function addToEnvironmentArray(name, value) {
|
|||||||
return name + "=" + result.join(" ");
|
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) {
|
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
|
// Sometimes the __tag__ property of the code in the lambdas may be
|
||||||
// missing. :-(
|
// missing. Compensate by detecting commonly defined languages.
|
||||||
if (
|
if (
|
||||||
(value.__tag__ === "code") ||
|
(value.__tag__ === "code") ||
|
||||||
(value.ruby && value.php && value.perl)
|
(value.ruby && value.php && value.perl)
|
||||||
@ -103,11 +145,8 @@ function addToEnvironmentObject(name, value) {
|
|||||||
return `${name}() { perl -e 'print ((${value.perl})->("'"$1"'"))'; }`;
|
return `${name}() { perl -e 'print ((${value.perl})->("'"$1"'"))'; }`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `#${name} is an object and will not work in Bash`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// null
|
return addToEnvironmentObjectConvertedToAssociativeArray(name, value);
|
||||||
return `#${name} is null`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToEnvironment(name, value) {
|
function addToEnvironment(name, value) {
|
||||||
@ -119,10 +158,6 @@ function addToEnvironment(name, value) {
|
|||||||
return addToEnvironmentObject(name, value);
|
return addToEnvironmentObject(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
return `${name}="${value ? "true" : ""}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${name}=${makeShellString(value)}`;
|
return `${name}=${makeShellString(value)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,19 +239,26 @@ function showFailureDetails(test) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function applyTestOverrides(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)) {
|
for (const [key, value] of Object.entries(overrides)) {
|
||||||
|
originals[key] = test[key];
|
||||||
test[key] = value;
|
test[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test.valuesBeforeOverride = originals;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runTest(testSet, test) {
|
function runTest(testSet, test) {
|
||||||
test.script = buildScript(test);
|
|
||||||
test.partials = test.partials || {};
|
test.partials = test.partials || {};
|
||||||
test.fullName = `${testSet.name} -> ${test.name}`;
|
test.fullName = `${testSet.name} -> ${test.name}`;
|
||||||
|
|
||||||
applyTestOverrides(test);
|
applyTestOverrides(test);
|
||||||
|
test.script = buildScript(test);
|
||||||
|
|
||||||
if (test.skip) {
|
if (test.skip) {
|
||||||
debug('Skipping test:', testSet.fullName, `$(${test.skip})`);
|
debug('Skipping test:', testSet.fullName, `$(${test.skip})`);
|
||||||
|
10
tests/unbound-variable
Executable file
10
tests/unbound-variable
Executable 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
|
Loading…
Reference in New Issue
Block a user