mirror of https://github.com/espruino/BangleApps
runapptests - Tweak some of the logging
parent
1b4af29529
commit
816313e136
|
@ -110,20 +110,23 @@ function getValue(js){
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertArray(step){
|
function assertArray(step){
|
||||||
|
console.log(`> ASSERT ARRAY ${step.js} IS`,step.is.toUpperCase(), step.text ? "- " + step.text : "");
|
||||||
let isOK;
|
let isOK;
|
||||||
switch (step.is.toLowerCase()){
|
switch (step.is.toLowerCase()){
|
||||||
case "notempty": isOK = getValue(`${step.js} && ${step.js}.length > 0`); break;
|
case "notempty": isOK = getValue(`${step.js} && ${step.js}.length > 0`); break;
|
||||||
case "undefinedorempty": isOK = getValue(`!${step.js} || (${step.js} && ${step.js}.length === 0)`); break;
|
case "undefinedorempty": isOK = getValue(`!${step.js} || (${step.js} && ${step.js}.length === 0)`); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOK)
|
if (isOK) {
|
||||||
console.log("> OK - ASSERT ARRAY " + step.is.toUpperCase(), step.text ? "- " + step.text : "");
|
if (verbose)
|
||||||
else
|
console.log("> OK -", `\`${step.js}\``);
|
||||||
console.log("> FAIL - ASSERT ARRAY " + step.is.toUpperCase(), step.text ? "- " + step.text : "");
|
} else
|
||||||
|
console.log("> FAIL -", `\`${step.js}\``);
|
||||||
return isOK;
|
return isOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertValue(step){
|
function assertValue(step){
|
||||||
|
console.log("> ASSERT " + `\`${step.js}\``, "IS", step.is.toUpperCase(), step.to ? "TO " + `\`${step.js}\`` : "", step.text ? "- " + step.text : "");
|
||||||
let isOK;
|
let isOK;
|
||||||
switch (step.is.toLowerCase()){
|
switch (step.is.toLowerCase()){
|
||||||
case "truthy": isOK = getValue(`!!${step.js}`); break;
|
case "truthy": isOK = getValue(`!!${step.js}`); break;
|
||||||
|
@ -134,15 +137,16 @@ function assertValue(step){
|
||||||
case "function": isOK = getValue(`typeof ${step.js} === "function"`); break;
|
case "function": isOK = getValue(`typeof ${step.js} === "function"`); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOK)
|
if (isOK){
|
||||||
console.log("> OK - ASSERT " + step.is.toUpperCase(), step.text ? "- " + step.text : "");
|
if (verbose)
|
||||||
else
|
console.log("> OK - " + `\`${step.js}\``, "IS", step.is.toUpperCase(), step.to ? "TO " + `\`${step.js}\`` : "");
|
||||||
console.log("> FAIL - ASSERT " + step.is.toUpperCase(), step.text ? "- " + step.text : "");
|
} else
|
||||||
|
console.log("> FAIL - " + `\`${step.js}\``, "IS", step.is.toUpperCase(), step.to ? "TO " + `\`${step.js}\`` : "");
|
||||||
return isOK;
|
return isOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrap(func, id){
|
function wrap(func, id){
|
||||||
console.log(`> Wrapping "${func}"`);
|
console.log(`> WRAPPING \`${func}\` AS ${id}`);
|
||||||
|
|
||||||
let wrappingCode = `
|
let wrappingCode = `
|
||||||
if(!global.APPTESTS) global.APPTESTS={};
|
if(!global.APPTESTS) global.APPTESTS={};
|
||||||
|
@ -161,6 +165,7 @@ function wrap(func, id){
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertCall(step){
|
function assertCall(step){
|
||||||
|
console.log("> ASSERT CALL", step.id, step.text ? "- " + step.text : "");
|
||||||
let isOK = true;
|
let isOK = true;
|
||||||
let id = step.id;
|
let id = step.id;
|
||||||
let args = step.argAsserts;
|
let args = step.argAsserts;
|
||||||
|
@ -187,9 +192,10 @@ function assertCall(step){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isOK)
|
if (isOK){
|
||||||
|
if (verbose)
|
||||||
console.log("OK - ASSERT CALL", step.text ? "- " + step.text : "");
|
console.log("OK - ASSERT CALL", step.text ? "- " + step.text : "");
|
||||||
else
|
} else
|
||||||
console.log("FAIL - ASSERT CALL", step.text ? "- " + step.text : "");
|
console.log("FAIL - ASSERT CALL", step.text ? "- " + step.text : "");
|
||||||
return isOK;
|
return isOK;
|
||||||
}
|
}
|
||||||
|
@ -248,14 +254,17 @@ function runStep(step, subtest, test, state){
|
||||||
break;
|
break;
|
||||||
case "eval" :
|
case "eval" :
|
||||||
p = p.then(() => {
|
p = p.then(() => {
|
||||||
console.log(`> Evaluate "${step.js}"`);
|
console.log(`> EVAL \`${step.js}\``);
|
||||||
emu.tx(`\x10print(JSON.stringify(${step.js}))\n`);
|
emu.tx(`\x10print(JSON.stringify(${step.js}))\n`);
|
||||||
var result = getSanitizedLastLine();
|
var result = getSanitizedLastLine();
|
||||||
var expected = JSON.stringify(step.eq);
|
var expected = JSON.stringify(step.eq);
|
||||||
|
if (verbose)
|
||||||
console.log("> GOT `"+result+"`");
|
console.log("> GOT `"+result+"`");
|
||||||
if (result!=expected) {
|
if (result!=expected) {
|
||||||
console.log("> FAIL: EXPECTED "+expected);
|
console.log("> FAIL: EXPECTED "+expected);
|
||||||
state.ok = false;
|
state.ok = false;
|
||||||
|
} else if (verbose) {
|
||||||
|
console.log("> OK: EXPECTED "+expected);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -291,8 +300,8 @@ function runStep(step, subtest, test, state){
|
||||||
case "checkMemoryUsage" :
|
case "checkMemoryUsage" :
|
||||||
p = p.then(() => {
|
p = p.then(() => {
|
||||||
emu.tx(`\x10print(process.memory().usage)\n`);
|
emu.tx(`\x10print(process.memory().usage)\n`);
|
||||||
var memUsage = getSanitizedLastLine();
|
var memUsage = parseInt(getSanitizedLastLine());
|
||||||
console.log("> CURRENT MEMORY USAGE", memUsage);
|
console.log("> COMPARE MEMORY USAGE", memUsage);
|
||||||
if (subtest.memUsage != memUsage ) {
|
if (subtest.memUsage != memUsage ) {
|
||||||
console.log("> FAIL: EXPECTED MEMORY USAGE OF "+subtest.memUsage);
|
console.log("> FAIL: EXPECTED MEMORY USAGE OF "+subtest.memUsage);
|
||||||
state.ok = false;
|
state.ok = false;
|
||||||
|
@ -388,6 +397,7 @@ function runTest(test, testState) {
|
||||||
emu.factoryReset();
|
emu.factoryReset();
|
||||||
console.log("> SENDING APP "+test.app);
|
console.log("> SENDING APP "+test.app);
|
||||||
emu.tx(command);
|
emu.tx(command);
|
||||||
|
if (verbose)
|
||||||
console.log("> SENT APP");
|
console.log("> SENT APP");
|
||||||
emu.tx("reset()\n");
|
emu.tx("reset()\n");
|
||||||
console.log("> RESET");
|
console.log("> RESET");
|
||||||
|
|
Loading…
Reference in New Issue