[otrs-cvs] UnitTest/Kernel/System UnitTest.pm,1.42,1.42.2.1

"CVS commits notifications of OTRS.org" <[email protected]> Mon, 15 Apr 2013 08:29:33 +0000
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/UnitTest/Kernel/System
In directory lancelot:/tmp/cvs-serv1532/Kernel/System

Modified Files:
      Tag: rel-1_3
	UnitTest.pm 
Log Message:
Updated file to current framework version.

Author: mh

Index: UnitTest.pm
===================================================================
RCS file: /home/cvs/UnitTest/Kernel/System/UnitTest.pm,v
retrieving revision 1.42
retrieving revision 1.42.2.1
diff -2 -u -d -r1.42 -r1.42.2.1
--- UnitTest.pm	15 Apr 2013 08:10:30 -0000	1.42
+++ UnitTest.pm	15 Apr 2013 08:29:28 -0000	1.42.2.1
@@ -3,7 +3,4 @@
 # Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
 # --
-# $Id$
-# $OldId: UnitTest.pm,v 1.60.2.1 2012-08-14 11:23:22 mh Exp $
-# --
 # This software comes with ABSOLUTELY NO WARRANTY. For details, see
 # the enclosed file COPYING for license information (AGPL). If you
@@ -16,6 +13,8 @@
 use warnings;
 
-use vars qw(@ISA $VERSION);
-$VERSION = qw($Revision$) [1];
+use if $^O eq 'MSWin32', "Win32::Console::ANSI";
+use Term::ANSIColor;
+
+use vars qw(@ISA);
 
 =head1 NAME
@@ -186,5 +185,5 @@
 
                 # HERE the actual tests are run!!!
-                if ( !eval ${$UnitTestFile} ) {
+                if ( !eval ${$UnitTestFile} ) {    ## no critic
                     $Self->True( 0, "ERROR: Syntax error in $File: $@" );
                     print STDERR "ERROR: Syntax error in $File: $@\n";
@@ -340,8 +339,8 @@
     }
 
-# ---
-# OPMS
-# ---
-#    if ( $Self->{Output} eq 'XML' ) {
+    # ---
+    # OPMS
+    # ---
+    #    if ( $Self->{Output} eq 'XML' ) {
 
     if ( lc $ResultSummary{Database} eq 'mysql' ) {
@@ -397,35 +396,41 @@
     $ResultSummary{DatabaseVersion} ||= '';
 
-# ---
-        my $XML = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
-        $XML .= "<otrs_test>\n";
-        $XML .= "<Summary>\n";
-        for my $Key ( sort keys %ResultSummary ) {
-            $ResultSummary{$Key} =~ s/&/&amp;/g;
-            $ResultSummary{$Key} =~ s/</&lt;/g;
-            $ResultSummary{$Key} =~ s/>/&gt;/g;
-            $ResultSummary{$Key} =~ s/"/&quot;/g;
-            $XML .= "  <Item Name=\"$Key\">$ResultSummary{$Key}</Item>\n";
-        }
-        $XML .= "</Summary>\n";
-        for my $Key ( sort keys %{ $Self->{XML}->{Test} } ) {
-            $XML .= "<Unit Name=\"$Key\">\n";
-            for my $TestCount ( sort { $a <=> $b } keys %{ $Self->{XML}->{Test}->{$Key} } ) {
-                my $Result  = $Self->{XML}->{Test}->{$Key}->{$TestCount}->{Result};
-                my $Content = $Self->{XML}->{Test}->{$Key}->{$TestCount}->{Name};
-                $Content =~ s/&/&amp;/g;
-                $Content =~ s/</&lt;/g;
-                $Content =~ s/>/&gt;/g;
-                $XML .= qq|  <Test Result="$Result" Count="$TestCount">$Content</Test>\n|;
-            }
-            $XML .= "</Unit>\n";
+    # ---
+    my $XML = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
+    $XML .= "<otrs_test>\n";
+    $XML .= "<Summary>\n";
+    for my $Key ( sort keys %ResultSummary ) {
+        $ResultSummary{$Key} =~ s/&/&amp;/g;
+        $ResultSummary{$Key} =~ s/</&lt;/g;
+        $ResultSummary{$Key} =~ s/>/&gt;/g;
+        $ResultSummary{$Key} =~ s/"/&quot;/g;
+        $XML .= "  <Item Name=\"$Key\">$ResultSummary{$Key}</Item>\n";
+    }
+    $XML .= "</Summary>\n";
+    for my $Key ( sort keys %{ $Self->{XML}->{Test} } ) {
+
+        # extract duration time
+        my $Duration = $Self->{Duration}->{$Key};
+
+        $XML .= "<Unit Name=\"$Key\" Duration=\"$Duration\">\n";
+
+        for my $TestCount ( sort { $a <=> $b } keys %{ $Self->{XML}->{Test}->{$Key} } ) {
+            my $Result  = $Self->{XML}->{Test}->{$Key}->{$TestCount}->{Result};
+            my $Content = $Self->{XML}->{Test}->{$Key}->{$TestCount}->{Name};
+            $Content =~ s/&/&amp;/g;
+            $Content =~ s/</&lt;/g;
+            $Content =~ s/>/&gt;/g;
+            $XML .= qq|  <Test Result="$Result" Count="$TestCount">$Content</Test>\n|;
         }
-        $XML .= "</otrs_test>\n";
 
-# ---
-# OPMS
-# ---
-#        print $XML;
-#    }
+        $XML .= "</Unit>\n";
+    }
+    $XML .= "</otrs_test>\n";
+
+    # ---
+    # OPMS
+    # ---
+    #        print $XML;
+    #    }
 
     use SOAP::Lite( 'autodispatch', proxy => 'http://opms.otrs.com/otrs/unittest.pl' );
@@ -439,5 +444,5 @@
     print STDERR "NOTICE: SubmitID: $Key\n";
 
-# ---
+    # ---
 
     return 1;
@@ -826,5 +831,5 @@
 
         # compare %A with %B and remove it if checked
-        for my $Key ( keys %A ) {
+        for my $Key ( sort keys %A ) {
 
             # Check if both are undefined
@@ -910,7 +915,7 @@
 sub _PrintHeadlineStart {
     my ( $Self, $Name ) = @_;
-    if ( !$Name ) {
-        $Name = '->>No Name!<<-';
-    }
+
+    # set default name
+    $Name ||= '->>No Name!<<-';
 
     if ( $Self->{Output} eq 'HTML' ) {
@@ -923,5 +928,10 @@
         print "+-------------------------------------------------------------------+\n";
     }
+
     $Self->{XMLUnit} = $Name;
+
+    # set duration start time
+    $Self->{DurationStartTime}->{$Name} = $Self->{TimeObject}->SystemTime();
+
     return 1;
 }
@@ -929,7 +939,7 @@
 sub _PrintHeadlineEnd {
     my ( $Self, $Name ) = @_;
-    if ( !$Name ) {
-        $Name = '->>No Name!<<-';
-    }
+
+    # set default name
+    $Name ||= '->>No Name!<<-';
 
     if ( $Self->{Output} eq 'HTML' ) {
@@ -938,4 +948,15 @@
     elsif ( $Self->{Output} eq 'ASCII' ) {
     }
+
+    # calculate duration time
+    my $Duration = '';
+    if ( $Self->{DurationStartTime}->{$Name} ) {
+
+        $Duration = $Self->{TimeObject}->SystemTime() - $Self->{DurationStartTime}->{$Name};
+
+        delete $Self->{DurationStartTime}->{$Name};
+    }
+    $Self->{Duration}->{$Name} = $Duration;
+
     return 1;
 }
@@ -955,5 +976,5 @@
         }
         elsif ( $Self->{Output} eq 'ASCII' ) {
-            print " ok $Self->{TestCount} - $Name\n";
+            print color('green') . " ok" . color('reset') . " $Self->{TestCount} - $Name\n";
         }
         $Self->{XML}->{Test}->{ $Self->{XMLUnit} }->{ $Self->{TestCount} }->{Result} = 'ok';
@@ -968,5 +989,5 @@
         }
         elsif ( $Self->{Output} eq 'ASCII' ) {
-            print " not ok $Self->{TestCount} - $Name\n";
+            print color('red') . " not ok" . color('reset') . " $Self->{TestCount} - $Name\n";
         }
         $Self->{XML}->{Test}->{ $Self->{XMLUnit} }->{ $Self->{TestCount} }->{Result} = 'not ok';
@@ -1001,8 +1022,2 @@
 
 =cut
-
-=head1 VERSION
-
-$Revision$ $Date$
-
-=cut
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log