测试Main模块中定义的Haskell代码

 飞鱼 发布于 2023-01-31 21:30

我正在寻找有关如何编写Main模块中定义的Haskell代码的测试的帮助.

我想测试的项目是一个cabal包,我在其中定义了多个可执行文件.每个可执行代码只声明一个文件(每个项目euler问题一个),我通常使用该cabal run命令单独运行它们.

我曾尝试在Main模块中编写测试,但在编译时,找不到我要测试的函数("不在范围内"错误).

在这种情况下编写测试的正确方法是什么?

有关信息,以下是我的项目的目录布局:

pe/                     # root
  pe.cabal
  src/
    Util.hs
    Problem001.hs       # "module Main where" and declares a main function
    Problem002.hs       # "module Main where" and declares a main function
    (...)
  test/
    TestProblem001.hs   # "module Main where" and declares a main function

以下是pe.cabal的摘录:

test-suite test-all
    hs-source-dirs:      test
    type:                exitcode-stdio-1.0
    main-is:             TestProblem001.hs
    build-depends:       base, HUnit, Cabal >= 1.9.2

executable problem-001
    hs-source-dirs:      src
    main-is:             Problem001.hs
    build-depends:       base
    ghc-options:         -Wall -Werror -O2

[编辑]

由于我找不到任何资源来满足这个要求,我选择了一个更容易测试的项目架构:问题被定义为库而不是单个可执行文件.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有