You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2020/06/06 20:05:24 UTC

[maven-integration-testing] branch master updated: add color to ITs rendering

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c060cc  add color to ITs rendering
2c060cc is described below

commit 2c060ccf4912313eef65a5f6de0684efd7185979
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Jun 6 22:05:19 2020 +0200

    add color to ITs rendering
---
 .../maven/it/AbstractMavenIntegrationTestCase.java | 49 +++++++++++++++------
 .../main/java/org/apache/maven/it/AnsiSupport.java | 50 ++++++++++++++++++++++
 2 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
index 9e0edc4..a237dc7 100644
--- a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
+++ b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AbstractMavenIntegrationTestCase.java
@@ -200,13 +200,34 @@ public abstract class AbstractMavenIntegrationTestCase
     protected void runTest()
         throws Throwable
     {
-        String line = getTestName();
-        out.print( line );
-        out.print( pad( RESULT_COLUMN - line.length() ) );
+        String testName = getTestName();
+
+        if ( testName.startsWith( "mng" ) || Character.isDigit( testName.charAt( 0 ) ) )
+        {
+            int mng = 4;
+            while ( Character.isDigit( testName.charAt( mng ) ) )
+            {
+                mng++;
+            }
+            out.print( AnsiSupport.bold( testName.substring( 0, mng ) ) );
+            out.print( ' ' );
+            out.print( testName.substring( mng ) );
+        }
+        else
+        {
+            int index = testName.indexOf( ' ' );
+            out.print( AnsiSupport.bold( testName.substring( 0, index ) ) );
+            out.print( testName.substring( index ) );
+            out.print( '.' );
+        }
+
+        out.print( pad( RESULT_COLUMN - testName.length() ) );
+        out.print( ' ' );
 
         if ( skip )
         {
-            out.println( "SKIPPED - Maven version " + getMavenVersion() + " not in range " + versionRange );
+            out.println( AnsiSupport.warning( "SKIPPED" ) + " - Maven version " + getMavenVersion() + " not in range "
+                + versionRange );
             return;
         }
 
@@ -225,22 +246,24 @@ public abstract class AbstractMavenIntegrationTestCase
             {
                 throw invert;
             }
-            out.println( "OK " + formatTime( milliseconds ) );
+            out.println( AnsiSupport.success( "OK" ) + " " + formatTime( milliseconds ) );
         }
         catch ( UnsupportedJavaVersionException e )
         {
-            out.println( "SKIPPED - Java version " + e.javaVersion + " not in range " + e.supportedRange );
+            out.println( AnsiSupport.warning( "SKIPPED" ) + " - Java version " + e.javaVersion + " not in range "
+                + e.supportedRange );
             return;
         }
         catch ( UnsupportedMavenVersionException e )
         {
-            out.println( "SKIPPED - Maven version " + e.mavenVersion + " not in range " + e.supportedRange );
+            out.println( AnsiSupport.warning( "SKIPPED" ) + " - Maven version " + e.mavenVersion + " not in range "
+                + e.supportedRange );
             return;
         }
         catch ( BrokenMavenVersionException e )
         {
-            out.println( "UNEXPECTED OK - Maven version " + e.mavenVersion + " expected to fail "
-                    + formatTime( milliseconds ) );
+            out.println( AnsiSupport.error( "UNEXPECTED OK" ) + " - Maven version " + e.mavenVersion
+                + " expected to fail " + formatTime( milliseconds ) );
             fail( "Expected failure when with Maven version " + e.mavenVersion );
         }
         catch ( Throwable t )
@@ -248,12 +271,12 @@ public abstract class AbstractMavenIntegrationTestCase
             milliseconds = System.currentTimeMillis() - milliseconds;
             if ( invert != null )
             {
-                out.println( "EXPECTED FAIL - Maven version " + invert.mavenVersion + " expected to fail "
-                        + formatTime( milliseconds ) );
+                out.println( AnsiSupport.success( "EXPECTED FAIL" ) + " - Maven version " + invert.mavenVersion
+                    + " expected to fail " + formatTime( milliseconds ) );
             }
             else
             {
-                out.println( "FAILURE " + formatTime( milliseconds ) );
+                out.println( AnsiSupport.error( "FAILURE" ) + " " + formatTime( milliseconds ) );
                 throw t;
             }
         }
@@ -426,7 +449,7 @@ public abstract class AbstractMavenIntegrationTestCase
         {
             methodName = methodName.substring( 4 );
         }
-        return className + '(' + methodName + ')';
+        return className + " (" + methodName + ')';
     }
 
     private String pad( int chars )
diff --git a/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AnsiSupport.java b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AnsiSupport.java
new file mode 100644
index 0000000..1764ec9
--- /dev/null
+++ b/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/AnsiSupport.java
@@ -0,0 +1,50 @@
+package org.apache.maven.it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Basic Ansi support: can't use Ansi because IT is executed in separate classloader.
+ */
+class AnsiSupport
+{
+    private static final String ESC = String.valueOf( (char) 27 ) + '[';
+
+    private static final String NORMAL = ESC + "0;39m";
+
+    static String success( String msg )
+    {
+        return ESC + "1;32m" + msg + NORMAL;
+    }
+
+    static String warning( String msg )
+    {
+        return ESC + "1;33m" + msg + NORMAL;
+    }
+
+    static String error( String msg )
+    {
+        return ESC + "1;31m" + msg + NORMAL;
+    }
+
+    static String bold( String msg )
+    {
+        return ESC + "1m" + msg + NORMAL;
+    }
+}