微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将内部模块暴露于Cabal中的测试

如何解决将内部模块暴露于Cabal中的测试

我正在为open source project做出贡献,该cabal file在看起来像这样的cabal docs中定义了项目设置(省略了许多与此问题无关的属性):

library
  hs-source-dirs:    src
  build-depends:
                     base >= 4.9 && < 5,some-other-deps
  exposed-modules:
                     Data.Foo.Bar,Data.Foo.Baz
  other-modules:
                     Data.Foo.Bar.Internal

test-suite test
  hs-source-dirs:
                     tests
  build-depends:
                     foo-library
  other-modules:
                     Foo.Bar.Tests,Foo.Baz.Tests

现在,为了测试我要添加功能,我希望测试可以访问Data.Foo.Bar.Internal模块,但是由于它已隐藏在库中,因此无法从测试中访问它。

我查看了Current dataframe,它建议添加第三个组件-内部库(不幸的是不可链接,但搜索“内部库”)。如果我正确理解了文档,则应该可以执行以下操作:

library foo-internal
  hs-source-dirs:    src
  build-depends:
                     base,some-other-deps
  exposed-modules:
                     Data.Foo.Bar.Internal

library
  hs-source-dirs:    src
  build-depends:
                     base >= 4.9 && < 5,foo-internal,Data.Foo.Baz

test-suite test
  hs-source-dirs:
                     tests
  build-depends:
                     foo-library,foo-internal
  other-modules:
                     Foo.Bar.Tests,Foo.Baz.Tests

但是在这里运行stack build时,警告我Data.Foo.Bar.Internal“应添加到./foo.cabal中的公开模块或其他模块”,然后出现测试错误归因于失败的统一(它指向库中定义的函数函数参数,表示必须在包Data.Foo.Bar.Internal.Qux中定义其类型foo,类型foo:Data.Foo.Bar.Internal.Qux不匹配)。

如何将内部模块公开给测试套件,而又不将其公开给库的使用者?

解决方法

如评论中所述,不同的组件(内部库,可执行文件)应具有位于不同根目录下的模块。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。