2002-02-27 Martin Baulig <martin@gnome.org>
[mono.git] / mcs / tools / scan-tests.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Carp;
5
6 my @alltests;
7 my @allsuites;
8
9 my @badtests = qw[System.Collections.HastableTest System.Collections.StackTest System.IO.PathTest];
10
11 die "Usage: $0 input output" unless $#ARGV == 1;
12
13 open INPUT, $ARGV[0] or croak "open ($ARGV[0]): $!";
14 while (defined ($_ = <INPUT>)) {
15     next unless /^\s*suite\.AddTest\s*\((.*)\.(.*?)\.Suite\)/;
16
17     push @alltests, [$1,$2];
18 }
19 close INPUT;
20
21 open OUTPUT, "> $ARGV[1]" or croak "open (> $ARGV[1]): $!";
22 select OUTPUT;
23
24 print qq[using NUnit.Framework;\n];
25 print qq[using System;\n];
26 print qq[using System.Threading;\n];
27 print qq[using System.Globalization;\n\n];
28
29
30 my $alltest;
31 foreach $alltest (@alltests) {
32
33     my @suites;
34
35     my $testname = $alltest->[0];
36     my $filename = $alltest->[0]."/".$alltest->[1].".cs";
37
38     open ALLTEST, $filename or croak "open ($filename): $!";
39     while (defined ($_ = <ALLTEST>)) {
40         next unless /^\s*suite\.AddTest\s*\((.*)\.Suite\)/;
41         my $name = $1;
42
43         next if grep $name, @badtests;
44
45         push @suites, $name;
46         push @allsuites, qq[$testname.Run$name];
47     }
48     close ALLTEST;
49
50     print qq[namespace MonoTests.$testname\n\{\n];
51
52     my $suite;
53     foreach $suite (@suites) {
54
55         my @tests;
56
57         open SUITE, qq[$testname/$suite.cs] or
58             croak "open ($testname/$suite.cs): $!";
59         while (defined ($_ = <SUITE>)) {
60             next unless /^\s*public\s+void\s+(Test.*?)\s*\(\s*\)/;
61             push @tests, $1;
62         }
63         close SUITE;
64
65         print qq[\tpublic class Run$suite : $suite\n\t\{\n];
66         print qq[\t\tprotected override void RunTest ()\n\t\t\{\n];
67         foreach (@tests) {
68             print qq[\t\t\t$_ ();\n];
69         }
70         print qq[\t\t\}\n\t\}\n];
71     }
72     print qq[\}\n\n];
73 }
74
75 print qq[namespace MonoTests\n\{\n];
76 print qq[\tpublic class RunAllTests\n\t\{\n];
77 print qq[\t\tpublic static void AddAllTests (TestSuite suite)\n];
78 print qq[\t\t\{\n];
79
80 my $suite;
81 foreach $suite (@allsuites) {
82     print qq[\t\t\tsuite.AddTest (new MonoTests.$suite ());\n];
83 }
84
85 print qq[\t\t\}\n\t\}\n\}\n\n];
86
87 print qq[class MainApp\n\{\n];
88 print qq[\tpublic static void Main()\n\t\{\n];
89 print qq[\t\tThread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");\n\n];
90 print qq[\t\tTestResult result = new TestResult ();\n];
91 print qq[\t\tTestSuite suite = new TestSuite ();\n];
92 print qq[\t\tMonoTests.RunAllTests.AddAllTests (suite);\n];
93 print qq[\t\tsuite.Run (result);\n];
94 print qq[\t\tMonoTests.MyTestRunner.Print (result);\n];
95 print qq[\t\}\n\}\n\n];
96
97 close OUTPUT;
98