9 die "Usage: tesh.pl <options> <teshfile.tesh>\n";
17 my($command_executed)=0;
18 my($expected_result_line)=0;
24 my(@list_of_commands)=();
31 my($no_output_ignore)=1;
46 if($ARGV[$nb_arg] =~ /^--cd$/)
49 if(!$ARGV[$nb_arg] or $ARGV[$nb_arg] =~ /^--/){die "Usage: tesh.pl --cd <directory>\n";}
50 my($directory)=$ARGV[$nb_arg];
54 print "[Tesh/INFO] --cd \"$directory\"\n";
58 die "[Tesh/CRITICAL] Directory not found : \"$directory\"\n";
62 elsif($ARGV[$nb_arg] =~ /^--setenv$/)
65 if(!$ARGV[$nb_arg] or $ARGV[$nb_arg] =~ /^--/){die "Usage: tesh.pl --setenv environment_variable\n";}
66 $ARGV[$nb_arg] =~ /^(.*)=(.*)$/;
69 $ENV{$var} = $content;
70 print "[Tesh/INFO] --setenv $var=$content\n";
73 elsif($ARGV[$nb_arg] =~ /^--cfg$/)
76 if(!$ARGV[$nb_arg] or $ARGV[$nb_arg] =~ /^--/){die "Usage: tesh.pl --setenv environment_variable\n";}
77 $config = "$config--cfg=$ARGV[$nb_arg] ";
78 print "[Tesh/INFO] $config\n";
81 elsif($ARGV[$nb_arg] =~ /^--verbose$/)
87 print "[Tesh/CRITICAL] Unrecognized option : $ARGV[$nb_arg]\n";
90 }while(($nb_arg) < $#ARGV);
92 #Add current directory to path
93 $ENV{PATH} = "$ENV{PATH}:.";
96 if(!$ARGV[$nb_arg]){die "tesh.pl <options> <teshfile.tesh>\n";}
97 print "[Tesh/INFO] load file : $ARGV[$nb_arg]\n";
98 my($file)=$ARGV[$nb_arg];
99 open SH_LIGNE, $file or die "[Tesh/CRITICAL] Unable to open $file. $!\n";
101 while(defined($line1=<SH_LIGNE>))
103 if($line1 =~ /^\< \$ /){ # arg command line
104 $line1 =~ s/\${EXEEXT:=}//g;
105 $line1 =~ s/^\< \$\ *//g;
106 $line1 =~ s/^.\/lua/lua/g;
107 $line1 =~ s/^.\/ruby/ruby/g;
109 $line1 =~ s/^tesh/.\/tesh/g;
110 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
112 $command_tesh = $line1;
113 print "[Tesh/INFO] arg_exec_line : $command_tesh\n";
115 elsif($line1 =~ /^\< \< /){ # arg buffer line
116 $line1 =~ s/^\< \<\ *//g;
118 print "[Tesh/INFO] arg_buffer_line : $line1\n";
119 push @buffer_tesh, "$line1\n";
121 elsif($line1 =~ /^\< \> /){ # arg output line
122 $line1 =~ s/^\< \>\ *//g;
126 print "[Tesh/INFO] arg_output_line : $line1\n";
127 $expected_result_line = 1;
129 elsif($line1 =~ /^\$ mkfile/){ # "mkfile" command line
131 $line1 =~ s/mkfile//g;
135 print "[Tesh/INFO] exec_line : mkfile $fich_name\n";
137 open(FILE,">$fich_name") or die "[Tesh/CRITICAL] Unable to make file : $fich_name. $!\n";
142 elsif($line1 =~ /^\$ cd/){ # "cd" command line
145 print "[Tesh/INFO] exec_line : $line1\n";
147 chdir("$line1") or die "[Tesh/CRITICAL] Unable to open $line1. $!\n";
149 elsif($line1 =~ /^\$ /){ #command line
150 if($line1 =~ /^\$ .\/tesh/){ # tesh command line
152 @buffer = @buffer_tesh;
155 $line1 =~ s/\${EXEEXT:=}//g;
156 $line1 =~ s/^\$\ *//g;
157 $line1 =~ s/^.\/lua/lua/g;
158 $line1 =~ s/^.\/ruby/ruby/g;
160 $line1 =~ s/^tesh/.\/tesh/g;
161 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
163 $line1 = "$line1 $config";
167 print "[Tesh/CRITICAL] -\n";
168 print "[Tesh/CRITICAL] + @list1";
169 print color("reset"), "\n";
171 if(@list_of_commands){ # need parallel execution
172 push @list_of_commands, $line1;
173 print "[Tesh/INFO] exec_line : $line1\n";
176 print "[Tesh/INFO] exec_line : $line1\n";
178 { $execline = $command_tesh;
181 { $execline = $line1;}
182 $pid = open3(\*IN, \*OUT, \*OUT, $execline );
184 $forked = fork();die "fork() failed: $!" unless defined $forked;
195 $line1 = shift (@buffer);
201 if($timeout){kill(9, $forked);$timeout=0;}
204 while(defined($linebis=<OUT>))
207 $linebis =~ s/^( )*//g;
209 push @list1,"$linebis";
212 $command_executed = 1;
215 elsif($line1 =~ /^\& /){ # parallel command line
216 $command_executed = 0;
217 $expected_result_line = 0;
218 $line1 =~ s/\${EXEEXT:=}//g;
220 $line1 =~ s/^.\/lua/lua/g;
221 $line1 =~ s/^.\/ruby/ruby/g;
223 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
225 $line1 = "$line1 $config";
227 $execline = "$line1";
228 print "[Tesh/INFO] exec_line : $execline\n";
229 push @list_of_commands, $execline;
231 elsif($line1 =~ /^\>/){ #expected result line
232 $line1 =~ s/^\>( )*//g;
236 $expected_result_line = 1;
238 elsif($line1 =~ /^\</ or $encore==1){ #need to buffer
239 $line1 =~ s/^\<( )*//g; #delete < with space or tab after
242 if($line1 =~ /\\$/) # need to store this line into old_buff
246 $old_buffer = "$old_buffer$line1";
250 if($encore == 1){push @buffer, "$old_buffer$line1";}
251 else{push @buffer, "$line1\n";}
256 elsif($line1 =~ /^p/){ #comment
260 print "[Tesh/INFO] comment_line :$line1\n";
262 elsif($line1 =~ /^! output sort/){ #output sort
265 elsif($line1 =~ /^! output ignore/){ #output ignore
268 elsif($line1 =~ /^! expect signal SIGABRT$/) #expect signal SIGABRT
272 elsif($line1 =~ /^! expect return/){ #expect return
273 $line1 =~ s/^! expect return //g;
277 print color("red"), "[Tesh/INFO] expect return $return";
278 print color("reset"), "\n";
281 elsif($line1 =~ /^! setenv/){ #setenv
282 $line1 =~ s/^! setenv //g;
285 $line1 =~ /^(.*)=(.*)$/;
287 print "[Tesh/INFO] setenv: $1=$2\n";
289 elsif($line1 =~ /^! include/){ #output sort
290 print color("red"), "[Tesh/CRITICAL] need include";
291 print color("reset"), "\n";
294 elsif($line1 =~ /^! timeout/){ #timeout
295 $line1 =~ s/^! timeout //g;
298 if($timeout != $line1){
300 print "[Tesh/INFO] timeout : $timeout\n";}
302 elsif($line1 =~ /^! need execute/){ #need execute // commands
304 $sort = 1; # need sort output
305 while(@list_of_commands)
307 $command = shift (@list_of_commands);
308 if($execline){$execline = "$command & $execline";}
309 else{$execline = "$command";}
311 $pid = open3(\*IN, \*OUT, \*OUT, $execline);
313 $forked = fork();die "fork() failed: $!" unless defined $forked;
324 $line1 = shift (@buffer);
329 if($timeout){kill(9, $forked);$timeout=0;}
333 while(defined($linebis=<OUT>))
336 $linebis =~ s/^( )*//g;
338 push @list1,"$linebis";
341 $command_executed = 1;
343 elsif($command_executed and $expected_result_line)
345 if($no_output_ignore){
349 @list3 = sort @list1;
354 @list3 = sort @list2;
363 push @list2,"Aborted";
367 while(@list1 or @list2)
369 if(@list1){$line1 = shift (@list1);$expected_result_line = "x$line1";}
370 if(@list2){$line2 = shift (@list2);$command_executed = "x$line2";}
371 if($command_executed and $expected_result_line)
374 if($line1 eq $line2){
375 if($verbose == 1){print color("green"),"[Tesh/VERB] $line1\n",color("reset");}
376 else{push @buffer, "[Tesh/CRITICAL] $line1\n";}
380 { if($verbose == 0){print color("green"),@buffer,color("reset");}
381 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
382 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
387 { if($verbose == 0){print color("green"),@buffer,color("reset");}
388 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
389 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
393 }else{$no_output_ignore = 1;}
394 $command_executed = 0;
395 $expected_result_line = 0;
405 if(@list_of_commands){ # need parallel execution
407 $sort = 1; # need sort output
408 while(@list_of_commands)
410 $command = shift (@list_of_commands);
411 if($execline){$execline = "$command & $execline";}
412 else{$execline = "$command";}
414 print "[Tesh/INFO] exec_line : $execline\n";
415 $pid = open3(\*IN, \*OUT, \*OUT,"$execline");
418 $forked = fork();die "fork() failed: $!" unless defined $forked;
429 $line1 = shift (@buffer);
434 if($timeout){kill(9, $forked);$timeout=0;}
438 while(defined($linebis=<OUT>))
441 $linebis =~ s/^( )*//g;
443 push @list1,"$linebis";
446 $command_executed = 1;
449 if($command_executed and $expected_result_line ){
450 if($no_output_ignore){
454 @list3 = sort @list1;
459 @list3 = sort @list2;
468 push @list2,"Aborted";
472 while(@list1 or @list2)
474 if(@list1){$line1 = shift (@list1);$expected_result_line = "x$line1";}
475 if(@list2){$line2 = shift (@list2);$command_executed = "x$line2";}
476 if($command_executed and $expected_result_line)
478 if($line1 eq $line2){
479 if($verbose == 1){print color("green"),"[Tesh/VERB] $line1\n",color("reset");}
480 else{push @buffer, "[Tesh/CRITICAL] $line1\n";}
484 { if($verbose == 0){print color("green"),@buffer,color("reset");}
485 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
486 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
491 { if($verbose == 0){print color("green"),@buffer,color("reset");}
492 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
493 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
497 }else{$no_output_ignore = 1;}
498 $command_executed = 0;
499 $expected_result_line= 0;