@@ -9,10 +9,11 @@ import {TestScenario} from './scenario/TestScenario';
99import { OutofPlaceSpecification , PlatformType , TestbedSpecification } from '../testbeds/TestbedSpecification' ;
1010import { CompileOutput , CompilerFactory } from '../manage/Compiler' ;
1111import { WABT } from '../util/env' ;
12- import { Completion , expect , ScenarioResult , SuiteResults } from '../reporter/Reporter ' ;
12+ import { Outcome } from '../reporter/describers/Describer ' ;
1313import { WASM } from '../sourcemap/Wasm' ;
1414import { DummyProxy } from '../testbeds/Emulator' ;
15- import { Result } from '../reporter/Result' ;
15+ import { ScenarioResult , Skipped , StepOutcome , SuiteResult } from '../reporter/Results' ;
16+ import { Verifier } from './Verifier' ;
1617
1718export function timeout < T > ( label : string , time : number , promise : Promise < T > ) : Promise < T > {
1819 if ( time === 0 ) {
@@ -46,14 +47,14 @@ export function getValue(object: any, field: string): any {
4647}
4748
4849export enum Target {
49- supervisor ,
50- proxy
50+ supervisor = 'supervisor' ,
51+ proxy = 'proxy'
5152}
5253
5354export class Testee { // TODO unified with testbed interface
5455
5556 /** The current state for each described test */
56- private states : Map < string , Result > = new Map < string , Result > ( ) ;
57+ private states : Map < string , StepOutcome > = new Map < string , StepOutcome > ( ) ;
5758
5859 /** Factory to establish new connections to VMs */
5960 public readonly connector : TestbedFactory ;
@@ -132,16 +133,16 @@ export class Testee { // TODO unified with testbed interface
132133 }
133134
134135 private run ( name : string , limit : number , fn : ( ) => Promise < any > ) {
135- return timeout < Object | void > ( name , limit , fn ( ) ) ;
136+ return timeout < object | void > ( name , limit , fn ( ) ) ;
136137 }
137138
138139 private step ( name : string , limit : number , fn : ( ) => Promise < any > ) {
139- return timeout < Object | void > ( name , limit , fn ( ) ) ;
140+ return timeout < object | void > ( name , limit , fn ( ) ) ;
140141 }
141142
142- public async describe ( description : TestScenario , suiteResult : SuiteResults , runs : number = 1 ) {
143+ public async describe ( description : TestScenario , suiteResult : SuiteResult , runs : number = 1 ) {
143144 const testee = this ;
144- const scenarioResult : ScenarioResult = new ScenarioResult ( description , testee ) ;
145+ const scenarioResult : ScenarioResult = new ScenarioResult ( description ) ;
145146
146147 if ( description . skip ) {
147148 return ;
@@ -154,11 +155,11 @@ export class Testee { // TODO unified with testbed interface
154155 await this . run ( 'Check for failing dependencies' , testee . timeout , async function ( ) {
155156 const failedDependencies : TestScenario [ ] = testee . failedDependencies ( description ) ;
156157 if ( failedDependencies . length > 0 ) {
157- testee . states . set ( description . title , new Result ( 'Skipping' , 'Test has failing dependencies' , Completion . skipped ) ) ;
158+ testee . states . set ( description . title , new Skipped ( 'Skipping' , 'Test has failing dependencies' ) ) ;
158159 throw new Error ( `Skipped: failed dependent tests: ${ failedDependencies . map ( dependence => dependence . title ) } ` ) ;
159160 }
160161 } ) . catch ( ( e : Error ) => {
161- scenarioResult . error = e ;
162+ scenarioResult . error ( e . message ) ;
162163 } ) ;
163164
164165 await this . run ( 'Compile and upload program' , testee . connector . timeout , async function ( ) {
@@ -169,31 +170,31 @@ export class Testee { // TODO unified with testbed interface
169170
170171 const compiled : CompileOutput = await new CompilerFactory ( WABT ) . pickCompiler ( description . program ) . compile ( description . program ) ;
171172 try {
172- await timeout < Object | void > ( `uploading module` , testee . timeout , testee . bed ( ) ! . sendRequest ( new SourceMap . Mapping ( ) , Message . updateModule ( compiled . file ) ) ) . catch ( ( e ) => Promise . reject ( e ) ) ;
173+ await timeout < object | void > ( `uploading module` , testee . timeout , testee . bed ( ) ! . sendRequest ( new SourceMap . Mapping ( ) , Message . updateModule ( compiled . file ) ) ) . catch ( ( e ) => Promise . reject ( e ) ) ;
173174 testee . current = description . program ;
174175 } catch ( e ) {
175176 await testee . initialize ( description . program , description . args ?? [ ] ) . catch ( ( o ) => Promise . reject ( o ) ) ;
176177 }
177178 } ) . catch ( ( e : Error | string ) => {
178179 if ( typeof e === 'string' ) {
179- scenarioResult . error = new Error ( e ) ;
180+ scenarioResult . error ( e ) ;
180181 } else {
181- scenarioResult . error = e ;
182+ scenarioResult . error ( e . toString ( ) ) ;
182183 }
183184 } ) ;
184185
185186 await this . run ( 'Get source mapping' , testee . connector . timeout , async function ( ) {
186187 map = await testee . mapper . map ( description . program ) ;
187188 } ) . catch ( ( e : Error | string ) => {
188189 if ( typeof e === 'string' ) {
189- scenarioResult . error = new Error ( e ) ;
190+ scenarioResult . error ( e ) ;
190191 } else {
191- scenarioResult . error = e ;
192+ scenarioResult . error ( e . toString ( ) ) ;
192193 }
193194 } ) ;
194195
195- if ( scenarioResult . error ) {
196- suiteResult . scenarios . push ( scenarioResult ) ;
196+ if ( scenarioResult . outcome === Outcome . error ) {
197+ suiteResult . add ( scenarioResult ) ;
197198 return ;
198199 }
199200
@@ -205,62 +206,60 @@ export class Testee { // TODO unified with testbed interface
205206 await this . run ( 'resetting before retry' , testee . timeout , async function ( ) {
206207 await testee . reset ( testee . testbed ) ;
207208 } ) . catch ( ( e : Error ) => {
208- scenarioResult . error = e ;
209+ scenarioResult . error ( e . toString ( ) ) ;
209210 } ) ;
210211 }
211212
212213 for ( const step of description . steps ?? [ ] ) {
213214 /** Perform the step and check if expectations were met */
214215 await this . step ( step . title , testee . timeout , async function ( ) {
215- let result : Result = new Result ( step . title , 'incomplete' ) ;
216+ const verifier : Verifier = new Verifier ( step ) ;
216217 if ( testee . bed ( step . target ?? Target . supervisor ) === undefined ) {
217- testee . states . set ( description . title , result ) ;
218- result . error ( 'Cannot run test: no debugger connection.' ) ;
219- testee . states . set ( description . title , result ) ;
218+ testee . states . set ( description . title , verifier . error ( 'Cannot run test: no debugger connection.' ) ) ;
220219 return ;
221220 }
222221
223- let actual : Object | void ;
222+ let actual : object | void ;
224223 if ( step . instruction . kind === Kind . Action ) {
225- actual = await timeout < Object | void > ( `performing action . ${ step . title } ` , testee . timeout ,
224+ actual = await timeout < object | void > ( `performing action . ${ step . title } ` , testee . timeout ,
226225 step . instruction . value . act ( testee ) ) . catch ( ( err ) => {
227- result . error ( err ) ;
226+ testee . states . set ( description . title , verifier . error ( err ) ) ;
227+ return ;
228228 } ) ;
229229 } else {
230230 actual = await testee . recoverable ( testee , step . instruction . value , map ,
231- ( testee , req , map ) => timeout < Object | void > ( `sending instruction ${ req . type } ` , testee . timeout ,
231+ ( testee , req , map ) => timeout < object | void > ( `sending instruction ${ req . type } ` , testee . timeout ,
232232 testee . bed ( step . target ?? Target . supervisor ) ! . sendRequest ( map , req ) ) ,
233233 ( testee ) => testee . run ( `Recover: re-initialize ${ testee . testbed ?. name } ` , testee . connector . timeout , async function ( ) {
234234 await testee . initialize ( description . program , description . args ?? [ ] ) . catch ( ( o ) => {
235235 return Promise . reject ( o )
236236 } ) ;
237237 } ) , 1 ) . catch ( ( e : Error ) => {
238- result . completion = ( e . message . includes ( 'timeout' ) ) ? Completion . timedout : Completion . error ;
239- result . description = e . message ;
238+ const result = new StepOutcome ( step ) ;
239+ testee . states . set ( description . title , result . update ( ( e . message . includes ( 'timeout' ) ) ? Outcome . timedout : Outcome . error , e . message ) ) ;
240240 } ) ;
241241 }
242242
243- if ( result . completion === Completion . uncommenced ) {
244- result = expect ( step , actual , previous ) ;
245- }
243+ const result = verifier . verify ( actual , previous ) ;
246244
247245 if ( actual !== undefined ) {
248246 previous = actual ;
249247 }
250248
251249 testee . states . set ( description . title , result ) ;
252- scenarioResult . results . push ( result ) ;
250+ scenarioResult . add ( result ) ;
253251 } ) ;
254252 }
255- suiteResult . scenarios . push ( scenarioResult ) ;
253+ suiteResult . add ( scenarioResult ) ;
256254 }
257255 }
258256
257+ /* eslint @typescript-eslint/no-explicit-any: off */
259258 private async recoverable ( testee : Testee , step : Request < any > , map : SourceMap . Mapping ,
260- attempt : ( t : Testee , req : Request < any > , m : SourceMap . Mapping ) => Promise < Object | void > ,
259+ attempt : ( t : Testee , req : Request < any > , m : SourceMap . Mapping ) => Promise < object | void > ,
261260 recover : ( t : Testee ) => Promise < any > ,
262- retries : number = 0 ) : Promise < Object | void > {
263- let result : Object | void = undefined ;
261+ retries : number = 0 ) : Promise < object | void > {
262+ let result : object | void = undefined ;
264263 let error ;
265264 while ( 0 <= retries && result === undefined ) {
266265 result = await attempt ( testee , step , map ) . catch ( async ( err ) => {
@@ -281,7 +280,7 @@ export class Testee { // TODO unified with testbed interface
281280 if ( instance === undefined ) {
282281 this . framework . reporter . error ( 'Cannot run test: no debugger connection.' ) ; // todo
283282 } else {
284- await timeout < Object | void > ( 'resetting vm' , this . timeout , this . testbed ! . sendRequest ( new SourceMap . Mapping ( ) , Message . reset ) ) ;
283+ await timeout < object | void > ( 'resetting vm' , this . timeout , this . testbed ! . sendRequest ( new SourceMap . Mapping ( ) , Message . reset ) ) ;
285284 }
286285 }
287286
@@ -293,8 +292,8 @@ export class Testee { // TODO unified with testbed interface
293292 private failedDependencies ( description : TestScenario ) : TestScenario [ ] {
294293 return ( description ?. dependencies ?? [ ] ) . filter ( dependence => {
295294 if ( this . states . get ( dependence . title ) ) {
296- const c = this . states . get ( dependence . title ) ! . completion ;
297- return ! ( c === Completion . succeeded || c === Completion . uncommenced ) ;
295+ const c = this . states . get ( dependence . title ) ! . outcome ;
296+ return ! ( c === Outcome . succeeded || c === Outcome . uncommenced ) ;
298297 } else {
299298 return false ;
300299 }
0 commit comments