1

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:          "[email protected]"
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:     [email protected]
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.

5
  • Do you have a .cabal file? You may need to add the package to build-depends there. Commented Jun 24, 2018 at 10:11
  • @MarkSeemann Added the contents of the cabal file. Commented Jun 24, 2018 at 10:23
  • What if you remove the two occurences of other-modules: Path_schemer? Commented Jun 24, 2018 at 12:10
  • @Li-yaoXia It compiles. Odd. One would expect generated by stack stuff to be valid. Maybe you have an idea how to instruct stack to not generate this? Commented Jun 24, 2018 at 13:22
  • @Li-yaoXia Tried setting other-modules setting in the package.yaml to an empty list, worked like a charm. Not sure what was going on with that, maybe some weird default? If you write up an answer from this, I'll accept. It was yours intuition, after all. Commented Jun 24, 2018 at 13:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.