Uploaded image for project: 'test.check'
  1. TCHECK-126

Refactor c.t.c/quick-check as a state machine to provide more extension points

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Labels:
      None
    • Patch:
      Code and Test

      Description

      We can think of the quick-check process as a state machine with a state flow like:

             started
                v
        trying, trying, [...]
                v
      succeeded | failure
                       v
          shrinking, shrinking, [...]
                       v
                     shrunk"
      

      The process starts, runs trials based on the generated values and either it succeeds or it fails. If it succeeds, the process is done. If it fails, then it runs successive shrinks of the failed args until it gets to the terminal shrunk state.

      Modelling the process this way, we can call a step-fn at interesting points of the process that serves two purposes:

      • Provide feedback to the user about the process (via side-effects)
      • Augment/modify the state being tracked by the process, making it easy to implement things like gracefully aborting the process before it finishes, calculating statistics on the generated values ( TCHECK-87 Open ), add timestamps ( TCHECK-8 Open , TCHECK-95 Resolved , TCHECK-96 Open ), etc.

      The attached patch aims at being 100% backwards compatible. Adds a new clojure.test.check2/quick-check function. The "old" clojure.test.check/quick-check is re-implemented by calling the new one, maintaining all the current behavior by lifting the reporter-fn into a step-fn via a reporter-fn->step-fn adapter fn.

      EDIT: Added an alternative patch (TCHECK126-test.check-refactor.patch) that refactors `c.t.c/quick-check` "in-place", instead of adding a new test.check2 namespace. The most important change is that it switches from the reporter-fn to a step-fn which gives the possibility to drive/augment the quick-check process by feeding back changes to the quick-check state (as the return value of step-fn).

        Attachments

          Activity

            People

            • Assignee:
              gfredericks gfredericks
              Reporter:
              nberger Nicolás Berger
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: