haskellhaskell-stackhft

Not in scope: type constructor or class ‘Test.Framework.TestSuite’ when trying to create unit tests


I'm writing a small library in Haskell, and want to have tests to accompany it. For testing I intend to use HFT, and the project as a whole is managed by stack. stack test fails for some reason with the following output:

[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.                                                                                                                                                                 │····························

My Ini.hs file that will later contain the tests is very bare-bone, just

import Test.Framework

main :: IO ()
main = htfMain htf_thisModulesTests

My package.yaml is

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

Here's the autogenerated 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

I'm not sure what's wrong and what is this Paths_schemer thing. Help is appreciated.


Solution

  • The options -F -pgmF htfpp are switched on globally. This applies the HTF preprocessor to all the files of the test suite, including the autogenerated Paths_schemer.

    The more scalable solution is to enable the preprocessor only on files that import Test.Framework, using the OPTIONS_GHC pragma in each one:

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

    Another way is to set other-modules: [] in the test-suite section in package.yaml to avoid generating Paths_schemer, although that only solves the problem for this one module.