JetBrains / educational-plugin

Educational plugin to learn and teach programming languages such as Kotlin, Java, Python, JavaScript, and others right inside of JetBrains IntelliJ Platform based IDEs.
https://jetbrains.com/edu-products
Apache License 2.0
147 stars 48 forks source link

Run task with argument #22

Closed alfianyusufabdullah closed 5 years ago

alfianyusufabdullah commented 5 years ago

How to run/check task with value from parameter in main function? it's posible?

Undin commented 5 years ago

@alfianyusufabdullah Hi! Do you mean check how main function works if some particular command line argument is passed into it? or something else?

alfianyusufabdullah commented 5 years ago

Yess @Undin

Undin commented 5 years ago

@alfianyusufabdullah For example, you can write something like this

import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class Tests {

    @Test
    public void test() {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        System.setOut(new PrintStream(outputStream));
        YourClassWithMain.main(new String[]{"YourCommandLineArg"});
        String output = outputStream.toString();
        // check output here
    }
}
alfianyusufabdullah commented 5 years ago

in kotlin i can't direct access the main function and the command line argument will be set from Run/Debug Configuration. it's posible to use that? @Undin

Undin commented 5 years ago

in kotlin i can't direct access the main function

I can come up with only one case when it's possible - main function is located in private class. But in this case you can make it public. Could you provide a precise example what you want to do?

the command line argument will be set from Run/Debug Configuration. it's posible to use that?

But they won't be taken into account while task checking because task check doesn't use existing run configuration. So no, you can't use command line arguments from run configuration for task checking

alfianyusufabdullah commented 5 years ago

thanks for the time @Undin , i think my case is close.