Skip to content

fmt: make the tests read back what fmt wrote - #216

Merged
JalonSolov merged 1 commit into
vlang:mainfrom
metif12:fix/fmt-tests
Oct 5, 2026
Merged

JalonSolov merged 1 commit into
vlang:mainfrom
metif12:fix/fmt-tests

Conversation

@metif12

@metif12 metif12 commented Oct 4, 2026

Copy link
Copy Markdown
Member

fmt: make the tests read back what fmt wrote

Every test in this file compared an empty list against its expected output, and the
failure named a file argument rather than the thing that was wrong:

fmt: failed to open file "Now is the time for all good"

fmt is handed a closure to write through, and setup() built one that appended to a
&[]string pointing at a local in setup(). That local is gone by the time fmt runs,
so nothing was ever appended. Measured on current V:

closure appending to a captured `mut []string`   reads back empty
closure appending through a `&[]string`          reads back empty, and
                                                    crashes in array__push

A pointer to a heap struct does share, so the sink is a &Sink with a mut field
and the two closures capture that. The same trap in tail_test.v is #207.

fmt itself was never wrong here; it is handed the file, it reads it, and what came
back was being thrown away.

Tests

src/fmt is 1 of 1 and v fmt -verify src/fmt passes.

@JalonSolov

Copy link
Copy Markdown
Contributor

Conflicts.

Every test in this file compared an empty list against its expected output, and the
failure named a file argument rather than the thing that was wrong:

	fmt: failed to open file "Now is the time for all good"

fmt is handed a closure to write through, and setup() built one that appended to a
`&[]string` pointing at a local in setup(). That local is gone by the time fmt runs,
so nothing was ever appended. Measured on current V:

	closure appending to a captured `mut []string`   reads back empty
	closure appending through a `&[]string`          reads back empty, and
	                                                    crashes in array__push

A pointer to a heap struct does share, so the sink is a `&Sink` with a `mut` field
and the two closures capture that. The same trap in tail_test.v is vlang#207.

fmt itself was never wrong here; it is handed the file, it reads it, and what came
back was being thrown away.

src/fmt is 1 of 1 and `v fmt -verify src/fmt` passes.
@JalonSolov
JalonSolov merged commit 51c44bd into vlang:main Oct 5, 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