That sounds like expect tests in OCaml [1]. I've found them quite a joy to work with and I'm surprised more languages don't have something similar.
[1] https://dev.realworldocaml.org/testing.html#expect-tests