Skip to content

Stacktraces in comments should be escaped #609

Closed
@Vassiliy-Kudryashov

Description

@Vassiliy-Kudryashov
Member

Description

Example: There are hundreds of error messages in the UTBot log. Looks like the problem is in the concrete executor.

To Reproduce
Try to generate tests for the following method:

    public int error(String s) {
        if (s.length() == 3 && !"   ".equals(s)) {
            return Integer.parseInt(s);
        }
        return -1;
    }

Generated test should looks like this:

    @Test
    @DisplayName("error: s has special characters -> throw NumberFormatException")
    public void testErrorThrowsNFEWithBlankString() {
        A a = new A();
        
        /* This test fails because method [hello.A.error] produces [java.lang.NumberFormatException: For input string: "
HERE COME SEPARATORS THAT BREAK Document in IDEA	
"]
            java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
            java.lang.Integer.parseInt(Integer.java:569)
            java.lang.Integer.parseInt(Integer.java:615)
            hello.A.error(A.java:11) */
        a.error("\n\t\r");
    }

but it fails.

java.lang.AssertionError: Wrong line separators: '...tring: \"\n\t\r\"]\n      ...' at offset 547
	at com.intellij.openapi.util.text.StringUtil.assertValidSeparators(StringUtil.java:2450)
	at com.intellij.openapi.editor.impl.DocumentImpl.assertValidSeparators(DocumentImpl.java:690)
	at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:599)
	at com.intellij.openapi.editor.impl.DocumentImpl.lambda$setText$2(DocumentImpl.java:1061)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:211)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:167)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:153)
	at com.intellij.openapi.editor.impl.DocumentImpl.setText(DocumentImpl.java:1066)
	at org.utbot.intellij.plugin.generator.CodeGenerationController$generateCodeAndReport$1$1$1$$special$$inlined$executeCommand$1.run(actions.kt:13)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:167)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:153)
	at org.utbot.intellij.plugin.generator.CodeGenerationController$generateCodeAndReport$1$1$1.run(CodeGenerationController.kt:590)

Expected behavior
\n\t\r should be escaped in a comment

Actual behavior
We get empty test class

Activity

moved this to Todo in UTBot Javaon Jul 29, 2022
added this to UTBot Java and removed this from UTBot Javaon Jul 29, 2022
Vassiliy-Kudryashov

Vassiliy-Kudryashov commented on Aug 1, 2022

@Vassiliy-Kudryashov
MemberAuthor

The issue was introduced in #477

moved this from Todo to In Progress in UTBot Javaon Aug 1, 2022
changed the title [-]Stackstraces in comments should be escaped[/-] [+]Stacktraces in comments should be escaped[/+] on Aug 1, 2022

6 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @Vassiliy-Kudryashov@EgorkaKulikov

    Issue actions

      Stacktraces in comments should be escaped · Issue #609 · UnitTestBot/UTBotJava