Merge pull request #2810 from kumpera/fix_hazard_free
[mono.git] / mono / mini / emitnunit.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Cwd;
5 use POSIX qw(strftime uname locale_h);
6 use Net::Domain qw(hostname hostfqdn);
7 use locale;
8
9 my $line;
10 foreach $line (<STDIN>) {
11     chomp ($line);
12     print "$line\n";
13     if ($line =~ /^Overall results:/) {
14         # do magic nunit emission here
15         # failures look like:
16         #    Overall results: tests: 19992, failed: 48, opt combinations: 24 (pass: 99.76%)
17         # passes look like:
18         #    Overall results: tests: 20928, 100% pass, opt combinations: 24
19         my @words = split (/ /, $line);
20         my $failed;
21         my $successbool;
22         my $total = $words[3];
23         my $mylocale = setlocale (LC_CTYPE);
24         $mylocale = substr($mylocale, 0, index($mylocale, '.'));
25         $mylocale =~ s/_/-/;
26         if ($line =~ /failed:/) {
27             $failed = $words[5];
28         } else {
29             $failed = "0,";
30         }
31         chop ($failed);
32         chop ($total);
33         if ($failed > 0) {
34             $successbool = "False";
35         } else {
36             $successbool = "True";
37         }
38         open (my $nunitxml, '>', 'TestResult-regression.xml') or die "Could not write to 'TestResult-regression.xml' $!";
39         print $nunitxml "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n";
40         print $nunitxml "<!--This file represents the results of running a test suite-->\n";
41         print $nunitxml "<test-results name=\"regression-tests.dummy\" total=\"$total\" failures=\"$failed\" not-run=\"0\" date=\"" . strftime ("%F", localtime) . "\" time=\"" . strftime ("%T", localtime) . "\">\n";
42         print $nunitxml "  <environment nunit-version=\"2.4.8.0\" clr-version=\"4.0.30319.17020\" os-version=\"Unix " . (uname ())[2]  . "\" platform=\"Unix\" cwd=\"" . getcwd . "\" machine-name=\"" . hostname . "\" user=\"" . getpwuid ($<) . "\" user-domain=\"" . hostfqdn  . "\" />\n";
43         print $nunitxml "  <culture-info current-culture=\"$mylocale\" current-uiculture=\"$mylocale\" />\n";
44         print $nunitxml "  <test-suite name=\"regression-tests.dummy\" success=\"$successbool\" time=\"0\" asserts=\"0\">\n";
45         print $nunitxml "    <results>\n";
46         print $nunitxml "      <test-suite name=\"MonoTests\" success=\"$successbool\" time=\"0\" asserts=\"0\">\n";
47         print $nunitxml "        <results>\n";
48         print $nunitxml "          <test-suite name=\"regressions\" success=\"$successbool\" time=\"0\" asserts=\"0\">\n";
49         print $nunitxml "            <results>\n";
50         print $nunitxml "              <test-case name=\"MonoTests.regressions.100percentsuccess\" executed=\"True\" success=\"$successbool\" time=\"0\" asserts=\"0\"";
51         if ( $failed > 0) {
52         print $nunitxml ">\n";
53         print $nunitxml "                <failure>\n";
54         print $nunitxml "                  <message><![CDATA[";
55         foreach $line (<STDIN>) {
56             chomp ($line);
57             print "$line\n";
58         }
59         print $nunitxml "]]></message>\n";
60         print $nunitxml "                  <stack-trace>\n";
61         print $nunitxml "                  </stack-trace>\n";
62         print $nunitxml "                </failure>\n";
63         print $nunitxml "              </test-case>\n";
64         } else {
65         print $nunitxml " />\n";
66         }
67         print $nunitxml "            </results>\n";
68         print $nunitxml "          </test-suite>\n";
69         print $nunitxml "        </results>\n";
70         print $nunitxml "      </test-suite>\n";
71         print $nunitxml "    </results>\n";
72         print $nunitxml "  </test-suite>\n";
73         print $nunitxml "</test-results>\n";
74         close $nunitxml;
75     }
76 }