Hspec - Haskell 中的快照测试?

Hspec - snapshot testing in Haskell?

是否可以在 hspec 测试框架中创建快照测试? 对于快照,我的意思是,可以将函数的输出与存储在文件中的预期输出进行比较。

或者是否有破解包可以启用此功能?

hspec-golden does what you want (the feature is called “golden tests”). Quoting their Haddocks (Test.Hspec.Golden):

Golden tests store the expected output in a separated file. Each time a golden test is executed the output of the subject under test (SUT) is compared with the expected output. If the output of the SUT changes then the test will fail until the expected output is updated.

从该模块导出的主要函数是defaultGolden。这是一个例子:

describe "myFunc" $
  it "generates the right output with the right params" $
     let output = show $ myFunc params
       in defaultGolden "myFunc" output