Skip to content

ppx_devtools.expect: indent promoted code like the code around it, and fixes - #7

Merged
hhugo merged 2 commits into
mainfrom
expect-promotion-indent
Nov 16, 2026
Merged

hhugo merged 2 commits into
mainfrom
expect-promotion-indent

Conversation

@hhugo

@hhugo hhugo commented Nov 3, 2026

Copy link
Copy Markdown
Member

Stacked on #6.

  • Indentation of promoted code is copied from the source, tabs included, instead of being counted in spaces; literals indented with tabs compare equal to the output. A body written on the let%expect_test line, a test nested in a module, and an inserted [@@expect.uncaught_exn] no longer get code at the wrong column.
  • The CR header of an [%expect] that saw different outputs uses our own wording: (* CR ppx_devtools-expect: this [%expect] saw different outputs *).
  • Fixes:
    • Deleting a [@@expect.uncaught_exn] attribute deleted everything from the end of the test body, including other attributes and comments. Only the attribute and the whitespace in front of it are deleted now.
    • A match, try or function ending the body as the last argument of an application (e.g. print_string @@ match ...) got the appended [%expect] in its last case.
    • Outputs that differ only in tabs versus spaces of indentation compared equal.

Tests: new cases in test/promote/promote_me.ml.

🤖 Generated with Claude Code

@hhugo
hhugo force-pushed the expect-promotion-indent branch from 91bace2 to f7105b3 Compare November 3, 2026 08:16
@hhugo
hhugo force-pushed the expect-unreachable branch from 516f86f to d2ffc3b Compare November 3, 2026 08:16
@hhugo
hhugo force-pushed the expect-promotion-indent branch from f7105b3 to 9ebce58 Compare November 3, 2026 08:28
@hhugo
hhugo force-pushed the expect-unreachable branch from 661410f to a65423d Compare November 3, 2026 08:42
@hhugo
hhugo force-pushed the expect-promotion-indent branch from 9ebce58 to 5db69eb Compare November 3, 2026 08:42
@hhugo
hhugo force-pushed the expect-unreachable branch from a65423d to e183abe Compare November 3, 2026 08:53
@hhugo
hhugo force-pushed the expect-promotion-indent branch from 5db69eb to 50b2b55 Compare November 3, 2026 08:53
@hhugo
hhugo force-pushed the expect-unreachable branch from e183abe to 6f606c1 Compare November 3, 2026 09:03
@hhugo
hhugo force-pushed the expect-promotion-indent branch 2 times, most recently from 8fb5c5d to 86f849c Compare November 4, 2026 08:12
@hhugo
hhugo force-pushed the expect-promotion-indent branch from 5b7943e to 7be5447 Compare November 16, 2026 22:59
Base automatically changed from expect-unreachable to main November 16, 2026 23:13
hhugo and others added 2 commits November 17, 2026 00:14
- Indentation is copied from the source, tabs included, instead of being
  counted in spaces. Literals indented with tabs now compare equal to the
  output.
- A new [%expect] after a body written on the [let%expect_test] line is
  indented one step past the test instead of starting at column 0.
- An inserted [@@expect.uncaught_exn] is indented like its test, e.g.
  inside a module.

Also use our own wording for the header of an [%expect] that saw
different outputs: "CR ppx_devtools-expect: this [%expect] saw different
outputs".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Deleting a [@@expect.uncaught_exn] attribute deleted everything from
  the end of the test body, including other attributes such as [@@if]
  and comments. Only the attribute and the whitespace in front of it are
  deleted now.
- A [match], [try] or [function] ending the body as the last argument of
  an application (e.g. [print_string @@ match ...]) got the appended
  [%expect] in its last case. The search for such an expression now goes
  through applications, constructors and field assignments.
- Counting a tab as a column of common indentation made outputs that
  differ in tabs and spaces compare equal. The common indentation is now
  a common whitespace prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hhugo
hhugo force-pushed the expect-promotion-indent branch from 7be5447 to c89dd6f Compare November 16, 2026 23:14
@hhugo
hhugo merged commit f597941 into main Nov 16, 2026
13 checks passed
@hhugo
hhugo deleted the expect-promotion-indent branch November 16, 2026 23:15
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.

1 participant