Search code examples
haskelltestingcabal

cabal test fails to link its own objects


I am trying to add a detailed-0.9 test suite to a cabal package that provides an executable. Thus I added:

test-suite igor2-test
  type: detailed-0.9
  hs-source-dirs: src
  test-module: Igor2.Tests
  build-depends: Cabal

There is no library in this package, but the executable uses the same source tree. During cabal test it fails linking:

Preprocessing test suite 'igor2-test' for igor2-0.7.1.3...
[1 of 5] Compiling Syntax.Name      ( src/Syntax/Name.hs, dist/build/Syntax/Name.o )
... (more compiling)
[1 of 5] Compiling Syntax.Name      ( src/Syntax/Name.hs, dist/build/Syntax/Name.p_o )
... (more compiling)
In-place registering igor2-test-0.7.1.3...
[1 of 1] Compiling Main             ( dist/build/igor2-testStub/igor2-testStub-tmp/igor2-testStub.hs, dist/build/igor2-testStub/igor2-testStub-tmp/Main.o )
Linking dist/build/igor2-testStub/igor2-testStub ...
/full/path/to/igor2/dist/build/libigor2-test.a(Tests.o): In function `cd3z_info':
(.text+0x2d7): undefined reference to `igor2zmtestzm0zi7zi1zi3_SyntaxziName_arrowName3_closure'
... (more undefined references)
collect2: error: ld returned 1 exit status

Why is this failing? The function arrowName is defined in the module Syntax.Name and this module is compiled. It is not used in the test module though.

I also tried turning the package into a library and having the test-suite build-depends on the library. The linker error proceeds.

This is the Haskell Platform from OpenSuSE 13.1, GHC 7.8.3 which locks Cabal to 1.18.1.3.


Solution

  • Today I stumbled on the same issue. I found the following workaround:

    Add

    other-modules: Syntax.Name

    to your test-suite declaration.