jtreg adds additional backslashes in Strings that are written to System.out/err?
Jonathan Gibbons
jonathan.gibbons at oracle.com
Wed Sep 15 14:30:39 UTC 2021
Jaikiran,
The encoding is intentional ... and has been there since the beginning
of jtreg!
While .jtr files are intended to only contain ASCII characters, they are
not intended for direct human consumption. The stream output from tests
is encoded so that it can be subsequently read back in by jtreg and
related software.
To view the output of a test without the encoding used in the .jtr file,
use one of:
* run the test under jtreg with the -va option
* run the test directly, using its main(String...) method ... you can
get a script to run the test from the "rerun" section in the .jtr file
* use jtreg to report the content of the stream using the
`-show:<name>` option, such as `jtreg -w:/path/to/work
-show:System.out /path/to/test
-- Jon
On 9/3/21 7:25 AM, Jaikiran Pai wrote:
> Any inputs? Is this a bug or an intentional implementation detail?
>
> -Jaikiran
>
> On 29/08/21 6:54 pm, Jaikiran Pai wrote:
>> Please consider this trivial Java code which prints to System.out:
>>
>> public class FooTest {
>> public static void main(final String[] args) throws Exception {
>> final String m = "hello \\ world";
>> System.out.println("Message is " + m);
>> }
>> }
>>
>> When you run this as Java code using the "java" command, the output
>> that gets printed is (as expected):
>>
>> Message is hello \ world
>>
>> Now, if I convert this Java code a jtreg test as follows (without any
>> code change, just adding jtreg tags):
>>
>> /**
>> * @test
>> * @run main FooTest
>> */
>> public class FooTest {
>> public static void main(final String[] args) throws Exception {
>> final String m = "hello \\ world";
>> System.out.println("Message is " + m);
>> }
>> }
>>
>> Running it as a jtreg test, generates a report which has the
>> System.out section that is:
>>
>> ----------System.out:(1/26)*----------
>> Message is hello \\ world
>>
>> Notice the unexpected additional backslash in that output. Is this
>> intentional?
>>
>> In a non-trivial test case, that I was working on, it took me a
>> (long) while to figure out that it was jtreg which was adding the
>> additional backslash in the output and it wasn't my test case that
>> had something wrong.
>>
>> For reference, jtreg -version gives:
>>
>> jtreg -version
>> jtreg 6-dev+0
>> Installed in /jtreg/build/images/jtreg/lib/jtreg.jar
>> Running on platform version 1.8.0_265 from
>> /adoptopenjdk-8.jdk/Contents/Home/jre.
>> Built with Java(TM) 2 SDK, Version 1.8.0_265-b01 on June 27, 2021.
>> Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights
>> reserved.
>> Use is subject to license terms.
>> JT Harness, version 6.0 ea b14 (June 27, 2021)
>> JCov 3.0-2
>> Java Assembler Tools, version 7.0 ea b09 (June 27, 2021)
>> TestNG (testng.jar): version 7.3.0
>> TestNG (jcommander.jar): version unknown
>> TestNG (guice.jar): version 4.2.3
>> JUnit (junit.jar): version 4.13.2
>> JUnit (hamcrest.jar): version 2.2
>>
>> -Jaikiran
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/jtreg-use/attachments/20210915/3cf52082/attachment.htm>
More information about the jtreg-use
mailing list