Open xsebek opened 1 year ago
Some other ideas, that may or may not be worth to do in this issue:
Yes, now that we actually have some rudimentary pretty-printing in place we absolutely need to test that we can round-trip with pretty-printing and parsing.
Another idea would be to test the round-trip in the other direction: have several scripts (it does not need to be all of them) which are formatted according to the output of --format
, and we could then test that parsing + pretty-printing them does not modify them at all.
Another idea would be to use QuickCheck Arbitrary instance and see what kind of code it cooks up.
Arbitrary
instances for large AST types can be problematic, but yes, in general, testing on some kind of randomly generated ASTs is a great idea.
Turns out we already have a function to round trip parse and format in unit tests:
That specific function needs to be updated though, namely to not elaborate and to ignore source location.
Actually, I would like to have this tested even before the comments (#1467) are fixed. Implementing the other issues from #1571 will be a lot of trial and error and having tests for round tripping would be helpful.
We can workaround the comments by doing the round trip twice, which will remove them the first time and we can still check terms match.
Any tests that do not pass we can mark as expected failure and link an Issue.
There are actually two directions to think about here.
@byorgey indeed, I would like to test that the printer round trips and eventually that the canonical forms is how we write the scripts.
Essentially the same as Fourmolu&Restyled do for Haskell, but for Swarm code. At least that is the vision. 🙂
I would like to test that the printer round trips and eventually that the canonical forms is how we write the scripts.
Ah, I see! Yes, that is a nice idea.
The pretty-printer may have bugs in more complex scripts.
We should add formatting and parsing the formatted output of all our swarm scripts in integration tests.
This would make the pretty printer significantly more robust as it would work on our most complex scripts.
This idea was sparked by this bug:
1468