Small Go CLI that generates one Zed task per test in a selected Go file.


Install
go get github.com/VashingMachine/go-zed-test

Documentation

go-zed-tasks

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-subtests is enabled).
  • Writes/updates tasks with labels like go:TestName.
  • Keeps non-generated tasks untouched.

Usage

From your workspace root (generate tasks):

go run ./cmd/go-zed-tasks generate -file path/to/foo_test.go

Optional 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-run

You can also pass extra go test args after --:

go run ./cmd/go-zed-tasks generate -file path/to/foo_test.go -- -v -count=1

Generate debug configs (.zed/debug.json by default):

go run ./cmd/go-zed-tasks generate-debug -file path/to/foo_test.go

Generate 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 vscode

Discover 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-subtests

Clear all previously generated tasks:

go run ./cmd/go-zed-tasks clear

Clear generated VS Code tasks:

go run ./cmd/go-zed-tasks clear -editor vscode

Backward compatibility:

  • go run ./cmd/go-zed-tasks -file path/to/foo_test.go still works (treated as generate).

Zed integration

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"
  }
]

VS Code integration

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

Configuration is read from environment variables with prefix ZED_GO_TASKS_.

Common variables:

  • ZED_GO_TASKS_TASKS_PATH (default .zed/tasks.json; with -editor vscode default is .vscode/tasks.json unless env/flag overrides it)
  • ZED_GO_TASKS_DEBUG_PATH (default .zed/debug.json; with -editor vscode default is .vscode/launch.json unless env/flag overrides it)
  • ZED_GO_TASKS_LABEL_PREFIX (default go:)
  • ZED_GO_TASKS_DEBUG_LABEL_PREFIX (default go:debug:)
  • ZED_GO_TASKS_GO_BINARY (default go)
  • 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 (default false)
  • ZED_GO_TASKS_ALLOW_CONCURRENT_RUNS (default false)
  • ZED_GO_TASKS_REVEAL (default always)
  • ZED_GO_TASKS_HIDE (default never)
  • ZED_GO_TASKS_PRUNE_GENERATED (default true)
  • ZED_GO_TASKS_GENERATED_ENV_KEY (default ZED_GO_TEST_TASK_GENERATED)
  • ZED_GO_TASKS_GENERATED_ENV_VALUE (default 1)
  • ZED_GO_TASKS_SUBTEST_DISCOVERY_TIMEOUT (default 30s)

Notes:

  • prune_generated=true removes tasks previously generated by this tool before adding current ones.
  • ZED_GO_TASKS_ADDITIONAL_GO_TEST_ARGS is useful for defaults like -count=1.
  • CLI -go-test-arg values are appended to ZED_GO_TASKS_ADDITIONAL_GO_TEST_ARGS.
  • Generated tasks are identified by ZED_GO_TASKS_GENERATED_ENV_KEY=ZED_GO_TASKS_GENERATED_ENV_VALUE (default ZED_GO_TEST_TASK_GENERATED=1), and clear removes only those.
  • In Zed mode, the generated marker is stored in env; in VS Code task mode, it is stored in options.env.
  • Existing .zed/tasks.json can include comments and trailing commas; the tool accepts that relaxed JSON format when reading.
  • Existing .zed/debug.json can include comments and trailing commas; relaxed JSON is supported there as well.
  • Existing .vscode/tasks.json and .vscode/launch.json can include comments and trailing commas; relaxed JSON is supported there as well.