Small Go CLI that generates one task per test in a selected Go file for Zed or VS Code, can generate matching debug configs, and can clear generated tasks.
It:
- Finds test functions in the given file (
Test...by default). - Verifies runnable tests with
go test -list. - Discovers dynamic subtests by running tests first with
go test -json(when-discover-subtestsis enabled). - Writes/updates tasks with labels like
go:TestName. - Keeps non-generated tasks untouched.
From your workspace root (generate tasks):
go run ./cmd/go-zed-tasks generate -file path/to/foo_test.goOptional flags:
go run ./cmd/go-zed-tasks generate \
-file path/to/foo_test.go \
-tasks .zed/tasks.json \
-editor zed \
-go-test-arg=-v \
-go-test-arg=-count=1 \
-root . \
-dry-runYou can also pass extra go test args after --:
go run ./cmd/go-zed-tasks generate -file path/to/foo_test.go -- -v -count=1Generate debug configs (.zed/debug.json by default):
go run ./cmd/go-zed-tasks generate-debug -file path/to/foo_test.goGenerate VS Code tasks/debug configs (.vscode/tasks.json and .vscode/launch.json):
go run ./cmd/go-zed-tasks generate -file path/to/foo_test.go -editor vscode
go run ./cmd/go-zed-tasks debug -file path/to/foo_test.go -editor vscodeDiscover dynamic subtests first, then generate tasks.
Important: subtest discovery executes the tests (via go test -json) before writing tasks:
go run ./cmd/go-zed-tasks generate -file path/to/foo_test.go -discover-subtestsClear all previously generated tasks:
go run ./cmd/go-zed-tasks clearClear generated VS Code tasks:
go run ./cmd/go-zed-tasks clear -editor vscodeBackward compatibility:
-
go run ./cmd/go-zed-tasks -file path/to/foo_test.gostill works (treated asgenerate).
You just need to add this to your tasks.json file to make this package work for you:
[
{
"label": "go-discover",
"command": "go run github.com/VashingMachine/go-zed-test/cmd/go-zed-tasks@0.0.5 generate -file ${ZED_FILE} -discover-subtests -go-test-arg='-v' -go-test-arg='-count=1'",
"env": { "ZED_GO_TASKS_PRUNE_GENERATED": "false" },
"reveal": "always",
"reveal_target": "dock",
"hide": "never",
"shell": "system"
},
{
"label": "go-discover-debug",
"command": "go run github.com/VashingMachine/go-zed-test/cmd/go-zed-tasks@0.0.5 debug -file ${ZED_FILE} -discover-subtests -go-test-arg='-v' -go-test-arg='-count=1'",
"reveal": "always",
"reveal_target": "dock",
"hide": "never",
"shell": "system"
}
]Use -editor vscode and optional defaults from .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "go-discover",
"type": "shell",
"command": "go run github.com/VashingMachine/go-zed-test/cmd/go-zed-tasks@0.0.5 generate -editor vscode -file ${file} -discover-subtests -go-test-arg=-v -go-test-arg=-count=1"
},
{
"label": "go-discover-debug",
"type": "shell",
"command": "go run github.com/VashingMachine/go-zed-test/cmd/go-zed-tasks@0.0.5 debug -editor vscode -file ${file} -discover-subtests -go-test-arg=-v -go-test-arg=-count=1"
}
]
}Configuration is read from environment variables with prefix ZED_GO_TASKS_.
Common variables:
-
ZED_GO_TASKS_TASKS_PATH(default.zed/tasks.json; with-editor vscodedefault is.vscode/tasks.jsonunless env/flag overrides it) -
ZED_GO_TASKS_DEBUG_PATH(default.zed/debug.json; with-editor vscodedefault is.vscode/launch.jsonunless env/flag overrides it) -
ZED_GO_TASKS_LABEL_PREFIX(defaultgo:) -
ZED_GO_TASKS_DEBUG_LABEL_PREFIX(defaultgo:debug:) -
ZED_GO_TASKS_GO_BINARY(defaultgo) -
ZED_GO_TASKS_TEST_NAME_REGEX(default^Test) -
ZED_GO_TASKS_GO_LIST_REGEX(default^Test) -
ZED_GO_TASKS_ADDITIONAL_GO_TEST_ARGS(comma-separated, e.g.-count=1,-timeout=30s) -
ZED_GO_TASKS_USE_NEW_TERMINAL(defaultfalse) -
ZED_GO_TASKS_ALLOW_CONCURRENT_RUNS(defaultfalse) -
ZED_GO_TASKS_REVEAL(defaultalways) -
ZED_GO_TASKS_HIDE(defaultnever) -
ZED_GO_TASKS_PRUNE_GENERATED(defaulttrue) -
ZED_GO_TASKS_GENERATED_ENV_KEY(defaultZED_GO_TEST_TASK_GENERATED) -
ZED_GO_TASKS_GENERATED_ENV_VALUE(default1) -
ZED_GO_TASKS_SUBTEST_DISCOVERY_TIMEOUT(default30s)
Notes:
-
prune_generated=trueremoves tasks previously generated by this tool before adding current ones. -
ZED_GO_TASKS_ADDITIONAL_GO_TEST_ARGSis useful for defaults like-count=1. - CLI
-go-test-argvalues are appended toZED_GO_TASKS_ADDITIONAL_GO_TEST_ARGS. - Generated tasks are identified by
ZED_GO_TASKS_GENERATED_ENV_KEY=ZED_GO_TASKS_GENERATED_ENV_VALUE(defaultZED_GO_TEST_TASK_GENERATED=1), andclearremoves only those. - In Zed mode, the generated marker is stored in
env; in VS Code task mode, it is stored inoptions.env. - Existing
.zed/tasks.jsoncan include comments and trailing commas; the tool accepts that relaxed JSON format when reading. - Existing
.zed/debug.jsoncan include comments and trailing commas; relaxed JSON is supported there as well. - Existing
.vscode/tasks.jsonand.vscode/launch.jsoncan include comments and trailing commas; relaxed JSON is supported there as well.