Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tesh for windows
[simgrid.git] / buildtools / Cmake / tesh.pl
1 #!perl -w
2 use strict;
3 use IPC::Open3;
4
5 if($#ARGV!=1) {
6     die "Usage: perl tesh.pl <directory> <teshfile.tesh>\n";
7 }
8
9 my($directory)=$ARGV[0];
10 my($file)=$ARGV[1];
11
12 chdir("$directory");
13 print "Change directory to \"$directory\"\n";
14
15 open SH_LIGNE, $file or die "Unable to open $file. $!\n";
16
17 my($line1);
18 my($line2);
19 my($execline);
20 my($ok)=0;
21 my(@result)=();
22
23 while(defined($line1=<SH_LIGNE>))
24 {
25                 if($line1 =~ /^\$(.*)$/) #command line
26                 { 
27                 $ok = 1;
28                 @result = ();
29                         $line1 =~ s/\$\{srcdir\:\=\.\}/./g;
30                         $line1 =~ s/\$SG_TEST_EXENV//g;
31                         $line1 =~ s/\$EXEEXT//g;
32                         $line1 =~ s/\${EXEEXT:=}//g;
33                         $line1 =~ s/^\$\ */.\//g;
34                         $line1 =~ s/^.\/lua/lua/g;
35                         $line1 =~ s/^.\/ruby/ruby/g;
36                         chomp $line1;
37                         $execline = $line1;
38                         close(FILE_ERR);
39                         close(FILE);
40                         open3("&STDIN",\*FILE,\*FILE_ERR,"$execline") or die "cannot run $execline:\n$!";       
41                         print "$execline";
42                         
43                 }
44                 elsif($line1 =~ /^\>(.*)$/) #expected result line       
45                 {
46                         if($ok == 0){die "No command line$!";}
47                         $line1 =~ s/^\> //g;
48                         chomp $line1;
49                         
50                         if($line1 =~ /^.*\[.*\].*\[.*\/INFO\]/)
51                         {
52                                 if(!defined($line2=<FILE_ERR>)){die "Don't have FILE_ERR$!";}
53                         }
54                         else
55                         {
56                                 if(!defined($line2=<FILE>)){die "Don't have FILE$!";}
57                         }
58                         
59                         if($line2 =~ /^.*$/) #command result line
60                         {
61                                 $line2 =~ s/\r//g;                                                      
62                                 chomp $line2;
63                                 
64                                 if($line2 eq $line1)
65                                 {
66                                         push @result, "$line1 \n";
67                                 }
68                                 else
69                                 {
70                                         print @result;
71                                         print "- $line1\n";
72                                         print "+ $line2\n";
73                                         print " NOK";
74                                         die;
75                                 }
76                         }
77                         else
78                         {
79                                 print @result;
80                                 print "- $line1\n";
81                                 print "+ $line2\n";
82                                 print " NOK";
83                                 die;
84                         }
85                 }
86                 else
87                 {
88                         if($ok == 1)
89                         {
90                         print " OK\n";
91                         $ok = 0;                                
92                         }
93                         else
94                         {
95                                 print " erreur\n";
96                         }
97                 }
98 }
99 if($ok == 1)
100 {
101         print " OK\n";
102         $ok = 0;                                
103 }
104 close(SH_LIGNE);
105 close(FILE_ERR);
106 close(FILE);