vendredi 22 février 2019

"module cannot be found locally" when running detailed-0.9 test suite with Haskell Stack

I have a Haskell project with a test suite using detailed-0.9. I can run the test correctly with cabal, but with stack I get errors. The exitcode-stdio-1.0 test suites seem to work fine.

MWE

Below is a minimum working example, containing both test-suite types. A full repository is available here.

stack-test-detailed.cabal

name: stack-test-detailed
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.20

test-suite exitcode
  type: exitcode-stdio-1.0
  main-is: Exitcode.hs
  other-modules: MyModule
  build-depends: base >=4.10
  hs-source-dirs: src testsuite
  default-language: Haskell2010

test-suite detailed
  type: detailed-0.9
  test-module: Detailed
  other-modules: MyModule
  build-depends: base >=4.10, Cabal >=1.20
  hs-source-dirs: src testsuite
  default-language: Haskell2010

src/MyModule.hs

module MyModule where

myFunction :: Int
myFunction = 1

testsuite/Exitcode.hs

import MyModule (myFunction)
import System.Exit (exitSuccess, exitFailure)

main :: IO ()
main =
  if myFunction == 1
  then exitSuccess
  else exitFailure

testsuite/Detailed.hs

module Detailed where

import MyModule (myFunction)
import Distribution.TestSuite

tests :: IO [Test]
tests = return
  [ Test $ TestInstance
    { run = return $ Finished $ if myFunction == 1 then Pass else Fail "not equal 1"
    , name = "my test"
    , Distribution.TestSuite.tags = []
    , options = []
    , setOption = \opt val -> Left "options not supported"
    }
  ]

stack.yaml

resolver: lts-11.22


Output

cabal

Everything works normally:

$ cabal test exitcode
Preprocessing test suite 'exitcode' for stack-test-detailed-0.1.0.0..
Building test suite 'exitcode' for stack-test-detailed-0.1.0.0..
Running 1 test suites...
Test suite exitcode: RUNNING...
Test suite exitcode: PASS
Test suite logged to: dist/test/stack-test-detailed-0.1.0.0-exitcode.log
1 of 1 test suites (1 of 1 test cases) passed.

$ cabal test detailed
Preprocessing test suite 'detailed' for stack-test-detailed-0.1.0.0..
Building test suite 'detailed' for stack-test-detailed-0.1.0.0..
[1 of 1] Compiling Main             ( dist/build/detailedStub/detailedStub-tmp/detailedStub.hs, dist/build/detailedStub/detailedStub-tmp/Main.o )
Linking dist/build/detailedStub/detailedStub ...
Running 1 test suites...
Test suite detailed: RUNNING...
Test suite detailed: PASS
Test suite logged to: dist/test/stack-test-detailed-0.1.0.0-detailed.log
1 of 1 test suites (1 of 1 test cases) passed.

stack

Exitcode test works:

$ stack test :exitcode
stack-test-detailed-0.1.0.0: build (test)
Preprocessing test suite 'exitcode' for stack-test-detailed-0.1.0.0..
Building test suite 'exitcode' for stack-test-detailed-0.1.0.0..
stack-test-detailed-0.1.0.0: test (suite: exitcode)


stack-test-detailed-0.1.0.0: Test suite exitcode passed
Completed 2 action(s).

Detailed test fails to compile:

$ stack test :detailed
stack-test-detailed-0.1.0.0: build (test)
Preprocessing test suite 'detailed' for stack-test-detailed-0.1.0.0..
Building test suite 'detailed' for stack-test-detailed-0.1.0.0..

<no location info>: error:
    module ‘MyModule’ cannot be found locally

Progress 1/2

--  While building custom Setup.hs for package stack-test-detailed-0.1.0.0 using:
      /Users/john/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-2.0.1.0 build test:detailed --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1


From looking around I gather that detailed-0.9 is somehow uncool and people just seem to give up on it immediately. But it is properly documented and indeed works with cabal, so I don't see why stack should fail with it.

Aucun commentaire:

Enregistrer un commentaire