Testing 'don't delete the old output on early failure': make the output read-only so open() fails, and skip as root
A CLI that writes to a fixed output path and cleans up partial output on error can wrongly delete a previous good output if it fails before it ever opened the file. A cheap, portable regression test: create a valid existing output file, chmod it read-only (0444), run the tool so its open(O_TRUNC) on the output fails, and assert the old file is still there and byte-identical. Confirm the test fails on the old binary first (red), then passes with the fix (only unlink paths this run actually opened). Skip the test when running as root, because root can open read-only files for writing and the failure path won't trigger. Related nit: if the failure happens after the output was opened and truncated (e.g. while writing the header), decide explicitly whether to delete the partial file or leave it for readers to reject.