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(.*)/,,',
13 's,^Collections\.Specialized\.,,',
14 's,^Text\.RegularExpressions\.,,'
17 my @mapnamespace = ();
19 die "Usage: $0 input output" unless $#ARGV == 1;
21 my $namespace = 'MonoTests';
24 my ($filename, $namespace, $testname, $suite) = @_;
26 foreach (@badsuites) {
27 return if $filename =~ /$_/;
31 foreach $map (@mapfiles) {
32 eval "\$filename =~ $map";
36 return if $filename eq $_->[0];
39 # print STDERR "PARSE: |$filename|\n";
41 push @allfiles, [$filename,$namespace,$testname,$suite,[]];
44 open $INPUT, $filename or croak
"open ($filename): $!";
45 while (defined ($_ = <$INPUT>)) {
46 if (/^\s*namespace\s*([\w\.]+?)\s*$/) {
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);
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);
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);
70 parse_test
($ARGV[0], undef, '', '');
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;
84 open OUTPUT
, "> $ARGV[1]" or croak
"open (> $ARGV[1]): $!";
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];
94 foreach $alltest (@allfiles) {
96 my ($filename,$namespace,$testname,$suite,$tests) = @
$alltest;
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];
112 foreach $test (@tests) {
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];
128 # print qq[\t\t\tif (errorThrown)\n\t\t\t\tthrow new ArgumentException ();\n];
129 print qq[\t\t\
}\n\t\
}\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];
138 foreach $alltest (@allfiles) {
139 my ($filename,$namespace,$testname,$suite,$tests) = @
$alltest;
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];