Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
665 views
in Technique[技术] by (71.8m points)

testing - Organizing Haskell Tests

So I'm trying to follow the suggested structure of a Haskell project, and I'm having a couple problems organizing my tests.

For simplicity, let's start with:

src/Clue/Cards.hs # defines Clue.Cards module
testsuite/tests/Clue/Cards.hs # tests Clue.Cards module

For one, I'm not sure what to name the module in testsuite/tests/Clue/Cards.hs that contains the test code, and for another, I'm no sure how to compile my test code so that I can link to my source:

% ghc -c testsuite/tests/Clue/Cards.hs -L src
testsuite/tests/Clue/Cards.hs:5:0:
    Failed to load interface for `Clue.Cards':
      Use -v to see a list of the files searched for.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I use myself the approach taken by Snap Framework for their test-suites, which basically boils down to:

  1. Use a test-framework such as haskell-test-framework or HTF
  2. Name the modules containing tests by appending .Tests to the module-name containing the IUT, e.g.:

    module Clue.Cards where ... -- module containing IUT
    
    module Clue.Cards.Tests where ... -- module containing tests for IUT
    
  3. By using separate namespaces, you can put your tests in a separate source-folder tests/, you can then use a separate Cabal build-target (see also cabal test-build-target support in recent Cabal versions) for the test-suite which includes the additional source folder in its hs-source-dirs setting, e.g.:

    Executable clue
      hs-source-dirs: src
      ...
    
    Executable clue-testsuite
      hs-source-dirs: src tests
      ...
    

    This works, since there's no namespace collision between the modules in your IUT and the test-suite anymore.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...