Skip to content

Stacktraces in comments should be escaped #609

Closed
@Vassiliy-Kudryashov

Description

@Vassiliy-Kudryashov

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

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

No branches or pull requests

Issue actions