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

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

Open
Vladislav0Art opened this issue Oct 28, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@Vladislav0Art
Copy link
Collaborator

Vladislav0Art commented Oct 28, 2024

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.

@Vladislav0Art Vladislav0Art added the bug Something isn't working label Oct 28, 2024
@SergeyDatskiv
Copy link
Collaborator

... 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"

#406 (comment)

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.

#406 (comment)

@SergeyDatskiv
Copy link
Collaborator

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
Copy link
Collaborator

SergeyDatskiv commented Oct 29, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants