【问题标题】:Import from child directory in ghci session (import modules from tests in yesod)从 ghci 会话中的子目录导入(从 yesod 中的测试导入模块)
【发布时间】:2013-06-25 06:13:52
【问题描述】:

当您在 yesod 中创建脚手架站点时,它会将测试放入单独的目录中,如下所示:

YourProj/
YourProj/SomeModule.hs
YourProj/Handlers/FooHandler.hs
...
YourProj/tests/main.hs
YourProj/tests/FooTests.hs

所以,现在我想启动 ghci 并从 YourProj/tests/main.hsYourProj/tests/FooTests.hs 导入一些代码来玩。我该怎么做?我试过了:

cabal-dev ghci
> :set -itests
> :load tests/TestImport.hs
tests/TestImport.hs:15:8:
    Could not find module `Control.Monad.IO.Class'
    It is a member of the hidden package `transformers-0.3.0.0'.
    Perhaps you need to add `transformers' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

所以,虽然我成功添加了子目录,但由于测试套件的 cabal 文件中 build-depends 参数的不同 cabal 配置,我仍然遇到问题。

我将如何启动 cabal-dev ghci 并从 Yesod 的测试中导入一些代码?

【问题讨论】:

  • 好的,我手动将测试套件中的 build-depends 行添加到 main build-depends 部分,现在它抱怨“不在范围内:`$'”。
  • 只需要导入Preludecabal文件默认开启NoImplicitPrelude
  • @MichaelSnoyman 谢谢,现在一切正常!我会在这里写一个答案。

标签: haskell cabal yesod ghci cabal-dev


【解决方案1】:

好的,所以答案是这样的:

  1. 将测试套件的build-depends 的cabal 文件中所有缺少的模块添加到顶部应用的build-depends
  2. 在应用程序的根目录中运行cabal-dev ghci 并执行:set -itests

然后您应该可以执行:load tests/EntriesTest.hs 之类的操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多