2010-05-19 Jb Evain <jbevain@novell.com>
[mcs.git] / tools / scan-tests.pl
blob5cb0f8625f5a1a55c58b320bd1a79ebb14b8edf1
1 #!/usr/bin/perl -w
3 use strict;
4 use Carp;
6 my @allfiles;
8 my @badsuites = qw[System\.Collections/HashtableTest System\.Collections/StackTest System\.Collections\.Specialized\.BasicOperationsTest];
9 my @badtests = qw[PathTest:TestGetTempFileName XmlTextReaderTests:TestIsNameChar XmlTextReaderTests:TestIsFirstNameChar ByteTest:TestParse];
10 my @mapfiles = ('s,^MonoTests\.(.*)/,$1/,',
11 's,^Ximian\.Mono\.Tests(.*)/,,',
12 's,^System\.Net/,,',
13 's,^Collections\.Specialized\.,,',
14 's,^Text\.RegularExpressions\.,,'
16 my @maptests = ();
17 my @mapnamespace = ();
19 die "Usage: $0 input output" unless $#ARGV == 1;
21 my $namespace = 'MonoTests';
23 sub parse_test {
24 my ($filename, $namespace, $testname, $suite) = @_;
26 foreach (@badsuites) {
27 return if $filename =~ /$_/;
30 my $map;
31 foreach $map (@mapfiles) {
32 eval "\$filename =~ $map";
35 foreach (@allfiles) {
36 return if $filename eq $_->[0];
39 # print STDERR "PARSE: |$filename|\n";
41 push @allfiles, [$filename,$namespace,$testname,$suite,[]];
43 my $INPUT;
44 open $INPUT, $filename or croak "open ($filename): $!";
45 while (defined ($_ = <$INPUT>)) {
46 if (/^\s*namespace\s*([\w\.]+?)\s*$/) {
47 $namespace = $1;
48 next;
50 if (/^\s*suite\.AddTest\s*\((.*)\.(.*?)\.Suite\)/) {
51 my $filename = (defined $namespace) ? qq[$namespace.$1/$2.cs] : qq[$1/$2.cs];
52 my $nsprefix = (defined $namespace) ? qq[$namespace.$1] : qq[MonoTests.$1];
53 parse_test ($filename, $nsprefix, $1, $2);
54 next;
56 if (/^\s*suite\.AddTest\s*\((.*?)\.Suite\)/) {
57 my $filename = (defined $namespace) ? qq[$namespace/$1.cs] : qq[$1.cs];
58 parse_test ($filename, $namespace, '', $1);
59 next;
61 if (/^\s*suite\.AddTest\s*\(\s*new\s+TestSuite\s*\(\s*typeof\(\s*(.*)\s*\)\s*\)\s*\);/) {
62 my $filename = (defined $namespace) ? qq[$namespace/$1.cs] : qq[$1.cs];
63 parse_test ($filename, $namespace, '', $1);
64 next;
67 close $INPUT;
70 parse_test ($ARGV[0], undef, '', '');
72 my $file;
73 foreach $file (@allfiles) {
74 my ($filename,$namespace,$testname,$suite) = @$file;
76 open SUITE, $filename or croak "open ($filename): $!";
77 while (defined ($_ = <SUITE>)) {
78 next unless /^\s*public\s+void\s+(Test.*?)\s*\(\s*\)/;
79 push @{$file->[4]}, $1;
81 close SUITE;
84 open OUTPUT, "> $ARGV[1]" or croak "open (> $ARGV[1]): $!";
85 select OUTPUT;
87 print qq[using NUnit.Framework;\n];
88 print qq[using System;\n];
89 print qq[using System.Threading;\n];
90 print qq[using System.Globalization;\n\n];
93 my $alltest;
94 foreach $alltest (@allfiles) {
96 my ($filename,$namespace,$testname,$suite,$tests) = @$alltest;
97 my @tests = @$tests;
99 next unless defined $namespace;
100 next unless $#tests >= 0;
102 # print STDERR "DOING TEST: |$testname|$filename|\n";
104 $namespace .= ".$testname" unless $testname eq '';
106 print qq[namespace $namespace\n\{\n];
107 print qq[\tpublic class Run$suite : $suite\n\t\{\n];
108 print qq[\t\tprotected override void RunTest ()\n\t\t\{\n];
109 # print qq[\t\t\tbool errorThrown = false;\n\n];
110 my $test;
111 testloop:
112 foreach $test (@tests) {
113 my $badtest;
114 $filename =~ s/\.cs$//;
115 my $fullname = qq[$filename:$test];
116 # print STDERR "TEST: |$fullname|\n";
117 foreach $badtest (@badtests) {
118 next testloop if $fullname =~ /$badtest/;
120 # print qq[\t\t\ttry \{\n\t\t\t\t$test ();\n\t\t\t\} catch \{\n];
121 # print qq[\t\t\t\tConsole.WriteLine ("$namespace:$suite:$test failed");\n];
122 # print qq[\t\t\t\terrorThrown = true;\n];
123 # print qq[\t\t\t\}\n];
124 print qq[\t\t\t$test ();\n];
125 # print qq[\t\t\tConsole.WriteLine ("$namespace:$suite:$test DONE");\n];
127 print qq[\n];
128 # print qq[\t\t\tif (errorThrown)\n\t\t\t\tthrow new ArgumentException ();\n];
129 print qq[\t\t\}\n\t\}\n];
130 print qq[\}\n\n];
133 print qq[namespace $namespace\n\{\n];
134 print qq[\tpublic class RunAllTests\n\t\{\n];
135 print qq[\t\tpublic static void AddAllTests (TestSuite suite)\n];
136 print qq[\t\t\{\n];
138 foreach $alltest (@allfiles) {
139 my ($filename,$namespace,$testname,$suite,$tests) = @$alltest;
140 my @tests = @$tests;
142 next unless defined $namespace;
143 next unless $#tests >= 0;
145 $namespace .= ".$testname" unless $testname eq '';
147 print qq[\t\t\tsuite.AddTest (new $namespace.Run$suite ());\n];
150 print qq[\t\t\}\n\t\}\n\}\n\n];
152 print qq[class MainApp\n\{\n];
153 print qq[\tpublic static void Main()\n\t\{\n];
154 print qq[\t\tThread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");\n\n];
155 print qq[\t\tTestResult result = new TestResult ();\n];
156 print qq[\t\tTestSuite suite = new TestSuite ();\n];
157 print qq[\t\t$namespace.RunAllTests.AddAllTests (suite);\n];
158 print qq[\t\tsuite.Run (result);\n];
159 print qq[\t\tMonoTests.MyTestRunner.Print (result);\n];
160 print qq[\t\}\n\}\n\n];
162 close OUTPUT;