1+ import { singleFileTestSuite , workspaceTestSuite } from "../../../test/suite/ASM.test" ;
12
2- import * as assert from 'assert' ;
3-
4- // You can import and use all API from the 'vscode' module
5- // as well as import your extension to test it
6- import * as vscode from 'vscode' ;
7- import { AsmResult } from '../../../ASM/manager' ;
8- import { DosEmulatorType , Assembler } from '../../../utils/configuration' ;
9-
10- // import * as myExtension from '../../extension';
11- const folders = vscode . workspace . workspaceFolders ;
12- if ( folders === undefined ) {
13- throw new Error ( ) ;
14- }
15- const samplesUri = folders [ 0 ] . uri ;
16-
17- suite ( 'Extension Test Suite' , function ( ) {
18- vscode . window . showInformationMessage ( 'Start all tests.' ) ;
19- const MASMorTASM = [
20- 'MASM-v5.00' ,
21- 'MASM-v6.11' ,
22- 'TASM' ,
23- ] ;
24- const emulator : DosEmulatorType [ ] = [
25- DosEmulatorType . jsdos ,
26- ] ;
27-
28- const filelist : [ string , number ] [ ] = [
29- [ '1.asm' , 0 ] ,
30- [ '3中文路径hasError.asm' , 1 ] ,
31- // ['2.asm', DIAGCODE.ok],
32- ] ;
33-
34- const args : [ string , number , DosEmulatorType , Assembler ] [ ] = [ ] ;
35- for ( const file of filelist ) {
36- for ( const emu of emulator ) {
37- for ( const asm of MASMorTASM ) {
38- args . push ( [ file [ 0 ] , file [ 1 ] , emu , asm ] ) ;
39- }
40- }
41- }
42-
43- this . beforeEach ( async function ( ) {
44- await vscode . commands . executeCommand ( 'workbench.action.closeAllEditors' ) ;
45- } ) ;
46-
47- shuffle ( args ) . forEach ( ( val ) => { testAsmCode ( ...val ) ; } ) ;
48- } ) ;
49-
50- function testAsmCode ( file : string , shouldErr : number , emu : DosEmulatorType , asm : Assembler ) : void {
51- test ( `test file ${ file } in ${ emu } use ${ asm } want should ${ shouldErr } error` ,
52- async function ( ) {
53- this . timeout ( '60s' ) ;
54- this . slow ( '20s' ) ;
55-
56- //open test file. NOTE: the extension will be activated when open .asm file
57- const samplefile = vscode . Uri . joinPath ( samplesUri , file ) ;
58-
59- //update settings
60- await vscode . workspace . getConfiguration ( 'masmtasm' ) . update ( "dosbox.run" , "exit" ) ;
61- await vscode . workspace . getConfiguration ( 'masmtasm' ) . update ( "ASM.emulator" , emu ) ;
62- await vscode . workspace . getConfiguration ( 'masmtasm' ) . update ( "ASM.assembler" , asm ) ;
63-
64- //assert the extension activated and command contributed
65- const vscodecmds = await vscode . commands . getCommands ( true ) ;
66- const cmd = 'masm-tasm.runASM' ;
67- if ( ! vscodecmds . includes ( cmd ) ) {
68- await vscode . extensions . getExtension ( 'xsro.masm-tasm' ) ?. activate ( ) ;
69- }
70- const vscodecmds2 = await vscode . commands . getCommands ( true ) ;
71- assert . ok ( vscodecmds2 . includes ( cmd ) ) ;
72-
73- //assert message processed
74- const _result = await vscode . commands . executeCommand ( cmd , samplefile ) ;
75- const { message, error } = _result as AsmResult ;
76- assert . strictEqual ( error , shouldErr , message ) ;
77- } ) ;
78- }
79-
80- function shuffle < T > ( arr : T [ ] ) : T [ ] {
81- for ( let i = 1 ; i < arr . length ; i ++ ) {
82- const random = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
83- [ arr [ i ] , arr [ random ] ] = [ arr [ random ] , arr [ i ] ] ;
84- }
85- return arr ;
86- }
3+ singleFileTestSuite ;
4+ workspaceTestSuite ;
0 commit comments