# HG changeset patch # User Josef Eisl # Date 1400093915 -7200 # Node ID ec29b2d3bdb4f381b7c889cd9680ba337e62ca73 # Parent 4735aabe8444fdd142b0ef00a4892c41508e9da2 mx unittest: add color support. diff -r 4735aabe8444 -r ec29b2d3bdb4 graal/com.oracle.graal.test/src/com/oracle/graal/test/AnsiTerminalDecorator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/AnsiTerminalDecorator.java Wed May 14 20:58:35 2014 +0200 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.test; + +import org.junit.runner.*; +import org.junit.runner.notification.*; + +import static com.oracle.graal.debug.AnsiColor.*; + +/** + * Color support for JUnit test output using ANSI escapes codes. + */ +public class AnsiTerminalDecorator extends GraalJUnitRunListenerDecorator { + + public AnsiTerminalDecorator(GraalJUnitRunListener l) { + super(l); + } + + @Override + public void testSucceeded(Description description) { + getWriter().print(BOLD_GREEN); + super.testSucceeded(description); + getWriter().print(RESET); + } + + @Override + public void testFailed(Failure failure) { + getWriter().print(BOLD_RED); + super.testFailed(failure); + getWriter().print(RESET); + } + + @Override + public void testIgnored(Description description) { + getWriter().print(BOLD_MAGENTA); + super.testIgnored(description); + getWriter().print(RESET); + } +} diff -r 4735aabe8444 -r ec29b2d3bdb4 graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java --- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java Wed May 14 20:15:17 2014 +0200 +++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalJUnitCore.java Wed May 14 20:58:35 2014 +0200 @@ -49,6 +49,7 @@ List missingClasses = new ArrayList<>(); boolean verbose = false; boolean enableTiming = false; + boolean color = false; for (String each : args) { if (each.charAt(0) == '-') { // command line arguments @@ -56,6 +57,8 @@ verbose = true; } else if (each.contentEquals("-JUnitEnableTiming")) { enableTiming = true; + } else if (each.contentEquals("-JUnitColor")) { + color = true; } else { system.out().println("Unknown command line argument: " + each); } @@ -80,6 +83,9 @@ if (enableTiming) { graalListener = new TimingDecorator(graalListener); } + if (color) { + graalListener = new AnsiTerminalDecorator(graalListener); + } junitCore.addListener(GraalTextListener.createRunListener(graalListener)); Result result = junitCore.run(classes.toArray(new Class[0])); for (Failure each : missingClasses) { diff -r 4735aabe8444 -r ec29b2d3bdb4 mx/mx_graal.py --- a/mx/mx_graal.py Wed May 14 20:15:17 2014 +0200 +++ b/mx/mx_graal.py Wed May 14 20:58:35 2014 +0200 @@ -957,7 +957,7 @@ f_testfile.close() harness(projectscp, vmArgs) -def _unittest(args, annotations, prefixcp="", whitelist=None, verbose=False, enable_timing=False, regex=None): +def _unittest(args, annotations, prefixcp="", whitelist=None, verbose=False, enable_timing=False, regex=None, color=False): mxdir = dirname(__file__) name = 'JUnitWrapper' javaSource = join(mxdir, name + '.java') @@ -976,6 +976,8 @@ coreArgs.append('-JUnitVerbose') if enable_timing: coreArgs.append('-JUnitEnableTiming') + if color: + coreArgs.append('-JUnitColor') def harness(projectscp, vmArgs): @@ -1006,6 +1008,7 @@ --verbose enable verbose JUnit output --enable-timing enable JUnit test timing --regex run only testcases matching a regular expression + --color enable colors output To avoid conflicts with VM options '--' can be used as delimiter. @@ -1046,6 +1049,7 @@ parser.add_argument('--verbose', help='enable verbose JUnit output', action='store_true') parser.add_argument('--enable-timing', help='enable JUnit test timing', action='store_true') parser.add_argument('--regex', help='run only testcases matching a regular expression', metavar='') + parser.add_argument('--color', help='enable color output', action='store_true') ut_args = [] delimiter = False @@ -1072,7 +1076,7 @@ except IOError: mx.log('warning: could not read whitelist: ' + parsed_args.whitelist) - _unittest(args, ['@Test', '@Parameters'], whitelist=whitelist, verbose=parsed_args.verbose, enable_timing=parsed_args.enable_timing, regex=parsed_args.regex) + _unittest(args, ['@Test', '@Parameters'], whitelist=whitelist, verbose=parsed_args.verbose, enable_timing=parsed_args.enable_timing, regex=parsed_args.regex, color=parsed_args.color) def shortunittest(args): """alias for 'unittest --whitelist test/whitelist_shortunittest.txt'{0}""" diff -r 4735aabe8444 -r ec29b2d3bdb4 mx/projects --- a/mx/projects Wed May 14 20:15:17 2014 +0200 +++ b/mx/projects Wed May 14 20:58:35 2014 +0200 @@ -568,7 +568,7 @@ # graal.test project@com.oracle.graal.test@subDir=graal project@com.oracle.graal.test@sourceDirs=src -project@com.oracle.graal.test@dependencies=JUNIT +project@com.oracle.graal.test@dependencies=JUNIT,com.oracle.graal.debug project@com.oracle.graal.test@checkstyle=com.oracle.graal.graph project@com.oracle.graal.test@javaCompliance=1.8 project@com.oracle.graal.test@workingSets=Graal,Test