Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/framework/Testee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {WASM} from '../sourcemap/Wasm';
import {DummyProxy} from '../testbeds/Emulator';
import {ScenarioResult, Skipped, StepOutcome, SuiteResult} from '../reporter/Results';
import {Verifier} from './Verifier';
import {stringify} from "../util/util";

export function timeout<T>(label: string, time: number, promise: Promise<T>): Promise<T> {
if (time === 0) {
Expand Down Expand Up @@ -211,9 +212,10 @@ export class Testee { // TODO unified with testbed interface
}

for (const step of description.steps ?? []) {
const verifier: Verifier = new Verifier(step);

/** Perform the step and check if expectations were met */
await this.step(step.title, testee.timeout, async function () {
const verifier: Verifier = new Verifier(step);
if (testee.bed(step.target ?? Target.supervisor) === undefined) {
testee.states.set(description.title, verifier.error('Cannot run test: no debugger connection.'));
return;
Expand Down Expand Up @@ -246,6 +248,10 @@ export class Testee { // TODO unified with testbed interface
previous = actual;
}

testee.states.set(description.title, result);
scenarioResult.add(result);
}).catch((error: Error | string) => {
const result = verifier.error(stringify(error));
testee.states.set(description.title, result);
scenarioResult.add(result);
});
Expand Down
4 changes: 1 addition & 3 deletions src/framework/Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export class Verifier {
}

public error(clarification: string): StepOutcome {
const result: StepOutcome = new StepOutcome(this.step);
result.update(Outcome.succeeded);
return result.update(Outcome.error, clarification);
return new StepOutcome(this.step).update(clarification.includes('timeout') ? Outcome.timedout : Outcome.error, clarification);
}

private expectPrimitive<T>(actual: T, expected: T): StepOutcome {
Expand Down
6 changes: 4 additions & 2 deletions src/messaging/Parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ export function signed(value: bigint, bits = 32) {
}

function extractType(object: {value: bigint | number, type: any}): Type {
if (isNaN(<number>object.value)) return WASM.Special.nan;
if (<number>object.value === Infinity) return WASM.Special.infinity;
if (typeof object.value === 'number') {
if (Number.isNaN(object.value)) return WASM.Special.nan;
if (object.value === Infinity) return WASM.Special.infinity;
}
return WASM.typing.get(object.type.toLowerCase()) ?? WASM.Special.unknown;
}

Expand Down
2 changes: 1 addition & 1 deletion src/reporter/Results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ abstract class AbstractAggregateResult implements AggregateResult {
}

private failing(): boolean {
return this.subOutcomes.some((outcome) => outcome.outcome === Outcome.failed);
return this.subOutcomes.some((outcome) => outcome.outcome === Outcome.failed || outcome.outcome === Outcome.timedout);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/reporter/Style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Labels {

success: string;
skipped: string;
timeout: string;
failure: string;
error: string;
}
Expand Down Expand Up @@ -68,6 +69,7 @@ export class Plain implements Style {
suiteSkipped: ' SKIPPED ',
success: ' PASS ',
skipped: ' SKIP ',
timeout: ' TIMEOUT ',
failure: ' FAIL ',
error: ' ERROR '
}
Expand Down
2 changes: 2 additions & 0 deletions src/reporter/describers/Describer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class StepDescriber extends Describer<StepOutcome> {
case Outcome.uncommenced:
case Outcome.skipped:
return [`${style.colors.skipped(style.labels.skipped)} ${this.item.name}`];
case Outcome.timedout:
return [`${style.colors.failure(style.labels.timeout)} ${this.item.name}`];
case Outcome.error:
case Outcome.failed:
default:
Expand Down
4 changes: 4 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ export function find(regex: RegExp, input: string) {
return '';
}
return match[1];
}

export function stringify(chunk: Error | string): string {
return chunk instanceof Error ? chunk.message : chunk;
}
21 changes: 18 additions & 3 deletions tests/unit/parsing.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import test from 'ava';
import {signed, stateParser} from "../../src/messaging/Parsers";
import {WARDuino} from "../../src";
import {invokeParser, signed, stateParser} from "../../src/messaging/Parsers";
import {Exception, WARDuino} from "../../src";
import {WASM} from "../../src/sourcemap/Wasm";
import State = WARDuino.State;
import Type = WASM.Type;

/**
* Check unsigned 32-bit integer to signed conversion
Expand Down Expand Up @@ -53,4 +55,17 @@ test('[state parser] : 64-bit integer precision', t => {
const state: State = stateParser(`{\"stack\": [{\"idx\":0,\"type\":\"i32\",\"value\":${value}}]}\n`);
t.true(equality(state.stack?.[0].value, value));
}
});
});

test('[invoke parser] : i64 signed conversion', t => {
const result: WASM.Value<Type> | Exception = invokeParser('{"stack": [{"idx":0,"type":"i64","value":18446744073709551615}]}\n');

if ('text' in result) { // check if exception
t.fail(`Expected parsed value, got exception: ${result.text}`);
return;
}

t.is(result.type, WASM.Integer.i64);
t.is(result.value, -1n);
});

Loading