Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacktraces in comments should be escaped #609

Closed
Vassiliy-Kudryashov opened this issue Jul 29, 2022 · 1 comment · Fixed by #638
Closed

Stacktraces in comments should be escaped #609

Vassiliy-Kudryashov opened this issue Jul 29, 2022 · 1 comment · Fixed by #638
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug

Comments

@Vassiliy-Kudryashov
Copy link
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

@Vassiliy-Kudryashov
Copy link
Member Author

The issue was introduced in #477

@Vassiliy-Kudryashov Vassiliy-Kudryashov moved this from Todo to In Progress in UTBot Java Aug 1, 2022
@Vassiliy-Kudryashov Vassiliy-Kudryashov changed the title Stackstraces in comments should be escaped Stacktraces in comments should be escaped Aug 1, 2022
@Vassiliy-Kudryashov Vassiliy-Kudryashov linked a pull request Aug 1, 2022 that will close this issue
3 tasks
Repository owner moved this from In Progress to Done in UTBot Java Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants