haskellcompilationcompiler-flagshpack

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?


Solution

  • It is a two steps process:

    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: {}