不在范围内:尝试创建单元测试时,请输入构造函数或类“ Test.Framework.TestSuite”

时间:2018-06-24 09:52:11

标签: haskell haskell-stack hft

我正在Haskell中编写一个小型库,并希望进行测试。为了进行测试,我打算使用HFT,整个项目由堆栈管理。 stack test由于某些原因而失败,并显示以下输出:

[1 of 2] Compiling Main             ( test/Ini.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/ini-tests-tmp/Main.o )                                                                      │····························
[2 of 2] Compiling Paths_schemer    ( .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/autogen/Paths_schemer.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/ini-tests-tm│····························
p/Paths_schemer.o )                                                                                                                                                                                               │····························
                                                                                                                                                                                                                  │····························
/stuff/projects/schemer/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/autogen/Paths_schemer.hs:54:39: error:                                                                                 │····························
    Not in scope: type constructor or class ‘Test.Framework.TestSuite’                                                                                                                                            │····························
    No module named ‘Test.Framework’ is imported.                                                                                                                                                                 │····························
                                                                                                                                                                                                                  │····························
/stuff/projects/schemer/.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0/build/ini-tests/autogen/Paths_schemer.hs:55:38: error:                                                                                 │····························
    Not in scope: ‘Test.Framework.makeTestSuite’                                                                                                                                                                  │····························
    No module named ‘Test.Framework’ is imported.                                                                                                                                                                 │····························

稍后将包含测试的我的Ini.hs文件非常准,

import Test.Framework

main :: IO ()
main = htfMain htf_thisModulesTests

我的package.yaml

name:                schemer
version:             0.1.0.0
github:              "mpevnev/schemer"
license:             BSD3
author:              "Michail Pevnev"
maintainer:          "mpevnev@gmail.com"
copyright:           ""

extra-source-files: []

# Metadata used when publishing your package
# synopsis:            Short description of your package
# category:            Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description:         Please see the README on GitHub at <https://github.com/mpevnev/schemer#readme>

dependencies:
- attoparsec
- base >= 4.7 && < 5
- text


library:
  source-dirs: src

tests:
  ini-tests:
    main:                Ini.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    - -F
    - -pgmF htfpp
    dependencies:
    - schemer
    - text
    - HTF

这是自动生成的schemer.cabal

-- This file has been generated from package.yaml by hpack version 0.28.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 17ae623236b8f5b101f56373c975656e898efa7506acb143db7375f229509a79

name:           schemer
version:        0.1.0.0
description:    Please see the README on GitHub at <https://github.com/mpevnev/schemer#readme>
homepage:       https://github.com/mpevnev/schemer#readme
bug-reports:    https://github.com/mpevnev/schemer/issues
author:         Michail Pevnev
maintainer:     mpevnev@gmail.com
license:        BSD3
license-file:   LICENSE
build-type:     Simple
cabal-version:  >= 1.10

source-repository head
  type: git
  location: https://github.com/mpevnev/schemer

library
  exposed-modules:
      Control.Scheme.Ini
      Control.Schemer
  other-modules:
      Paths_schemer
  hs-source-dirs:
      src
  build-depends:
      attoparsec
    , base >=4.7 && <5
    , text
  default-language: Haskell2010

test-suite ini-tests
  type: exitcode-stdio-1.0
  main-is: Ini.hs
  other-modules:
      Paths_schemer
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N -F -pgmF htfpp
  build-depends:
      HTF
    , attoparsec
    , base >=4.7 && <5
    , schemer
    , text
  default-language: Haskell2010

我不确定这是什么问题以及Paths_schemer的问题是什么。感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

-F -pgmF htfpp选项已全局打开。这会将HTF预处理程序应用于测试套件的所有文件,包括自动生成的Paths_schemer

更具可扩展性的解决方案是使用每个文件中的Test.Framework编译指示,仅对导入OPTIONS_GHC的文件启用预处理器:

{-# OPTIONS_GHC -F -pgmF htfpp #-}

另一种方法是在other-modules: []的test-suite部分中设置package.yaml以避免生成Paths_schemer,尽管这只能解决该模块的问题。