You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by John Passaro <jo...@gmail.com> on 2019/05/07 18:07:08 UTC

[surefire] possible bug: cannot set line.separator in systemPropertyVariables

Hi, I may have found a bug.

My team's code has tests failing depending on what system they're run
on, apparently because of conflicting line separator. I'm trying to
change the line.separator value so I can debug.

My normal setting is line.separator=\n, and tests currently pass. I
tried adding this to my surefire config:

<systemPropertyVariables>
    <line.separator>&#x0A;</line.separator>
</systemPropertyVariables>

I expected that this was just giving explicitly the same setting that
was normally natively available, so the tests should be unaffected. In
fact, tests started to fail, it seems like the VM is treating
line.separator as empty. For example, we expected a formatted stack
trace:

* Stack trace:
java.lang.Exception: exception message
    at com.poppin.Foo.bar(Foo.java:47)
    at com.poppin.Eggs.spam(Eggs.java:305)

and we got one without line breaks:

* Stack trace:
java.lang.Exception: exception message    at
com.poppin.Foo.bar(Foo.java:47)    at
com.poppin.Eggs.spam(Eggs.java:305)

(the above is all one line)

Similar results when I give <line.separator>&#x0D;&#x0A;</line.separator>.

Am I right in thinking this is a bug? Maybe when reading the xml,
whitespace is stripped, including my &#x0A;, and the property entry
winds up empty (though I can't find anything in the surefire source
explicitly doing that). Or is there something else I am doing wrong?

Appreciate

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [surefire] possible bug: cannot set line.separator in systemPropertyVariables

Posted by Tibor Digana <ti...@apache.org>.
Maybe we are missing CDATA here:
<testsuite ...>
...
  <testcase name="test" classname="MyTest" time="0.032">
    <error type="java.lang.RuntimeException">java.lang.RuntimeException
    at MyTest.test(MyTest.java:7)
</error>
  </testcase>
</testsuite>

On Tue, May 7, 2019 at 11:18 PM Laird Nelson <lj...@gmail.com> wrote:

> On Tue, May 7, 2019 at 2:07 PM Tibor Digana <ti...@apache.org>
> wrote:
>
> > strange thing is that the new line is ignored.
> >
>
> Lurking here, but (a) I thought <systemPropertyVariables> in a forked
> execution were indeed passed on the command line as -D arguments, (b) the
> behavior may have to do instead with the fact that whitespace in XML is
> generally not significant so after &#x0A; is expanded it is effectively
> stripped/trimmed from the XML yielding the empty string, and (c) the OP
> could try CDATA and an actual line separator character instead, maybe?
>
> Best,
> Laird
>

Re: [surefire] possible bug: cannot set line.separator in systemPropertyVariables

Posted by Tibor Digana <ti...@apache.org>.
This is my experiment, see the HTML (contains the stacktrace within
<pre>...</pre>) and a picture attached.

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jxr-plugin</artifactId>
    <version>2.3</version>
</plugin>
<plugin>
    <artifactId>maven-surefire-report-plugin</artifactId>
    <version>3.0.0-M3</version>
</plugin>


here is MyTest.java:

import org.junit.jupiter.api.Test;

class MyTest
{
    @Test
    void test() {
        throw new RuntimeException();
    }
}

*$ mvn test*

[INFO] Running MyTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed:
0.037 s <<< FAILURE! - in MyTest
[ERROR] test  Time elapsed: 0.032 s  <<< ERROR!
java.lang.RuntimeException
    at MyTest.test(MyTest.java:7)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR]   MyTest.test:7 Runtime
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

*$ cat target/surefire-reports/TEST-MyTest.xml*

<testsuite ...>
...
  <testcase name="test" classname="MyTest" time="0.032">
    <error type="java.lang.RuntimeException">java.lang.RuntimeException
    at MyTest.test(MyTest.java:7)
</error>
  </testcase>
</testsuite>


*$ mvn site*

*$ cat target/site/surefire-report.html*


<div id="MyTest.test-error" style="display:none;">
<div>
<pre>java.lang.RuntimeException
    at MyTest.test(MyTest.java:7)</pre></div></div></td>
<td></td></tr></table></div><br /></div>


[image: obrázok.png]




On Tue, May 7, 2019 at 11:18 PM Laird Nelson <lj...@gmail.com> wrote:

> On Tue, May 7, 2019 at 2:07 PM Tibor Digana <ti...@apache.org>
> wrote:
>
> > strange thing is that the new line is ignored.
> >
>
> Lurking here, but (a) I thought <systemPropertyVariables> in a forked
> execution were indeed passed on the command line as -D arguments, (b) the
> behavior may have to do instead with the fact that whitespace in XML is
> generally not significant so after &#x0A; is expanded it is effectively
> stripped/trimmed from the XML yielding the empty string, and (c) the OP
> could try CDATA and an actual line separator character instead, maybe?
>
> Best,
> Laird
>

Re: [surefire] possible bug: cannot set line.separator in systemPropertyVariables

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, May 7, 2019 at 2:07 PM Tibor Digana <ti...@apache.org> wrote:

> strange thing is that the new line is ignored.
>

Lurking here, but (a) I thought <systemPropertyVariables> in a forked
execution were indeed passed on the command line as -D arguments, (b) the
behavior may have to do instead with the fact that whitespace in XML is
generally not significant so after &#x0A; is expanded it is effectively
stripped/trimmed from the XML yielding the empty string, and (c) the OP
could try CDATA and an actual line separator character instead, maybe?

Best,
Laird

Re: [surefire] possible bug: cannot set line.separator in systemPropertyVariables

Posted by Tibor Digana <ti...@apache.org>.
strange thing is that the new line is ignored.
What version of plugin you use?
Where you see the stack trace? In console, in text report or XML report?

Perhaps we have to see your project. You can post the code with POM on Gist
but I think we cannot help you more unless we see the POM and try out.

On Tue, May 7, 2019 at 10:30 PM John Passaro <jo...@gmail.com>
wrote:

> Hi, I may have found a bug.
>
> My team's code has tests failing depending on what system they're run
> on, apparently because of conflicting line separator. I'm trying to
> change the line.separator value so I can debug.
>
> My normal setting is line.separator=\n, and tests currently pass. I
> tried adding this to my surefire config:
>
> <systemPropertyVariables>
>     <line.separator>&#x0A;</line.separator>
> </systemPropertyVariables>
>
> I expected that this was just giving explicitly the same setting that
> was normally natively available, so the tests should be unaffected. In
> fact, tests started to fail, it seems like the VM is treating
> line.separator as empty. For example, we expected a formatted stack
> trace:
>
> * Stack trace:
> java.lang.Exception: exception message
>     at com.poppin.Foo.bar(Foo.java:47)
>     at com.poppin.Eggs.spam(Eggs.java:305)
>
> and we got one without line breaks:
>
> * Stack trace:
> java.lang.Exception: exception message    at
> com.poppin.Foo.bar(Foo.java:47)    at
> com.poppin.Eggs.spam(Eggs.java:305)
>
> (the above is all one line)
>
> Similar results when I give <line.separator>&#x0D;&#x0A;</line.separator>.
>
> Am I right in thinking this is a bug? Maybe when reading the xml,
> whitespace is stripped, including my &#x0A;, and the property entry
> winds up empty (though I can't find anything in the surefire source
> explicitly doing that). Or is there something else I am doing wrong?
>
> Appreciate
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: [surefire] possible bug: cannot set line.separator in systemPropertyVariables

Posted by Anthony Whitford <an...@whitford.com>.
line.separator is a system dependent property, and not a system property that you can override.

This will be CRLF for Windows, and LF for *Nix & MacOS.
https://www.geeksforgeeks.org/system-lineseparator-method-in-java-with-examples/ <https://www.geeksforgeeks.org/system-lineseparator-method-in-java-with-examples/>

Normally code should be flexible to accommodate different line separators — it is usually whitespace that can be safely ignored.  For example:
* PrintWriter allows code to output using println, and the output will automatically use system dependent line separators.
* BufferedReader.readLine allows code to input lines, ignoring line separators.



> On May 7, 2019, at 11:07 AM, John Passaro <jo...@gmail.com> wrote:
> 
> Hi, I may have found a bug.
> 
> My team's code has tests failing depending on what system they're run
> on, apparently because of conflicting line separator. I'm trying to
> change the line.separator value so I can debug.
> 
> My normal setting is line.separator=\n, and tests currently pass. I
> tried adding this to my surefire config:
> 
> <systemPropertyVariables>
>    <line.separator>&#x0A;</line.separator>
> </systemPropertyVariables>
> 
> I expected that this was just giving explicitly the same setting that
> was normally natively available, so the tests should be unaffected. In
> fact, tests started to fail, it seems like the VM is treating
> line.separator as empty. For example, we expected a formatted stack
> trace:
> 
> * Stack trace:
> java.lang.Exception: exception message
>    at com.poppin.Foo.bar(Foo.java:47)
>    at com.poppin.Eggs.spam(Eggs.java:305)
> 
> and we got one without line breaks:
> 
> * Stack trace:
> java.lang.Exception: exception message    at
> com.poppin.Foo.bar(Foo.java:47)    at
> com.poppin.Eggs.spam(Eggs.java:305)
> 
> (the above is all one line)
> 
> Similar results when I give <line.separator>&#x0D;&#x0A;</line.separator>.
> 
> Am I right in thinking this is a bug? Maybe when reading the xml,
> whitespace is stripped, including my &#x0A;, and the property entry
> winds up empty (though I can't find anything in the surefire source
> explicitly doing that). Or is there something else I am doing wrong?
> 
> Appreciate
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


Re: [surefire] possible bug: cannot set line.separator in systemPropertyVariables

Posted by Tibor Digana <ti...@apache.org>.
Hi John,

You must observe the warning in this case:
line.separator cannot be set as system property, use
<argLine>-Dline.separator=...</argLine> instead

The same is with
"java.library.path", "file.encoding", "jdk.map.althashing.threshold",
"line.separator" .


This means that you should not use these property keys in
systemPropertyVariables because setting such ones in here would not take
effect.
These properties do not present in CLI. They are set too late after JVM
startup by Surefire code.

If you want to apply such of these properties and see their effect, you
should use them in CLI, this means in argLine, and this would be then fully
controlled by JVM spec.
I guess you use forking mode (or you implicitely use the default
forkCount=0).

Cheers
Tibor

On Tue, May 7, 2019 at 10:30 PM John Passaro <jo...@gmail.com>
wrote:

> Hi, I may have found a bug.
>
> My team's code has tests failing depending on what system they're run
> on, apparently because of conflicting line separator. I'm trying to
> change the line.separator value so I can debug.
>
> My normal setting is line.separator=\n, and tests currently pass. I
> tried adding this to my surefire config:
>
> <systemPropertyVariables>
>     <line.separator>&#x0A;</line.separator>
> </systemPropertyVariables>
>
> I expected that this was just giving explicitly the same setting that
> was normally natively available, so the tests should be unaffected. In
> fact, tests started to fail, it seems like the VM is treating
> line.separator as empty. For example, we expected a formatted stack
> trace:
>
> * Stack trace:
> java.lang.Exception: exception message
>     at com.poppin.Foo.bar(Foo.java:47)
>     at com.poppin.Eggs.spam(Eggs.java:305)
>
> and we got one without line breaks:
>
> * Stack trace:
> java.lang.Exception: exception message    at
> com.poppin.Foo.bar(Foo.java:47)    at
> com.poppin.Eggs.spam(Eggs.java:305)
>
> (the above is all one line)
>
> Similar results when I give <line.separator>&#x0D;&#x0A;</line.separator>.
>
> Am I right in thinking this is a bug? Maybe when reading the xml,
> whitespace is stripped, including my &#x0A;, and the property entry
> winds up empty (though I can't find anything in the surefire source
> explicitly doing that). Or is there something else I am doing wrong?
>
> Appreciate
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: [surefire] possible bug: cannot set line.separator in systemPropertyVariables

Posted by Tibor Digana <ti...@apache.org>.
I am asking all participants directly as I have created Jira issue [1]
related to our previous talk.
If you agree with the text in Jira, we can follow the idea of the fix.
The fix seems to be very simple. If you have spare time, please open a
pullreq on GitHub.
I have already assigned this issue to the next release version because I
believe that somebody would simplify our work load a bit.
[1]
https://issues.apache.org/jira/browse/SUREFIRE-1668

Cheers
Tibo17



On Tue, May 7, 2019 at 10:30 PM John Passaro <jo...@gmail.com>
wrote:

> Hi, I may have found a bug.
>
> My team's code has tests failing depending on what system they're run
> on, apparently because of conflicting line separator. I'm trying to
> change the line.separator value so I can debug.
>
> My normal setting is line.separator=\n, and tests currently pass. I
> tried adding this to my surefire config:
>
> <systemPropertyVariables>
>     <line.separator>&#x0A;</line.separator>
> </systemPropertyVariables>
>
> I expected that this was just giving explicitly the same setting that
> was normally natively available, so the tests should be unaffected. In
> fact, tests started to fail, it seems like the VM is treating
> line.separator as empty. For example, we expected a formatted stack
> trace:
>
> * Stack trace:
> java.lang.Exception: exception message
>     at com.poppin.Foo.bar(Foo.java:47)
>     at com.poppin.Eggs.spam(Eggs.java:305)
>
> and we got one without line breaks:
>
> * Stack trace:
> java.lang.Exception: exception message    at
> com.poppin.Foo.bar(Foo.java:47)    at
> com.poppin.Eggs.spam(Eggs.java:305)
>
> (the above is all one line)
>
> Similar results when I give <line.separator>&#x0D;&#x0A;</line.separator>.
>
> Am I right in thinking this is a bug? Maybe when reading the xml,
> whitespace is stripped, including my &#x0A;, and the property entry
> winds up empty (though I can't find anything in the surefire source
> explicitly doing that). Or is there something else I am doing wrong?
>
> Appreciate
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>