Visual Studio Code 任务参数

huangapple go评论95阅读模式
英文:

Visual Studio Code Task Argument

问题

我正在尝试在Visual Studio Code中创建一些任务,以便运行我的Go项目中的所有测试。

我通常在命令行中使用以下命令来执行测试:

go test ./...

在Visual Studio Code中,我的tasks.json文件如下所示:

{
    "version": "0.1.0",
    "command": "go",

    "tasks": [
        {
            "taskName": "build",
            "isBuildCommand": true
        },
        {
            "taskName": "test",
            "isTestCommand": true,
            "args": ["./..."]
        }
    ]
}

所以构建(CTRL + SHIFT + B)正常工作。

但是当我尝试运行测试(CTRL + SHIFT + T)时,出现以下错误:

go: unknown subcommand "./..."

似乎省略了"test"参数,但是当我注释掉args时,go test可以正常运行。

有什么想法吗?

英文:

I'm trying to create some tasks in Visual Studio Code to run all the tests in my go project.

I usually execute the tests on the command line using:

go test ./...

In Visual Studio Code my tasks.json looks like this:

{
    "version": "0.1.0",
    "command": "go",
   
    "tasks": [
	    {
		    "taskName": "build",
		    "isBuildCommand": true
	    },
	    {
		    "taskName": "test",
		    "isTestCommand": true,
		    "args": ["./..."]
	    }
    ]
}

So Build works fine (CTRL + SHIFT + B)

But when I try to run the tests (CTRL + SHIFT + T) the following error occurs:

go: unknown subcommand "./..."

It seems to be omitting the "test" param, but when I comment out the args it runs go test fine.

Any ideas?

答案1

得分: 0

这可能是一个错误


VSCode Reverse Args and Task as of v0.8.0

这可能是一个仍然存在于较新版本中的错误。截至v0.9.1,我还没有机会进行测试。在0.9.1之前,至少有一种方法可以通过反转任务及其参数来解决,如下面的示例所示:

{
"version": "0.1.0",
"command": "go",

"tasks": [
    {
        "taskName": "build",
        "isBuildCommand": true
    },
    {
        "taskName": "./...",
        "isTestCommand": true,
        "args": ["test"]
    }
  ]
}

很难相信这个问题在v0.8.0之前仍然存在,所以可能存在一种我尚未发现的更好的解决方案。

这是一个处理类似问题的先前帖子的链接:

在VSCode中定义多个任务

向下滚动到我的答案以获取更多解释。

英文:

THIS MAY BE A BUG


VSCode Reverse Args and Task as of v0.8.0

This may be a bug that still persists in the newer versions. As of v0.9.1 I have not had a chance to test. Prior to 0.9.1 at least one hack worked by reversing the task and it's arg as in the following example:

{
"version": "0.1.0",
"command": "go",

"tasks": [
    {
        "taskName": "build",
        "isBuildCommand": true
    },
    {
        "taskName": "./...",
        "isTestCommand": true,
        "args": ["test"]
    }
  ]
}

It's hard to believe that this has still persisted until v0.8.0 so there may be a preferred solution that I have not discovered.

Here is a link to a prior post that deals with a similar issue:

Define multiple tasks in VSCode

Scroll down to my answer for more explanation.

huangapple
  • 本文由 发表于 2015年10月9日 23:25:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/33042017.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定