diff --git a/raw/embedded/haskell-template-task-embedded.cabal b/raw/embedded/haskell-template-task-embedded.cabal index 4590edd..05bb2dc 100644 --- a/raw/embedded/haskell-template-task-embedded.cabal +++ b/raw/embedded/haskell-template-task-embedded.cabal @@ -10,6 +10,11 @@ name: haskell-template-task-embedded version: 0.0.0 build-type: Simple +flag iotasks + description: enables test helpers for IOTasks + manual: True + default: True + library other-modules: TestHarness @@ -19,7 +24,6 @@ library ghc-options: -Wall build-depends: HUnit - , IOTasks , QuickCheck , base , deepseq @@ -27,3 +31,7 @@ library , random , syb default-language: Haskell2010 + if flag(iotasks) + cpp-options: -DIOTASKS + build-depends: + IOTasks diff --git a/raw/embedded/package.yaml b/raw/embedded/package.yaml index 95009cf..2239c13 100644 --- a/raw/embedded/package.yaml +++ b/raw/embedded/package.yaml @@ -1,17 +1,28 @@ name: haskell-template-task-embedded ghc-options: -Wall +flags: + iotasks: + description: enables test helpers for IOTasks + manual: True + default: True dependencies: - base - deepseq - haskell-src-exts - HUnit - - IOTasks - QuickCheck - random - syb library: - source-dirs: src + source-dirs: + - src other-modules: - TestHarness - TestHelper +when: + - condition: flag(iotasks) + dependencies: + - IOTasks + cpp-options: -DIOTASKS + diff --git a/raw/embedded/src/TestHelper.hs b/raw/embedded/src/TestHelper.hs index 2505e42..ab1108d 100644 --- a/raw/embedded/src/TestHelper.hs +++ b/raw/embedded/src/TestHelper.hs @@ -1,13 +1,25 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE ScopedTypeVariables #-} module TestHelper ( - isDefined, isDeeplyDefined, mustFail, - qcWithTimeout, qcWithTimeoutAndArgs, qcWithTimeoutAndRuns - , qc, qc', qcWithArgs --DEPRECATED - , tcWithTimeout, tcWithTimeoutAndArgs, tcCustomizedWithTimeoutAndArgs, tcWithInputsOnFailure + isDefined, + isDeeplyDefined, + mustFail, + qcWithTimeout, + qcWithTimeoutAndArgs, + qcWithTimeoutAndRuns, + qc, + qc', + qcWithArgs, --DEPRECATED +#ifdef IOTASKS + tcWithTimeout, + tcWithTimeoutAndArgs, + tcCustomizedWithTimeoutAndArgs, + tcWithInputsOnFailure, +#endif ) where import Prelude ( - Bool (..), Either (Left, Right), Int, IO, String, Maybe (Nothing, Just), - const, error, return, seq, ($), (++), show, (.), id) + Bool (..), Either (Left, Right), Int, IO, String, + const, error, return, seq, ($), (++)) import Control.Exception (ErrorCall, SomeException, catch, evaluate, try) @@ -19,6 +31,7 @@ import Test.QuickCheck import Test.QuickCheck.Monadic (monadicIO, run) import Control.DeepSeq (NFData, deepseq) +#ifdef IOTASKS import Test.IOTasks ( IOrep, Specification, @@ -33,7 +46,9 @@ import qualified Test.IOTasks as IOTasks ( Outcome (..), stdArgs, ) +import Prelude (Maybe(..), (.), id, show) import qualified System.Timeout as System (timeout) +#endif qcWithArgs :: Testable prop => Int -> Args -> prop -> Assertion qcWithArgs = qcWithTimeoutAndArgs @@ -82,6 +97,7 @@ isDefined x = catch (seq x $ return True) ((const $ return False) :: ErrorCall -> IO Bool) +#ifdef IOTASKS -- helper for new IOTasks implementation tcWithTimeout :: Int -> IOrep () -> Specification -> Assertion tcWithTimeout to = tcWithTimeoutAndArgs to IOTasks.stdArgs @@ -109,3 +125,4 @@ tcTimeoutAndArgsHandleFailure to args prog spec withFailure = do Just (IOTasks.Outcome IOTasks.GaveUp _) -> assertFailure "Gave up on testing. This is usually not caused by a fault within your solution. Please contact your lecturers" Just o@(IOTasks.Outcome IOTasks.Failure{} _) -> assertFailure $ withFailure o Nothing -> assertFailure "Failure: Timeout" +#endif diff --git a/raw/haskell-template-task-raw.cabal b/raw/haskell-template-task-raw.cabal index 52f45e6..953302b 100644 --- a/raw/haskell-template-task-raw.cabal +++ b/raw/haskell-template-task-raw.cabal @@ -8,6 +8,11 @@ name: haskell-template-task-raw version: 0.0.0.1 build-type: Simple +flag iotasks + description: enables test helpers for IOTasks + manual: True + default: True + library exposed-modules: Haskell.Template.FileContents @@ -18,7 +23,10 @@ library ghc-options: -Wall build-depends: base >=4.7 && <5 + , cpphs , filepath , template-haskell , th-utilities default-language: Haskell2010 + if flag(iotasks) + cpp-options: -DIOTASKS diff --git a/raw/package.yaml b/raw/package.yaml index b0ef3a9..a3a2c82 100644 --- a/raw/package.yaml +++ b/raw/package.yaml @@ -2,11 +2,20 @@ name: haskell-template-task-raw version: 0.0.0.1 ghc-options: - -Wall +flags: + iotasks: + description: enables test helpers for IOTasks + manual: True + default: True dependencies: - base >= 4.7 && < 5 - filepath + - cpphs - template-haskell - th-utilities +when: + - condition: flag(iotasks) + cpp-options: -DIOTASKS library: source-dirs: src diff --git a/raw/src/Haskell/Template/FileContents.hs b/raw/src/Haskell/Template/FileContents.hs index e204fd0..dd7e1dc 100644 --- a/raw/src/Haskell/Template/FileContents.hs +++ b/raw/src/Haskell/Template/FileContents.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-} {-# OPTIONS -fforce-recomp #-} module Haskell.Template.FileContents ( @@ -5,6 +6,13 @@ module Haskell.Template.FileContents ( testHelperContents, ) where +import Language.Preprocessor.Cpphs ( + BoolOptions(..), + CpphsOptions(..), + defaultBoolOptions, + defaultCpphsOptions, + runCpphs + ) import Language.Haskell.TH (runIO, stringE) import System.FilePath (()) import TH.RelativePaths (pathRelativeToCabalPackage) @@ -13,7 +21,17 @@ testHelperContents :: String testHelperContents = $(do file <- pathRelativeToCabalPackage $ "embedded" "src" "TestHelper.hs" - contents <- runIO $ readFile file + contents <- runIO $ readFile file >>= runCpphs defaultCpphsOptions { + defines = [ +#ifdef IOTASKS + ("IOTASKS", "") +#else + +#endif + ], + boolopts = defaultBoolOptions {locations = False} + } + "" stringE contents) testHarnessContents :: String