Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion raw/embedded/haskell-template-task-embedded.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,11 +24,14 @@ library
ghc-options: -Wall
build-depends:
HUnit
, IOTasks
, QuickCheck
, base
, deepseq
, haskell-src-exts
, random
, syb
default-language: Haskell2010
if flag(iotasks)
cpp-options: -DIOTASKS
build-depends:
IOTasks
15 changes: 13 additions & 2 deletions raw/embedded/package.yaml
Original file line number Diff line number Diff line change
@@ -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

29 changes: 23 additions & 6 deletions raw/embedded/src/TestHelper.hs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions raw/haskell-template-task-raw.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
9 changes: 9 additions & 0 deletions raw/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 19 additions & 1 deletion raw/src/Haskell/Template/FileContents.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS -fforce-recomp #-}
module Haskell.Template.FileContents (
testHarnessContents,
testHelperContents,
) where

import Language.Preprocessor.Cpphs (
BoolOptions(..),
CpphsOptions(..),
defaultBoolOptions,
defaultCpphsOptions,
runCpphs
)
import Language.Haskell.TH (runIO, stringE)
import System.FilePath ((</>))
import TH.RelativePaths (pathRelativeToCabalPackage)
Expand All @@ -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
Expand Down