简体   繁体   中英

Problems while integrating HUnit with Cabal

The command cabal install works fine, as does cabal configure --enable-tests . However, when I run cabal build -j it does not compile:

Building MoodleLatex-0.1.0.0...
Preprocessing executable 'moddlelat' for MoodleLatex-0.1.0.0...
Preprocessing test suite 'Moodle-Tests' for MoodleLatex-0.1.0.0...
In-place registering Moodle-Tests-0.1.0.0...
[1 of 1] Compiling Main             ( dist/build/Moodle-TestsStub/Moodle-TestsStub-tmp/Moodle-TestsStub.hs, dist/build/Moodle-TestsStub/Moodle-TestsStub-tmp/Main.o )
Linking dist/build/Moodle-TestsStub/Moodle-TestsStub ...
/home/miki/exp/moodle/dist/build/libMoodle-Tests.a(Moodle.o):(.text+0x26): undefined reference to `MoodlzuHFs0eta1wVtKnH9dbfcoDT_MoodleziTypes_zdfShowMoodleVal_closure'
/home/miki/exp/moodle/dist/build/libMoodle-Tests.a(Moodle.o):(.text+0xd9): undefined reference to `MoodlzuHFs0eta1wVtKnH9dbfcoDT_MoodleziTypes_zdfShowMoodleVal_closure'
/home/miki/exp/moodle/dist/build/libMoodle-Tests.a(Moodle.o):(.text+0xeba): undefined reference to `MoodlzuHFs0eta1wVtKnH9dbfcoDT_MoodleziParser_parseExpr2_closure'
[..snip..]
/home/miki/exp/moodle/dist/build/libMoodle-Tests.a(Moodle.o):(.data+0x570): undefined reference to `MoodlzuHFs0eta1wVtKnH9dbfcoDT_MoodleziParser_parseExpr2_closure'
/home/miki/exp/moodle/dist/build/libMoodle-Tests.a(Moodle.o):(.data+0x578): undefined reference to `MoodlzuHFs0eta1wVtKnH9dbfcoDT_MoodleziParser_parseExpr9_closure'
/home/miki/exp/moodle/dist/build/libMoodle-Tests.a(Moodle.o):(.data+0x580): undefined reference to `MoodlzuHFs0eta1wVtKnH9dbfcoDT_MoodleziParser_zdwa1_closure'
collect2: error: ld returned 1 exit status

This is the structure of the source directory:

src
├── Main.hs
├── Moodle
│   ├── Parser.hs
│   ├── Translator.hs
│   └── Types.hs
└── Test
    └── Moodle.hs

And this is my Cabal file (relevant lines only):

name:                MoodleLatex
version:             0.1.0.0
category:            Text
build-type:          Simple
extra-source-files:  README.md
cabal-version:       >=1.10

executable moddlelat
  main-is:             Main.hs
  -- other-modules:
  other-extensions:    OverloadedStrings
  build-depends: base       >=4.8  && <4.9
               , scientific >=0.3  && <0.4
               , text       >=1.2  && <1.3
               , attoparsec >=0.13 && <0.14
  hs-source-dirs:      src
  default-language:    Haskell2010

Test-Suite Moodle-Tests
  type:          detailed-0.9
  test-module:   Test.Moodle
  build-depends: base       >=4.8  && <4.9
               , scientific >=0.3  && <0.4
               , text       >=1.2  && <1.3
               , attoparsec >=0.13 && <0.14
               , Cabal
               , HUnit
               , cabal-test-hunit
  hs-source-dirs:      src
  default-language:    Haskell2010

I followed the steps in the cabal-test-hunit README . I also wonder, is it even necessary to declare the dependencies two times?! It's not very DRY.

EDIT : It seems that it cannot find my modules. However, if I add MoodleLatex to build-depends I run into another error:

Building MoodleLatex-0.1.0.0...
Preprocessing executable 'moddlelat' for MoodleLatex-0.1.0.0...
Preprocessing test suite 'Moodle-Tests' for MoodleLatex-0.1.0.0...
<command line>: cannot satisfy -package-id MoodleLatex-0.1.0.0-inplace

You should add the additional modules to the other-modules field. If you build with Stack, it should give you a warning about which modules need to be specified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM