Skip to content

Improving correctness #95

Open
Open

Description

@sjakobi

I'm quite impressed by (and a bit proud of!) the number of bugs that has been revealed through dhall's usage of prettyprinter!

I wonder how prettyprinter could rely less on the users to discover these bugs though.

In particular I wonder whether property tests could help – IMHO they've been quite effective in dhall!

For example I believe that the recent bugs could have been discovered by tests for the following properties:

  • Unbounded layout of grouped Line fails #91: The result of applying layout{Pretty,Smart} opts . group to a Doc that doesn't contain Fail, should never contain SFail.
  • For removeTrailingWhitespace:
    • The (rendered) input and output should only differ by trailing spaces.
    • The output should never contain trailing spaces.
    • removeTrailingWhitespace is idempotent.

It's probably more difficult to come up with properties that would reveal unknown bugs, but it might be worth trying!

Activity

  1. sjakobi commented on Nov 4, 2019

    @sjakobi
    CollaboratorAuthor

    Oh, I see that there is already an Arbitrary instance and a non-trivial property test:

    https://github.com/quchen/prettyprinter/blob/4d51362d7ea8bca0fe9e7ffec2ccd8fcd0065c0d/prettyprinter/test/Testsuite/Main.hs#L79-L99

  2. sjakobi commented on Nov 4, 2019

    @sjakobi
    CollaboratorAuthor

    Here's a property for #83:

    When layouting f (align (vsep […, x, …, x, …])), both instances of x should have the same layout.

  3. quchen commented on Nov 5, 2019

    @quchen
    Collaborator

    The main difficulty here is putting the properties into code, but I totally agree! The Arbitrary instance is not used very much right now, but I prefer Quickcheck to handwritten tests whenever possible.

  4. sjakobi commented on Nov 6, 2019

    @sjakobi
    CollaboratorAuthor

    Another property had come up in #89:

    layoutWadlerLeijen fp opts (unAnnotate doc) === unAnnotateS (layoutWadlerLeijen fp opts doc)
    

    But layoutCompact should be included too, so we probably want

    layout (unAnnotate doc) === unAnnotateS (layout doc)
    

    with layout being one of layout{Pretty,Smart,Compact} with arbitrary LayoutOptions.

  5. sjakobi commented on Jan 23, 2020

    @sjakobi
    CollaboratorAuthor

    @1Jajen1 mentioned that he has some effective property tests in his kotlin clone.

    Maybe we can copy some of those…

  6. 1Jajen1 commented on Jan 23, 2020

    @1Jajen1
    Contributor

    @sjakobi Not sure that will work much better, currently I literally just generate random elements of Doc (without Union/Fail to preserve invariants although you could call group on them randomly to produce those as well). Shrinking is also done manually for most of it as I too use a quickcheck derivative for tests. I'll change those tests to more hedgehog style tests later this week to check out how well integrated shrinking works, it seems to be the better choice if you want to preserve invariants on more complex datatypes without writing shrinkers manually.

  7. sjakobi commented on Jan 23, 2020

    @sjakobi
    CollaboratorAuthor

    @1Jajen1 Well somehow your tests were able to detect the problems with the modified group, right?

    Which properties did you check there?

  8. 1Jajen1 commented on Jan 23, 2020

    @1Jajen1
    Contributor

    So what I have right now is basically just a few property tests: (The kotlin source for these is actually readable!)
    This one for the group (passes around 100k tests just fine, so it might actually work^^):
    https://github.com/1Jajen1/kotlin-pretty/blob/master/kotlin-pretty/src/test/kotlin/pretty/GroupTest.kt
    https://github.com/1Jajen1/kotlin-pretty/blob/master/kotlin-pretty/src/test/kotlin/pretty/Generators.kt
    https://github.com/1Jajen1/kotlin-pretty/blob/master/kotlin-pretty/src/test/kotlin/pretty/DocTest.kt

    They actually find a bug in flatten (did not handle Line correctly, only in the kotlin version).

  9. sjakobi commented on Jan 24, 2020

    @sjakobi
    CollaboratorAuthor

    #126 (comment) lists a bunch of tests from dhall's testsuite, at least some of which we ought to adopt into prettyprinter's testsuite…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions