Saturday, October 1, 2011

New Version of HTF with Diffs, Colors, and Pretty-printing

I've just uploaded version 0.8.1.0 of HTF to hackage. HTF (Haskell Test Framework) allows you to define unit tests, QuickCheck properties, and black box tests in an easy and convenient way. We use HTF at work all the time, where it has proven to be quite valuable for organizing our test suite. An earlier blog post describes HTF in more detail.

The new version comes with some cool new features:

  • Support for diffs and pretty-printing. If an equality assertions fails, you now get a proper diff of the two values involved. If possible, the values are pretty-printed (thanks to Edward Yang and his groom package for inspiration). Here's an example:
    [TEST] Main:diff (TestHTF.hs:68)
    assertEqual failed at TestHTF.hs:68
    * expected:
    PlusExpr
      (PlusExpr
         (MultExpr
            (PlusExpr (Variable "foo")
               (MultExpr (Literal 42) (Variable "bar")))
            (PlusExpr (Literal 1) (Literal 2)))
         (Literal 581))
      (Variable "egg")
    * but got:
    PlusExpr
      (PlusExpr
         (MultExpr
            (PlusExpr (Variable "foo")
               (MultExpr (Literal 42) (Variable "bar")))
            (PlusExpr (Literal 2) (Literal 2)))
         (Literal 581))
      (Variable "egg")
    * diff:
    6c6
    <         (PlusExpr (Literal 1) (Literal 2)))
    ---
    >         (PlusExpr (Literal 2) (Literal 2)))
    *** Failed!
        
  • As you can see from the example above, HTF now supports colored output.
  • There's a new commandline option --quiet which causes HTF to produce output only if absolutely necessary (e.g. for failed test cases).

Just get HTF from hackage, it now also works with GHC 7.0.* and 7.2.1!

No comments:

Post a Comment

Post a Comment