
I can do that indeed, and I guess I could reimplement everything I have
at the moment on top of HUnit.
However, an important part of functionality isn't there at the moment —
golden file management. You should be able to say, "for this test,
take its current output and write it to the corresponding golden file".
In order to do that, you need to have access to the list of golden tests
in the suite. This is where implementation details of different test
frameworks start to matter. Probably one can make an abstraction over
test frameworks that would give the list of all golden tests.
(Although when you start abstracting over test frameworks, which are
abstractions themselves, it becomes somewhat funny.)
Speaking of such functionality, correct me if I'm wrong, but neither
HUnit nor hspec won't be able to support it anyway, because they
represent tests as opaque IO actions.
Nor can HTF provide such support — although its TestSort type could be
extended to indicate that the test is a golden test, still there's no
way to get hold of the golden file name.
test-framework will support this once the Typeable constraint is added
for tests.
Roman
* Simon Hengel
1. It's hard to guess at the moment how a good interface to the "pure golden" part should look like.
Maybe just produce HUnit assertions, e.g.:
goldenVsFile :: FilePath -> FilePath -> IO () -> Assertion
That way it works with plain HUnit
main = runTestTT $ TestLabel "someAction produce desired output $ goldenVsFile "ref.txt" "out.txt" someAction
test-framework
main = defaultMain [ testGroup "someAction" [ testCase "produces some desired output" $ goldenVsFile "ref.txt" "out.txt" someAction ] ]
Hspec
main = hspec $ do describe "someAction" $ do it "produces some desired output" $ do goldenVsFile "ref.txt" "out.txt" someAction
and probably every other current or future Haskell test framework.
Cheers, Simon