Skip to content

feat: add a code action that generates a test skeleton - #565

Merged
JalonSolov merged 1 commit into
vlang:masterfrom
metif12:feat/generate-test-skeleton
Oct 7, 2026
Merged

JalonSolov merged 1 commit into
vlang:masterfrom
metif12:feat/generate-test-skeleton

Conversation

@metif12

@metif12 metif12 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

What this adds

A code action that generates a test skeleton.

V has no test framework, so the file layout is the whole contract: foo.v is
tested by foo_test.v beside it, and a test file holds only test_ functions.
Remembering that convention is a small tax on every new file.

On a .v file with public functions, V: Generate Test File creates the
_test.v file beside it with one test_ function per public function, each with
a placeholder assertion to replace.

Design

  • Offered on .v files only, and only when the source has public functions. A
    module with nothing public has nothing to test, and an empty test file is worse
    than no test file.
  • Refuses to overwrite an existing test file, because that would discard work the
    user already wrote.
  • The generation lives in a pure module so it can be tested without an editor.

Verification

npm run lint, npm run lint:md, npm run test:grammar, npm run build and
npm run package all pass.

npm test reports 26 tests, 23 pass, 3 fail. The three failures are the
pre-existing Windows path-separator tests on master, fixed in
#561 and not touched here.

Proof the new tests catch something. I broke the public-function regex in
testSkeleton.ts and watched generates one test function per public function
go red, then reverted it.

Known limitations

  • Not exercised in a real VS Code window. The code action provider and the file
    creation are not covered by the extension-host suite; the generation logic is.
  • The placeholder assertion is assert true, which always passes. The user
    replaces it with a real assertion. A generated test that passes is not
    evidence that it tests anything.
  • Only top-level pub fn declarations are found. A public function inside a
    struct or a pub fn with a receiver is not matched, because the regex is
    anchored to column zero and V has no nested function declarations.

Relation to other PRs

Independent of #556, #557, #558, #559, #560, #561, #562, #563 and #564. It adds
new files and touches extension.ts and package.json only where the other PRs
do not.

V has no test framework, so the file layout is the whole contract: `foo.v` is
tested by `foo_test.v` beside it, and a test file holds only `test_` functions.
Remembering that convention is a small tax on every new file.

The code action creates the `_test.v` file with one `test_` function per public
function in the source, each with a placeholder assertion to replace. It is
offered on `.v` files only, and only when the source has public functions — a
module with nothing public has nothing to test, and an empty test file is worse
than no test file.

It refuses to overwrite an existing test file, because that would discard work
the user already wrote.

The generation lives in a pure module so it can be tested without an editor. I
confirmed the tests catch something by breaking the public-function regex and
watching the generation test fail, then reverting.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@metif12
metif12 force-pushed the feat/generate-test-skeleton branch from 07952b3 to 49effc6 Compare October 7, 2026 06:26
@JalonSolov
JalonSolov merged commit 6af83fa into vlang:master Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants