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;
45 if($ARGV[$nb_arg] =~ /^--cd$/)
48 if(!$ARGV[$nb_arg] or $ARGV[$nb_arg] =~ /^--/){die "Usage: tesh.pl --cd <directory>\n";}
49 my($directory)=$ARGV[$nb_arg];
53 print "[Tesh/INFO] Change directory to \"$directory\"\n";
57 die "[Tesh/CRITICAL] Directory not found : \"$directory\"\n";
61 elsif($ARGV[$nb_arg] =~ /^--setenv$/)
64 if(!$ARGV[$nb_arg] or $ARGV[$nb_arg] =~ /^--/){die "Usage: tesh.pl --setenv environment_variable\n";}
65 if(!$ARGV[$nb_arg+1] or $ARGV[$nb_arg+1] =~ /^--/){die "Usage: tesh.pl --setenv environment_variable\n";}
66 $ENV{$ARGV[$nb_arg]} = "$ENV{$ARGV[$nb_arg]}:$ARGV[$nb_arg+1]";
67 print "[Tesh/INFO] export $ARGV[$nb_arg]=\"$ENV{$ARGV[$nb_arg]}\"\n";
71 elsif($ARGV[$nb_arg] =~ /^--verbose$/)
77 print "[Tesh/CRITICAL] Unrecognized option : $ARGV[$nb_arg]\n";
80 }while(($nb_arg) < $#ARGV);
82 #Add current directory to path
83 $ENV{PATH} = "$ENV{PATH}:.";
86 if(!$ARGV[$nb_arg]){die "tesh.pl <options> <teshfile.tesh>\n";}
87 print "[Tesh/INFO] load file : $ARGV[$nb_arg]\n";
88 my($file)=$ARGV[$nb_arg];
89 open SH_LIGNE, $file or die "[Tesh/CRITICAL] Unable to open $file. $!\n";
91 while(defined($line1=<SH_LIGNE>))
93 if($line1 =~ /^\< \$ /){ # arg command line
94 $line1 =~ s/\$\{srcdir\:\=\.\}/./g;
95 $line1 =~ s/\${EXEEXT:=}//g;
96 $line1 =~ s/^\< \$\ *//g;
97 $line1 =~ s/^.\/lua/lua/g;
98 $line1 =~ s/^.\/ruby/ruby/g;
100 $line1 =~ s/^tesh/.\/tesh/g;
101 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
103 $command_tesh = $line1;
104 print "[Tesh/INFO] arg_exec_line : $command_tesh\n";
106 elsif($line1 =~ /^\< \< /){ # arg buffer line
107 $line1 =~ s/^\< \<\ *//g;
109 print "[Tesh/INFO] arg_buffer_line : $line1\n";
110 push @buffer_tesh, "$line1\n";
112 elsif($line1 =~ /^\< \> /){ # arg output line
113 $line1 =~ s/^\< \>\ *//g;
117 print "[Tesh/INFO] arg_output_line : $line1\n";
118 $expected_result_line = 1;
120 elsif($line1 =~ /^\$ mkfile/){ # "mkfile" command line
122 $line1 =~ s/mkfile//g;
126 print "[Tesh/INFO] exec_line : mkfile $fich_name\n";
128 open(FILE,">$fich_name") or die "[Tesh/CRITICAL] Unable to make file : $fich_name. $!\n";
133 elsif($line1 =~ /^\$ cd/){ # "cd" command line
136 print "[Tesh/INFO] exec_line : $line1\n";
138 chdir("$line1") or die "[Tesh/CRITICAL] Unable to open $line1. $!\n";
140 elsif($line1 =~ /^\$ /){ #command line
141 if($line1 =~ /^\$ .\/tesh/){ # tesh command line
143 @buffer = @buffer_tesh;
146 $line1 =~ s/\$\{srcdir\:\=\.\}/./g;
147 $line1 =~ s/\${EXEEXT:=}//g;
148 $line1 =~ s/^\$\ *//g;
149 $line1 =~ s/^.\/lua/lua/g;
150 $line1 =~ s/^.\/ruby/ruby/g;
152 $line1 =~ s/^tesh/.\/tesh/g;
153 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
157 print "[Tesh/CRITICAL] -\n";
158 print "[Tesh/CRITICAL] + @list1\n";
159 print color("reset");
161 if(@list_of_commands){ # need parallel execution
162 push @list_of_commands, $line1;
163 print "[Tesh/INFO] exec_line : $line1\n";
166 print "[Tesh/INFO] exec_line : $line1\n";
168 { $execline = $command_tesh;
171 { $execline = $line1;}
172 $pid = open3(\*IN, \*OUT, \*OUT, $execline );
174 $forked = fork();die "fork() failed: $!" unless defined $forked;
185 $line1 = shift (@buffer);
191 if($timeout){kill(9, $forked);$timeout=0;}
194 while(defined($linebis=<OUT>))
197 $linebis =~ s/^( )*//g;
199 push @list1,"$linebis";
202 $command_executed = 1;
205 elsif($line1 =~ /^\& /){ # parallel command line
206 $command_executed = 0;
207 $expected_result_line = 0;
208 $line1 =~ s/\$\{srcdir\:\=\.\}/./g;
209 $line1 =~ s/\${EXEEXT:=}//g;
211 $line1 =~ s/^.\/lua/lua/g;
212 $line1 =~ s/^.\/ruby/ruby/g;
214 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
216 $execline = "$line1";
217 print "[Tesh/INFO] exec_line : $execline\n";
218 push @list_of_commands, $execline;
220 elsif($line1 =~ /^\>/){ #expected result line
221 $line1 =~ s/^\>( )*//g;
225 $expected_result_line = 1;
227 elsif($line1 =~ /^\</ or $encore==1){ #need to buffer
228 $line1 =~ s/^\<( )*//g; #delete < with space or tab after
231 if($line1 =~ /\\$/) # need to store this line into old_buff
235 $old_buffer = "$old_buffer$line1";
239 if($encore == 1){push @buffer, "$old_buffer$line1";}
240 else{push @buffer, "$line1\n";}
245 elsif($line1 =~ /^p/){ #comment
249 print "[Tesh/INFO] comment_line :$line1\n";
251 elsif($line1 =~ /^! output sort/){ #output sort
254 elsif($line1 =~ /^! output ignore/){ #output ignore
257 elsif($line1 =~ /^! expect signal SIGABRT$/) #expect signal SIGABRT
261 elsif($line1 =~ /^! expect return/){ #expect return
262 $line1 =~ s/^! expect return //g;
266 print color("red"), "[Tesh/INFO] expect return $return\n";
269 elsif($line1 =~ /^! setenv/){ #setenv
270 $line1 =~ s/^! setenv //g;
273 $line1 =~ /^(.*)=(.*)$/;
275 print "[Tesh/INFO] setenv: $1=$2\n";
277 elsif($line1 =~ /^! include/){ #output sort
278 color("red");die "[Tesh/CRITICAL] need include\n";
280 elsif($line1 =~ /^! timeout/){ #timeout
281 $line1 =~ s/^! timeout //g;
284 if($timeout != $line1){
286 print "[Tesh/INFO] timeout : $timeout\n";}
288 elsif($line1 =~ /^! need execute/){ #need execute // commands
290 $sort = 1; # need sort output
291 while(@list_of_commands)
293 $command = shift (@list_of_commands);
294 if($execline){$execline = "$command & $execline";}
295 else{$execline = "$command";}
297 $pid = open3(\*IN, \*OUT, \*OUT, $execline);
299 $forked = fork();die "fork() failed: $!" unless defined $forked;
310 $line1 = shift (@buffer);
315 if($timeout){kill(9, $forked);$timeout=0;}
319 while(defined($linebis=<OUT>))
322 $linebis =~ s/^( )*//g;
324 push @list1,"$linebis";
327 $command_executed = 1;
329 elsif($command_executed and $expected_result_line)
331 if($no_output_ignore){
335 @list3 = sort @list1;
340 @list3 = sort @list2;
349 push @list2,"Aborted";
353 while(@list1 or @list2)
355 if(@list1){$line1 = shift (@list1);$expected_result_line = "x$line1";}
356 if(@list2){$line2 = shift (@list2);$command_executed = "x$line2";}
357 if($command_executed and $expected_result_line)
360 if($line1 eq $line2){
361 if($verbose == 1){print color("green"),"[Tesh/VERB] $line1\n",color("reset");}
362 else{push @buffer, "[Tesh/CRITICAL] $line1\n";}
366 { if($verbose == 0){print color("green"),@buffer,color("reset");}
367 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2\n",color("reset");}
368 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1\n",color("reset");}
373 { if($verbose == 0){print color("green"),@buffer,color("reset");}
374 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2\n",color("reset");}
375 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1\n",color("reset");}
379 }else{$no_output_ignore = 1;}
380 $command_executed = 0;
381 $expected_result_line = 0;
391 if(@list_of_commands){ # need parallel execution
393 $sort = 1; # need sort output
394 while(@list_of_commands)
396 $command = shift (@list_of_commands);
397 if($execline){$execline = "$command & $execline";}
398 else{$execline = "$command";}
400 print "[Tesh/INFO] exec_line : $execline\n";
401 $pid = open3(\*IN, \*OUT, \*OUT,"$execline");
404 $forked = fork();die "fork() failed: $!" unless defined $forked;
415 $line1 = shift (@buffer);
420 if($timeout){kill(9, $forked);$timeout=0;}
424 while(defined($linebis=<OUT>))
427 $linebis =~ s/^( )*//g;
429 push @list1,"$linebis";
432 $command_executed = 1;
435 if($command_executed and $expected_result_line ){
436 if($no_output_ignore){
440 @list3 = sort @list1;
445 @list3 = sort @list2;
454 push @list2,"Aborted";
458 while(@list1 or @list2)
460 if(@list1){$line1 = shift (@list1);$expected_result_line = "x$line1";}
461 if(@list2){$line2 = shift (@list2);$command_executed = "x$line2";}
462 if($command_executed and $expected_result_line)
464 if($line1 eq $line2){
465 if($verbose == 1){print color("green"),"[Tesh/VERB] $line1\n",color("reset");}
466 else{push @buffer, "[Tesh/CRITICAL] $line1\n";}
470 { if($verbose == 0){print color("green"),@buffer,color("reset");}
471 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2\n",color("reset");}
472 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1\n",color("reset");}
477 { if($verbose == 0){print color("green"),@buffer,color("reset");}
478 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2\n",color("reset");}
479 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1\n",color("reset");}
483 }else{$no_output_ignore = 1;}
484 $command_executed = 0;
485 $expected_result_line= 0;