Why does the BasePlatformTestCase fixture change the formatting of the file under test?

Answered

Starting from the JetBrains plugin template, I've created a basic plugin that helps modify text written in comments. It works by overriding a `beforeCharTyped` function on a `TypedHandler`. I've created some unit tests using `BasePlatformTestCase`. The issue with the tests is that the project that the test fixture sets up seems to be applying some formatting rules to the test data files, which is breaking the tests.

For example, I have the following test:

    fun testOneSpaceBeforeCaretAtMaxEvenlyIndentedSymbols() {
        myFixture.configureByFiles("$currentTestName/foo.kt")
        myFixture.type("l")
        println("fixture text")
        println(myFixture.file.text)
        myFixture.checkResultByFile("$currentTestName/foo_after.kt")
    }

foo.kt is

package com.loganmay.test

    /*
hello hello wo <caret>
     */

and foo_after.kt is

package com.loganmay.test

    /*
hello hello wo
l<caret>
     */

The test is failing. The `actual` value of the file is:

package com.loganmay.test

/*
hello hello wo
l<caret>
*/

As you can see, it's formatting the `/*` and `*/` by removing the spaces before them. Why is this happening and is there any way I can fix this?

I know that my plugin logic is not causing this behavior for two reasons:

  1. When I execute the `runIde` task and open a Kotlin file that looks exactly like foo.kt and manually perform the same type action as the unit test, it works as I expect and doesn't change the indenting before the comment symbols.
  2. At the end of my `beforeCharTyped` implementation, I added a print statement `println("file text at end: ${file.text}")` and it prints the text that I expect (i.e. what you see in foo_after.kt). However, the print statement in the unit test above `println(myFixture.file.text)` prints what I do not expect - that is, the file with the indents before the symbols trimmed.

So, it appears the issue is with the project inside the `BasePlatformTestCase`. Any advice is much appreciated!

1 comment
Comment actions Permalink

Hi Logan,

Please provide more information. What is the exact `TypedHandler` implementation? Are the sources available publicly?

0

Please sign in to leave a comment.