better test support

This commit is contained in:
Peli de Halleux
2017-12-19 13:10:40 -08:00
parent e07d6e3a31
commit eac3e183c3
4 changed files with 38 additions and 31 deletions

View File

@ -67,8 +67,8 @@ namespace console.screen {
if (!lines) {
lines = [];
console.addListener(log);
brick.buttonUp.onEvent(ButtonEvent.Click, () => scroll(1))
brick.buttonDown.onEvent(ButtonEvent.Click, () => scroll(-1))
brick.buttonUp.onEvent(ButtonEvent.Click, () => scroll(-1))
brick.buttonDown.onEvent(ButtonEvent.Click, () => scroll(1))
}
}

View File

@ -75,9 +75,9 @@ namespace motors {
* @param buf message buffer
*/
//%
export function readPWM(buf: Buffer): number {
export function readPWM(buf: Buffer): void {
init()
return pwmMM.read(buf);
pwmMM.read(buf);
}
/**
@ -261,9 +261,16 @@ namespace motors {
//%
isReady(): boolean {
this.init();
const r = readPWM(mkCmd(this._port, DAL.opOutputTest, 0))
// 0 = ready, 1 = busy
return r == 0;
const buf = mkCmd(this._port, DAL.opOutputTest, 2);
readPWM(buf)
const flags = buf.getNumber(NumberFormat.UInt8LE, 2);
// TODO: FIX with ~ support
for(let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
const flag = 1 << i;
if ((this._port & flag) && (flags & flag))
return false;
}
return true;
}
/**
@ -529,8 +536,8 @@ namespace motors {
export const largeCD = new SynchedMotorPair(Output.CD);
function reset(out: Output) {
let b = mkCmd(out, DAL.opOutputReset, 0)
writePWM(b)
writePWM(mkCmd(out, DAL.opOutputReset, 0))
writePWM(mkCmd(out, DAL.opOutputClearCount, 0))
}
function outOffset(out: Output) {

View File

@ -23,9 +23,12 @@ namespace tests {
// clear state
this.reset();
console.log(`# ${this.name}`)
console.log(`> ${this.name}`)
this.handler()
if (this.errors.length)
console.log('')
// ensure clean state after test
this.reset();
}
@ -39,13 +42,15 @@ namespace tests {
const start = control.millis();
console.sendToScreen();
console.log(`${_tests.length} tests`)
console.log(`${_tests.length} tests found`)
console.log(` `)
for (let i = 0; i < _tests.length; ++i) {
const t = _currentTest = _tests[i];
t.run();
_currentTest = undefined;
}
console.log(`${_tests.map(t => t.errors.length).reduce((p, c) => p + c, 0)} X, ${Math.ceil((control.millis() - start) / 1000)}s`)
console.log(` `)
console.log(`${_tests.length} tests, ${_tests.map(t => t.errors.length).reduce((p, c) => p + c, 0)} errs in ${Math.ceil((control.millis() - start) / 1000)}s`)
}
/**
@ -71,7 +76,7 @@ namespace tests {
//% blockId=testAssert block="assert %message|%condition"
export function assert(message: string, condition: boolean) {
if (!condition) {
console.log(` X ${message || ''}`)
console.log(`!!! ${message || ''}`)
if (_currentTest)
_currentTest.errors.push(message);
}