Skip to content

Use indoc for multiline strings in tests - #7169

Merged
jieyouxu merged 2 commits into
rust-lang:mainfrom
joshka:joshka/indoc-tests
Oct 10, 2026
Merged

jieyouxu merged 2 commits into
rust-lang:mainfrom
joshka:joshka/indoc-tests

Conversation

@joshka

@joshka joshka commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Use indoc where it makes visible indentation and before / after
comparisons easier to read. Use raw strings for embedded quotes. Not all
places were modified. Kept compact strings and escapes where they were
subjectively easier to visually inspect. Indoc is only added as a
dev-dependency to avoid increasing the runtime dependencies.

Assisted-by: Codex, with prior discussion with the maintainers via Zulip
https://rust-lang.zulipchat.com/#narrow/channel/357797-t-rustfmt/topic/Characterization.20tests/with/630013200

Codex identified candidates and made the fixes.
I directed the scope and reviewed readability tradeoffs rejecting several
changes that didn't seem to be worth the churn.

Fixes: #7166

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Oct 9, 2026
@joshka
joshka force-pushed the joshka/indoc-tests branch 2 times, most recently from d936ddf to b1518c9 Compare October 9, 2026 03:52

@joshka joshka left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small self-review notes

View changes since this review

Comment thread src/test/mod.rs Outdated
Comment thread src/lib.rs Outdated
@jieyouxu jieyouxu added the llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee. label Oct 9, 2026

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the picked instances here:

  • I do find some of these tactically selected instances to be more readable, when the test intention is moreso "hey something has changed, I don't really care exactly how"
  • But, sometimes I find that the original string literal version is better (more directly obvious) when for the test intention you care about the exact presence/absence (and quantity) of newlines and other whitespaces.

TL;DR: overall I feel neutral about the changes.

View changes since this review

Comment thread src/emitter/json.rs Outdated
Comment thread src/test/mod.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/string.rs Outdated
Comment thread src/string.rs Outdated
Comment thread src/string.rs Outdated
Comment thread tests/rustfmt/main.rs Outdated
Use indoc where it makes visible indentation and before / after
comparisons easier to read. Use raw strings for embedded quotes. Not all
places were modified. Kept compact strings and escapes where they were
subjectively easier to visually inspect. Indoc is only added as a
dev-dependency to avoid increasing the runtime dependencies.

Assisted-by: Codex, with prior discussion with the maintainers via Zulip
https://rust-lang.zulipchat.com/#narrow/channel/357797-t-rustfmt/topic/Characterization.20tests/with/630013200

Codex identified candidates and made the fixes.
I directed the scope and reviewed readability tradeoffs rejecting several
changes that didn't seem to be worth the churn.
@joshka
joshka force-pushed the joshka/indoc-tests branch from b1518c9 to ac4369b Compare October 9, 2026 10:10
@joshka
joshka requested a review from jieyouxu October 9, 2026 10:14
@joshka

joshka commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

I dropped all the review items that were mentioned - no strong concerns. Mostly they felt subjective and I was 60/40 or 51/49 on a bunch of them as being better.

I also added a panicdoc! macro to indoc, and it’s published in 2.0.8, so I added the two diagnostic conversions in 5c23798d. I validated that both helpers still produce the same panic messages.

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remaining cases here seem reasonable to me 👍

View changes since this review

Comment thread Cargo.toml
semver = "1.0.21"

[dev-dependencies]
indoc = "2.0.8"

@jieyouxu jieyouxu Oct 10, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ytmimi a quick vibecheck on the extra dev-dependency: do you think the changes here pull its weight? I more-or-less neutral with a lean towards "seems nicer for these cases".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes—I think the places where indoc helps read a bit nicer, and I have more tests planned that would benefit similarly. I wrote a small dedent! macro as an alternative in that upcoming change (respecting the one LLM change in flight request to post this and the followups that sit on top of it), but that leaves rustfmt maintainers maintaining code that duplicates an established, stable solution.

My calculus is that indoc is a small crate—about 17 KB and 405 lines of code—with broad adoption. The readability benefit seems worth the dependency, especially as a dev-dependency.

Personally, I’d also be comfortable with it as a regular dependency, though I understand why a foundational tool like rustfmt would be more conservative. It feels like functionality that could reasonably belong in the standard library.

So I see little downside to using it for tests, and a relatively small tradeoff even for production code.

@jieyouxu jieyouxu Oct 10, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah. Since this is dev-deps and test-only, I think it's fine introducing it.

Re. the calculus, indoc also has the other variants for UX that I don't think we want to be maintaining ourselves.

@jieyouxu jieyouxu left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jieyouxu
jieyouxu added this pull request to the merge queue Oct 10, 2026
Merged via the queue into rust-lang:main with commit ff02051 Oct 10, 2026
33 checks passed
@rustbot rustbot added release-notes Needs an associated changelog entry and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Oct 10, 2026
@joshka

joshka commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review :)

@jieyouxu jieyouxu removed the release-notes Needs an associated changelog entry label Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-assisted An LLM-assisted PR as defined by the LLM policy. Requires ahead-of-time consent by assignee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use indoc for dedenting test data

3 participants