JetBrains-Research / TestSpark

TestSpark - a plugin for generating unit tests. TestSpark natively integrates different AI-based test generation tools and techniques in the IDE. Started by SERG TU Delft. Currently under implementation by JetBrains Research (Software Testing Research) for research purposes.
MIT License
51 stars 21 forks source link

Kotlin test compilation fails on Windows due to unresolved symbols #407

Open Vladislav0Art opened 3 days ago

Vladislav0Art commented 3 days ago

Describe the bug

Kotlinc tests cannot be compiled successfully on Windows due to an unresolved symbol error.

I have java installed on my machine and present in PATH, which allows hotline to execute successfully. However, there is potentially another issue when no java in PATH is present (TODO(@Vladislav0Art): check it!). A potential solution is to search for Java on Windows as well.

// src/main/koltin/org/sample/Main.kt
package org.sample

class Calculator {
    fun mult(a: Int, b: Int): Int {
        return a * b;
    }

    fun sum(a: Int, b: Int): Int {
        return a + b;
    }
}

There is a warning that the file location does not match its package:

image

The file is located under:

C:\Users\Vladislav\AppData\Local\Temp\testSparkResults\test_gen_result_6d098e7f-cd64-4360-a460-2b1990f1c1a3\org\sample\GeneratedMultPositiveNumbersTest.kt

Here is the type of error I get for all test cases:

16:43:17.243 [ApplicationImpl pooled thread 4] INFO org.jetbrains.research.testspark.core.test.kotlin.KotlinTestCompiler - [KotlinTestCompiler] Compiling C:\Users\Vladislav\AppData\Local\Temp\testSparkResults\test_gen_result_6d098e7f-cd64-4360-a460-2b1990f1c1a3\org\sample\GeneratedMultPositiveNumbersTest.kt
16:43:22.281 [ApplicationImpl pooled thread 4] INFO org.jetbrains.research.testspark.core.test.kotlin.KotlinTestCompiler - Exit code: '1'; Execution message: 'C:\Users\Vladislav\AppData\Local\Temp\testSparkResults\test_gen_result_6d098e7f-cd64-4360-a460-2b1990f1c1a3\org\sample\GeneratedMultPositiveNumbersTest.kt:10:37: error: unresolved reference: Calculator
        val calculator = org.sample.Calculator()
                                    ^
'

To Reproduce Steps to reproduce the behavior:

  1. Run test generation on Windows (on any kotlin file probably, but you can use the one above preserving the folder structure).
  2. View the console output: you will see the above error on every compilation attempt.
  3. Once test cases are presented in the tab, try to execute them -> they will fail with the same error.

Expected behavior Kotlin compilation should work on Windows.

Additional context Compilation for Java works fine on the other hand.

SergeyDatskiv commented 2 days ago

... Actually, I get the following error when running kotlinc from command prompt. So it seems the problem is in the kotlinc path, not in the location where the files are saved (at least not yet).

'java' is not recognized as an internal or external command, operable program or batch file.

My path to kotlinc (according to TestSpark) is following "C:\Users\my_user_name\.gradle\caches\8.8\transforms\59dd4cdd51e5ae6cd765ecd455ab2df8\transformed\ideaIC-2024.2.3-win\plugins\Kotlin\kotlinc\bin\kotlinc"

https://github.com/JetBrains-Research/TestSpark/pull/406#issuecomment-2443609308

So... I debugged the problem a bit more and found out that the reason I get 'java' is not recognized as an internal or external command, operable program or batch file. is because I do not have java in my path variable. To overcome this problem, you can change the command to include the java path or add it to the path variables of your system. The former will probably resolve the issue for all windows machines, while the latter will resolve the issue only on a local machine.

The new command will look something like C:\Program Files\Java\jdk-11\bin\java -jar path\to\kotlinc.jar -cp . -d out src\main\kotlin\Main.kt according to Bing Copilot. I tried it, and it seems to work.

https://github.com/JetBrains-Research/TestSpark/pull/406#issuecomment-2443663083

SergeyDatskiv commented 2 days ago

Never mind, I could not fix. I got an Invalid or corrupt jarfile file because kotlinc is not a jar file and java cannot run it.

SergeyDatskiv commented 2 days ago

@Vladislav0Art I think the problem you described with regard to the Calculator is a Kotlin problem, not TestSpark. Update: never mind, I just cannot write kotlin code without an IDE. It's been a long day.

image