[llvm] [lit] Add JSON diffing support to lit (PR #177513)

Henrik G. Olsson via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 20:04:25 PST 2026


https://github.com/hnrklssn requested changes to this pull request.

Overall I'm in favour of more specialised test utilities when they can do a better job than diff or FileCheck could, but I have some things I would like to see fixed.

First of all, this should be a separate utility under `llvm/utils/json-diff` in my opinion. The other builtin commands are Python replacements for standard POSIX utilities, so people on systems with those utilities don't need to add `llvm/utils/lit/lit/builtin_commands/` to their path to run them. The same is not true for `json-diff`, which is more like FileCheck (which lives under `llvm/utils/FileCheck`). If a test fails and I copy the commands from the output I think it's reasonable to expect to be able to manually re-run the same commands if I have `$BUILD_DIR/bin` on my PATH.

I also think you should strongly consider adding support for comments, or risk falling back to using FileCheck as soon as you want to provide additional context for some check. Not being able to add inline comments is also one of the big drawbacks for diff based tests. To be clear, something like this is what I'm advocating:
```json
{
  "foo": "bar", // "bar" means that the baz system responded correctly
  "responses": [1, "X", 2,],
}
```
The trailing commas are intentional as I think that's also a nice quality of life feature. I *think* trailing commas should also be possible to implement as preprocessing rather than swapping the parser, by checking for `,\s*[\]}]`.

https://github.com/llvm/llvm-project/pull/177513


More information about the llvm-commits mailing list