2005-07-20 Aldo Monteiro <aldo@psl-pr.softwarelivre.org>, Renato Suga <renato@psl...
[mono.git] / mcs / mbas / Test / tests / test-mbas.pl
1 #!/usr/bin/perl -w
2 use Cwd;
3 use File::Basename;
4 use File::Find;
5 use Getopt::Long;
6
7
8 my $Compiler = "mbas";
9 my $Runtime;
10 my $CompilerFlags = "";
11
12 my $Execute = 1;
13 my $CompileCmd;
14 my $RunCmd;
15 my $RetVal=-1;
16
17 my $VBFile="";
18 my $VBExeFile;
19 my $VBLogFile;
20 my $TestResultsFile = "TestResults.log";
21 my $ExpectedResult="SUCCESS";
22 my @ActualResults = ();
23
24
25 my $VerboseMode=1;
26 my $FilePattern = "*.vb"; 
27 my $PrintHelp;
28
29 sub Command
30 {
31     my $retVal;
32     my $cmdLine = shift(@_);
33
34     open SAVEOUT, ">&STDOUT";
35     open SAVEERR, ">&STDERR";
36
37     print SAVEOUT "";
38     print SAVEERR "";
39
40     open STDOUT, ">>$VBLogFile";
41     open STDERR, ">&STDOUT";
42
43     print "\n";
44     print $cmdLine . "\n";
45     system($cmdLine);
46
47     $retVal = $?;
48
49     close STDOUT;
50     close STDERR;
51
52     open STDOUT, ">&SAVEOUT";
53     open STDERR, ">&SAVEERR";
54
55     return $retVal;
56 }
57
58 sub LogResults
59 {
60     my($retVal, $msg) = @_;
61
62     LogMessage("========================");
63     if($retVal == 0) {
64         LogMessage($VBFile . ": OK");
65     } 
66     else {
67         LogMessage($VBFile . ": FAILED " . $msg);
68     }
69 }
70
71
72
73 sub LogMessage
74 {
75     my $msg = shift(@_);
76
77     if($VerboseMode) {
78         print $msg . "\n";
79     }
80
81     print TEST_RESULTS_FILE $msg . "\n";
82 }
83
84 sub PrintUsage() {
85     print "\nUsage: test-mbas.pl [options]";
86     print "\nTypical Usage: test-mbas.pl --p=Accessibility*.vb --res=test-results.log";
87     print "\n\noptions:";
88     print "\n\t--help\t\tprints this help";
89     print "\n\t--verbose\tprints the results on the screen";
90     print "\n\t--compiler\tspecify mbas or vbc";
91     print "\n\t--compilerflags\tuse this to pass additional flags to the compiler";
92     print "\n\t--runtime\tspecify mono or dotnet";
93     print "\n\t--results\tname of the logfile";
94     print "\n\t--pattern\tshell pattern for test case files\n\n";
95 }
96
97 # Process the command line
98
99 $result = GetOptions( "verbose!"=>\$VerboseMode,
100                       "help"=>\$PrintHelp,
101             "compiler:s"=>\$Compiler,
102             "compilerflags:s"=>\$CompilerFlags,
103             "runtime:s"=>\$Runtime,
104             "results:s"=>\$TestResultsFile,
105             "pattern:s"=>\$FilePattern);
106
107 if(!$result || $PrintHelp) {
108     PrintUsage();
109     exit 1;
110 }
111
112 # Build the list of tests to run
113
114 open(TEST_RESULTS_FILE, ">$TestResultsFile");
115 while(defined ($vbFile = glob($FilePattern))) {
116     $VBFile = $vbFile;
117     $VBLogFile = $VBFile . ".log";
118
119     $CompileCmd = $Compiler . " " . $CompilerFlags . " " . $VBFile;
120     $RetVal = Command($CompileCmd);
121
122     if($ExpectedResult eq "SUCCESS") {
123         if($RetVal != 0) {
124             LogResults($RetVal, "COMPILATION");
125             next;
126         }
127         else {
128             if($Execute == 1) {
129                 $VBExeFile = $VBFile;
130                 $VBExeFile =~ s/\.vb$/\.exe/;
131                 $RunCmd = "$Runtime ./$VBExeFile";
132                 $RetVal = Command($RunCmd);
133                 LogResults($RetVal, "EXECUTION");
134             } 
135             else {
136                 LogResults($RetVal, "");
137             }
138         }
139     }
140
141     if($RetVal == 0) {
142         unlink($VBLogFile);
143     }
144 }
145 close TEST_RESULTS_FILE;
146