Skip to content

test: pin each report with a case and its stderr - #20

Merged
webern merged 1 commit into
m/repo-layoutfrom
m/test-cases
Sep 24, 2026
Merged

webern merged 1 commit into
m/repo-layoutfrom
m/test-cases

Conversation

@webern

@webern webern commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a second kind of test data next to the corpus: cases, written for one lint and shipped with whatever they need on disk.

The corpus can't do this job. Its fixtures are quoted from other repos and never edited, and the repos they describe aren't there. A lint like repo_layout needs a directory tree to check paths against, and its report is only worth pinning on a document written to break it in known ways.

A case is a directory under tests/cases/<lint>/ that is a whole repo root: the Markdown, a deslag.toml, and any files the lint looks for. Beside it, <case>.stderr holds exactly what deslag check prints there:

tests/cases/repo_layout/
  broken/
    deslag.toml
    AGENTS.md
    Makefile
    src/lib.rs
    ...
  broken.stderr     <- the exact report
  clean/
    ...
  clean.stderr      <- empty: the run must pass

tests/cases.rs copies each case to a temp directory, runs the binary there, and compares its stderr with the file. Some other details:

  • The exit code isn't stored. An empty .stderr means the run must exit 0, and any other means exit 1. That is the contract the binary already has.
  • Config errors print absolute paths, so the temp root is written as [ROOT].
  • A .stderr file with no case beside it, or any other stray file, fails the test, so renaming a case can't leave a stale file behind.
  • On a mismatch, the test prints the first line that differs, both outputs, and the command to accept the new output.

Accepting new output is make fix-test-output, which runs the test with DESLAG_FIX_TEST_OUTPUT=1. It is part of make fix, and the build doctrine's definition of fix now says so. It accepts whatever deslag prints, so the diff has to be read.

The first cases replace the tests in tests/layout.rs that ran the binary. Those tests checked pieces of the report with contains, while the cases pin all of it:

  • broken: one layout with every kind of problem, so every message's wording is pinned. It sets max_width = 80, so the advice and the width problem must both show the configured width.
  • clean: a good layout passes on the default limits
  • no_section, no_block: the short report, and a heading with no code block (not covered before)
  • custom_message: a config message replaces the advice, with every placeholder filled in
  • nested: paths are relative to src/AGENTS.md, not the repo root
  • min_over_max, min_over_default_max: the two ways the limits can contradict each other

The tests of read and check stay in tests/layout.rs.

tests/cases/ isn't excluded from the spell check: cases are ours, unlike the corpus. The self-lint globs are anchored, so the cases' AGENTS.md files aren't linted as this repo's own.

A case can't hold a .git directory, or a .gitignore that ignores its own files, because git would apply it to this repo too. The harness's doc comment says so.

AGENTS.md and the as-built doc are updated.

Testing

  • make ci: exit 0
  • Ran the harness before any .stderr existed: every case reported its file as missing. Then ran make fix-test-output and checked each .stderr line by line against its source: line numbers, columns, entry counts and file counts.
  • Changed one line of nested.stderr and added a stray orphan.stderr: the test failed on both, naming line 10 as the first difference. Restored both.

References

@webern webern added enhancement New feature or request area/build Deals with deslag build, scripts, ci, cd. labels Sep 24, 2026
@webern
webern added this pull request to stack #21 September 24, 2026 11:44
@webern
webern force-pushed the m/test-cases branch 2 times, most recently from 4d36bf2 to b2ccaf6 Compare September 24, 2026 12:51
A case is a small repo under tests/cases/<lint>/, written to show one
behavior, with the exact stderr deslag must print there in a .stderr
file beside it. An empty .stderr means the run must pass.
tests/cases.rs runs each case in a temp copy and compares.
make fix-test-output rewrites the .stderr files, and make fix runs it.

The report tests in tests/layout.rs move into eight cases. They now
pin the whole report instead of pieces of it, including the wording of
every kind of problem, and add the missing-block and clean runs.
@webern
webern merged commit a42cd24 into main Sep 24, 2026
2 checks passed
@webern
webern deleted the m/test-cases branch September 24, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Deals with deslag build, scripts, ci, cd. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant