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
6 changes: 2 additions & 4 deletions raw/embedded/src/TestHarness.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ import Data.List (elem, intercalate, notElem, null)
import Language.Haskell.Exts
(Decl (..), Exp (..), Match (..) , Module (..), Name (..), ParseResult (..), Pat (..),
Rhs (..), SrcSpanInfo, classifyExtension, parseFileContentsWithExts)
import System.IO.Unsafe (unsafePerformIO) -- We need to run the tests inside the interpreter
import System.Random (randomRIO)
import Test.HUnit.Base
(Node (Label), Test, Counts (Counts), errors, failures, path, performTest)
import Test.HUnit.Text (showPath)

{-| Function called by the interpreter, getting the tests to run as the argument. -}
run :: HU.Testable t => [t] -> (HU.Counts, ShowS)
run :: HU.Testable t => [t] -> IO (HU.Counts, ShowS)
run testables =
unsafePerformIO $
catches
catches
(foldM performTestUnlessError (Counts 0 0 0 0, id) testables)
[Handler $ \(e :: ErrorCall) -> pairWith e,
Handler $ \(e :: PatternMatchFail) -> pairWith e,
Expand Down
24 changes: 13 additions & 11 deletions src/Haskell/Template/Task.hs
Original file line number Diff line number Diff line change
Expand Up @@ -534,18 +534,20 @@ Please inform a tutor about this issue providing your solution and this message.
deriving instance Typeable Counts

handleCounts
:: Monad m
:: MonadIO m
=> (Doc -> m ())
-> (Doc -> m ())
-> (Counts, String -> String)
-> IO (Counts, String -> String)
-> m ()
handleCounts reject inform result = case result of
(Counts {errors=a,failures=0} ,f) | a /= 0 -> do
inform "Some error occurred before fully testing the solution:"
reject (string (f ""))
-- e.g. quickcheck timeout errors
(Counts {errors=0, failures=0},_) -> return ()
(_ ,f) -> reject (string (f ""))
handleCounts reject inform runResult = do
result <- liftIO runResult
case result of
(Counts {errors=x, failures=0}, f) | x /= 0 -> do
inform "Some error occurred before fully testing the solution:"
reject (string (f ""))
-- e.g. quickcheck timeout errors
(Counts {errors=0, failures=0}, _) -> pure ()
(_ , f) -> reject (string (f ""))

checkResult
:: Monad m
Expand Down Expand Up @@ -595,10 +597,10 @@ interpreter
=> FilePath
-> SolutionConfig
-> [String]
-> m (Counts, ShowS)
-> m (IO (Counts, ShowS))
interpreter dirname config modules = do
prepareInterpreter dirname config modules
interpret "TestHarness.run Test.test" (as :: (Counts, ShowS))
interpret "TestHarness.run Test.test" (as :: IO (Counts, ShowS))

compiler :: MonadInterpreter m => FilePath -> SolutionConfig -> [String] -> m Bool
compiler dirname config modules = do
Expand Down