test/hotspot/jtreg/compiler/graalunit/com.oracle.mxtool.junit/com/oracle/mxtool/junit/TextRunListener.java
author epavlova
Wed, 09 Oct 2019 10:59:45 -0700
changeset 58523 fb3d408c7a7e
parent 50908 7c51db95ccb6
permissions -rw-r--r--
8231903: [Graal] Update com.oracle.mxtool.junit classes Reviewed-by: kvn
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 java.io.PrintStream;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    26
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    27
import org.junit.internal.JUnitSystem;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    28
import org.junit.internal.TextListener;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    29
import org.junit.runner.Description;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    30
import org.junit.runner.Result;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    31
import org.junit.runner.notification.Failure;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    32
import org.junit.runner.notification.RunListener;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    33
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    34
class TextRunListener implements MxRunListener {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    35
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    36
    private final PrintStream fWriter;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    37
    protected Failure lastFailure;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    38
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    39
    TextRunListener(JUnitSystem system) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    40
        this(system.out());
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    41
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    42
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    43
    TextRunListener(PrintStream writer) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    44
        fWriter = writer;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    45
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    46
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    47
    public boolean beVerbose() {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    48
        return false;
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
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    51
    @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    52
    public PrintStream getWriter() {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    53
        return fWriter;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    54
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    55
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    56
    public Failure getLastFailure() {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    57
        return lastFailure;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    58
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    59
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    60
    @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    61
    public void testStarted(Description description) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    62
        getWriter().print('.');
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    63
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    64
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    65
    @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    66
    public void testFailed(Failure failure) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    67
        getWriter().print('E');
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    68
        lastFailure = failure;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    69
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    70
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    71
    @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    72
    public void testIgnored(Description description) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    73
        getWriter().print('I');
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    74
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    75
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    76
    public static RunListener createRunListener(MxRunListener l) {
58523
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
    77
        PrintStream theWriter = l.getWriter();
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
    78
        return new TextListener(theWriter) {
50908
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    79
            private Class<?> lastClass;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    80
            private int passedInLastClass;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    81
            private int failedInLastClass;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    82
            private boolean failed;
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
            @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    85
            public void testStarted(Description description) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    86
                Class<?> currentClass = description.getTestClass();
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    87
                if (currentClass != lastClass) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    88
                    if (lastClass != null) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    89
                        l.testClassFinished(lastClass, passedInLastClass, failedInLastClass);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    90
                        l.testClassFinishedDelimiter();
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
                    lastClass = currentClass;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    93
                    passedInLastClass = 0;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    94
                    failedInLastClass = 0;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    95
                    l.testClassStarted(currentClass);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    96
                    l.testClassStartedDelimiter();
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    97
                }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    98
                failed = false;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
    99
                l.testStarted(description);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   100
                l.testStartedDelimiter();
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   101
            }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   102
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   103
            @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   104
            public void testFailure(Failure failure) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   105
                failed = true;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   106
                failedInLastClass++;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   107
                l.testFailed(failure);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   108
            }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   109
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   110
            @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   111
            public void testFinished(Description description) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   112
                // we have to do this because there is no callback for successful tests
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   113
                if (!failed) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   114
                    l.testSucceeded(description);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   115
                    passedInLastClass++;
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   116
                }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   117
                l.testFinished(description);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   118
                l.testFinishedDelimiter();
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
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   121
            @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   122
            public void testIgnored(Description description) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   123
                testStarted(description);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   124
                l.testIgnored(description);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   125
                l.testFinished(description);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   126
                l.testFinishedDelimiter();
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   127
            }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   128
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   129
            @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   130
            public void testRunStarted(Description description) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   131
                l.testRunStarted(description);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   132
            }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   133
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   134
            @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   135
            public void testRunFinished(Result result) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   136
                if (lastClass != null) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   137
                    l.testClassFinished(lastClass, passedInLastClass, failedInLastClass);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   138
                }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   139
                l.testRunFinished(result);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   140
                super.testRunFinished(result);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   141
            }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   142
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   143
            @Override
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   144
            public void testAssumptionFailure(Failure failure) {
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   145
                l.testAssumptionFailure(failure);
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   146
            }
58523
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   147
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   148
            @Override
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   149
            protected void printFailure(Failure each, String prefix) {
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   150
                // Print out the test message in the same format used to run a single test:
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   151
                // my.package.MyClass#methodName
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   152
                String header = each.getDescription().getClassName() + "#" + each.getDescription().getMethodName();
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   153
                theWriter.println(prefix + ") " + header);
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   154
                theWriter.print(each.getTrace());
fb3d408c7a7e 8231903: [Graal] Update com.oracle.mxtool.junit classes
epavlova
parents: 50908
diff changeset
   155
            }
50908
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   156
        };
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   157
    }
7c51db95ccb6 8205207: Port Graal unit tests under jtreg
epavlova
parents:
diff changeset
   158
}