11 B<tesh> [I<options>] I<tesh_file>
15 use Pod::Usage qw(pod2usage);
16 use Getopt::Long qw(GetOptions);
22 my($line1,$line2,$execline,$command,$command_tesh);
23 my($command_executed)=0;
24 my($expected_result_line)=0;
27 my(@list1,@list2,@list3,@list_of_commands)=();
34 my($no_output_ignore)=1;
47 # make sure we received a tesh file
48 scalar @ARGV > 0 || pod2usage(-exitval => 1);
50 #Add current directory to path
51 $ENV{PATH} = "$ENV{PATH}:.";
59 print "[Tesh/INFO] change directory to $directory\n";
61 die "[Tesh/CRITICAL] Directory not found : \"$directory\"\n";
66 if ($_[1] =~ /^(.*)=(.*)$/) {
67 my($var,$ctn)=($1,$2);
69 print "[Tesh/INFO] setenv $var=$ctn\n";
71 die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$_[1]'\n";
77 # remove the tesh file from the ARGV used
79 $tesh_file = pop @ARGV;
81 # temporary arrays for GetOption
91 Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
94 'help|h' => \$opt{'help'},
96 'verbose|v' => \@verbose,
97 'debug|d' => \$opt{"debug"},
100 'setenv=s' => \&setenv_cmd,
104 $opt{'verbose'} = scalar @verbose;
106 $opt{'cfg'} .= " --cfg=$_";
111 my %opts = get_options(@ARGV);
114 open SH_LIGNE, $tesh_file or die "[Tesh/CRITICAL] Unable to open $tesh_file: $!\n";
116 while(defined($line1=<SH_LIGNE>))
118 if($line1 =~ /^\< \$ /){ # arg command line
119 $line1 =~ s/\${EXEEXT:=}//g;
120 $line1 =~ s/^\< \$\ *//g;
121 $line1 =~ s/^.\/lua/lua/g;
122 $line1 =~ s/^.\/ruby/ruby/g;
124 $line1 =~ s/^tesh/.\/tesh/g;
125 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
127 $command_tesh = $line1;
128 print "[Tesh/INFO] arg_exec_line : $command_tesh\n";
130 elsif($line1 =~ /^\< \< /){ # arg buffer line
131 $line1 =~ s/^\< \<\ *//g;
133 print "[Tesh/INFO] arg_buffer_line : $line1\n";
134 push @buffer_tesh, "$line1\n";
136 elsif($line1 =~ /^\< \> /){ # arg output line
137 $line1 =~ s/^\< \>\ *//g;
141 print "[Tesh/INFO] arg_output_line : $line1\n";
142 $expected_result_line = 1;
144 elsif($line1 =~ /^\$ mkfile/){ # "mkfile" command line
146 $line1 =~ s/mkfile//g;
150 print "[Tesh/INFO] exec_line : mkfile $fich_name\n";
152 open(FILE,">$fich_name") or die "[Tesh/CRITICAL] Unable to make file : $fich_name. $!\n";
157 elsif($line1 =~ /^\$ cd/){ # "cd" command line
160 print "[Tesh/INFO] exec_line : $line1\n";
162 chdir("$line1") or die "[Tesh/CRITICAL] Unable to open $line1. $!\n";
164 elsif($line1 =~ /^\$ /){ #command line
165 if($line1 =~ /^\$ .\/tesh/){ # tesh command line
167 @buffer = @buffer_tesh;
170 $line1 =~ s/\${EXEEXT:=}//g;
171 $line1 =~ s/^\$\ *//g;
172 $line1 =~ s/^.\/lua/lua/g;
173 $line1 =~ s/^.\/ruby/ruby/g;
175 $line1 =~ s/^tesh/.\/tesh/g;
176 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
178 $line1 = "$line1 $config";
182 print "[Tesh/CRITICAL] -\n";
183 print "[Tesh/CRITICAL] + @list1";
184 print color("reset"), "\n";
186 if(@list_of_commands){ # need parallel execution
187 push @list_of_commands, $line1;
188 print "[Tesh/INFO] exec_line : $line1\n";
191 print "[Tesh/INFO] exec_line : $line1\n";
193 { $execline = $command_tesh;
196 { $execline = $line1;}
197 $pid = open3(\*IN, \*OUT, \*OUT, $execline );
199 $forked = fork();die "fork() failed: $!" unless defined $forked;
210 $line1 = shift (@buffer);
216 if($timeout){kill(9, $forked);$timeout=0;}
219 while(defined($linebis=<OUT>))
222 $linebis =~ s/^( )*//g;
224 push @list1,"$linebis";
227 $command_executed = 1;
230 elsif($line1 =~ /^\& /){ # parallel command line
231 $command_executed = 0;
232 $expected_result_line = 0;
233 $line1 =~ s/\${EXEEXT:=}//g;
235 $line1 =~ s/^.\/lua/lua/g;
236 $line1 =~ s/^.\/ruby/ruby/g;
238 $line1 =~ s/\(%i:%P@%h\)/\\\(%i:%P@%h\\\)/g;
240 $line1 = "$line1 $config";
242 $execline = "$line1";
243 print "[Tesh/INFO] exec_line : $execline\n";
244 push @list_of_commands, $execline;
246 elsif($line1 =~ /^\>/){ #expected result line
247 $line1 =~ s/^\>( )*//g;
251 $expected_result_line = 1;
253 elsif($line1 =~ /^\</ or $encore==1){ #need to buffer
254 $line1 =~ s/^\<( )*//g; #delete < with space or tab after
257 if($line1 =~ /\\$/) # need to store this line into old_buff
261 $old_buffer = "$old_buffer$line1";
265 if($encore == 1){push @buffer, "$old_buffer$line1";}
266 else{push @buffer, "$line1\n";}
271 elsif($line1 =~ /^p/){ #comment
275 print "[Tesh/INFO] comment_line :$line1\n";
277 elsif($line1 =~ /^! output sort/){ #output sort
280 elsif($line1 =~ /^! output ignore/){ #output ignore
283 elsif($line1 =~ /^! expect signal SIGABRT$/) #expect signal SIGABRT
287 elsif($line1 =~ /^! expect return/){ #expect return
288 $line1 =~ s/^! expect return //g;
292 print color("red"), "[Tesh/INFO] expect return $return";
293 print color("reset"), "\n";
296 elsif($line1 =~ /^! setenv/){ #setenv
297 $line1 =~ s/^! setenv //g;
300 $line1 =~ /^(.*)=(.*)$/;
302 print "[Tesh/INFO] setenv: $1=$2\n";
304 elsif($line1 =~ /^! include/){ #output sort
305 print color("red"), "[Tesh/CRITICAL] need include";
306 print color("reset"), "\n";
309 elsif($line1 =~ /^! timeout/){ #timeout
310 $line1 =~ s/^! timeout //g;
313 if($timeout != $line1){
315 print "[Tesh/INFO] timeout : $timeout\n";}
317 elsif($line1 =~ /^! need execute/){ #need execute // commands
319 $sort = 1; # need sort output
320 while(@list_of_commands)
322 $command = shift (@list_of_commands);
323 if($execline){$execline = "$command & $execline";}
324 else{$execline = "$command";}
326 $pid = open3(\*IN, \*OUT, \*OUT, $execline);
328 $forked = fork();die "fork() failed: $!" unless defined $forked;
339 $line1 = shift (@buffer);
344 if($timeout){kill(9, $forked);$timeout=0;}
348 while(defined($linebis=<OUT>))
351 $linebis =~ s/^( )*//g;
353 push @list1,"$linebis";
356 $command_executed = 1;
358 elsif($command_executed and $expected_result_line)
360 if($no_output_ignore){
364 @list3 = sort @list1;
369 @list3 = sort @list2;
378 push @list2,"Aborted";
382 while(@list1 or @list2)
384 if(@list1){$line1 = shift (@list1);$expected_result_line = "x$line1";}
385 if(@list2){$line2 = shift (@list2);$command_executed = "x$line2";}
386 if($command_executed and $expected_result_line)
389 if($line1 eq $line2){
390 if($verbose == 1){print color("green"),"[Tesh/VERB] $line1\n",color("reset");}
391 else{push @buffer, "[Tesh/CRITICAL] $line1\n";}
395 { if($verbose == 0){print color("green"),@buffer,color("reset");}
396 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
397 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
402 { if($verbose == 0){print color("green"),@buffer,color("reset");}
403 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
404 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
408 }else{$no_output_ignore = 1;}
409 $command_executed = 0;
410 $expected_result_line = 0;
420 if(@list_of_commands){ # need parallel execution
422 $sort = 1; # need sort output
423 while(@list_of_commands)
425 $command = shift (@list_of_commands);
426 if($execline){$execline = "$command & $execline";}
427 else{$execline = "$command";}
429 print "[Tesh/INFO] exec_line : $execline\n";
430 $pid = open3(\*IN, \*OUT, \*OUT,"$execline");
433 $forked = fork();die "fork() failed: $!" unless defined $forked;
444 $line1 = shift (@buffer);
449 if($timeout){kill(9, $forked);$timeout=0;}
453 while(defined($linebis=<OUT>))
456 $linebis =~ s/^( )*//g;
458 push @list1,"$linebis";
461 $command_executed = 1;
464 if($command_executed and $expected_result_line ){
465 if($no_output_ignore){
469 @list3 = sort @list1;
474 @list3 = sort @list2;
483 push @list2,"Aborted";
487 while(@list1 or @list2)
489 if(@list1){$line1 = shift (@list1);$expected_result_line = "x$line1";}
490 if(@list2){$line2 = shift (@list2);$command_executed = "x$line2";}
491 if($command_executed and $expected_result_line)
493 if($line1 eq $line2){
494 if($verbose == 1){print color("green"),"[Tesh/VERB] $line1\n",color("reset");}
495 else{push @buffer, "[Tesh/CRITICAL] $line1\n";}
499 { if($verbose == 0){print color("green"),@buffer,color("reset");}
500 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
501 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
506 { if($verbose == 0){print color("green"),@buffer,color("reset");}
507 if($line2) {print color("red"), "[Tesh/CRITICAL] - $line2",color("reset"),"\n";}
508 if($line1) {print color("red"), "[Tesh/CRITICAL] + $line1",color("reset"),"\n";}
512 }else{$no_output_ignore = 1;}
513 $command_executed = 0;
514 $expected_result_line= 0;