hiroga
hiroga

Reputation: 930

If kotlin package has multiple main function, how can I call specific one?

I want to test the main function for competitive programming.

Kotlin can have multiple main functions, however how to call specific one?
In other words, how to specify a function in the specific file?

Upvotes: 3

Views: 923

Answers (2)

æ-ra-code
æ-ra-code

Reputation: 2350

As workaround, In JVM, in tests, we can create Java class which delegates calls to target main functions.

This is based on the fact that by default FileName.kt translates into Java class FileNameKt

public final class Mains {

    public static void section01() {
        Section01Kt.main();
    }

    public static void section02() {
        Section02Kt.main();
    }
}

Then use wrapper method in tests:

    @Test 
    fun testMain() {
        Mains.section01() // instead of main()
    }

Upvotes: 0

Manushin Igor
Manushin Igor

Reputation: 3689

It depends on compilation and execution tools:

Upvotes: 2

Related Questions