Skip to content

Commit

Permalink
Fix verbosity levels again
Browse files Browse the repository at this point in the history
  • Loading branch information
tolauwae committed Dec 12, 2024
1 parent 3de3672 commit 9fb4d65
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/framework/Testee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TestScenario} from './scenario/TestScenario';
import {OutofPlaceSpecification, PlatformType, TestbedSpecification} from '../testbeds/TestbedSpecification';
import {CompileOutput, CompilerFactory} from '../manage/Compiler';
import {WABT} from '../util/env';
import {Outcome} from '../reporter/verbosity/Describer';
import {Outcome} from '../reporter/describers/Describer';
import {WASM} from '../sourcemap/Wasm';
import {DummyProxy} from '../testbeds/Emulator';
import {ScenarioResult, Skipped, StepOutcome, SuiteResult} from '../reporter/Results';
Expand Down
2 changes: 1 addition & 1 deletion src/framework/Verifier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Behaviour, Description, Step} from './scenario/Step';
import {StepOutcome} from '../reporter/Results';
import {getValue} from './Testee';
import {Outcome} from '../reporter/verbosity/Describer';
import {Outcome} from '../reporter/describers/Describer';
import {bold} from 'ansi-colors';

// decorator for Step class
Expand Down
1 change: 0 additions & 1 deletion src/manage/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,3 @@ function getIndex(line: string): number {
function getName(line: string): string {
return find(/-> "([^"]+)"/, line);
}

34 changes: 26 additions & 8 deletions src/reporter/Reporter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import {StepOutcome, SuiteResult} from './Results';
import {SuiteResult} from './Results';
import {Archiver} from '../framework/Archiver';
import {Style} from './Style';
import {Verbosity} from './index';
import {version} from '../../package.json';
import {NormalSuiteDescriber} from './verbosity/SuiteDescribers';
import {green, red, yellow} from 'ansi-colors';
import {Outcome, StepDescriber} from './verbosity/Describer';
import {Outcome, SilentDescriber} from './describers/Describer';
import {indent} from '../util/printing';
import {
MinimalSuiteDescriber,
NormalSuiteDescriber,
ShortSuiteDescriber,
SuiteDescriber
} from './describers/SuiteDescribers';

function describer(verbosity: Verbosity, item: SuiteResult): SuiteDescriber {
switch (verbosity) {
case Verbosity.none:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
return new SilentDescriber<SuiteResult>(item);

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 8 spaces but found 12.
case Verbosity.minimal:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
return new MinimalSuiteDescriber(item);

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 8 spaces but found 12.
case Verbosity.short:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
return new ShortSuiteDescriber(item);

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 8 spaces but found 12.
case Verbosity.normal:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
case Verbosity.more:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
case Verbosity.all:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
case Verbosity.debug:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
default:

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 8.
return new NormalSuiteDescriber(item);

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 8 spaces but found 12.
}
}

export class Reporter {
private output: string = '';
Expand Down Expand Up @@ -42,7 +64,7 @@ export class Reporter {

report(suiteResult: SuiteResult) {
this.suites.push(suiteResult);
const report: string[] = new NormalSuiteDescriber(suiteResult).describe(this.style);
const report: string[] = describer(this.verbosity, suiteResult).describe(this.style);

for (const line of report) {
console.log(this.indent() + line);
Expand Down Expand Up @@ -115,8 +137,4 @@ export class Reporter {
test(title: string) {
this.output += ` test: ${title}\n`;
}

step(result: StepOutcome) {
this.output += ` ${new StepDescriber(result).describe(this.style).flat()}\n`;
}
}
2 changes: 1 addition & 1 deletion src/reporter/Results.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Step} from '../framework/scenario/Step';
import {Outcome} from './verbosity/Describer';
import {Outcome} from './describers/Describer';
import {TestScenario} from '../framework/scenario/TestScenario';
import {Suite} from '../framework/Framework';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import {Result, StepOutcome} from '../Results';
import {Style} from '../Style';

export interface Describable<R extends Result> {
readonly item: R;

describe(style: Style): string[];
}

export abstract class Describer<R extends Result> implements Describable<R> {
public item: R;
public readonly item: R;

constructor(item: R) {
this.item = item;
Expand All @@ -15,7 +17,7 @@ export abstract class Describer<R extends Result> implements Describable<R> {
abstract describe(style: Style): string[];
}

class SilentDescriber<R extends Result> extends Describer<R> {
export class SilentDescriber<R extends Result> extends Describer<R> {
describe(style: Style): string[] {

Check failure

Code scanning / ESLint

Disallow unused variables Error

'style' is defined but never used.
return [];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// decorator class for minimal verbosity
// decorator class for minimal describers
import {Outcome, Describer, StepDescriber} from './Describer';
import {ScenarioResult} from '../Results';
import {Style} from '../Style';
Expand Down Expand Up @@ -42,6 +42,3 @@ export class NormalScenarioDescriber extends ShortScenarioDescriber {
return report;
}
}

// / factory /
// reporter(verbosity, style).report()
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const table: (style: Style) => Map<Outcome, string> =
[Outcome.failed, style.colors.failure(style.labels.failure)],
[Outcome.skipped, style.colors.skipped(style.labels.suiteSkipped)]]);

export abstract class SuiteDescriber extends Describer<SuiteResult> {}

export class MinimalSuiteDescriber extends Describer<SuiteResult> {
export class MinimalSuiteDescriber extends SuiteDescriber {
describe(style: Style): string[] {
const report: string[] = [];
const status = (this.item.outcome === Outcome.error ? style.colors.error(style.labels.error) :
Expand All @@ -22,7 +23,7 @@ export class MinimalSuiteDescriber extends Describer<SuiteResult> {
}
}

export class ShortSuiteDescriber extends Describer<SuiteResult> {
export class ShortSuiteDescriber extends SuiteDescriber {
describe(style: Style): string[] {
let report: string[] = [];
report = report.concat(this.overview(style));
Expand Down Expand Up @@ -57,6 +58,7 @@ export class NormalSuiteDescriber extends ShortSuiteDescriber {

this.item.outcomes().forEach((scenario, index) => {
report = report.concat(new NormalScenarioDescriber(scenario, `(#${index + 1})`).describe(style));
report.push('');
});

if (this.item.outcome === Outcome.error) {
Expand Down
1 change: 0 additions & 1 deletion src/util/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function retry<T>(promise: () => Promise<T>, retries: number): Promise<T>
trying = ++attempt < retries;
}
}

reject(`exhausted number of retries (${retries})`);
});
}
23 changes: 23 additions & 0 deletions tests/examples/example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Description,
EmulatorSpecification,
Expected,
Framework,
Expand Down Expand Up @@ -73,6 +74,28 @@ debug.test({
}]
});

const DUMP: Step = {
title: 'Send DUMP command',
instruction: {kind: Kind.Request, value: Message.dump},
expected: [
{'pc': {kind: 'description', value: Description.defined} as Expected<string>},
{
'breakpoints': {
kind: 'comparison', value: (state: Object, value: Array<any>) => {
return value.length === 0;
}, message: 'list of breakpoints should be empty'
} as Expected<Array<any>>
},
{'callstack[0].sp': {kind: 'primitive', value: -1} as Expected<number>},
{'callstack[0].fp': {kind: 'primitive', value: -1} as Expected<number>}]
};

debug.test({
title: 'Test DUMP blink',
program: `tests/examples/blink.wast`,
steps: [DUMP]
});

const primitives = framework.suite('Test primitives');

primitives.testee('debug[:8700]', new EmulatorSpecification(8700));
Expand Down

0 comments on commit 9fb4d65

Please sign in to comment.