test/hotspot/jtreg/compiler/graalunit/com.oracle.mxtool.junit/com/oracle/mxtool/junit/AnsiTerminalDecorator.java
changeset 50908 7c51db95ccb6
equal deleted inserted replaced
50907:39d27210c627 50908:7c51db95ccb6
       
     1 /*
       
     2  * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 package com.oracle.mxtool.junit;
       
    24 
       
    25 import org.junit.runner.*;
       
    26 import org.junit.runner.notification.*;
       
    27 
       
    28 /**
       
    29  * Color support for JUnit test output using ANSI escapes codes.
       
    30  */
       
    31 class AnsiTerminalDecorator extends MxRunListenerDecorator {
       
    32 
       
    33     /** Foreground black. */
       
    34     public static final String BLACK = "\u001b[30m";
       
    35     /** Foreground red. */
       
    36     public static final String RED = "\u001b[31m";
       
    37     /** Foreground green. */
       
    38     public static final String GREEN = "\u001b[32m";
       
    39     /** Foreground yellow. */
       
    40     public static final String YELLOW = "\u001b[33m";
       
    41     /** Foreground blue. */
       
    42     public static final String BLUE = "\u001b[34m";
       
    43     /** Foreground magenta. */
       
    44     public static final String MAGENTA = "\u001b[35m";
       
    45     /** Foreground cyan. */
       
    46     public static final String CYAN = "\u001b[36m";
       
    47     /** Foreground white. */
       
    48     public static final String WHITE = "\u001b[37m";
       
    49 
       
    50     /** Foreground bold black. */
       
    51     public static final String BOLD_BLACK = "\u001b[30;1m";
       
    52     /** Foreground bold red. */
       
    53     public static final String BOLD_RED = "\u001b[31;1m";
       
    54     /** Foreground bold green. */
       
    55     public static final String BOLD_GREEN = "\u001b[32;1m";
       
    56     /** Foreground bold yellow. */
       
    57     public static final String BOLD_YELLOW = "\u001b[33;1m";
       
    58     /** Foreground bold blue. */
       
    59     public static final String BOLD_BLUE = "\u001b[34;1m";
       
    60     /** Foreground bold magenta. */
       
    61     public static final String BOLD_MAGENTA = "\u001b[35;1m";
       
    62     /** Foreground bold cyan. */
       
    63     public static final String BOLD_CYAN = "\u001b[36;1m";
       
    64     /** Foreground bold white. */
       
    65     public static final String BOLD_WHITE = "\u001b[37;1m";
       
    66 
       
    67     /** Background black. */
       
    68     public static final String BG_BLACK = "\u001b[40m";
       
    69     /** Background red. */
       
    70     public static final String BG_RED = "\u001b[41m";
       
    71     /** Background green. */
       
    72     public static final String BG_GREEN = "\u001b[42m";
       
    73     /** Background yellow. */
       
    74     public static final String BG_YELLOW = "\u001b[43m";
       
    75     /** Background blue. */
       
    76     public static final String BG_BLUE = "\u001b[44m";
       
    77     /** Background magenta. */
       
    78     public static final String BG_MAGENTA = "\u001b[45m";
       
    79     /** Background cyan. */
       
    80     public static final String BG_CYAN = "\u001b[46m";
       
    81     /** Background white. */
       
    82     public static final String BG_WHITE = "\u001b[47m";
       
    83 
       
    84     /** Reset. */
       
    85     public static final String RESET = "\u001b[0m";
       
    86     /** Underline. */
       
    87     public static final String UNDERLINED = "\u001b[4m";
       
    88 
       
    89     AnsiTerminalDecorator(MxRunListener l) {
       
    90         super(l);
       
    91     }
       
    92 
       
    93     @Override
       
    94     public void testSucceeded(Description description) {
       
    95         getWriter().print(GREEN);
       
    96         super.testSucceeded(description);
       
    97         getWriter().print(RESET);
       
    98     }
       
    99 
       
   100     @Override
       
   101     public void testAssumptionFailure(Failure failure) {
       
   102         getWriter().print(BLUE);
       
   103         super.testAssumptionFailure(failure);
       
   104         getWriter().print(RESET);
       
   105     }
       
   106 
       
   107     @Override
       
   108     public void testFailed(Failure failure) {
       
   109         getWriter().print(RED);
       
   110         super.testFailed(failure);
       
   111         getWriter().print(RESET);
       
   112     }
       
   113 
       
   114     @Override
       
   115     public void testIgnored(Description description) {
       
   116         getWriter().print(MAGENTA);
       
   117         super.testIgnored(description);
       
   118         getWriter().print(RESET);
       
   119     }
       
   120 }