From cf5e473eeee287b4ac488ba0a39ba1ac62f3c645 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sun, 23 Aug 2015 17:47:40 +0200 Subject: [PATCH] create a challenge, cntd. --- src/GEval/Core.hs | 4 +++- src/GEval/CreateChallenge.hs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/GEval/Core.hs b/src/GEval/Core.hs index 13d8218..bd0c251 100644 --- a/src/GEval/Core.hs +++ b/src/GEval/Core.hs @@ -5,6 +5,7 @@ module GEval.Core MetricValue, GEvalSpecification(..), GEvalOptions(..), + GEvalException(..), defaultGEvalSpecification, defaultOutDirectory, defaultTestName, @@ -67,6 +68,7 @@ data GEvalException = NoExpectedFile FilePath | NoOutDirectory FilePath | NoExpectedTestDirectory FilePath | NoOutTestDirectory FilePath + | FileAlreadyThere FilePath instance Exception GEvalException @@ -77,7 +79,7 @@ instance Show GEvalException where show (NoOutDirectory filePath) = somethingWrongWithFilesMessage "No directory with the test results" filePath show (NoExpectedTestDirectory filePath) = somethingWrongWithFilesMessage "No test subdirectory with the expected results" filePath show (NoOutTestDirectory filePath) = somethingWrongWithFilesMessage "No test subdirectory with the results obtained" filePath - + show (FileAlreadyThere filePath) = somethingWrongWithFilesMessage "File already there" filePath somethingWrongWithFilesMessage :: String -> FilePath -> String somethingWrongWithFilesMessage msg filePath = Prelude.concat diff --git a/src/GEval/CreateChallenge.hs b/src/GEval/CreateChallenge.hs index ebf0010..6c1e705 100644 --- a/src/GEval/CreateChallenge.hs +++ b/src/GEval/CreateChallenge.hs @@ -5,6 +5,17 @@ module GEval.CreateChallenge where import GEval.Core +import qualified System.Directory as D +import Control.Conditional (whenM) + +import System.IO +import Control.Exception +import Control.Monad.Trans.Resource createChallenge :: FilePath -> GEvalSpecification -> IO () createChallenge expectedDirectory spec = putStrLn "creating challange..." + +createFile :: FilePath -> String -> IO () +createFile filePath contents = do + whenM (D.doesFileExist filePath) $ throwM $ FileAlreadyThere filePath + writeFile filePath contents