如何将内存分析选项添加到堆栈测试

How to add memory profiling options to stack test

当 运行 stack test --profile 时它会自动添加 -p rts 选项。 我正在尝试对我的测试套件进行一些内存分析,因此想添加 hc 或 hy rts 选项。

这似乎行不通

stack test --profile --ghc-options="+RTS -hc -RTS"

它给出了错误

ghc: the flag -hc requires the program to be built with -prof

如果我不得不猜测,您打算将 +RTS 选项传递给最终测试程序,但在您上面的调用中,这些选项可能是由 ghc 可执行文件本身接收的;就像你告诉 ghc "compile this code but please profile your memory while you do that"。我的建议是在启用分析的情况下构建测试(例如,通过 运行 测试首先使用 stack test --profile,尽管您可能也可以使用某种形式的 stack build)然后 运行 生成的测试可执行文件(带有分析)通过 RTS 选项。