Merge pull request #1563 from directhex/emit-nunit-xml-in-unmanaged-tests
authorMiguel de Icaza <miguel@gnome.org>
Wed, 18 Feb 2015 04:27:58 +0000 (23:27 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 18 Feb 2015 04:27:58 +0000 (23:27 -0500)
Generate NUnit interpretation of whether "mono --regressions" passed

mono/mini/Makefile.am.in
mono/mini/emitnunit.pl [new file with mode: 0755]

index ad1a4b3239da02b72e3a6c255ec97cc9a23e6fca..48162213bd2eda2c8dfd9c2e080c9865f483558b 100755 (executable)
@@ -660,7 +660,8 @@ rcheck: mono $(regtests)
 if NACL_CODEGEN
        for i in $(regtests); do echo "running test $$i"; $(RUNTIME) $$i --exclude 'NaClDisable' || exit 1; done
 else
-       $(RUNTIME) --regression $(regtests)
+       -($(RUNTIME) --regression $(regtests); echo $$? > regressionexitcode.out) | ./emitnunit.pl
+       exit $$(cat regressionexitcode.out)
 endif
 
 check-seq-points: mono $(regtests)
@@ -727,7 +728,7 @@ docu: mini.sgm
 check-local: rcheck check-seq-points
 
 clean-local:
-       rm -f mono a.out gmon.out *.o buildver-boehm.h buildver-sgen.h test.exe
+       rm -f mono a.out gmon.out *.o buildver-boehm.h buildver-sgen.h test.exe regressionexitcode.out
 
 pkgconfigdir = $(libdir)/pkgconfig
 
diff --git a/mono/mini/emitnunit.pl b/mono/mini/emitnunit.pl
new file mode 100755 (executable)
index 0000000..b511e7d
--- /dev/null
@@ -0,0 +1,76 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Cwd;
+use POSIX qw(strftime uname locale_h);
+use Net::Domain qw(hostname hostfqdn);
+use locale;
+
+my $line;
+foreach $line (<STDIN>) {
+    chomp ($line);
+    print "$line\n";
+    if ($line =~ /^Overall results:/) {
+        # do magic nunit emission here
+        # failures look like:
+        #    Overall results: tests: 19992, failed: 48, opt combinations: 24 (pass: 99.76%)
+        # passes look like:
+        #    Overall results: tests: 20928, 100% pass, opt combinations: 24
+        my @words = split (/ /, $line);
+        my $failed;
+        my $successbool;
+        my $total = $words[3];
+        my $mylocale = setlocale (LC_CTYPE);
+        $mylocale = substr($mylocale, 0, index($mylocale, '.'));
+        $mylocale =~ s/_/-/;
+        if ($line =~ /failed:/) {
+            $failed = $words[5];
+        } else {
+            $failed = "0,";
+        }
+        chop ($failed);
+        chop ($total);
+        if ($failed > 0) {
+            $successbool = "False";
+        } else {
+            $successbool = "True";
+        }
+        open (my $nunitxml, '>', 'TestResults_regression.xml') or die "Could not write to 'TestResults_regression.xml' $!";
+        print $nunitxml "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n";
+        print $nunitxml "<!--This file represents the results of running a test suite-->\n";
+        print $nunitxml "<test-results name=\"regression-tests.dummy\" total=\"$total\" failures=\"$failed\" not-run=\"0\" date=\"" . strftime ("%F", localtime) . "\" time=\"" . strftime ("%T", localtime) . "\">\n";
+        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";
+        print $nunitxml "  <culture-info current-culture=\"$mylocale\" current-uiculture=\"$mylocale\" />\n";
+        print $nunitxml "  <test-suite name=\"regression-tests.dummy\" success=\"$successbool\" time=\"0\" asserts=\"0\">\n";
+        print $nunitxml "    <results>\n";
+        print $nunitxml "      <test-suite name=\"MonoTests\" success=\"$successbool\" time=\"0\" asserts=\"0\">\n";
+        print $nunitxml "        <results>\n";
+        print $nunitxml "          <test-suite name=\"regressions\" success=\"$successbool\" time=\"0\" asserts=\"0\">\n";
+        print $nunitxml "            <results>\n";
+        print $nunitxml "              <test-case name=\"MonoTests.regressions.100percentsuccess\" executed=\"True\" success=\"$successbool\" time=\"0\" asserts=\"0\"";
+        if ( $failed > 0) {
+        print $nunitxml ">\n";
+        print $nunitxml "                <failure>\n";
+        print $nunitxml "                  <message><![CDATA[";
+        foreach $line (<STDIN>) {
+            chomp ($line);
+            print "$line\n";
+        }
+        print $nunitxml "]]></message>\n";
+        print $nunitxml "                  <stack-trace>\n";
+        print $nunitxml "                  </stack-trace>\n";
+        print $nunitxml "                </failure>\n";
+        print $nunitxml "              </test-case>\n";
+        } else {
+        print $nunitxml " />\n";
+        }
+        print $nunitxml "            </results>\n";
+        print $nunitxml "          </test-suite>\n";
+        print $nunitxml "        </results>\n";
+        print $nunitxml "      </test-suite>\n";
+        print $nunitxml "    </results>\n";
+        print $nunitxml "  </test-suite>\n";
+        print $nunitxml "</test-results>\n";
+        close $nunitxml;
+    }
+}