Home > Back-end >  How to add a test file to Java in Windows using VScode tasks?
How to add a test file to Java in Windows using VScode tasks?

Time:11-06

I'm learning how VSCode tasks works. I'm doing a task that compiles a Java file, executes it and then inserts a "test file", a .txt file with some data that I want to test. I did this in Ubuntu, using this task I created, and everything worked fine:

{
"version": "2.0.0",
"tasks": [
    {
        "label": "Compilar",
        "type": "shell",
        "command": "javac ${input:fileName}.java && java ${input:fileName} < ${input:proves}",
    }
],
"inputs": [
    {
        "id": "fileName",
        "description": "Java file name:",
        "default": "Bucle",
        "type": "promptString"
    },
    {
        "id": "proves",
        "description": "File name with extension:",
        "default": "proves.txt",
        "type": "promptString"
    },
]
}

When I execute the task, everything works. VSCode asks me the name of the Java's file and the name of the test's file. Then, it compiles the Java file and executes it with the data that's in the test file (proves.txt).

But when I executed the same in Windows, I had some problems. Firstly, the "&&" doesn't work (I had to use ";" in order to accomplish that). But I'm not able to get the < ${input:proves} to work. I tried without the "<", or using "<-", but nothing of this worked.

How could I do it? Or it's not possible to do that in Windows? Thanks!

CodePudding user response:

Put it in another args:

 "args":["${input:proves}"]

More information please view Input Variables.

  • Related