ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Automatic testing of comments

Open Julow opened this issue 5 years ago • 2 comments

Related issue: https://github.com/ocaml-ppx/ocamlformat/issues/1503

Finding a test case for every call sites is not possible: some calls are unreachable and others are reachable in specific cases that are very hard to guess due to side effects and unspecified internals.

This PR tries to fix this in an automated way. For each tokens in a source file, a comment is inserted (then removed), formatting is called and the diff is printed. I added a sample containing a big part of the language, more is still needed.

This finds:

  • a lot of inserted newlines (sometimes 2)
  • moved comments that can be considered bugs
  • dropped comments

There is also a lot of false-positive:

  • wrapping because of the margin on long lines (the sample file could be improved)
  • moved comments that are definitely not bugs (eg. M.(* comment *)N)

The gained coverage is not huge (116/154 covered vs 91 on master) and we still cannot say which are unreachable.

The diff algorithm is from https://github.com/craigfe/diff. Other released libraries have incompatible dependencies.

Julow avatar Nov 06 '20 18:11 Julow