@@ -21,6 +21,7 @@ class snort3SpellCheck implements snort3Test {
2121 private readonly description :string = '' ;
2222 private readonly out_file :string = '' ;
2323 private readonly type :"source" | "manual" ;
24+ private active_child :child_process . ChildProcess | undefined ;
2425 constructor (
2526 private readonly id :string ,
2627 private readonly testpath :string ,
@@ -38,44 +39,41 @@ class snort3SpellCheck implements snort3Test {
3839 {
3940 return new Promise ( ( resolve ) => {
4041 testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'running' } ) ;
41- const args = [ this . target , '-name' ] ;
42- const skips :string [ ] = [ ] ;
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 ) ) ; }
46- const files = child_process . spawnSync ( 'find' , args , { encoding : 'utf8' } )
47- . stdout . split ( '\n' ) . sort ( ) . filter ( x => ! skips . includes ( getLastItem ( x ) ) ) ;
48- files . shift ( ) ;
49- if ( ! files . length ) {
50- testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
51- resolve ( ) ;
52- }
53- files . forEach ( file => {
54- if ( ! this . process ( file ) ) {
42+
43+ let find_args :string = ' -name' ;
44+ if ( this . type === 'source' ) find_args += ' *.cc -o -name *.[ch]' ;
45+ else find_args += ' *.txt ! -name *CMakeLists.txt ! -name *config_changes.txt' ;
46+
47+ let xargs = ' | xargs -I {}' ;
48+ if ( this . type === 'source' ) xargs += ' strdump -c {} |' ;
49+
50+ let spell_cmd = ' hunspell -l -p exception' ;
51+ if ( this . type === 'manual' ) spell_cmd += ' {}' ;
52+
53+ const sort_cmd = ' sort -u -o ' + this . out_file + ' ' + this . out_file ;
54+
55+ const command = 'find ' + this . target + find_args + xargs + spell_cmd + ' >> ' + this . out_file + ';' + sort_cmd ;
56+
57+ const runner = child_process . spawn ( 'bash' , [ '-c' , command ] , { cwd : this . testpath } ) . once ( 'exit' , ( code , signal ) => {
58+ this . active_child = undefined ;
59+ if ( code || signal ) {
5560 testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
5661 resolve ( ) ;
5762 }
63+ const diff = child_process . spawnSync ( 'diff' , [ 'expected' , this . out_file ] , { cwd :this . testpath } ) ;
64+ if ( ! diff . pid || diff . signal ) testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
65+ else if ( diff . status )
66+ testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'failed' , tooltip :diff . stdout . toString ( ) } ) ;
67+ else testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'passed' } )
68+ resolve ( ) ;
5869 } ) ;
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 ( ) ;
67- } ) ;
68- }
6970
70- private process ( file :string ) :boolean
71- {
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 ) ) ;
71+ if ( ! runner || ! runner . pid ) {
72+ testStatesEmitter . fire ( < TestEvent > { type : 'test' , test : this . id , state : 'errored' } ) ;
73+ resolve ( ) ;
74+ }
75+ this . active_child = runner ;
76+ } ) ;
7977 }
8078
8179 reload ( ) :Promise < void >
@@ -84,7 +82,7 @@ class snort3SpellCheck implements snort3Test {
8482 }
8583
8684 abort ( ) {
87-
85+ if ( this . active_child ) this . active_child . kill ( )
8886 }
8987}
9088
0 commit comments