Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update perl version of tesh with sorting, trimming ..
authorAugustin Degomme <degomme@idpann.imag.fr>
Thu, 26 Sep 2013 16:42:25 +0000 (18:42 +0200)
committerAugustin Degomme <degomme@idpann.imag.fr>
Thu, 26 Sep 2013 16:43:06 +0000 (18:43 +0200)
buildtools/Cmake/Scripts/tesh.pl
tools/tesh/CMakeLists.txt

index a5b53c4..aef4938 100755 (executable)
@@ -13,8 +13,8 @@ tesh -- testing shell
 B<tesh> [I<options>] I<tesh_file>
 
 =cut
 B<tesh> [I<options>] I<tesh_file>
 
 =cut
-my($bindir);
-my($srcdir);
+my($bindir)=".";
+my($srcdir)=".";
 my $path = $0;
 $path =~ s|[^/]*$||;
 push @INC,$path;
 my $path = $0;
 $path =~ s|[^/]*$||;
 push @INC,$path;
@@ -25,13 +25,23 @@ use Term::ANSIColor;
 use IPC::Open3;
 
 my($OS)=`echo %OS%`;
 use IPC::Open3;
 
 my($OS)=`echo %OS%`;
-if($OS eq "%OS%"){
+if($OS eq "%OS%\n"){
        $OS = "UNIX";
 }
 else{
        $OS = "UNIX";
 }
 else{
+    print("$OS and %OS%\n");
        $OS = "WIN";
 }
 
        $OS = "WIN";
 }
 
+
+sub trim($)
+{
+       my $string = shift;
+       $string =~ s/^\s+//;
+       $string =~ s/\s+$//;
+       return $string;
+}
+
 print "OS: ".$OS."\n";
 
 # make sure we received a tesh file
 print "OS: ".$OS."\n";
 
 # make sure we received a tesh file
@@ -59,8 +69,14 @@ sub cd_cmd {
 }
 
 sub setenv_cmd {
 }
 
 sub setenv_cmd {
-    if ($_[1] =~ /^(.*)=(.*)$/) {
-       my($var,$ctn)=($1,$2);
+    my($var,$ctn);
+    if ($_[0] =~ /^(.*)=(.*)$/) {
+        ($var,$ctn)=($1,$2);
+    }elsif ($_[1] =~ /^(.*)=(.*)$/) {
+        ($var,$ctn)=($1,$2);
+    } else { 
+           die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$_[1]'\n";
+    }
        
        if($var =~ /bindir/){
                print "[Tesh/INFO] setenv $var=$ctn\n";
        
        if($var =~ /bindir/){
                print "[Tesh/INFO] setenv $var=$ctn\n";
@@ -76,9 +92,6 @@ sub setenv_cmd {
                        print "[Tesh/INFO] setenv $var=$ctn\n";
                }
        }       
                        print "[Tesh/INFO] setenv $var=$ctn\n";
                }
        }       
-       } else { 
-       die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$_[1]'\n";
-    }
 }
 
 # Main option parsing sub
 }
 
 # Main option parsing sub
@@ -220,12 +233,25 @@ sub exec_cmd {
     my @got;
     while(defined(my $got=<OUT>)) {
        $got =~ s/\r//g;
     my @got;
     while(defined(my $got=<OUT>)) {
        $got =~ s/\r//g;
-       #$got =~ s/^( )*//g;
+       $got =~ s/^( )*//g;
        chomp $got;
        chomp $got;
-       push @got, "$got";
+    $got=trim($got);
+       if( $got ne ""){
+        push @got, "$got";
+    }
     }  
     close OUT;
     }  
     close OUT;
-    
+   
+    if ($sort){   
+      sub mysort{
+        $a cmp $b
+        }
+      use sort qw(defaults _quicksort); # force quicksort
+      @got = sort mysort @got;
+      #also resort the other one, as perl sort is not the same as the C one used to generate teshes
+      @{$cmd{'out'}}=sort mysort @{$cmd{'out'}};
+    }
+  
     # Cleanup the executing child, and kill the timeouter brother on need
     $cmd{'return'} = 0 unless defined($cmd{'return'});
     my $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0);
     # Cleanup the executing child, and kill the timeouter brother on need
     $cmd{'return'} = 0 unless defined($cmd{'return'});
     my $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0);
@@ -304,7 +330,10 @@ LINE: while (defined(my $line=<TESH_FILE>)) {
     if ($cmd =~ /^#/) {        #comment
     } elsif ($cmd eq '> '){    #expected result line
        print "[TESH/debug] push expected result\n" if $opts{'debug'};
     if ($cmd =~ /^#/) {        #comment
     } elsif ($cmd eq '> '){    #expected result line
        print "[TESH/debug] push expected result\n" if $opts{'debug'};
-       push @{$cmd{'out'}}, $arg;
+    $arg=trim($arg);
+       if($arg ne ""){
+        push @{$cmd{'out'}}, $arg;
+    }
 
     } elsif ($cmd eq '< ') {   # provided input
        print "[TESH/debug] push provided input\n" if $opts{'debug'};
 
     } elsif ($cmd eq '< ') {   # provided input
        print "[TESH/debug] push provided input\n" if $opts{'debug'};
@@ -346,6 +375,7 @@ LINE: while (defined(my $line=<TESH_FILE>)) {
        $cmd{'cmd'} = $arg;
     }  
     elsif($line =~ /^! output sort/){  #output sort
        $cmd{'cmd'} = $arg;
     }  
     elsif($line =~ /^! output sort/){  #output sort
+    $sort=1;
        $cmd{'sort'} = 1;
     }
     elsif($line =~ /^! output ignore/){        #output ignore
        $cmd{'sort'} = 1;
     }
     elsif($line =~ /^! output ignore/){        #output ignore
index c099aa1..467c8e3 100644 (file)
@@ -1,16 +1,20 @@
 cmake_minimum_required(VERSION 2.6)
 
 if(WIN32)
 cmake_minimum_required(VERSION 2.6)
 
 if(WIN32)
-  #add_custom_target(tesh ALL
-  #  DEPENDS ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl
-  #  COMMENT "Install ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl"
-  #  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl ${CMAKE_BINARY_DIR}/bin/tesh
-  #  )
+#  add_custom_target(tesh ALL
+#    DEPENDS ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl
+#    COMMENT "Install ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl"
+#    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl ${CMAKE_BINARY_DIR}/bin/tesh
+#    )
     
     file(COPY        ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl 
          DESTINATION ${CMAKE_BINARY_DIR}/bin/
          FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
                           GROUP_EXECUTE GROUP_READ)
     
     file(COPY        ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/tesh.pl 
          DESTINATION ${CMAKE_BINARY_DIR}/bin/
          FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
                           GROUP_EXECUTE GROUP_READ)
+    file(COPY        ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/Diff.pm 
+         DESTINATION ${CMAKE_BINARY_DIR}
+         FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
+                          GROUP_EXECUTE GROUP_READ)
     file(RENAME ${CMAKE_BINARY_DIR}/bin/tesh.pl ${CMAKE_BINARY_DIR}/bin/tesh)                    
 else()
   set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
     file(RENAME ${CMAKE_BINARY_DIR}/bin/tesh.pl ${CMAKE_BINARY_DIR}/bin/tesh)                    
 else()
   set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")