GlinesMome
GlinesMome

Reputation: 1629

Create custom flags in Haskell

I have a test suite which runs the same test cases with two backends: the in-memory one and the real one, I am trying to create a function which only run the real one when a flag is present.

I have seen it from time to time in Prelude but I cannot make it work.

I would more or less be as following:

onFullSuite :: Spec -> Spec
#if defined(RUN_FULL_SUITE)
onFullSuite = id
#else
onFullSuite = xdescribe "Only on full test suite run"
#endif

Do you have any hints on the missing parts?

Upvotes: 1

Views: 468

Answers (1)

GlinesMome
GlinesMome

Reputation: 1629

It is a two steps process:

  • create a cabal flag
  • conditionally define it as ghc-option
flags:
  run-full-suite:
    manual: true
    default: false


library:
  source-dirs: src
  when:
  - condition: (flag(run-full-suite))
    then:
      cpp-options: -DRUN_FULL_SUITE
    else: {}

Upvotes: 2

Related Questions