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