@@ -17,17 +17,18 @@ export interface snort3Test {
1717}
1818
1919class snort3SpellCheck implements snort3Test {
20- private name :string = '' ;
21- private description :string = '' ;
22- private out_file :string = '' ;
20+ private readonly name :string = '' ;
21+ private readonly description :string = '' ;
22+ private readonly out_file :string = '' ;
23+ private readonly type :"source" | "manual" ;
2324 constructor (
2425 private readonly id :string ,
2526 private readonly testpath :string ,
26- private readonly type :string ,
2727 private readonly target :string )
2828 {
2929 this . name = getLastItem ( this . testpath ) ;
3030 this . description = 'Checks spell in ' + this . target ;
31+ this . type = < "source" | "manual" > getLastItem ( this . testpath ) ;
3132 this . out_file = 'unknown_' + this . type + '.txt' ;
3233 }
3334 getName ( ) :string { return this . name ; }
@@ -39,59 +40,42 @@ class snort3SpellCheck implements snort3Test {
3940 testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'running' } ) ;
4041 const args = [ this . target , '-name' ] ;
4142 const skips :string [ ] = [ ] ;
42- if ( this . type === 'source' ) args . concat ( [ '*.cc' , '-o' , '-name' , '*.[ch]' ] ) ;
43- else { args . push ( '*.txt' ) ; skips . concat ( [ 'CMakeLists.txt' , 'config_changes.txt' ] ) ; }
43+ if ( this . type === 'source' )
44+ [ '*.cc' , '-o' , '-name' , '*.[ch]' ] . forEach ( x => args . push ( x ) ) ;
45+ else { args . push ( '*.txt' ) ; [ 'CMakeLists.txt' , 'config_changes.txt' ] . forEach ( x => skips . push ( x ) ) ; }
4446 const files = child_process . spawnSync ( 'find' , args , { encoding : 'utf8' } )
4547 . stdout . split ( '\n' ) . sort ( ) . filter ( x => ! skips . includes ( getLastItem ( x ) ) ) ;
4648 files . shift ( ) ;
4749 if ( ! files . length ) {
4850 testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
4951 resolve ( ) ;
5052 }
51- const runner :Promise < void > [ ] = [ ] ;
5253 files . forEach ( file => {
53- runner . push ( this . run ( file ) ) ;
54+ if ( ! this . process ( file ) ) {
55+ testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
56+ resolve ( ) ;
57+ }
5458 } ) ;
55- Promise . all ( runner ) . then ( ( ) => {
56- const diff = child_process . spawnSync ( 'diff' , [ 'expected' , this . out_file ] , { cwd :this . testpath } ) ;
57- if ( ! diff . pid || diff . signal ) testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
58- else if ( diff . status )
59- testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'failed' , description :diff . stdout . toString ( ) } ) ;
60- else testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'passed' } )
61- } ) . catch ( ( ) => {
62- testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
63- } ) . finally ( ( ) => { resolve ( ) ; } ) ;
64- } ) ;
65- }
66-
67- private run_source ( file :string ) :Promise < void >
68- {
69- return new Promise ( ( resolve , reject ) => {
70- const strdump = child_process . spawn ( 'strdump' , [ '-c' , file ] , { cwd :this . testpath } ) ;
71- const spell = child_process . spawn ( 'hunspell' , [ '-l' , '-p' , 'exception' ] , { cwd :this . testpath } ) ;
72- const sort = child_process . spawn ( 'sort' , [ '-u' , '-o' , this . out_file ] , { cwd :this . testpath } ) ;
73- if ( ! strdump . pid || ! spell . pid || ! sort . pid ) reject ( ) ;
74- strdump . stdout . pipe ( spell . stdin ) ;
75- spell . stdout . pipe ( sort . stdin ) ;
76- sort . once ( 'exit' , ( ) => { resolve ( ) ; } ) ;
77- } ) ;
78- }
79-
80- private run_manual ( file :string ) :Promise < void >
81- {
82- return new Promise ( ( resolve , reject ) => {
83- const spell = child_process . spawn ( 'hunspell' , [ '-l' , '-p' , 'exception' , file ] , { cwd :this . testpath } ) ;
84- const sort = child_process . spawn ( 'sort' , [ '-u' , '-o' , this . out_file ] , { cwd :this . testpath } ) ;
85- if ( ! spell . pid || ! sort . pid ) reject ( ) ;
86- spell . stdout . pipe ( sort . stdin ) ;
87- sort . once ( 'exit' , ( ) => { resolve ( ) ; } ) ;
59+ const sort = child_process . spawnSync ( 'sort' , [ '-u' , '-o' , this . out_file , this . out_file ] , { cwd :this . testpath } ) ;
60+ if ( ! sort . pid || sort . signal || sort . status ) testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
61+ const diff = child_process . spawnSync ( 'diff' , [ 'expected' , this . out_file ] , { cwd :this . testpath } ) ;
62+ if ( ! diff . pid || diff . signal ) testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
63+ else if ( diff . status )
64+ testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'failed' , description :diff . stdout . toString ( ) } ) ;
65+ else testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'passed' } )
66+ resolve ( ) ;
8867 } ) ;
8968 }
9069
91- private run ( file :string ) :Promise < void >
70+ private process ( file :string ) :boolean
9271 {
93- if ( this . type === 'manual' ) return this . run_manual ( file ) ;
94- else return this . run_source ( file ) ;
72+ let args :string = '' ;
73+ if ( this . type === 'source' ) args += 'strdump -c ' + file + ' | ' ;
74+ args += 'hunspell -l -p exception ' ;
75+ if ( this . type === 'manual' ) args += file ;
76+ args += '>> ' + this . out_file ;
77+ const runner = child_process . spawnSync ( 'bash' , [ '-c' , args ] , { cwd :this . testpath } ) ;
78+ return ( ! ( runner . signal || runner . status ) ) ;
9579 }
9680
9781 reload ( ) :Promise < void >
@@ -337,7 +321,7 @@ export async function loadSnort3Tests(rootdir:vscode.WorkspaceFolder)
337321 var list = fs . readdirSync ( dir ) ;
338322 if ( list . includes ( 'run.sh' ) && test_env . SNORT_SRCPATH ) {
339323 //spell test
340- if ( dir === 'source' ) {
324+ if ( getLastItem ( dir ) === 'source' ) {
341325 const spells :TestSuiteInfo = {
342326 type :'suite' ,
343327 id :dir ,
@@ -346,10 +330,10 @@ export async function loadSnort3Tests(rootdir:vscode.WorkspaceFolder)
346330 } ;
347331 let src_id = dir ;
348332 let extraTest :snort3SpellCheck | undefined = undefined ;
349- const extra_path = < string > ( buildtool . get_snort3_src_extra_path ( ) ) ;
333+ const extra_path = '' // <string>(buildtool.get_snort3_src_extra_path());
350334 if ( extra_path !== '' ) {
351335 src_id = dir + '/snort3' ;
352- extraTest = new snort3SpellCheck ( dir + '/extra' , dir , 'source' , extra_path ) ;
336+ extraTest = new snort3SpellCheck ( dir + '/extra' , dir , extra_path ) ;
353337 snort3Tests . set ( dir + '/extra' , extraTest ) ;
354338 spells . children . push ( < TestInfo > {
355339 type : 'test' ,
@@ -360,7 +344,7 @@ export async function loadSnort3Tests(rootdir:vscode.WorkspaceFolder)
360344 tooltip : extraTest . getName ( ) + extraTest . getDescription ( )
361345 } ) ;
362346 }
363- const srcTest :snort3SpellCheck = new snort3SpellCheck ( src_id , dir , 'source' , test_env . SNORT_SRCPATH ) ;
347+ const srcTest :snort3SpellCheck = new snort3SpellCheck ( src_id , dir , test_env . SNORT_SRCPATH ) ;
364348 snort3Tests . set ( src_id , srcTest ) ;
365349 const src_test :TestInfo = {
366350 type : 'test' ,
@@ -376,13 +360,13 @@ export async function loadSnort3Tests(rootdir:vscode.WorkspaceFolder)
376360 }
377361 else return src_test ;
378362 } else {
379- const thisTest = new snort3SpellCheck ( dir , dir , 'manual' , test_env . SNORT_SRCPATH + '/doc' ) ;
363+ const thisTest = new snort3SpellCheck ( dir , dir , test_env . SNORT_SRCPATH + '/doc' ) ;
380364 snort3Tests . set ( dir , thisTest ) ;
381365 return < TestInfo > { type : 'test' ,
382366 id : dir ,
383- label : getLastItem ( dir ) ,
367+ label : thisTest . getName ( ) ,
384368 file : dir + '/run.sh' ,
385- description : thisTest . getName ( ) ,
369+ description : thisTest . getDescription ( ) ,
386370 tooltip :thisTest . getName ( ) + thisTest . getDescription ( )
387371 } ;
388372 }
0 commit comments